You are on page 1of 9

/*!

* 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) 2013 Jon Rohan, James M. Greene
* Licensed MIT
* http://zeroclipboard.org/
* v1.2.1
*/
(function() {
"use strict";
var _camelizeCssPropName = function() {
var matcherRegex = /\-([a-z])/g, replacerFn = function(match, group) {
return group.toUpperCase();
};
return function(prop) {
return prop.replace(matcherRegex, replacerFn);
};
}();
var _getStyle = function(el, prop) {
var value, camelProp, tagName, possiblePointers, i, len;
if (window.getComputedStyle) {
value = window.getComputedStyle(el, null).getPropertyValue(prop);
} else {
camelProp = _camelizeCssPropName(prop);
if (el.currentStyle) {
value = el.currentStyle[camelProp];
} else {
value = el.style[camelProp];
}
}
if (prop === "cursor") {
if (!value || value === "auto") {
tagName = el.tagName.toLowerCase();
possiblePointers = [ "a" ];
for (i = 0, len = possiblePointers.length; i < len; i++) {
if (tagName === possiblePointers[i]) {
return "pointer";
}
}
}
}
return value;
};
var _elementMouseOver = function(event) {
if (!ZeroClipboard.prototype._singleton) return;
if (!event) {
event = window.event;
}
var target;
if (this !== window) {
target = this;
} else if (event.target) {
target = event.target;
} else if (event.srcElement) {
target = event.srcElement;
}
ZeroClipboard.prototype._singleton.setCurrent(target);
};

setClass = element. } if (value && typeof value === "string") { var classNames = (value || ""). return element.split(/\s+/). var _addEventHandler = function(element.indexOf(" " + classNames[c] + " ") < 0) { setClass += " " + classNames[c]. if (element.removeClass(value).addEventListener) { element. c < cl. func). if (element. return element.replace(" " + classNames[c] + " ". func) { if (element. method. var _removeEventHandler = function(element. for (var c = 0. value) { if (element.attachEvent) { element. }. value) { if (element. . } } element. " "). func).length.nodeType === 1) { if (!element.className) { element.className = setClass. " "). } else { var className = " " + element.className = className.length.addClass(value). c < cl. } }. cl = classNames. method.addEventListener(method. c++) { if (className. "").className = "".removeEventListener) { element. "").className. } element. } else if (element.split(/\s+/).removeClass) { element.addClass) { element. c++) { className = className.className = value. false). }. } else if (element.replace(/^\s+|\s+$/g. false).replace(/[\n\t]/g. for (var c = 0.detachEvent) { element. } } } return element. func. func) { if (element.className + " ".detachEvent("on" + method. } else { element. cl = classNames. } } } return element.className) { if (value) { var className = (" " + element. var _addClass = function(element.className + " ").nodeType === 1 && element. } }. var _removeClass = function(element. } if (value && typeof value === "string" || value === undefined) { var classNames = (value || "").replace(/^\s+|\s+$/g.removeEventListener(method.attachEvent("on" + method. func.

left. zoomFactor = 1.top + pageYOffset . info.documentElement. 10).body. info.clientTop || 0. if (zi && zi !== "auto") { info. var _getDOMObjectPosition = function(obj) { var info = { left: 0. } else { zoomFactor = _getZoomFactor().body.right . logicalWidth.getBoundingClientRect().height : rect.trustedOrigins) { . var _getZoomFactor = function() { var rect.zIndex = parseInt(zi. var topBorderWidth = document.right .clientLeft || 0. } else { return "".topBorderWidth. var _vars = function(options) { var str = [].getTime(). } if (obj.offsetWidth.leftBorderWidth. logicalWidth = document. } return zoomFactor.bottom . pageYOffset.rect.rect. zIndex: 999999999 }. if (useNoCache) { return (path.useNoCache === false).rect. } var leftBorderWidth = document.documentElement. var pageXOffset. }. options) { var useNoCache = !(options && options. zoomFactor = Math. pageYOffset = Math.indexOf("?") === -1 ? "?" : "&") + "nocache=" + new Date(). var zi = _getStyle(obj. var origins = []. pageYOffset = window.left = rect.pageYOffset.trustedOrigins === "object" && "length" in options. if (options. } return info.round(physicalWidth / logicalWidth * 100) / 100.pageXOffset. pageXOffset = Math. if ("pageXOffset" in window && "pageYOffset" in window) { pageXOffset = window.width = "width" in rect ? rect.body.trustedOrigins) { if (typeof options.getBoundingClientRect === "function") { rect = document. zoomFactor.scrollTop / zoomFactor).top.trustedOrigins).scrollLeft / zoomFactor).push(options. height: 0.getBoundingClientRect) { var rect = obj. var _noCache = function(path. } else if (typeof options. if (typeof document.trustedOrigins === "string") { origins. } }. physicalWidth = rect.round(document. info.round(document.getBoundingClientRect(). "z-index"). }.width : rect. physicalWidth.left + pageXOffset .left. info. width: 0. top: 0.height = "height" in rect ? rect.documentElement.top = rect.documentElement.

origins = origins. async) { if (async) { window.options[ko] = options[ko]. ZeroClipboard. if (ZeroClipboard.trustedDomains). return elements. } } return -1.handlers = {}. for (var kd in _defaults) this.push("cjsModuleId=" + encodeURIComponent(options.detectFlashSupport()) _bridge(). array) { if (array.concat(options. 0).length) { str. var _inArray = function(elem. i++) { if (array[i] === elem) { return i. } } if (origins. args). for (var ko in options) this.prototype.indexOf) { return array. .push("trustedOrigins=" + encodeURIComponent(origins. this. }. }. instance._singleton.cjsModuleId)).trustedDomains). length = array.setTimeout(function() { func. instance. } if (typeof options.cjsModuleId) { str._singleton || this).push(options.trustedDomains === "string") { origins.trustedDomains) { origins = origins. } else { func.options[kd] = _defaults[kd]. }. } } if (options. if (!elements.prototype.glue(elements).concat(options. } for (var i = 0. } else if (typeof options.push("amdModuleId=" + encodeURIComponent(options. instance.call(element.join("&").indexOf(elem).prototype. } if (typeof options.call(element."))).trustedDomains) { if (typeof options.trustedDomains === "object" && "length" in options. var ZeroClipboard = function(elements.join(". var _prepGlue = function(elements) { if (typeof elements === "string") throw new TypeError("ZeroClipboard doesn't accept query strings. }.length. } }. }."). options) { if (elements) (ZeroClipboard. } return str. this. var _dispatchCallback = function(func. i < length.trustedOrigins).cjsModuleId === "string" && options.prototype._singleton) return ZeroClipboard.amdModuleId)). args. if (ZeroClipboard._singleton = this.amdModuleId === "string" && options.amdModuleId) { str.options = {}. element.length) return [ elements ]. args).

prototype.1".htmlBridge.prototype.detectFlashSupport = function() { .reposition().text = newText. }.flashBridge.prototype.setAttribute("title".setText(newText). height).prototype. ZeroClipboard. delete ZeroClipboard. this.prototype. return this.ready()) this.setText = function(newText) { if (newText && newText !== "") { this.setSize(width.setHandCursor(enabled).swf". useHandCursor).parentNode. newTitle).ready()) this. bridge.options. }.options. return this.setDefaults = function(options) { for (var ko in options) _defaults[ko] = options[ko].setTitle = function(newTitle) { if (newTitle && newTitle !== "") this.2. var _defaults = { moviePath: "ZeroClipboard. this. if (this.version = "1._singleton. "cursor") === "pointer".prototype.flashBridge. }. var currentElement.options. var bridge = ZeroClipboard. } return this.setCurrent = function(element) { currentElement = element.prototype. }. ZeroClipboard.htmlBridge. return this. if (titleAttr) { this. ZeroClipboard.destroy = function() { ZeroClipboard. return this. _setHandCursor._singleton._singleton. } var useHandCursor = this. }. ZeroClipboard. ZeroClipboard.prototype.setSize = function(width. ZeroClipboard. ZeroClipboard. var titleAttr = element. text: null.setTitle(titleAttr). ZeroClipboard. useNoCache: true. activeClass: "zeroclipboard-is-active".forceHandCursor = enabled.getAttribute("title"). _setHandCursor. hoverClass: "zeroclipboard-is-hover".flashBridge. var _setHandCursor = function(enabled) { if (this.forceHandCursor === true || _getStyle(element.removeChild(bridge).call(this.call(this.setHandCursor = function(enabled) { enabled = typeof enabled === "boolean" ? enabled : !!enabled. height) { if (this.unglue(gluedElements). trustedOrigins: null.ready()) this. gluedElements = []. }. allowScriptAccess: "sameDomain". ZeroClipboard. enabled). }. }. forceHandCursor: false }.

options) opts[ko] = client.style. "global-zeroclipboard-container").setAttribute("data-clipboard-ready". container.style.width = "15px". client. }.zIndex = "9999".height = "15px". client.style.style. container.options. var html = ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8- 444553540000" id="global-zeroclipboard-flash-bridge" width="100%" height="100%"> <param name="movie" value="' + client. var _bridge = function() { var client = ZeroClipboard.options.macromedia.resetBridge = function() { . var hasFlash = false. ZeroClipboard.options) + '"/> <param name="allowScriptAccess" value="' + client. } return hasFlash.lastElementChild.ShockwaveFlash")) { hasFlash = true. }. opts. container. container.innerHTML = html.setAttribute("class". var _amdModuleId = null. for (var ko in client. var _cjsModuleId = null. opts.options[ko]. client. if (!container) { var opts = {}.cjsModuleId = _cjsModuleId. } } catch (error) {} } if (!hasFlash && navigator.top = "-9999px".position = "absolute". container.id = "global-zeroclipboard-html-bridge". container = document.options.prototype.body. false). container.htmlBridge = container._singleton.children[0].options. document. var flashvars = _vars(opts).moviePath. container.createElement("div"). container.moviePath + _noCache(client.left = "-9999px".moviePath + _noCache(client. if (typeof ActiveXObject === "function") { try { if (new ActiveXObject("ShockwaveFlash. container.prototype.flashBridge = document["global-zeroclipboard-flash-bridge"] || container.allowScriptAccess + '"/> <param name="scale" value="exactfit"/> <param name="loop" value="false"/> <param name="menu" value="false"/> <param name="quality" value="best" /> <param name="bgcolor" value="#ffffff"/> <param name="wmode" value="transparent"/> <param name="flashvars" value="' + flashvars + '"/> <embed src="' + client. } client.options.style. container.getElementById("global-zeroclipboard-html-bridge").style.options) + '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="100%" height="100%" name="global- zeroclipboard-flash-bridge" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.moviePath.appendChild(container).amdModuleId = _amdModuleId.mimeTypes["application/x-shockwave-flash"]) { hasFlash = true.com/go/getflashplayer" flashvars="' + flashvars + '" scale="exactfit"> </embed> </object>'. var container = document.

""). ZeroClipboard.noflash && !ZeroClipboard.ready = function() { var ready = this.prototype. "").on = function(eventName. this. this.top = pos. pos. ZeroClipboard.htmlBridge. return this.style.style.getAttribute("data-clipboard-ready").top = "-9999px". args).toString().left = "-9999px".style.style. }. "").off.zIndex = pos. this. this. } } } return this.left + "px". ZeroClipboard.style.prototype. null).replace(/^on/.split(/\s/g). this.flashVersion.handlers[eventName] = func. this. var performCallbackAsync = true. func) { var events = eventName.prototype.toLowerCase(). ". for (var i = 0.zIndex + 1. i < events. if (!this. ZeroClipboard.replace(/^on/. i++) { eventName = events[i].htmlBridge. this.htmlBridge. i < events.activeClass).options. this. } return this. ZeroClipboard. }.length. } if (this._singleton.replace(".".split(/\s/g).detectFlashSupport()) { this. }.toString().reposition = function() { if (!currentElement) return false.htmlBridge. }. }.toLowerCase().htmlBridge. this.setSize(pos.height + "px".removeAttribute("data-clipboard-text"). ZeroClipboard.height).text = null.replace(/^on/.prototype. args) { eventName = eventName.addEventListener = ZeroClipboard.off = function(eventName.htmlBridge.removeEventListener = ZeroClipboard. return this. return ready === "true" || ready === true. switch (eventName) { case "load": if (args && parseFloat(args.handlers[eventName]) this.width + "px".prototype.length.top + "px".options.receiveEvent(eventName.replace(/[^0- . ZeroClipboard.htmlBridge. var pos = _getDOMObjectPosition(currentElement).receiveEvent = function(eventName. for (var i = 0.dispatch = function(eventName. this.prototype. args) { ZeroClipboard.width = pos.handlers.width.removeAttribute("title").prototype. }."). this.style.prototype.height = pos.handlers[event] === func) { delete this.htmlBridge. for (var event in this.left = pos. _removeClass(currentElement.on. ZeroClipboard. var element = currentElement.handlers[event].handlers) { if (event === eventName && this. this.style.toString().toLowerCase().receiveEvent("onNoFlash". currentElement = null. i++) { eventName = events[i].htmlBridge.htmlBridge.prototype. func) { var events = eventName.prototype.

i++) { if (_inArray(elements[i]. break.options.activeClass). if (defaultText) this.]/gi. element.length.handlers[eventName].value || targetEl. } performCallbackAsync = false.glue = function(elements) { elements = _prepGlue(elements).push(elements[i]).receiveEvent("onWrongFlash".activeClass). } if (typeof func === "function") { _dispatchCallback(func. break. args.text = null.9\.setText(defaultText).getAttribute("data-clipboard-text").htmlBridge.getElementById(targetId). case "mousedown": _addClass(element.options. targetEl = ! targetId ? null : document. { flashVersion: args. break. case "datarequested": var targetId = element. . this.prototype. for (var i = 0. if (targetEl) { var textContent = targetEl.setAttribute("data-clipboard-ready". case "complete": this.innerText.handlers[eventName]) { var func = this. break. } else { var defaultText = element. true).hoverClass). this. gluedElements) == -1) { gluedElements. } } }. case "mouseover": _addClass(element. break.options. } if (this. "")) < 10) { this. this.hoverClass). if (textContent) this. this. this. performCallbackAsync).options.setText(textContent). this. break.options. case "mouseout": _removeClass(element. case "mouseup": _removeClass(element. if (typeof func === "string" && typeof window[func] === "function") { func = window[func].resetBridge(). i < elements. break. return.getAttribute("data-clipboard-target"). } this.textContent || targetEl. ZeroClipboard.flashVersion }).

function(require. } })(). "mouseover".amd) { define([ "require". _elementMouseOver).id || null. _addEventHandler(elements[i]. }. 1). var arrayIndex = _inArray(elements[i]. } return this. "mouseover". i++) { _removeEventHandler(elements[i]. module) { _amdModuleId = module && module.splice(arrayIndex. i < elements.id || null. _elementMouseOver).exports = ZeroClipboard. gluedElements). ZeroClipboard. }). exports. .exports === "object" && module. }.exports) { _cjsModuleId = module. if (typeof define === "function" && define. "exports". } else { window.length. module. } else if (typeof module === "object" && module && typeof module. if (arrayIndex != -1) gluedElements. } } return this.prototype. for (var i = 0. return ZeroClipboard. "module" ].unglue = function(elements) { elements = _prepGlue(elements).ZeroClipboard = ZeroClipboard.