jquery.zclip.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. ;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. /*!
  3. * zeroclipboard
  4. * The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface.
  5. * Copyright 2012 Jon Rohan, James M. Greene, .
  6. * Released under the MIT license
  7. * http://jonrohan.github.com/ZeroClipboard/
  8. * v1.1.7
  9. */(function() {
  10. "use strict";
  11. var _getStyle = function(el, prop) {
  12. var y = el.style[prop];
  13. if (el.currentStyle) y = el.currentStyle[prop]; else if (window.getComputedStyle) y = document.defaultView.getComputedStyle(el, null).getPropertyValue(prop);
  14. if (y == "auto" && prop == "cursor") {
  15. var possiblePointers = [ "a" ];
  16. for (var i = 0; i < possiblePointers.length; i++) {
  17. if (el.tagName.toLowerCase() == possiblePointers[i]) {
  18. return "pointer";
  19. }
  20. }
  21. }
  22. return y;
  23. };
  24. var _elementMouseOver = function(event) {
  25. if (!ZeroClipboard.prototype._singleton) return;
  26. if (!event) {
  27. event = window.event;
  28. }
  29. var target;
  30. if (this !== window) {
  31. target = this;
  32. } else if (event.target) {
  33. target = event.target;
  34. } else if (event.srcElement) {
  35. target = event.srcElement;
  36. }
  37. ZeroClipboard.prototype._singleton.setCurrent(target);
  38. };
  39. var _addEventHandler = function(element, method, func) {
  40. if (element.addEventListener) {
  41. element.addEventListener(method, func, false);
  42. } else if (element.attachEvent) {
  43. element.attachEvent("on" + method, func);
  44. }
  45. };
  46. var _removeEventHandler = function(element, method, func) {
  47. if (element.removeEventListener) {
  48. element.removeEventListener(method, func, false);
  49. } else if (element.detachEvent) {
  50. element.detachEvent("on" + method, func);
  51. }
  52. };
  53. var _addClass = function(element, value) {
  54. if (element.addClass) {
  55. element.addClass(value);
  56. return element;
  57. }
  58. if (value && typeof value === "string") {
  59. var classNames = (value || "").split(/\s+/);
  60. if (element.nodeType === 1) {
  61. if (!element.className) {
  62. element.className = value;
  63. } else {
  64. var className = " " + element.className + " ", setClass = element.className;
  65. for (var c = 0, cl = classNames.length; c < cl; c++) {
  66. if (className.indexOf(" " + classNames[c] + " ") < 0) {
  67. setClass += " " + classNames[c];
  68. }
  69. }
  70. element.className = setClass.replace(/^\s+|\s+$/g, "");
  71. }
  72. }
  73. }
  74. return element;
  75. };
  76. var _removeClass = function(element, value) {
  77. if (element.removeClass) {
  78. element.removeClass(value);
  79. return element;
  80. }
  81. if (value && typeof value === "string" || value === undefined) {
  82. var classNames = (value || "").split(/\s+/);
  83. if (element.nodeType === 1 && element.className) {
  84. if (value) {
  85. var className = (" " + element.className + " ").replace(/[\n\t]/g, " ");
  86. for (var c = 0, cl = classNames.length; c < cl; c++) {
  87. className = className.replace(" " + classNames[c] + " ", " ");
  88. }
  89. element.className = className.replace(/^\s+|\s+$/g, "");
  90. } else {
  91. element.className = "";
  92. }
  93. }
  94. }
  95. return element;
  96. };
  97. var _getDOMObjectPosition = function(obj) {
  98. var info = {
  99. left: 0,
  100. top: 0,
  101. width: obj.width || obj.offsetWidth || 0,
  102. height: obj.height || obj.offsetHeight || 0,
  103. zIndex: 9999
  104. };
  105. //console.log(info);
  106. var zi = _getStyle(obj, "zIndex");
  107. if (zi && zi != "auto") {
  108. info.zIndex = parseInt(zi, 10);
  109. }
  110. while (obj) {
  111. var borderLeftWidth = parseInt(_getStyle(obj, "borderLeftWidth"), 10);
  112. var borderTopWidth = parseInt(_getStyle(obj, "borderTopWidth"), 10);
  113. //console.log(info);
  114. info.left += isNaN(obj.offsetLeft) ? 0 : obj.offsetLeft;
  115. info.left += isNaN(borderLeftWidth) ? 0 : borderLeftWidth;
  116. info.top += isNaN(obj.offsetTop) ? 0 : obj.offsetTop;
  117. info.top += isNaN(borderTopWidth) ? 0 : borderTopWidth;
  118. //console.log(info);
  119. obj = obj.offsetParent;
  120. }
  121. return info;
  122. };
  123. var _noCache = function(path) {
  124. return (path.indexOf("?") >= 0 ? "&" : "?") + "nocache=" + (new Date).getTime();
  125. };
  126. var _vars = function(options) {
  127. var str = [];
  128. if (options.trustedDomains) {
  129. if (typeof options.trustedDomains === "string") {
  130. str.push("trustedDomain=" + options.trustedDomains);
  131. } else {
  132. str.push("trustedDomain=" + options.trustedDomains.join(","));
  133. }
  134. }
  135. return str.join("&");
  136. };
  137. var _inArray = function(elem, array) {
  138. if (array.indexOf) {
  139. return array.indexOf(elem);
  140. }
  141. for (var i = 0, length = array.length; i < length; i++) {
  142. if (array[i] === elem) {
  143. return i;
  144. }
  145. }
  146. return -1;
  147. };
  148. var _prepGlue = function(elements) {
  149. if (typeof elements === "string") throw new TypeError("ZeroClipboard doesn't accept query strings.");
  150. if (!elements.length) return [ elements ];
  151. return elements;
  152. };
  153. var ZeroClipboard = function(elements, options) {
  154. if (elements) (ZeroClipboard.prototype._singleton || this).glue(elements);
  155. if (ZeroClipboard.prototype._singleton) return ZeroClipboard.prototype._singleton;
  156. ZeroClipboard.prototype._singleton = this;
  157. this.options = {};
  158. for (var kd in _defaults) this.options[kd] = _defaults[kd];
  159. for (var ko in options) this.options[ko] = options[ko];
  160. this.handlers = {};
  161. if (ZeroClipboard.detectFlashSupport()) _bridge();
  162. };
  163. var currentElement, gluedElements = [];
  164. ZeroClipboard.prototype.setCurrent = function(element) {
  165. currentElement = element;
  166. this.reposition();
  167. if (element.getAttribute("title")) {
  168. this.setTitle(element.getAttribute("title"));
  169. }
  170. this.setHandCursor(_getStyle(element, "cursor") == "pointer");
  171. };
  172. ZeroClipboard.prototype.setText = function(newText) {
  173. if (newText && newText !== "") {
  174. this.options.text = newText;
  175. if (this.ready()) this.flashBridge.setText(newText);
  176. }
  177. };
  178. ZeroClipboard.prototype.setTitle = function(newTitle) {
  179. if (newTitle && newTitle !== "") this.htmlBridge.setAttribute("title", newTitle);
  180. };
  181. ZeroClipboard.prototype.setSize = function(width, height) {
  182. if (this.ready()) this.flashBridge.setSize(width, height);
  183. };
  184. ZeroClipboard.prototype.setHandCursor = function(enabled) {
  185. if (this.ready()) this.flashBridge.setHandCursor(enabled);
  186. };
  187. ZeroClipboard.version = "1.1.7";
  188. var _defaults = {
  189. moviePath: "ZeroClipboard.swf",
  190. trustedDomains: null,
  191. text: null,
  192. hoverClass: "zeroclipboard-is-hover",
  193. activeClass: "zeroclipboard-is-active",
  194. allowScriptAccess: "sameDomain"
  195. };
  196. ZeroClipboard.setDefaults = function(options) {
  197. for (var ko in options) _defaults[ko] = options[ko];
  198. };
  199. ZeroClipboard.destroy = function() {
  200. ZeroClipboard.prototype._singleton.unglue(gluedElements);
  201. var bridge = ZeroClipboard.prototype._singleton.htmlBridge;
  202. bridge.parentNode.removeChild(bridge);
  203. delete ZeroClipboard.prototype._singleton;
  204. };
  205. ZeroClipboard.detectFlashSupport = function() {
  206. var hasFlash = false;
  207. try {
  208. if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) {
  209. hasFlash = true;
  210. }
  211. } catch (error) {
  212. if (navigator.mimeTypes["application/x-shockwave-flash"]) {
  213. hasFlash = true;
  214. }
  215. }
  216. return hasFlash;
  217. };
  218. var _bridge = function() {
  219. var client = ZeroClipboard.prototype._singleton;
  220. var container = document.getElementById("global-zeroclipboard-html-bridge");
  221. if (!container) {
  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="' + 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>';
  223. container = document.createElement("div");
  224. container.id = "global-zeroclipboard-html-bridge";
  225. container.setAttribute("class", "global-zeroclipboard-container");
  226. container.setAttribute("data-clipboard-ready", false);
  227. container.style.position = "absolute";
  228. container.style.left = "-9999px";
  229. container.style.top = "-9999px";
  230. container.style.width = "15px";
  231. container.style.height = "15px";
  232. container.style.zIndex = "9999";
  233. container.innerHTML = html;
  234. document.body.appendChild(container);
  235. }
  236. client.htmlBridge = container;
  237. client.flashBridge = document["global-zeroclipboard-flash-bridge"] || container.children[0].lastElementChild;
  238. };
  239. ZeroClipboard.prototype.resetBridge = function() {
  240. this.htmlBridge.style.left = "-9999px";
  241. this.htmlBridge.style.top = "-9999px";
  242. this.htmlBridge.removeAttribute("title");
  243. this.htmlBridge.removeAttribute("data-clipboard-text");
  244. _removeClass(currentElement, this.options.activeClass);
  245. currentElement = null;
  246. this.options.text = null;
  247. };
  248. ZeroClipboard.prototype.ready = function() {
  249. var ready = this.htmlBridge.getAttribute("data-clipboard-ready");
  250. return ready === "true" || ready === true;
  251. };
  252. ZeroClipboard.prototype.reposition = function() {
  253. if (!currentElement) return false;
  254. var pos = _getDOMObjectPosition(currentElement);
  255. var scroll = 0;
  256. if($('#myModal').hasClass('in')){
  257. var scroll = $(document).scrollTop();
  258. }
  259. this.htmlBridge.style.top = pos.top + scroll + "px";
  260. this.htmlBridge.style.left = pos.left + "px";
  261. this.htmlBridge.style.width = pos.width + "px";
  262. this.htmlBridge.style.height = pos.height + "px";
  263. this.htmlBridge.style.zIndex = pos.zIndex + 1;
  264. this.setSize(pos.width, pos.height);
  265. };
  266. ZeroClipboard.dispatch = function(eventName, args) {
  267. ZeroClipboard.prototype._singleton.receiveEvent(eventName, args);
  268. };
  269. ZeroClipboard.prototype.on = function(eventName, func) {
  270. var events = eventName.toString().split(/\s/g);
  271. for (var i = 0; i < events.length; i++) {
  272. eventName = events[i].toLowerCase().replace(/^on/, "");
  273. if (!this.handlers[eventName]) this.handlers[eventName] = func;
  274. }
  275. if (this.handlers.noflash && !ZeroClipboard.detectFlashSupport()) {
  276. this.receiveEvent("onNoFlash", null);
  277. }
  278. };
  279. ZeroClipboard.prototype.addEventListener = ZeroClipboard.prototype.on;
  280. ZeroClipboard.prototype.off = function(eventName, func) {
  281. var events = eventName.toString().split(/\s/g);
  282. for (var i = 0; i < events.length; i++) {
  283. eventName = events[i].toLowerCase().replace(/^on/, "");
  284. for (var event in this.handlers) {
  285. if (event === eventName && this.handlers[event] === func) {
  286. delete this.handlers[event];
  287. }
  288. }
  289. }
  290. };
  291. ZeroClipboard.prototype.removeEventListener = ZeroClipboard.prototype.off;
  292. ZeroClipboard.prototype.receiveEvent = function(eventName, args) {
  293. eventName = eventName.toString().toLowerCase().replace(/^on/, "");
  294. var element = currentElement;
  295. switch (eventName) {
  296. case "load":
  297. if (args && parseFloat(args.flashVersion.replace(",", ".").replace(/[^0-9\.]/gi, "")) < 10) {
  298. this.receiveEvent("onWrongFlash", {
  299. flashVersion: args.flashVersion
  300. });
  301. return;
  302. }
  303. this.htmlBridge.setAttribute("data-clipboard-ready", true);
  304. break;
  305. case "mouseover":
  306. _addClass(element, this.options.hoverClass);
  307. break;
  308. case "mouseout":
  309. _removeClass(element, this.options.hoverClass);
  310. this.resetBridge();
  311. break;
  312. case "mousedown":
  313. _addClass(element, this.options.activeClass);
  314. break;
  315. case "mouseup":
  316. _removeClass(element, this.options.activeClass);
  317. break;
  318. case "datarequested":
  319. var targetId = element.getAttribute("data-clipboard-target"), targetEl = !targetId ? null : document.getElementById(targetId);
  320. if (targetEl) {
  321. var textContent = targetEl.value || targetEl.textContent || targetEl.innerText;
  322. if (textContent) this.setText(textContent);
  323. } else {
  324. var defaultText = element.getAttribute("data-clipboard-text");
  325. if (defaultText) this.setText(defaultText);
  326. }
  327. break;
  328. case "complete":
  329. this.options.text = null;
  330. break;
  331. }
  332. if (this.handlers[eventName]) {
  333. var func = this.handlers[eventName];
  334. if (typeof func == "function") {
  335. func.call(element, this, args);
  336. } else if (typeof func == "string") {
  337. window[func].call(element, this, args);
  338. }
  339. }
  340. };
  341. ZeroClipboard.prototype.glue = function(elements) {
  342. elements = _prepGlue(elements);
  343. for (var i = 0; i < elements.length; i++) {
  344. if (_inArray(elements[i], gluedElements) == -1) {
  345. gluedElements.push(elements[i]);
  346. _addEventHandler(elements[i], "mouseover", _elementMouseOver);
  347. }
  348. }
  349. };
  350. ZeroClipboard.prototype.unglue = function(elements) {
  351. elements = _prepGlue(elements);
  352. for (var i = 0; i < elements.length; i++) {
  353. _removeEventHandler(elements[i], "mouseover", _elementMouseOver);
  354. var arrayIndex = _inArray(elements[i], gluedElements);
  355. if (arrayIndex != -1) gluedElements.splice(arrayIndex, 1);
  356. }
  357. };
  358. if (typeof module !== "undefined") {
  359. module.exports = ZeroClipboard;
  360. } else if (typeof define === "function" && define.amd) {
  361. define(function() {
  362. return ZeroClipboard;
  363. });
  364. } else {
  365. window.ZeroClipboard = ZeroClipboard;
  366. }
  367. })();
  368. },{}],2:[function(require,module,exports){
  369. var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/*!
  370. * zClip
  371. * Copyright (c) 2013 Terin Stock, SteamDev
  372. * Licensed MIT
  373. */
  374. /* global jQuery:true */
  375. 'use strict';
  376. var ZeroClipboard = global.ZeroClipboard = require('ZeroClipboard'),
  377. defaults = {
  378. path: 'ZeroClipboard.swf',
  379. copy: null,
  380. beforeCopy: null,
  381. afterCopy: null,
  382. clickAfter: true
  383. },
  384. unique = (function() {
  385. var count = 0;
  386. return function() {
  387. return count++;
  388. };
  389. }()),
  390. clients = {},
  391. clip,
  392. $ = jQuery;
  393. $.fn.zclip = function(options) {
  394. var settings,
  395. clientId;
  396. if ($.isPlainObject(options)) {
  397. settings = $.extend({}, defaults, options);
  398. clientId = unique();
  399. clients[clientId] = settings;
  400. this.data('zclip-client', clientId);
  401. if (clip) {
  402. clip.glue(this);
  403. } else {
  404. clip = new ZeroClipboard(this, {
  405. moviePath: settings.path,
  406. trustedDomains: [global.location.protocol + '//' + global.location.host],
  407. hoverClass: 'hover',
  408. activeClass: 'active'
  409. });
  410. }
  411. if ($.isFunction(settings.copy)) {
  412. this.on('zClip_copy', $.proxy(settings.copy, this));
  413. }
  414. if ($.isFunction(settings.beforeCopy)) {
  415. this.on('zClip_beforeCopy', $.proxy(settings.beforeCopy, this));
  416. }
  417. if ($.isFunction(settings.afterCopy)) {
  418. this.on('zClip_afterCopy', $.proxy(settings.afterCopy, this));
  419. }
  420. clip.on('mouseover', function() {
  421. var zclip = $(this);
  422. zclip.trigger('mouseenter');
  423. });
  424. clip.on('mouseout', function() {
  425. var zclip = $(this);
  426. zclip.trigger('mouseleave');
  427. });
  428. clip.on('mousedown', function() {
  429. var zclip = $(this);
  430. zclip.trigger('mousedown');
  431. });
  432. clip.on('load', function(client) {
  433. client.setHandCursor(settings.setHandCursor);
  434. });
  435. clip.on('complete', function(client, args) {
  436. var text = args.text,
  437. $el = $(this),
  438. settings = clients[$el.data('zclip-client')];
  439. if ($.isFunction(settings.afterCopy)) {
  440. $el.trigger('zClip_afterCopy', text);
  441. } else {
  442. if (text.length > 500) {
  443. text = text.substr(0, 500) + '…\n\n(' + (text.length - 500) + 'characters not shown)';
  444. }
  445. global.alert('Copied text to clipboard:\n\n'+args.text);
  446. }
  447. if (settings.clickAfter) {
  448. $el.trigger('click');
  449. }
  450. });
  451. clip.on('dataRequested', function(client) {
  452. var $el = $(this),
  453. settings = clients[$el.data('zclip-client')];
  454. $el.trigger('zClip_beforeCopy');
  455. if ($.isFunction(settings.copy)) {
  456. client.setText(String($el.triggerHandler('zClip_copy')));
  457. } else {
  458. client.setText(settings.copy);
  459. }
  460. });
  461. $(global).on('load resize', function() {
  462. clip.reposition();
  463. });
  464. } else if (clip && typeof options === 'string') {
  465. switch (options) {
  466. case 'remove':
  467. case 'hide':
  468. clip.unglue(this);
  469. break;
  470. case 'show':
  471. clip.glue(this);
  472. }
  473. }
  474. };
  475. },{"ZeroClipboard":1}]},{},[2])
  476. ;