!function() {
-ZeroClipboard.config({
- swfPath: 'assets/ZeroClipboard.swf'
-});
-
-if (!ZeroClipboard.isFlashUnusable()) {
- var $buttonTemplate = $('<button class="docs-code-copy">Copy</button>');
-
- // Look for code samples and set up a copy button on each
- $('[data-docs-code]').each(function() {
- var $button = $buttonTemplate.clone();
- var text = $(this).find('code').text()
- .replace('<', '<')
- .replace('>', '>');
-
- $(this).prepend($button);
-
- var clipboard = new ZeroClipboard($button);
- clipboard.on('copy', function(event) {
- clipboard.setData('text/plain', text);
- });
-
- // Change the text of the copy button when it's clicked on
- $button.click(function() {
- $(this).text('Copied!');
- window.setTimeout(function() {
- $button.text('Copy');
- }, 3000);
- });
+// Look for code samples and set up a copy button on each
+$('[data-docs-code]').each(function(index, value) {
+ var copyBtnId = 'copy-btn-' + index.toString();
+ var $button = $('<button class="docs-code-copy" id="' + copyBtnId + '">Copy</button>');
+
+ var text = $(this).find('code').text()
+ .replace('<', '<')
+ .replace('>', '>');
+
+ $(this).prepend($button);
+
+ var clipboard = new Clipboard('#' + copyBtnId, {
+ text: function() {
+ return text;
+ }
});
-}
+
+ // Change the text of the copy button when it's clicked on
+ clipboard.on('success', function(event) {
+ $button.text('Copied!');
+ window.setTimeout(function() {
+ $button.text('Copy');
+ }, 3000);
+ });
+
+ // Log errors on copy failure
+ clipboard.on('error', function(event) {
+ console.error('Action:', event.action);
+ console.error('Trigger:', event.trigger);
+ });
+});
}()
\ No newline at end of file
"devDependencies": {
"bootcamp": "^1.1.7",
"browser-sync": "^2.8.2",
+ "clipboard": "^1.5.5",
"foundation-docs": "zurb/foundation-docs",
"gitty": "^3.3.0",
"gulp": "^3.8.10",
"rimraf": "^2.3.2",
"run-sequence": "^1.1.4",
"supercollider": "^1.1.0",
- "typeahead.js": "^0.11.1",
- "zeroclipboard": "^2.2.0"
+ "typeahead.js": "^0.11.1"
},
"repository": {
"type": "git",