HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<body>
<!-- スタイルシートの読み込み -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.2/css/bulma.min.css">
<!-- スタイルシートの読み込み -->
<!-- 「iost.min.js」の読み込み -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/iost@0.1.22/dist/iost.min.js"></script>
<!-- 「iost.min.js」の読み込み -->
<section class="section">
<div class="container">
<div id="log"></div>
<div id="suc"></div>
<div class="notification is-info">
Chrome拡張機能ウォレット「iWallet」が<strong>インストール済みで</strong>ウォレットの<strong>ロックが解除</strong>されていれば、ウォレットにインポートしているアカウント情報が表示されます。
</div>
<div class="card">
<div class="card-content">
<span class="tag is-black" id="login">利用できるアカウントはありません</span>
<div class="field">
<label class="label">送金先アカウントID</label>
<div class="control">
<input class="input" type="text" id="account_to" placeholder="送付先IDを入力">
</div>
</div>
<div class="field">
<label class="label">送金量</label>
<div class="control">
<input class="input" type="text" id="amount" placeholder="送金量">
</div>
</div>
<div class="field">
<label class="label">メモの内容</label>
<div class="control">
<input class="input" type="text" id="memo" placeholder="メモの値を入力">
</div>
</div>
<button class="button is-primary" onclick="transfer()">送金の実行</button>
<p class="help is-danger">※サンプルのため、バリデーションチェックは入れておりません。送金量に数字半角以外を入れるとiWalletが起動しません。</p>
</div>
<!-- フッター -->
<footer class="card-footer">
<p class="card-footer-item">
<span>
<a href="https://developers.iost.io/docs/ja/1-getting-started/Overview.html" target="_blank"
rel="noopener noreferrer">IOST開発ドキュメント</a>
</span>
</p>
<p class="card-footer-item">
<span>
<a href="https://github.com/iost-official" target="_blank"
rel="noopener noreferrer">IOSTのGitHub</a>
</span>
</p>
</footer>
<!-- フッター -->
</div>
</div>
</section>
</body>
function log(msg, flg) {
document.getElementById('suc').innerHTML = '';
var p = document.createElement('p');
p.innerHTML = msg;
if ('suc' == flg) {
document.getElementById('suc').appendChild(p);
document.getElementById('suc').className = "notification is-success";
return;
}
document.getElementById('log').innerHTML = '';
document.getElementById('log').appendChild(p);
document.getElementById('log').className = "notification is-danger";
}
var transfer;
var flg;
document.addEventListener(
// 500ミリ秒=0.5秒ごとにIOSTアカウント情報を取得するための時間設定
"DOMContentLoaded", async function (event) {
await new Promise(done => setTimeout(() => done(), 500));
// ここでChrome拡張機能のウォレット(IOSTアカウント)情報を取得
IWalletJS.enable().then(
function (account_from) {
// 【取得できない(空)】なら後の処理はしない
if (!account_from) return;
// 【取得できた】なら画面に表示
document.getElementById('login').innerHTML = "現在使用されているIOSTアカウントは「" + account_from + "」です";
// IOST送金のための処理を始めるための準備
const iost = IWalletJS.newIOST(IOST);
// ここから「送金の実行」が押された後の処理が始まります。
transfer = function () {
// テキストフィールドの値取得
const account_to = document.getElementById("account_to").value;
const amount = document.getElementById("amount").value;
const memo = document.getElementById("memo").value;
// トランザクション(この場合は送金)内容の設定
const tx = iost.callABI("token.iost", "transfer", ["iost", account_from, account_to, amount, memo]);
// 送金内容の反映(Chrome拡張機能ウォレットが起動)
tx.addApprove("iost", amount);
console.log(tx.getApproveList());
// 送金処理実行後の分岐
iost.signAndSend(tx)
// 【送金が成功した場合】トランザクションIDが取得できます。
.on('pending', function (txid) {
flg = "pen";
log("トランザクションID: " + txid, flg);
})
// 【送金が成功した場合】トランザクションの内容(レシート)が取得できます。
.on('success', function (result) {
flg = "suc";
log("送金結果: " + JSON.stringify(result), flg);
})
// 【送金が失敗した場合】エラー文言を取得または表示できます。
.on('failed', function (failed) {
flg = "fai";
log("送金失敗:ユーザーが署名要求を拒否しました→原文「 " + JSON.stringify(failed) + "」", flg);
})
}
}
)
}
)
Also see: Tab Triggers