You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by db...@apache.org on 2015/09/22 00:32:23 UTC

[2/2] docs commit: Added browser api fallback for copy buttons on main page. This closes #356.

Added browser api fallback for copy buttons on main page. This closes #356.


Project: http://git-wip-us.apache.org/repos/asf/cordova-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-docs/commit/63383ae5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-docs/tree/63383ae5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-docs/diff/63383ae5

Branch: refs/heads/cordova-website
Commit: 63383ae51a08131249f1f3d93c39af9de413cf1e
Parents: 95ee0e7
Author: riknoll <ri...@microsoft.com>
Authored: Fri Sep 18 18:34:37 2015 -0700
Committer: Dmitry Blotsky <dm...@gmail.com>
Committed: Mon Sep 21 15:32:03 2015 -0700

----------------------------------------------------------------------
 www/static/js/index.js | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/63383ae5/www/static/js/index.js
----------------------------------------------------------------------
diff --git a/www/static/js/index.js b/www/static/js/index.js
index a9ab5a4..c23b4e3 100644
--- a/www/static/js/index.js
+++ b/www/static/js/index.js
@@ -108,10 +108,38 @@ $(document).ready(function () {
         document.getElementById("new_blog_count").innerHTML = new_blog_count;
     }
 
-    var copyButtons = document.getElementsByClassName("btn-copy");
-    for(var i = 0; i < copyButtons.length; i++) {
-        new ZeroClipboard(copyButtons[i]);
-    }
+    var client = new ZeroClipboard();
+    client.on("ready", function(e) {
+        var copyButtons = document.getElementsByClassName("btn-copy");
+        for(var i = 0; i < copyButtons.length; i++) {
+            client.clip(copyButtons[i]);
+        }
+    });
+
+    // In the case that flash is disabled, fall back to browser API
+    client.on("error", function(e) {
+        var copyButtons = document.getElementsByClassName("btn-copy");
+        for(var i = 0; i < copyButtons.length; i++) {
+            copyButtons[i].addEventListener("click", function(clickEvent) {
+                var id = clickEvent.target.getAttribute("data-clipboard-target");
+
+                var range = document.createRange();
+                range.selectNode(document.getElementById(id));
+
+                var select = window.getSelection();
+                select.removeAllRanges();
+                select.addRange(range);
+
+                try {
+                    document.execCommand("copy");
+                } catch(e) {
+                    // Silently fail for now
+                }
+
+                select.removeAllRanges();
+            });
+        }
+    });
 
     // Smooth scroll to anchor links
     $("a[href^='#']").on('click', function(e) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org