app/assets/javascripts/zeroclipboard/ZeroClipboard.js in zeroclipboard-rails-0.0.12 vs app/assets/javascripts/zeroclipboard/ZeroClipboard.js in zeroclipboard-rails-0.0.13
- old
+ new
@@ -2,13 +2,13 @@
* ZeroClipboard
* The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.
* Copyright (c) 2014 Jon Rohan, James M. Greene
* Licensed MIT
* http://zeroclipboard.org/
-* v1.3.1
+* v1.3.5
*/
-(function() {
+(function(window) {
"use strict";
var currentElement;
var flashState = {
bridge: null,
version: "0.0.0",
@@ -442,10 +442,16 @@
}
}
}
return obj;
};
+ var _safeActiveElement = function() {
+ try {
+ return document.activeElement;
+ } catch (err) {}
+ return null;
+ };
var _detectFlashSupport = function() {
var hasFlash = false;
if (typeof flashState.disabled === "boolean") {
hasFlash = flashState.disabled === false;
} else {
@@ -498,26 +504,32 @@
}
};
ZeroClipboard.prototype.setText = function(newText) {
if (newText && newText !== "") {
_clipData["text/plain"] = newText;
- if (flashState.ready === true && flashState.bridge) {
+ if (flashState.ready === true && flashState.bridge && typeof flashState.bridge.setText === "function") {
flashState.bridge.setText(newText);
- } else {}
+ } else {
+ flashState.ready = false;
+ }
}
return this;
};
ZeroClipboard.prototype.setSize = function(width, height) {
- if (flashState.ready === true && flashState.bridge) {
+ if (flashState.ready === true && flashState.bridge && typeof flashState.bridge.setSize === "function") {
flashState.bridge.setSize(width, height);
- } else {}
+ } else {
+ flashState.ready = false;
+ }
return this;
};
var _setHandCursor = function(enabled) {
- if (flashState.ready === true && flashState.bridge) {
+ if (flashState.ready === true && flashState.bridge && typeof flashState.bridge.setHandCursor === "function") {
flashState.bridge.setHandCursor(enabled);
- } else {}
+ } else {
+ flashState.ready = false;
+ }
};
ZeroClipboard.prototype.destroy = function() {
this.unclip();
this.off();
delete _clientMeta[this.id];
@@ -530,11 +542,11 @@
clients.push(client);
}
}
return clients;
};
- ZeroClipboard.version = "1.3.1";
+ ZeroClipboard.version = "1.3.5";
var _globalConfig = {
swfPath: _swfPath,
trustedDomains: window.location.host ? [ window.location.host ] : [],
cacheBust: true,
forceHandCursor: false,
@@ -662,12 +674,14 @@
htmlBridge.style.left = pos.left + "px";
htmlBridge.style.width = pos.width + "px";
htmlBridge.style.height = pos.height + "px";
htmlBridge.style.zIndex = pos.zIndex + 1;
}
- if (flashState.ready === true && flashState.bridge) {
+ if (flashState.ready === true && flashState.bridge && typeof flashState.bridge.setSize === "function") {
flashState.bridge.setSize(pos.width, pos.height);
+ } else {
+ flashState.ready = false;
}
}
return this;
};
ZeroClipboard.prototype.on = function(eventName, func) {
@@ -860,11 +874,11 @@
};
ZeroClipboard.dispatch = function(eventName, args) {
if (typeof eventName === "string" && eventName) {
var cleanEventName = eventName.toLowerCase().replace(/^on/, "");
if (cleanEventName) {
- var clients = currentElement ? _getAllClientsClippedToElement(currentElement) : _getAllClients();
+ var clients = currentElement && _globalConfig.autoActivate === true ? _getAllClientsClippedToElement(currentElement) : _getAllClients();
for (var i = 0, len = clients.length; i < len; i++) {
_receiveEvent.call(clients[i], cleanEventName, args);
}
}
}
@@ -971,27 +985,32 @@
case "mouseup":
_removeClass(element, _globalConfig.activeClass);
break;
case "datarequested":
- var targetId = element.getAttribute("data-clipboard-target"), targetEl = !targetId ? null : document.getElementById(targetId);
- if (targetEl) {
- var textContent = targetEl.value || targetEl.textContent || targetEl.innerText;
- if (textContent) {
- this.setText(textContent);
+ if (element) {
+ var targetId = element.getAttribute("data-clipboard-target"), targetEl = !targetId ? null : document.getElementById(targetId);
+ if (targetEl) {
+ var textContent = targetEl.value || targetEl.textContent || targetEl.innerText;
+ if (textContent) {
+ this.setText(textContent);
+ }
+ } else {
+ var defaultText = element.getAttribute("data-clipboard-text");
+ if (defaultText) {
+ this.setText(defaultText);
+ }
}
- } else {
- var defaultText = element.getAttribute("data-clipboard-text");
- if (defaultText) {
- this.setText(defaultText);
- }
}
performCallbackAsync = false;
break;
case "complete":
_deleteOwnProperties(_clipData);
+ if (element && element !== _safeActiveElement() && element.focus) {
+ element.focus();
+ }
break;
}
var context = element;
var eventArgs = [ this, args ];
return _dispatchClientCallbacks.call(this, eventName, context, eventArgs, performCallbackAsync);
@@ -999,12 +1018,14 @@
if (typeof define === "function" && define.amd) {
define([ "require", "exports", "module" ], function(require, exports, module) {
_amdModuleId = module && module.id || null;
return ZeroClipboard;
});
- } else if (typeof module === "object" && module && typeof module.exports === "object" && module.exports) {
+ } else if (typeof module === "object" && module && typeof module.exports === "object" && module.exports && typeof window.require === "function") {
_cjsModuleId = module.id || null;
module.exports = ZeroClipboard;
} else {
window.ZeroClipboard = ZeroClipboard;
}
-})();
+})(function() {
+ return this;
+}());
\ No newline at end of file