<html>
<head>
<meta charset="utf-8" />
<title>ZeroClipboard Starter Snippet - JSBin</title>
<link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet" media="all" />
<script src="//code.jquery.com/jquery-2.1.0.js"></script>
<script src="//rawgit.com/JamesMGreene/sandblaster/master/dist/sandblaster.min.js"></script>
<script src="//rawgit.com/zeroclipboard/zeroclipboard/master/dist/ZeroClipboard.min.js"></script>
</head>
<body>
<div id="warning"></div>
<button
class="clipboard fa fa-copy"
data-clipboard-text="Copied Button 1 Text"
title="Copy button 1 text"></button>
<button
class="clipboard fa fa-copy"
data-clipboard-text="Copied Button 2 Text"
title="Copy button 2 text"></button>
<div id="zcState">
<h3>ZeroClipboard state: <button
class="zc-state-updater fa fa-refresh"
title="Refresh state"></button></h3>
<pre></pre>
</div>
<div>
<h3>Logs:</h3>
<ul id="logger"></ul>
</div>
</body>
</html>
//
// Utility code
//
function showActive(el) {
var $el = $(el);
$el.fadeOut(10, function() { $el.fadeIn(90); });
}
var $logger = $("#logger");
function log(msg) {
$logger.prepend("<li>" + msg + "</li>");
}
//
// Forcibly remove the JSBin iframe sandboxing with Sandblaster.js
// https://github.com/JamesMGreene/sandblaster
//
var result = sandblaster.detect();
if (result.framed && result.crossOrigin !== false && result.sandboxed !== false) {
$("#warning").html('<p><strong>IMPORTANT:</strong> This JSBin can only work correctly if visiting the result view in the top frame!</p><p>Paste this URL into your browser\'s address bar: <a href="' + window.location.href + '">' + window.location.href + '</a></p>').after("<hr />");
}
else if (result.sandboxed && sandblaster.unsandbox()) {
sandblaster.reload();
}
//
// Begin ZeroClipboard stuff
//
ZeroClipboard.config({
forceHandCursor: true
});
var client = new ZeroClipboard($("button[data-clipboard-text]"));
client.on("error", function(e) {
log("ERROR! [" + e.name + "] " + e.message);
});
client.on("copy", function(event) {
var clipboard = event.clipboardData;
clipboard.setData( "text/plain", event.target.innerHTML + " <-- added this text!" );
});
client.on("ready", function(e) {
log("Ready!");
client.on("aftercopy", function(e) {
log((e.success["text/plain"] ? "Copied" : "FAILED to copy") + ": " + e.data["text/plain"]);
showActive(e.target);
});
});
$(".zc-state-updater").on("click", function() {
$("#zcState pre").text(JSON.stringify(ZeroClipboard.state(), null, 2));
});
$("#zcState pre").text(JSON.stringify(ZeroClipboard.state(), null, 2));
Output
300px
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. |