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:22 UTC

[1/2] docs commit: Copy on plugins page now falls back to browser APIs

Repository: cordova-docs
Updated Branches:
  refs/heads/cordova-website f9f3f19df -> 63383ae51


Copy on plugins page now falls back to browser APIs


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

Branch: refs/heads/cordova-website
Commit: 95ee0e7a0271d516f0c4be38789db89095427072
Parents: f9f3f19
Author: riknoll <ri...@microsoft.com>
Authored: Fri Sep 18 17:36:47 2015 -0700
Committer: Dmitry Blotsky <dm...@gmail.com>
Committed: Mon Sep 21 15:31:15 2015 -0700

----------------------------------------------------------------------
 www/static/css-src/_plugins.scss  |  6 ++++++
 www/static/plugins/app.js         | 14 ++++++++++++--
 www/static/plugins/plugin.jsx     | 29 ++++++++++++++++++++++++-----
 www/static/plugins/pluginlist.jsx |  2 +-
 4 files changed, 43 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/95ee0e7a/www/static/css-src/_plugins.scss
----------------------------------------------------------------------
diff --git a/www/static/css-src/_plugins.scss b/www/static/css-src/_plugins.scss
index 20602ab..4344b28 100644
--- a/www/static/css-src/_plugins.scss
+++ b/www/static/css-src/_plugins.scss
@@ -170,6 +170,12 @@ hr.results-divider-line {
 	border-color:$gray-20;
 }
 
+.cordova-add-command {
+		width: 1px;
+		height: 1px;
+		overflow: hidden;
+}
+
 .results-supported-platforms {
                 list-style: none;
                 padding:0;

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/95ee0e7a/www/static/plugins/app.js
----------------------------------------------------------------------
diff --git a/www/static/plugins/app.js b/www/static/plugins/app.js
index c1a1557..c7fa7b2 100755
--- a/www/static/plugins/app.js
+++ b/www/static/plugins/app.js
@@ -4,7 +4,8 @@ var React           = window.React = require('react'), // assign it to window fo
     PlatformButton  = require('./platformbutton.jsx')
     App             = {},
     SortDropdown = require('./sortdropdown.jsx'),
-    SortCriteria = require('./SortCriteria');
+    SortCriteria = require('./SortCriteria'),
+    ZeroClipboard = require("../js/lib/ZeroClipboard.js");
 
 var INPUT_DELAY = 500; // in milliseconds
 
@@ -41,6 +42,7 @@ var App = React.createClass({
             searchResults: [],
             staticFilters: staticFilters,
             sortCriteria: sortBy,
+            flashEnabled: true,
             downloadsReceived: false
         }
 
@@ -293,6 +295,14 @@ var App = React.createClass({
             ga('send', 'pageview', '/index.html' + query);
         },
     },
+    componentWillMount: function() {
+        var that = this;
+        ZeroClipboard.config({swfPath: "{{ site.baseurl }}/static/js/lib/ZeroClipboard.swf"});
+        ZeroClipboard.on({
+            "ready": function(event) {that.setState({ flashEnabled: true });},
+            "error": function(event) {that.setState({ flashEnabled: false });}
+        });
+    },
     componentDidMount: function() {
         var plugins = [],
             officialPlugins = require('./official-plugins.json').plugins,
@@ -421,7 +431,7 @@ var App = React.createClass({
         }
         var listContent = null;
         if(window.location.protocol !== "https:") {
-            listContent = <PluginList plugins={this.state.searchResults} />;
+            listContent = <PluginList plugins={this.state.searchResults} flashEnabled={this.state.flashEnabled}/>;
         } else {
             var httpUrl = window.location.href.replace("https://", "http://");
             listContent = <div className="alert alert-warning" role="alert">Search results are not currently supported over HTTPS. Please visit this page <a href={httpUrl}>using HTTP</a></div>;

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/95ee0e7a/www/static/plugins/plugin.jsx
----------------------------------------------------------------------
diff --git a/www/static/plugins/plugin.jsx b/www/static/plugins/plugin.jsx
index 4a41550..2552c87 100755
--- a/www/static/plugins/plugin.jsx
+++ b/www/static/plugins/plugin.jsx
@@ -8,7 +8,7 @@ var Plugin = React.createClass({
         return this.props.plugin !== nextProps.plugin;
     },
     setClipboardText: function() {
-        if(this.props.plugin) {
+        if(this.props.plugin && this.props.flashEnabled) {
             var client = new ZeroClipboard(document.getElementById("copy-" + this.props.plugin.name));
             var copyText = "cordova plugin add " + this.props.plugin.name;
             client.off();
@@ -17,6 +17,24 @@ var Plugin = React.createClass({
             });
         }
     },
+    copyTextWithoutFlash: function() {
+        if(!this.props.flashEnabled) {
+            var range = document.createRange();
+            range.selectNode(this.getDOMNode().getElementsByClassName("cordova-add-command")[0]);
+
+            var select = window.getSelection();
+            select.removeAllRanges();
+            select.addRange(range);
+
+            try {
+                document.execCommand("copy");
+            } catch(e) {
+                // Silently fail for now
+            }
+
+            select.removeAllRanges();
+        }
+    },
     render: function() {
         if(!this.props.plugin) {
             // Empty card with loading wheel
@@ -52,7 +70,8 @@ var Plugin = React.createClass({
                         src="{{ site.baseurl}}/static/img/copy-clipboard-icon.svg"
                         title="Copy cordova plugin add command to clipboard"
                         data-toggle="tooltip"
-                        data-placement="auto" />
+                        data-placement="auto"
+                        onClick={this.copyTextWithoutFlash} />
             );
         }
 
@@ -87,12 +106,12 @@ var Plugin = React.createClass({
                         <p className="last-updated">Last updated <strong>{this.props.plugin.modified} days ago</strong></p>
                     </div>
                 </div>
+                <div className="cordova-add-command">
+                {"cordova plugin add " + this.props.plugin.name}
+                </div>
             </div>
         )
     },
-    componentWillMount: function() {
-        ZeroClipboard.config({swfPath: "{{ site.baseurl }}/static/js/lib/ZeroClipboard.swf"});
-    },
     componentDidMount: function() {
         this.setClipboardText();
         if(this.props.plugin) {

http://git-wip-us.apache.org/repos/asf/cordova-docs/blob/95ee0e7a/www/static/plugins/pluginlist.jsx
----------------------------------------------------------------------
diff --git a/www/static/plugins/pluginlist.jsx b/www/static/plugins/pluginlist.jsx
index a1e6afd..bf0fdff 100755
--- a/www/static/plugins/pluginlist.jsx
+++ b/www/static/plugins/pluginlist.jsx
@@ -53,7 +53,7 @@ var PluginList = React.createClass({
             } else {
                 for (var i = 0; i < InitialPageLength + this.state.searchPage * PageExtensionLength; i++) {
                     if (plugins[i]) {
-                        visiblePlugins.push(<Plugin plugin={plugins[i]} key={i}/>);
+                        visiblePlugins.push(<Plugin plugin={plugins[i]} key={i} flashEnabled={this.props.flashEnabled}/>);
                     } else {
                         break;
                     }


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


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

Posted by db...@apache.org.
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