From: colin-marshall Date: Mon, 21 Dec 2015 17:48:27 +0000 (-0700) Subject: Added clipboard.js, removed ZeroClipboard X-Git-Tag: v6.1.0~15^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb09c96a11fc84c2ed59b11df2ae772d67a3de2c;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Added clipboard.js, removed ZeroClipboard --- diff --git a/docs/assets/js/docs.copyButton.js b/docs/assets/js/docs.copyButton.js index 67e8489c7..697020d9c 100644 --- a/docs/assets/js/docs.copyButton.js +++ b/docs/assets/js/docs.copyButton.js @@ -2,35 +2,36 @@ !function() { -ZeroClipboard.config({ - swfPath: 'assets/ZeroClipboard.swf' -}); - -if (!ZeroClipboard.isFlashUnusable()) { - var $buttonTemplate = $(''); - - // 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 = $(''); + + 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 diff --git a/gulp/copy.js b/gulp/copy.js index effd3613b..2cbfb8cfe 100644 --- a/gulp/copy.js +++ b/gulp/copy.js @@ -2,7 +2,6 @@ var gulp = require('gulp'); var FILES = [ 'docs/assets/**/*', - 'node_modules/zeroclipboard/dist/ZeroClipboard.swf', '!docs/assets/{js,scss}', '!docs/assets/{js,scss}/**/*' ]; diff --git a/gulp/javascript.js b/gulp/javascript.js index fa2c59e36..282b712fa 100644 --- a/gulp/javascript.js +++ b/gulp/javascript.js @@ -14,7 +14,7 @@ var DEPS = [ ]; var DOCS = [ - 'node_modules/zeroclipboard/dist/ZeroClipboard.js', + 'node_modules/clipboard/dist/clipboard.js', 'node_modules/typeahead.js/dist/typeahead.bundle.js', 'docs/assets/js/docs.*.js', 'docs/assets/js/docs.js' diff --git a/package.json b/package.json index 60c6974a7..bc30f9706 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "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", @@ -53,8 +54,7 @@ "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",