PageSourceSearch

https://hyenasoft.com/common/lib//lib.zeroclipboard/ZeroClipboard.js

js hyenasoft.com collected 2026-10-04 01:41:16 UTC 14,306 bytes, 359 lines download raw bytes

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    if (element.getAttribute("title")) {
164      this.setTitle(element.getAttribute("title"));
165    }
166    this.setHandCursor(_getStyle(element, "cursor") == "pointer");
167  };
168  ZeroClipboard.prototype.setText = function(newText) {
169    if (newText && newText !== "") {
170      this.options.text = newText;
171      if (this.ready()) this.flashBridge.setText(newText);
172    }
173  };
174  ZeroClipboard.prototype.setTitle = function(newTitle) {
175    if (newTitle && newTitle !== "") this.htmlBridge.setAttribute("title", newTitle);
176  };
177  ZeroClipboard.prototype.setSize = function(width, height) {
178    if (this.ready()) this.flashBridge.setSize(width, height);
179  };
180  ZeroClipboard.prototype.setHandCursor = function(enabled) {
181    if (this.ready()) this.flashBridge.setHandCursor(enabled);
182  };
183  ZeroClipboard.version = "1.1.7";
184  var _defaults = {
185    moviePath: "ZeroClipboard.swf",
186    trustedDomains: null,
187    text: null,
188    hoverClass: "zeroclipboard-is-hover",
189    activeClass: "zeroclipboard-is-active",
190    allowScriptAccess: "sameDomain"
191  };
192  ZeroClipboard.setDefaults = function(options) {
193    for (var ko in options) _defaults[ko] = options[ko];
194  };
195  ZeroClipboard.destroy = function() {
196    ZeroClipboard.prototype._singleton.unglue(gluedElements);
197    var bridge = ZeroClipboard.prototype._singleton.htmlBridge;
198    bridge.parentNode.removeChild(bridge);
199    delete ZeroClipboard.prototype._singleton;
200  };
201  ZeroClipboard.detectFlashSupport = function() {
202    var hasFlash = false;
203    try {
204      if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) {
205        hasFlash = true;
206      }
207    } catch (error) {
208      if (navigator.mimeTypes["application/x-shockwave-flash"]) {
209        hasFlash = true;
210      }
211    }
212    return hasFlash;
213  };
214  var _bridge = function() {
215    var client = ZeroClipboard.prototype._singleton;
216    var container = document.getElementById("global-zeroclipboard-html-bridge");
217    if (!container) {
218      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="' + client.options.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="' + _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>';
219      container = document.createElement("div");
220      container.id = "global-zeroclipboard-html-bridge";
221      container.setAttribute("class", "global-zeroclipboard-container");
222      container.setAttribute("data-clipboard-ready", false);
223      container.style.position = "absolute";
224      container.style.left = "-9999px";
225      container.style.top = "-9999px";
226      container.style.width = "15px";
227      container.style.height = "15px";
228      container.style.zIndex = "9999";
229      container.innerHTML = html;
230      document.body.appendChild(container);
231    }
232    client.htmlBridge = container;
233    client.flashBridge = document["global-zeroclipboard-flash-bridge"] || container.children[0].lastElementChild;
234  };
235  ZeroClipboard.prototype.resetBridge = function() {
236    this.htmlBridge.style.left = "-9999px";
237    this.htmlBridge.style.top = "-9999px";
238    this.htmlBridge.removeAttribute("title");
239    this.htmlBridge.removeAttribute("data-clipboard-text");
240    _removeClass(currentElement, this.options.activeClass);
241    currentElement = null;
242    this.options.text = null;
243  };
244  ZeroClipboard.prototype.ready = function() {
245    var ready = this.htmlBridge.getAttribute("data-clipboard-ready");
246    return ready === "true" || ready === true;
247  };
248  ZeroClipboard.prototype.reposition = function() {
249    if (!currentElement) return false;
250    var pos = _getDOMObjectPosition(currentElement);
251    this.htmlBridge.style.top = pos.top + "px";
252    this.htmlBridge.style.left = pos.left + "px";
253    this.htmlBridge.style.width = pos.width + "px";
254    this.htmlBridge.style.height = pos.height + "px";
255    this.htmlBridge.style.zIndex = pos.zIndex + 1;
256    this.setSize(pos.width, pos.height);
257  };
258  ZeroClipboard.dispatch = function(eventName, args) {
259    ZeroClipboard.prototype._singleton.receiveEvent(eventName, args);
260  };
261  ZeroClipboard.prototype.on = function(eventName, func) {
262    var events = eventName.toString().split(/\s/g);
263    for (var i = 0; i < events.length; i++) {
264      eventName = events[i].toLowerCase().replace(/^on/, "");
265      if (!this.handlers[eventName]) this.handlers[eventName] = func;
266    }
267    if (this.handlers.noflash && !ZeroClipboard.detectFlashSupport()) {
268      this.receiveEvent("onNoFlash", null);
269    }
270  };
271  ZeroClipboard.prototype.addEventListener = ZeroClipboard.prototype.on;
272  ZeroClipboard.prototype.off = function(eventName, func) {
273    var events = eventName.toString().split(/\s/g);
274    for (var i = 0; i < events.length; i++) {
275      eventName = events[i].toLowerCase().replace(/^on/, "");
276      for (var event in this.handlers) {
277        if (event === eventName && this.handlers[event] === func) {
278          delete this.handlers[event];
279        }
280      }
281    }
282  };
283  ZeroClipboard.prototype.removeEventListener = ZeroClipboard.prototype.off;
284  ZeroClipboard.prototype.receiveEvent = function(eventName, args) {
285    eventName = eventName.toString().toLowerCase().replace(/^on/, "");
286    var element = currentElement;
287    switch (eventName) {
288     case "load":
289      if (args && parseFloat(args.flashVersion.replace(",", ".").replace(/[^0-9\.]/gi, "")) < 10) {
290        this.receiveEvent("onWrongFlash", {
291          flashVersion: args.flashVersion
292        });
293        return;
294      }
295      this.htmlBridge.setAttribute("data-clipboard-ready", true);
296      break;
297     case "mouseover":
298      _addClass(element, this.options.hoverClass);
299      break;
300     case "mouseout":
301      _removeClass(element, this.options.hoverClass);
302      this.resetBridge();
303      break;
304     case "mousedown":
305      _addClass(element, this.options.activeClass);
306      break;
307     case "mouseup":
308      _removeClass(element, this.options.activeClass);
309      break;
310     case "datarequested":
311      var targetId = element.getAttribute("data-clipboard-target"), targetEl = !targetId ? null : document.getElementById(targetId);
312      if (targetEl) {
313        var textContent = targetEl.value || targetEl.textContent || targetEl.innerText;
314        if (textContent) this.setText(textContent);
315      } else {
316        var defaultText = element.getAttribute("data-clipboard-text");
317        if (defaultText) this.setText(defaultText);
318      }
319      break;
320     case "complete":
321      this.options.text = null;
322      break;
323    }
324    if (this.handlers[eventName]) {
325      var func = this.handlers[eventName];
326      if (typeof func == "function") {
327        func.call(element, this, args);
328      } else if (typeof func == "string") {
329        window[func].call(element, this, args);
330      }
331    }
332  };
333  ZeroClipboard.prototype.glue = function(elements) {
334    elements = _prepGlue(elements);
335    for (var i = 0; i < elements.length; i++) {
336      if (_inArray(elements[i], gluedElements) == -1) {
337        gluedElements.push(elements[i]);
338        _addEventHandler(elements[i], "mouseover", _elementMouseOver);
339      }
340    }
341  };
342  ZeroClipboard.prototype.unglue = function(elements) {
343    elements = _prepGlue(elements);
344    for (var i = 0; i < elements.length; i++) {
345      _removeEventHandler(elements[i], "mouseover", _elementMouseOver);
346      var arrayIndex = _inArray(elements[i], gluedElements);
347      if (arrayIndex != -1) gluedElements.splice(arrayIndex, 1);
348    }
349  };
350  if (typeof module !== "undefined") {
351    module.exports = ZeroClipboard;
352  } else if (typeof define === "function" && define.amd) {
353    define(function() {
354      return ZeroClipboard;
355    });
356  } else {
357    window.ZeroClipboard = ZeroClipboard;
358  }
359})();

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.