]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Added clipboard.js, removed ZeroClipboard 7643/head
authorcolin-marshall <colin.michael.marshall@gmail.com>
Mon, 21 Dec 2015 17:48:27 +0000 (10:48 -0700)
committercolin-marshall <colin.michael.marshall@gmail.com>
Mon, 21 Dec 2015 17:48:27 +0000 (10:48 -0700)
docs/assets/js/docs.copyButton.js
gulp/copy.js
gulp/javascript.js
package.json

index 67e8489c70d0a8708236a40f55edfe8859e65f8a..697020d9c47287245a52bfcc736c69d9dedffc62 100644 (file)
@@ -2,35 +2,36 @@
 
 !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('&lt;', '<')
-      .replace('&gt;', '>');
-
-    $(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('&lt;', '<')
+    .replace('&gt;', '>');
+
+  $(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
index effd3613b82e076db5e72d5562203a0f351ab23d..2cbfb8cfe103c2e011625f4bee9bbc9f1022cd55 100644 (file)
@@ -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}/**/*'
 ];
index fa2c59e36f9c400dc2bb7da034256db5abe7ae45..282b712fa26ba7f3db3db77f639a1305baf6bf6f 100644 (file)
@@ -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'
index 60c6974a767245de72216ed7cedcea9913d12147..bc30f9706b979cc56b82bf59bf26fba9a11ceb81 100644 (file)
@@ -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",