1/*! 2 * zeroclipboard 3 * The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface. 4 * Copyright 2012 Jon Rohan, James M. Greene, . 5 * Released under the MIT license 6 * http://jonrohan.github.com/ZeroClipboard/ 7 * v1.1.7 8 */(function() { 9 "use strict"; 10 var _getStyle = function(el, prop) { 11 var y = el.style[prop]; 12 if (el.currentStyle) y = el.currentStyle[prop]; else if (window.getComputedStyle) y = document.defaultView.getComputedStyle(el, null).getPropertyValue(prop); 13 if (y == "auto" && prop == "cursor") { 14 var possiblePointers = [ "a" ]; 15 for (var i = 0; i < possiblePointers.length; i++) { 16 if (el.tagName.toLowerCase() == possiblePointers[i]) { 17 return "pointer"; 18 } 19 } 20 } 21 return y; 22 }; 23 var _elementMouseOver = function(event) { 24 if (!ZeroClipboard.prototype._singleton) return; 25 if (!event) { 26 event = window.event; 27 } 28 var target; 29 if (this !== window) { 30 target = this; 31 } else if (event.target) { 32 target = event.target; 33 } else if (event.srcElement) { 34 target = event.srcElement; 35 } 36 ZeroClipboard.prototype._singleton.setCurrent(target); 37 }; 38 var _addEventHandler = function(element, method, func) { 39 if (element.addEventListener) { 40 element.addEventListener(method, func, false); 41 } else if (element.attachEvent) { 42 element.attachEvent("on" + method, func); 43 } 44 }; 45 var _removeEventHandler = function(element, method, func) { 46 if (element.removeEventListener) { 47 element.removeEventListener(method, func, false); 48 } else if (element.detachEvent) { 49 element.detachEvent("on" + method, func); 50 } 51 }; 52 var _addClass = function(element, value) { 53 if (element.addClass) { 54 element.addClass(value); 55 return element; 56 } 57 if (value && typeof value === "string") { 58 var classNames = (value || "").split(/\s+/); 59 if (element.nodeType === 1) { 60 if (!element.className) { 61 element.className = value; 62 } else { 63 var className = " " + element.className + " ", setClass = element.className; 64 for (var c = 0, cl = classNames.length; c < cl; c++) { 65 if (className.indexOf(" " + classNames[c] + " ") < 0) { 66 setClass += " " + classNames[c]; 67 } 68 } 69 element.className = setClass.replace(/^\s+|\s+$/g, ""); 70 } 71 } 72 } 73 return element; 74 }; 75 var _removeClass = function(element, value) { 76 if (element.removeClass) { 77 element.removeClass(value); 78 return element; 79 } 80 if (value && typeof value === "string" || value === undefined) { 81 var classNames = (value || "").split(/\s+/); 82 if (element.nodeType === 1 && element.className) { 83 if (value) { 84 var className = (" " + element.className + " ").replace(/[\n\t]/g, " "); 85 for (var c = 0, cl = classNames.length; c < cl; c++) { 86 className = className.replace(" " + classNames[c] + " ", " "); 87 } 88 element.className = className.replace(/^\s+|\s+$/g, ""); 89 } else { 90 element.className = ""; 91 } 92 } 93 } 94 return element; 95 }; 96 var _getDOMObjectPosition = function(obj) { 97 var info = { 98 left: 0, 99 top: 0, 100 width: obj.width || obj.offsetWidth || 0, 101 height: obj.height || obj.offsetHeight || 0, 102 zIndex: 9999 103 }; 104 var zi = _getStyle(obj, "zIndex"); 105 if (zi && zi != "auto") { 106 info.zIndex = parseInt(zi, 10); 107 } 108 while (obj) { 109 var borderLeftWidth = parseInt(_getStyle(obj, "borderLeftWidth"), 10); 110 var borderTopWidth = parseInt(_getStyle(obj, "borderTopWidth"), 10); 111 info.left += isNaN(obj.offsetLeft) ? 0 : obj.offsetLeft; 112 info.left += isNaN(borderLeftWidth) ? 0 : borderLeftWidth; 113 info.top += isNaN(obj.offsetTop) ? 0 : obj.offsetTop; 114 info.top += isNaN(borderTopWidth) ? 0 : borderTopWidth; 115 obj = obj.offsetParent; 116 } 117 return info; 118 }; 119 var _noCache = function(path) { 120 return (path.indexOf("?") >= 0 ? "&" : "?") + "nocache=" + (new Date).getTime(); 121 }; 122 var _vars = function(options) { 123 var str = []; 124 if (options.trustedDomains) { 125 if (typeof options.trustedDomains === "string") { 126 str.push("trustedDomain=" + options.trustedDomains); 127 } else { 128 str.push("trustedDomain=" + options.trustedDomains.join(",")); 129 } 130 } 131 return str.join("&"); 132 }; 133 var _inArray = function(elem, array) { 134 if (array.indexOf) { 135 return array.indexOf(elem); 136 } 137 for (var i = 0, length = array.length; i < length; i++) { 138 if (array[i] === elem) { 139 return i; 140 } 141 } 142 return -1; 143 }; 144 var _prepGlue = function(elements) { 145 if (typeof elements === "string") throw new TypeError("ZeroClipboard doesn't accept query strings."); 146 if (!elements.length) return [ elements ]; 147 return elements; 148 }; 149 var ZeroClipboard = function(elements, options) { 150 if (elements) (ZeroClipboard.prototype._singleton || this).glue(elements); 151 if (ZeroClipboard.prototype._singleton) return ZeroClipboard.prototype._singleton; 152 ZeroClipboard.prototype._singleton = this; 153 this.options = {}; 154 for (var kd in _defaults) this.options[kd] = _defaults[kd]; 155 for (var ko in options) this.options[ko] = options[ko]; 156 this.handlers = {}; 157 if (ZeroClipboard.detectFlashSupport()) _bridge(); 158 }; 159 var currentElement, gluedElements = []; 160 ZeroClipboard.prototype.setCurrent = function(element) { 161 currentElement = element; 162 this.reposition(); 163 this.htmlBridge.setAttribute("data-clipboard-text", this.options.text || element.getAttribute("data-clipboard-text")); 164 if (this.ready()) this.flashBridge.setText(this.options.text || element.getAttribute("data-clipboard-text")); 165 if (element.getAttribute("title")) { 166 this.setTitle(element.getAttribute("title")); 167 } 168 this.setHandCursor(_getStyle(element, "cursor") == "pointer"); 169 }; 170 ZeroClipboard.prototype.setText = function(newText) { 171 if (newText && newText !== "") { 172 this.options.text = newText; 173 if (this.ready()) this.flashBridge.setText(newText); 174 } 175 }; 176 ZeroClipboard.prototype.setTitle = function(newTitle) { 177 if (newTitle && newTitle !== "") this.htmlBridge.setAttribute("title", newTitle); 178 }; 179 ZeroClipboard.prototype.setSize = function(width, height) { 180 if (this.ready()) this.flashBridge.setSize(width, height); 181 }; 182 ZeroClipboard.prototype.setHandCursor = function(enabled) { 183 if (this.ready()) this.flashBridge.setHandCursor(enabled); 184 }; 185 ZeroClipboard.version = "1.1.7"; 186 var _defaults = { 187 moviePath: "ZeroClipboard.swf", 188 trustedDomains: null, 189 text: null, 190 hoverClass: "zeroclipboard-is-hover", 191 activeClass: "zeroclipboard-is-active" 192 }; 193 ZeroClipboard.setDefaults = function(options) {
194 for (var ko in options) _defaults[ko] = options[ko]; 195 }; 196 ZeroClipboard.destroy = function() { 197 ZeroClipboard.prototype._singleton.unglue(gluedElements); 198 var bridge = ZeroClipboard.prototype._singleton.htmlBridge; 199 bridge.parentNode.removeChild(bridge); 200 delete ZeroClipboard.prototype._singleton; 201 }; 202 ZeroClipboard.detectFlashSupport = function() { 203 var hasFlash = false; 204 try { 205 if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) { 206 hasFlash = true; 207 } 208 } catch (error) { 209 if (navigator.mimeTypes["application/x-shockwave-flash"]) { 210 hasFlash = true; 211 } 212 } 213 return hasFlash; 214 }; 215 var _bridge = function() { 216 var client = ZeroClipboard.prototype._singleton; 217 client.htmlBridge = document.getElementById("global-zeroclipboard-html-bridge"); 218 if (client.htmlBridge) { 219 client.flashBridge = document["global-zeroclipboard-flash-bridge"]; 220 return; 221 } 222 var html = ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="global-zeroclipboard-flash-bridge" width="100%" height="100%"> <param name="movie" value="' + client.options.moviePath + _noCache(client.options.moviePath) + '"/> <param name="allowScriptAccess" value="always" /> <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="' + _vars(client.options) + '"/> <embed src="' + client.options.moviePath + _noCache(client.options.moviePath) + '" 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.macromedia.com/go/getflashplayer" flashvars="' + _vars(client.options) + '" scale="exactfit"> </embed> </object>'; 223 client.htmlBridge = document.createElement("div"); 224 client.htmlBridge.id = "global-zeroclipboard-html-bridge"; 225 client.htmlBridge.setAttribute("class", "global-zeroclipboard-container"); 226 client.htmlBridge.setAttribute("data-clipboard-ready", false); 227 client.htmlBridge.style.position = "absolute"; 228 client.htmlBridge.style.left = "-9999px"; 229 client.htmlBridge.style.top = "-9999px"; 230 client.htmlBridge.style.width = "15px"; 231 client.htmlBridge.style.height = "15px"; 232 client.htmlBridge.style.zIndex = "9999"; 233 client.htmlBridge.innerHTML = html; 234 document.body.appendChild(client.htmlBridge); 235 client.flashBridge = document["global-zeroclipboard-flash-bridge"]; 236 }; 237 ZeroClipboard.prototype.resetBridge = function() { 238 this.htmlBridge.style.left = "-9999px"; 239 this.htmlBridge.style.top = "-9999px"; 240 this.htmlBridge.removeAttribute("title"); 241 this.htmlBridge.removeAttribute("data-clipboard-text"); 242 _removeClass(currentElement, this.options.activeClass); 243 currentElement = null; 244 this.options.text = null; 245 }; 246 ZeroClipboard.prototype.ready = function() { 247 var ready = this.htmlBridge.getAttribute("data-clipboard-ready"); 248 return ready === "true" || ready === true; 249 }; 250 ZeroClipboard.prototype.reposition = function() { 251 if (!currentElement) return false; 252 var pos = _getDOMObjectPosition(currentElement); 253 this.htmlBridge.style.top = pos.top + "px"; 254 this.htmlBridge.style.left = pos.left + "px"; 255 this.htmlBridge.style.width = pos.width + "px"; 256 this.htmlBridge.style.height = pos.height + "px"; 257 this.htmlBridge.style.zIndex = pos.zIndex + 1; 258 this.setSize(pos.width, pos.height); 259 }; 260 ZeroClipboard.dispatch = function(eventName, args) { 261 ZeroClipboard.prototype._singleton.receiveEvent(eventName, args); 262 }; 263 ZeroClipboard.prototype.on = function(eventName, func) { 264 var events = eventName.toString().split(/\s/g); 265 for (var i = 0; i < events.length; i++) { 266 eventName = events[i].toLowerCase().replace(/^on/, ""); 267 if (!this.handlers[eventName]) this.handlers[eventName] = func; 268 } 269 if (this.handlers.noflash && !ZeroClipboard.detectFlashSupport()) { 270 this.receiveEvent("onNoFlash", null); 271 } 272 }; 273 ZeroClipboard.prototype.addEventListener = ZeroClipboard.prototype.on; 274 ZeroClipboard.prototype.receiveEvent = function(eventName, args) { 275 eventName = eventName.toString().toLowerCase().replace(/^on/, ""); 276 var element = currentElement; 277 switch (eventName) {
278 case "load": 279 if (args && parseFloat(args.flashVersion.replace(",", ".").replace(/[^0-9\.]/gi, "")) < 10) { 280 this.receiveEvent("onWrongFlash", { 281 flashVersion: args.flashVersion 282 }); 283 return; 284 } 285 this.htmlBridge.setAttribute("data-clipboard-ready", true); 286 break; 287 case "mouseover": 288 _addClass(element, this.options.hoverClass); 289 break; 290 case "mouseout": 291 _removeClass(element, this.options.hoverClass); 292 this.resetBridge(); 293 break; 294 case "mousedown": 295 _addClass(element, this.options.activeClass); 296 break; 297 case "mouseup": 298 _removeClass(element, this.options.activeClass); 299 break; 300 case "complete": 301 this.options.text = null; 302 break; 303 } 304 if (this.handlers[eventName]) { 305 var func = this.handlers[eventName]; 306 if (typeof func == "function") { 307 func.call(element, this, args); 308 } else if (typeof func == "string") { 309 window[func].call(element, this, args); 310 } 311 } 312 }; 313 ZeroClipboard.prototype.glue = function(elements) { 314 elements = _prepGlue(elements); 315 for (var i = 0; i < elements.length; i++) { 316 if (_inArray(elements[i], gluedElements) == -1) { 317 gluedElements.push(elements[i]); 318 _addEventHandler(elements[i], "mouseover", _elementMouseOver); 319 } 320 } 321 }; 322 ZeroClipboard.prototype.unglue = function(elements) { 323 elements = _prepGlue(elements); 324 for (var i = 0; i < elements.length; i++) { 325 _removeEventHandler(elements[i], "mouseover", _elementMouseOver); 326 var arrayIndex = _inArray(elements[i], gluedElements); 327 if (arrayIndex != -1) gluedElements.splice(arrayIndex, 1); 328 } 329 }; 330 if (typeof module !== "undefined") { 331 module.exports = ZeroClipboard; 332 } else { 333 window.ZeroClipboard = ZeroClipboard; 334 } 335})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.