<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<!-- Quill v1.0.0 -->
<script src="https://cdn.quilljs.com/1.0.0/quill.js"></script>
<script src="https://cdn.quilljs.com/1.0.0/quill.min.js"></script>
<link href="https://cdn.quilljs.com/1.0.0/quill.snow.css" rel="stylesheet">
<link href="https://cdn.quilljs.com/1.0.0/quill.bubble.css" rel="stylesheet">
</head>
<body>
<h3>Edit</h3>
<form id="form">
<div id="editor" style="background: #fff">
<p>Hello World</p>
</div>
<input type="submit" value="Save" />
</form>
<hr />
<h3>Result</h3>
<div id="result"></div>
<script>
function load()
{
quill.setContents([
{ insert: 'ABC', attributes: { bold: true } }
]);
}
function result()
{
// 將Delta格式轉成HTML,並輸出到前端
var el = document.createElement( "div" ),
ql = new Quill( el, {} );
ql.setContents( JSON.parse( DATA ).ops );
document.getElementById( "result" ).innerHTML = ql.root.innerHTML;
el = null;
}
document.getElementById( "form" ).onsubmit = function() {
DATA = JSON.stringify( quill.getContents() );
console.log( "Delta: " + JSON.stringify( quill.getContents() ) ); // Delta格式
console.log( "HTML: " + quill.root.innerHTML ); // HTML格式
console.log( "Text: " + quill.getText() ); //文字格式
result(); // 輸出到前端
return false;
};
var quill = new Quill( "#editor", {
theme: "snow", // 模板
modules: {
toolbar: [
// 工具列列表[註1]
['bold', 'italic', 'underline', 'strike'], // 粗體、斜體、底線和刪節線
['blockquote', 'code-block'], // 區塊、程式區塊
[{ 'header': 1 }, { 'header': 2 }], // 標題1、標題2
[{ 'list': 'ordered'}, { 'list': 'bullet' }], // 清單
[{ 'script': 'sub'}, { 'script': 'super' }], // 上標、下標
[{ 'indent': '-1'}, { 'indent': '+1' }], // 縮排
[{ 'direction': 'rtl' }], // 文字方向
[{ 'size': ['small', false, 'large', 'huge'] }], // 文字大小
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],// 標題
[{ 'color': [] }, { 'background': [] }], // 顏色
[{ 'font': [] }], // 字體
[{ 'align': [] }], // 文字方向
[ 'clean' ] // 清除文字格是
]
}
}),
DATA = null;
load(); // 模擬從Database載入資料
</script>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |