血透系统PC前端

ZeroClipboard.js 42KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. /*!
  2. * ZeroClipboard
  3. * The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.
  4. * Copyright (c) 2014 Jon Rohan, James M. Greene
  5. * Licensed MIT
  6. * http://zeroclipboard.org/
  7. * v2.0.0-beta.5
  8. */
  9. (function(window) {
  10. "use strict";
  11. var _currentElement;
  12. var _flashState = {
  13. bridge: null,
  14. version: "0.0.0",
  15. pluginType: "unknown",
  16. disabled: null,
  17. outdated: null,
  18. unavailable: null,
  19. deactivated: null,
  20. overdue: null,
  21. ready: null
  22. };
  23. var _clipData = {};
  24. var _clipDataFormatMap = null;
  25. var _clientIdCounter = 0;
  26. var _clientMeta = {};
  27. var _elementIdCounter = 0;
  28. var _elementMeta = {};
  29. var _swfPath = function() {
  30. var i, jsDir, tmpJsPath, jsPath, swfPath = "ZeroClipboard.swf";
  31. if (!(document.currentScript && (jsPath = document.currentScript.src))) {
  32. var scripts = document.getElementsByTagName("script");
  33. if ("readyState" in scripts[0]) {
  34. for (i = scripts.length; i--; ) {
  35. if (scripts[i].readyState === "interactive" && (jsPath = scripts[i].src)) {
  36. break;
  37. }
  38. }
  39. } else if (document.readyState === "loading") {
  40. jsPath = scripts[scripts.length - 1].src;
  41. } else {
  42. for (i = scripts.length; i--; ) {
  43. tmpJsPath = scripts[i].src;
  44. if (!tmpJsPath) {
  45. jsDir = null;
  46. break;
  47. }
  48. tmpJsPath = tmpJsPath.split("#")[0].split("?")[0];
  49. tmpJsPath = tmpJsPath.slice(0, tmpJsPath.lastIndexOf("/") + 1);
  50. if (jsDir == null) {
  51. jsDir = tmpJsPath;
  52. } else if (jsDir !== tmpJsPath) {
  53. jsDir = null;
  54. break;
  55. }
  56. }
  57. if (jsDir !== null) {
  58. jsPath = jsDir;
  59. }
  60. }
  61. }
  62. if (jsPath) {
  63. jsPath = jsPath.split("#")[0].split("?")[0];
  64. swfPath = jsPath.slice(0, jsPath.lastIndexOf("/") + 1) + swfPath;
  65. }
  66. return swfPath;
  67. }();
  68. var _camelizeCssPropName = function() {
  69. var matcherRegex = /\-([a-z])/g, replacerFn = function(match, group) {
  70. return group.toUpperCase();
  71. };
  72. return function(prop) {
  73. return prop.replace(matcherRegex, replacerFn);
  74. };
  75. }();
  76. var _getStyle = function(el, prop) {
  77. var value, camelProp, tagName;
  78. if (window.getComputedStyle) {
  79. value = window.getComputedStyle(el, null).getPropertyValue(prop);
  80. } else {
  81. camelProp = _camelizeCssPropName(prop);
  82. if (el.currentStyle) {
  83. value = el.currentStyle[camelProp];
  84. } else {
  85. value = el.style[camelProp];
  86. }
  87. }
  88. if (prop === "cursor") {
  89. if (!value || value === "auto") {
  90. tagName = el.tagName.toLowerCase();
  91. if (tagName === "a") {
  92. return "pointer";
  93. }
  94. }
  95. }
  96. return value;
  97. };
  98. var _elementMouseOver = function(event) {
  99. if (!event) {
  100. event = window.event;
  101. }
  102. var target;
  103. if (this !== window) {
  104. target = this;
  105. } else if (event.target) {
  106. target = event.target;
  107. } else if (event.srcElement) {
  108. target = event.srcElement;
  109. }
  110. ZeroClipboard.activate(target);
  111. };
  112. var _addEventHandler = function(element, method, func) {
  113. if (!element || element.nodeType !== 1) {
  114. return;
  115. }
  116. if (element.addEventListener) {
  117. element.addEventListener(method, func, false);
  118. } else if (element.attachEvent) {
  119. element.attachEvent("on" + method, func);
  120. }
  121. };
  122. var _removeEventHandler = function(element, method, func) {
  123. if (!element || element.nodeType !== 1) {
  124. return;
  125. }
  126. if (element.removeEventListener) {
  127. element.removeEventListener(method, func, false);
  128. } else if (element.detachEvent) {
  129. element.detachEvent("on" + method, func);
  130. }
  131. };
  132. var _addClass = function(element, value) {
  133. if (!element || element.nodeType !== 1) {
  134. return element;
  135. }
  136. if (element.classList) {
  137. if (!element.classList.contains(value)) {
  138. element.classList.add(value);
  139. }
  140. return element;
  141. }
  142. if (value && typeof value === "string") {
  143. var classNames = (value || "").split(/\s+/);
  144. if (element.nodeType === 1) {
  145. if (!element.className) {
  146. element.className = value;
  147. } else {
  148. var className = " " + element.className + " ", setClass = element.className;
  149. for (var c = 0, cl = classNames.length; c < cl; c++) {
  150. if (className.indexOf(" " + classNames[c] + " ") < 0) {
  151. setClass += " " + classNames[c];
  152. }
  153. }
  154. element.className = setClass.replace(/^\s+|\s+$/g, "");
  155. }
  156. }
  157. }
  158. return element;
  159. };
  160. var _removeClass = function(element, value) {
  161. if (!element || element.nodeType !== 1) {
  162. return element;
  163. }
  164. if (element.classList) {
  165. if (element.classList.contains(value)) {
  166. element.classList.remove(value);
  167. }
  168. return element;
  169. }
  170. if (value && typeof value === "string" || value === undefined) {
  171. var classNames = (value || "").split(/\s+/);
  172. if (element.nodeType === 1 && element.className) {
  173. if (value) {
  174. var className = (" " + element.className + " ").replace(/[\n\t]/g, " ");
  175. for (var c = 0, cl = classNames.length; c < cl; c++) {
  176. className = className.replace(" " + classNames[c] + " ", " ");
  177. }
  178. element.className = className.replace(/^\s+|\s+$/g, "");
  179. } else {
  180. element.className = "";
  181. }
  182. }
  183. }
  184. return element;
  185. };
  186. var _getZoomFactor = function() {
  187. var rect, physicalWidth, logicalWidth, zoomFactor = 1;
  188. if (typeof document.body.getBoundingClientRect === "function") {
  189. rect = document.body.getBoundingClientRect();
  190. physicalWidth = rect.right - rect.left;
  191. logicalWidth = document.body.offsetWidth;
  192. zoomFactor = Math.round(physicalWidth / logicalWidth * 100) / 100;
  193. }
  194. return zoomFactor;
  195. };
  196. var _getDOMObjectPosition = function(obj, defaultZIndex) {
  197. var info = {
  198. left: 0,
  199. top: 0,
  200. width: 0,
  201. height: 0,
  202. zIndex: _getSafeZIndex(defaultZIndex) - 1
  203. };
  204. if (obj.getBoundingClientRect) {
  205. var rect = obj.getBoundingClientRect();
  206. var pageXOffset, pageYOffset, zoomFactor;
  207. if ("pageXOffset" in window && "pageYOffset" in window) {
  208. pageXOffset = window.pageXOffset;
  209. pageYOffset = window.pageYOffset;
  210. } else {
  211. zoomFactor = _getZoomFactor();
  212. pageXOffset = Math.round(document.documentElement.scrollLeft / zoomFactor);
  213. pageYOffset = Math.round(document.documentElement.scrollTop / zoomFactor);
  214. }
  215. var leftBorderWidth = document.documentElement.clientLeft || 0;
  216. var topBorderWidth = document.documentElement.clientTop || 0;
  217. info.left = rect.left + pageXOffset - leftBorderWidth;
  218. info.top = rect.top + pageYOffset - topBorderWidth;
  219. info.width = "width" in rect ? rect.width : rect.right - rect.left;
  220. info.height = "height" in rect ? rect.height : rect.bottom - rect.top;
  221. }
  222. return info;
  223. };
  224. var _cacheBust = function(path, options) {
  225. var cacheBust = options == null || options && options.cacheBust === true;
  226. if (cacheBust) {
  227. return (path.indexOf("?") === -1 ? "?" : "&") + "noCache=" + new Date().getTime();
  228. } else {
  229. return "";
  230. }
  231. };
  232. var _vars = function(options) {
  233. var i, len, domain, domains, str = "", trustedOriginsExpanded = [];
  234. if (options.trustedDomains) {
  235. if (typeof options.trustedDomains === "string") {
  236. domains = [ options.trustedDomains ];
  237. } else if (typeof options.trustedDomains === "object" && "length" in options.trustedDomains) {
  238. domains = options.trustedDomains;
  239. }
  240. }
  241. if (domains && domains.length) {
  242. for (i = 0, len = domains.length; i < len; i++) {
  243. if (domains.hasOwnProperty(i) && domains[i] && typeof domains[i] === "string") {
  244. domain = _extractDomain(domains[i]);
  245. if (!domain) {
  246. continue;
  247. }
  248. if (domain === "*") {
  249. trustedOriginsExpanded = [ domain ];
  250. break;
  251. }
  252. trustedOriginsExpanded.push.apply(trustedOriginsExpanded, [ domain, "//" + domain, window.location.protocol + "//" + domain ]);
  253. }
  254. }
  255. }
  256. if (trustedOriginsExpanded.length) {
  257. str += "trustedOrigins=" + encodeURIComponent(trustedOriginsExpanded.join(","));
  258. }
  259. if (options.forceEnhancedClipboard === true) {
  260. str += (str ? "&" : "") + "forceEnhancedClipboard=true";
  261. }
  262. return str;
  263. };
  264. var _inArray = function(elem, array, fromIndex) {
  265. if (typeof array.indexOf === "function") {
  266. return array.indexOf(elem, fromIndex);
  267. }
  268. var i, len = array.length;
  269. if (typeof fromIndex === "undefined") {
  270. fromIndex = 0;
  271. } else if (fromIndex < 0) {
  272. fromIndex = len + fromIndex;
  273. }
  274. for (i = fromIndex; i < len; i++) {
  275. if (array.hasOwnProperty(i) && array[i] === elem) {
  276. return i;
  277. }
  278. }
  279. return -1;
  280. };
  281. var _prepClip = function(elements) {
  282. if (typeof elements === "string") {
  283. throw new TypeError("ZeroClipboard doesn't accept query strings.");
  284. }
  285. return typeof elements.length !== "number" ? [ elements ] : elements;
  286. };
  287. var _dispatchCallback = function(func, context, args, async) {
  288. if (async) {
  289. window.setTimeout(function() {
  290. func.apply(context, args);
  291. }, 0);
  292. } else {
  293. func.apply(context, args);
  294. }
  295. };
  296. var _getSafeZIndex = function(val) {
  297. var zIndex, tmp;
  298. if (val) {
  299. if (typeof val === "number" && val > 0) {
  300. zIndex = val;
  301. } else if (typeof val === "string" && (tmp = parseInt(val, 10)) && !isNaN(tmp) && tmp > 0) {
  302. zIndex = tmp;
  303. }
  304. }
  305. if (!zIndex) {
  306. if (typeof _globalConfig.zIndex === "number" && _globalConfig.zIndex > 0) {
  307. zIndex = _globalConfig.zIndex;
  308. } else if (typeof _globalConfig.zIndex === "string" && (tmp = parseInt(_globalConfig.zIndex, 10)) && !isNaN(tmp) && tmp > 0) {
  309. zIndex = tmp;
  310. }
  311. }
  312. return zIndex || 0;
  313. };
  314. var _extend = function() {
  315. var i, len, arg, prop, src, copy, target = arguments[0] || {};
  316. for (i = 1, len = arguments.length; i < len; i++) {
  317. if ((arg = arguments[i]) != null) {
  318. for (prop in arg) {
  319. if (arg.hasOwnProperty(prop)) {
  320. src = target[prop];
  321. copy = arg[prop];
  322. if (target === copy) {
  323. continue;
  324. }
  325. if (copy !== undefined) {
  326. target[prop] = copy;
  327. }
  328. }
  329. }
  330. }
  331. }
  332. return target;
  333. };
  334. var _extractDomain = function(originOrUrl) {
  335. if (originOrUrl == null || originOrUrl === "") {
  336. return null;
  337. }
  338. originOrUrl = originOrUrl.replace(/^\s+|\s+$/g, "");
  339. if (originOrUrl === "") {
  340. return null;
  341. }
  342. var protocolIndex = originOrUrl.indexOf("//");
  343. originOrUrl = protocolIndex === -1 ? originOrUrl : originOrUrl.slice(protocolIndex + 2);
  344. var pathIndex = originOrUrl.indexOf("/");
  345. originOrUrl = pathIndex === -1 ? originOrUrl : protocolIndex === -1 || pathIndex === 0 ? null : originOrUrl.slice(0, pathIndex);
  346. if (originOrUrl && originOrUrl.slice(-4).toLowerCase() === ".swf") {
  347. return null;
  348. }
  349. return originOrUrl || null;
  350. };
  351. var _determineScriptAccess = function() {
  352. var _extractAllDomains = function(origins, resultsArray) {
  353. var i, len, tmp;
  354. if (origins == null || resultsArray[0] === "*") {
  355. return;
  356. }
  357. if (typeof origins === "string") {
  358. origins = [ origins ];
  359. }
  360. if (!(typeof origins === "object" && typeof origins.length === "number")) {
  361. return;
  362. }
  363. for (i = 0, len = origins.length; i < len; i++) {
  364. if (origins.hasOwnProperty(i) && (tmp = _extractDomain(origins[i]))) {
  365. if (tmp === "*") {
  366. resultsArray.length = 0;
  367. resultsArray.push("*");
  368. break;
  369. }
  370. if (_inArray(tmp, resultsArray) === -1) {
  371. resultsArray.push(tmp);
  372. }
  373. }
  374. }
  375. };
  376. return function(currentDomain, configOptions) {
  377. var swfDomain = _extractDomain(configOptions.swfPath);
  378. if (swfDomain === null) {
  379. swfDomain = currentDomain;
  380. }
  381. var trustedDomains = [];
  382. _extractAllDomains(configOptions.trustedOrigins, trustedDomains);
  383. _extractAllDomains(configOptions.trustedDomains, trustedDomains);
  384. var len = trustedDomains.length;
  385. if (len > 0) {
  386. if (len === 1 && trustedDomains[0] === "*") {
  387. return "always";
  388. }
  389. if (_inArray(currentDomain, trustedDomains) !== -1) {
  390. if (len === 1 && currentDomain === swfDomain) {
  391. return "sameDomain";
  392. }
  393. return "always";
  394. }
  395. }
  396. return "never";
  397. };
  398. }();
  399. var _objectKeys = function(obj) {
  400. if (obj == null) {
  401. return [];
  402. }
  403. if (Object.keys) {
  404. return Object.keys(obj);
  405. }
  406. var keys = [];
  407. for (var prop in obj) {
  408. if (obj.hasOwnProperty(prop)) {
  409. keys.push(prop);
  410. }
  411. }
  412. return keys;
  413. };
  414. var _deleteOwnProperties = function(obj) {
  415. if (obj) {
  416. for (var prop in obj) {
  417. if (obj.hasOwnProperty(prop)) {
  418. delete obj[prop];
  419. }
  420. }
  421. }
  422. return obj;
  423. };
  424. var _safeActiveElement = function() {
  425. try {
  426. return document.activeElement;
  427. } catch (err) {}
  428. return null;
  429. };
  430. var _pick = function(obj, keys) {
  431. var newObj = {};
  432. for (var i = 0, len = keys.length; i < len; i++) {
  433. if (keys[i] in obj) {
  434. newObj[keys[i]] = obj[keys[i]];
  435. }
  436. }
  437. return newObj;
  438. };
  439. var _omit = function(obj, keys) {
  440. var newObj = {};
  441. for (var prop in obj) {
  442. if (_inArray(prop, keys) === -1) {
  443. newObj[prop] = obj[prop];
  444. }
  445. }
  446. return newObj;
  447. };
  448. var _mapClipDataToFlash = function(clipData) {
  449. var newClipData = {}, formatMap = {};
  450. if (!(typeof clipData === "object" && clipData)) {
  451. return;
  452. }
  453. for (var dataFormat in clipData) {
  454. if (dataFormat && clipData.hasOwnProperty(dataFormat) && typeof clipData[dataFormat] === "string" && clipData[dataFormat]) {
  455. switch (dataFormat.toLowerCase()) {
  456. case "text/plain":
  457. case "text":
  458. case "air:text":
  459. case "flash:text":
  460. newClipData.text = clipData[dataFormat];
  461. formatMap.text = dataFormat;
  462. break;
  463. case "text/html":
  464. case "html":
  465. case "air:html":
  466. case "flash:html":
  467. newClipData.html = clipData[dataFormat];
  468. formatMap.html = dataFormat;
  469. break;
  470. case "application/rtf":
  471. case "text/rtf":
  472. case "rtf":
  473. case "richtext":
  474. case "air:rtf":
  475. case "flash:rtf":
  476. newClipData.rtf = clipData[dataFormat];
  477. formatMap.rtf = dataFormat;
  478. break;
  479. default:
  480. break;
  481. }
  482. }
  483. }
  484. return {
  485. data: newClipData,
  486. formatMap: formatMap
  487. };
  488. };
  489. var _mapClipResultsFromFlash = function(clipResults, formatMap) {
  490. if (!(typeof clipResults === "object" && clipResults && typeof formatMap === "object" && formatMap)) {
  491. return clipResults;
  492. }
  493. var newResults = {};
  494. for (var prop in clipResults) {
  495. if (clipResults.hasOwnProperty(prop)) {
  496. if (prop !== "success" && prop !== "data") {
  497. newResults[prop] = clipResults[prop];
  498. continue;
  499. }
  500. newResults[prop] = {};
  501. var tmpHash = clipResults[prop];
  502. for (var dataFormat in tmpHash) {
  503. if (dataFormat && tmpHash.hasOwnProperty(dataFormat) && formatMap.hasOwnProperty(dataFormat)) {
  504. newResults[prop][formatMap[dataFormat]] = tmpHash[dataFormat];
  505. }
  506. }
  507. }
  508. }
  509. return newResults;
  510. };
  511. var _args = function(arraySlice) {
  512. return function(args) {
  513. return arraySlice.call(args, 0);
  514. };
  515. }(window.Array.prototype.slice);
  516. var _detectFlashSupport = function() {
  517. var plugin, ax, mimeType, hasFlash = false, isActiveX = false, isPPAPI = false, flashVersion = "";
  518. function parseFlashVersion(desc) {
  519. var matches = desc.match(/[\d]+/g);
  520. matches.length = 3;
  521. return matches.join(".");
  522. }
  523. function isPepperFlash(flashPlayerFileName) {
  524. return !!flashPlayerFileName && (flashPlayerFileName = flashPlayerFileName.toLowerCase()) && (/^(pepflashplayer\.dll|libpepflashplayer\.so|pepperflashplayer\.plugin)$/.test(flashPlayerFileName) || flashPlayerFileName.slice(-13) === "chrome.plugin");
  525. }
  526. function inspectPlugin(plugin) {
  527. if (plugin) {
  528. hasFlash = true;
  529. if (plugin.version) {
  530. flashVersion = parseFlashVersion(plugin.version);
  531. }
  532. if (!flashVersion && plugin.description) {
  533. flashVersion = parseFlashVersion(plugin.description);
  534. }
  535. if (plugin.filename) {
  536. isPPAPI = isPepperFlash(plugin.filename);
  537. }
  538. }
  539. }
  540. if (navigator.plugins && navigator.plugins.length) {
  541. plugin = navigator.plugins["Shockwave Flash"];
  542. inspectPlugin(plugin);
  543. if (navigator.plugins["Shockwave Flash 2.0"]) {
  544. hasFlash = true;
  545. flashVersion = "2.0.0.11";
  546. }
  547. } else if (navigator.mimeTypes && navigator.mimeTypes.length) {
  548. mimeType = navigator.mimeTypes["application/x-shockwave-flash"];
  549. plugin = mimeType && mimeType.enabledPlugin;
  550. inspectPlugin(plugin);
  551. } else if (typeof ActiveXObject !== "undefined") {
  552. isActiveX = true;
  553. try {
  554. ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
  555. hasFlash = true;
  556. flashVersion = parseFlashVersion(ax.GetVariable("$version"));
  557. } catch (e1) {
  558. try {
  559. ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
  560. hasFlash = true;
  561. flashVersion = "6.0.21";
  562. } catch (e2) {
  563. try {
  564. ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
  565. hasFlash = true;
  566. flashVersion = parseFlashVersion(ax.GetVariable("$version"));
  567. } catch (e3) {
  568. isActiveX = false;
  569. }
  570. }
  571. }
  572. }
  573. _flashState.disabled = hasFlash !== true;
  574. _flashState.outdated = flashVersion && parseFloat(flashVersion) < 11;
  575. _flashState.version = flashVersion || "0.0.0";
  576. _flashState.pluginType = isPPAPI ? "pepper" : isActiveX ? "activex" : hasFlash ? "netscape" : "unknown";
  577. };
  578. _detectFlashSupport();
  579. var ZeroClipboard = function(elements) {
  580. if (!(this instanceof ZeroClipboard)) {
  581. return new ZeroClipboard(elements);
  582. }
  583. this.id = "" + _clientIdCounter++;
  584. _clientMeta[this.id] = {
  585. instance: this,
  586. elements: [],
  587. handlers: {}
  588. };
  589. if (elements) {
  590. this.clip(elements);
  591. }
  592. if (typeof _flashState.ready !== "boolean") {
  593. _flashState.ready = false;
  594. }
  595. if (!ZeroClipboard.isFlashUnusable() && _flashState.bridge === null) {
  596. var _client = this;
  597. var maxWait = _globalConfig.flashLoadTimeout;
  598. if (typeof maxWait === "number" && maxWait >= 0) {
  599. setTimeout(function() {
  600. if (typeof _flashState.deactivated !== "boolean") {
  601. _flashState.deactivated = true;
  602. }
  603. if (_flashState.deactivated === true) {
  604. ZeroClipboard.emit({
  605. type: "error",
  606. name: "flash-deactivated",
  607. client: _client
  608. });
  609. }
  610. }, maxWait);
  611. }
  612. _flashState.overdue = false;
  613. _bridge();
  614. }
  615. };
  616. ZeroClipboard.prototype.setText = function(text) {
  617. ZeroClipboard.setData("text/plain", text);
  618. return this;
  619. };
  620. ZeroClipboard.prototype.setHtml = function(html) {
  621. ZeroClipboard.setData("text/html", html);
  622. return this;
  623. };
  624. ZeroClipboard.prototype.setRichText = function(richText) {
  625. ZeroClipboard.setData("application/rtf", richText);
  626. return this;
  627. };
  628. ZeroClipboard.prototype.setData = function() {
  629. ZeroClipboard.setData.apply(ZeroClipboard, _args(arguments));
  630. return this;
  631. };
  632. ZeroClipboard.prototype.clearData = function() {
  633. ZeroClipboard.clearData.apply(ZeroClipboard, _args(arguments));
  634. return this;
  635. };
  636. ZeroClipboard.prototype.setSize = function(width, height) {
  637. _setSize(width, height);
  638. return this;
  639. };
  640. var _setHandCursor = function(enabled) {
  641. if (_flashState.ready === true && _flashState.bridge && typeof _flashState.bridge.setHandCursor === "function") {
  642. _flashState.bridge.setHandCursor(enabled);
  643. } else {
  644. _flashState.ready = false;
  645. }
  646. };
  647. ZeroClipboard.prototype.destroy = function() {
  648. this.unclip();
  649. this.off();
  650. delete _clientMeta[this.id];
  651. };
  652. var _getAllClients = function() {
  653. var i, len, client, clients = [], clientIds = _objectKeys(_clientMeta);
  654. for (i = 0, len = clientIds.length; i < len; i++) {
  655. client = _clientMeta[clientIds[i]].instance;
  656. if (client && client instanceof ZeroClipboard) {
  657. clients.push(client);
  658. }
  659. }
  660. return clients;
  661. };
  662. ZeroClipboard.version = "2.0.0-beta.5";
  663. var _globalConfig = {
  664. swfPath: _swfPath,
  665. trustedDomains: window.location.host ? [ window.location.host ] : [],
  666. cacheBust: true,
  667. forceHandCursor: false,
  668. forceEnhancedClipboard: false,
  669. zIndex: 999999999,
  670. debug: false,
  671. title: null,
  672. autoActivate: true,
  673. flashLoadTimeout: 3e4
  674. };
  675. ZeroClipboard.isFlashUnusable = function() {
  676. return !!(_flashState.disabled || _flashState.outdated || _flashState.unavailable || _flashState.deactivated);
  677. };
  678. ZeroClipboard.config = function(options) {
  679. if (typeof options === "object" && options !== null) {
  680. _extend(_globalConfig, options);
  681. }
  682. if (typeof options === "string" && options) {
  683. if (_globalConfig.hasOwnProperty(options)) {
  684. return _globalConfig[options];
  685. }
  686. return;
  687. }
  688. var copy = {};
  689. for (var prop in _globalConfig) {
  690. if (_globalConfig.hasOwnProperty(prop)) {
  691. if (typeof _globalConfig[prop] === "object" && _globalConfig[prop] !== null) {
  692. if ("length" in _globalConfig[prop]) {
  693. copy[prop] = _globalConfig[prop].slice(0);
  694. } else {
  695. copy[prop] = _extend({}, _globalConfig[prop]);
  696. }
  697. } else {
  698. copy[prop] = _globalConfig[prop];
  699. }
  700. }
  701. }
  702. return copy;
  703. };
  704. ZeroClipboard.destroy = function() {
  705. ZeroClipboard.deactivate();
  706. for (var clientId in _clientMeta) {
  707. if (_clientMeta.hasOwnProperty(clientId) && _clientMeta[clientId]) {
  708. var client = _clientMeta[clientId].instance;
  709. if (client && typeof client.destroy === "function") {
  710. client.destroy();
  711. }
  712. }
  713. }
  714. var flashBridge = _flashState.bridge;
  715. if (flashBridge) {
  716. var htmlBridge = _getHtmlBridge(flashBridge);
  717. if (htmlBridge) {
  718. if (_flashState.pluginType === "activex" && "readyState" in flashBridge) {
  719. flashBridge.style.display = "none";
  720. (function removeSwfFromIE() {
  721. if (flashBridge.readyState === 4) {
  722. for (var prop in flashBridge) {
  723. if (typeof flashBridge[prop] === "function") {
  724. flashBridge[prop] = null;
  725. }
  726. }
  727. flashBridge.parentNode.removeChild(flashBridge);
  728. if (htmlBridge.parentNode) {
  729. htmlBridge.parentNode.removeChild(htmlBridge);
  730. }
  731. } else {
  732. setTimeout(removeSwfFromIE, 10);
  733. }
  734. })();
  735. } else {
  736. flashBridge.parentNode.removeChild(flashBridge);
  737. if (htmlBridge.parentNode) {
  738. htmlBridge.parentNode.removeChild(htmlBridge);
  739. }
  740. }
  741. }
  742. _flashState.ready = null;
  743. _flashState.bridge = null;
  744. _flashState.deactivated = null;
  745. }
  746. ZeroClipboard.clearData();
  747. };
  748. ZeroClipboard.activate = function(element) {
  749. if (_currentElement) {
  750. _removeClass(_currentElement, _globalConfig.hoverClass);
  751. _removeClass(_currentElement, _globalConfig.activeClass);
  752. }
  753. _currentElement = element;
  754. _addClass(element, _globalConfig.hoverClass);
  755. _reposition();
  756. var newTitle = _globalConfig.title || element.getAttribute("title");
  757. if (newTitle) {
  758. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  759. if (htmlBridge) {
  760. htmlBridge.setAttribute("title", newTitle);
  761. }
  762. }
  763. var useHandCursor = _globalConfig.forceHandCursor === true || _getStyle(element, "cursor") === "pointer";
  764. _setHandCursor(useHandCursor);
  765. };
  766. ZeroClipboard.deactivate = function() {
  767. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  768. if (htmlBridge) {
  769. htmlBridge.removeAttribute("title");
  770. htmlBridge.style.left = "0px";
  771. htmlBridge.style.top = "-9999px";
  772. _setSize(1, 1);
  773. }
  774. if (_currentElement) {
  775. _removeClass(_currentElement, _globalConfig.hoverClass);
  776. _removeClass(_currentElement, _globalConfig.activeClass);
  777. _currentElement = null;
  778. }
  779. };
  780. ZeroClipboard.state = function() {
  781. return {
  782. browser: _pick(window.navigator, [ "userAgent", "platform", "appName" ]),
  783. flash: _omit(_flashState, [ "bridge" ]),
  784. zeroclipboard: {
  785. version: ZeroClipboard.version,
  786. config: ZeroClipboard.config()
  787. }
  788. };
  789. };
  790. ZeroClipboard.setData = function(format, data) {
  791. var dataObj;
  792. if (typeof format === "object" && format && typeof data === "undefined") {
  793. dataObj = format;
  794. ZeroClipboard.clearData();
  795. } else if (typeof format === "string" && format) {
  796. dataObj = {};
  797. dataObj[format] = data;
  798. } else {
  799. return;
  800. }
  801. for (var dataFormat in dataObj) {
  802. if (dataFormat && dataObj.hasOwnProperty(dataFormat) && typeof dataObj[dataFormat] === "string" && dataObj[dataFormat]) {
  803. _clipData[dataFormat] = dataObj[dataFormat];
  804. }
  805. }
  806. };
  807. ZeroClipboard.clearData = function(format) {
  808. if (typeof format === "undefined") {
  809. _deleteOwnProperties(_clipData);
  810. _clipDataFormatMap = null;
  811. } else if (typeof format === "string" && _clipData.hasOwnProperty(format)) {
  812. delete _clipData[format];
  813. }
  814. };
  815. var _bridge = function() {
  816. var flashBridge, len;
  817. var container = document.getElementById("global-zeroclipboard-html-bridge");
  818. if (!container) {
  819. var allowScriptAccess = _determineScriptAccess(window.location.host, _globalConfig);
  820. var allowNetworking = allowScriptAccess === "never" ? "none" : "all";
  821. var flashvars = _vars(_globalConfig);
  822. var swfUrl = _globalConfig.swfPath + _cacheBust(_globalConfig.swfPath, _globalConfig);
  823. container = _createHtmlBridge();
  824. var divToBeReplaced = document.createElement("div");
  825. container.appendChild(divToBeReplaced);
  826. document.body.appendChild(container);
  827. var tmpDiv = document.createElement("div");
  828. var oldIE = _flashState.pluginType === "activex";
  829. tmpDiv.innerHTML = '<object id="global-zeroclipboard-flash-bridge" name="global-zeroclipboard-flash-bridge" ' + 'width="100%" height="100%" ' + (oldIE ? 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' : 'type="application/x-shockwave-flash" data="' + swfUrl + '"') + ">" + (oldIE ? '<param name="movie" value="' + swfUrl + '"/>' : "") + '<param name="allowScriptAccess" value="' + allowScriptAccess + '"/>' + '<param name="allowNetworking" value="' + allowNetworking + '"/>' + '<param name="menu" value="false"/>' + '<param name="wmode" value="transparent"/>' + '<param name="flashvars" value="' + flashvars + '"/>' + "</object>";
  830. flashBridge = tmpDiv.firstChild;
  831. tmpDiv = null;
  832. flashBridge.ZeroClipboard = ZeroClipboard;
  833. container.replaceChild(flashBridge, divToBeReplaced);
  834. }
  835. if (!flashBridge) {
  836. flashBridge = document["global-zeroclipboard-flash-bridge"];
  837. if (flashBridge && (len = flashBridge.length)) {
  838. flashBridge = flashBridge[len - 1];
  839. }
  840. if (!flashBridge) {
  841. flashBridge = container.firstChild;
  842. }
  843. }
  844. _flashState.bridge = flashBridge || null;
  845. };
  846. var _createHtmlBridge = function() {
  847. var container = document.createElement("div");
  848. container.id = "global-zeroclipboard-html-bridge";
  849. container.className = "global-zeroclipboard-container";
  850. container.style.position = "absolute";
  851. container.style.left = "0px";
  852. container.style.top = "-9999px";
  853. container.style.width = "1px";
  854. container.style.height = "1px";
  855. container.style.zIndex = "" + _getSafeZIndex(_globalConfig.zIndex);
  856. return container;
  857. };
  858. var _getHtmlBridge = function(flashBridge) {
  859. var htmlBridge = flashBridge && flashBridge.parentNode;
  860. while (htmlBridge && htmlBridge.nodeName === "OBJECT" && htmlBridge.parentNode) {
  861. htmlBridge = htmlBridge.parentNode;
  862. }
  863. return htmlBridge || null;
  864. };
  865. var _reposition = function() {
  866. if (_currentElement) {
  867. var pos = _getDOMObjectPosition(_currentElement, _globalConfig.zIndex);
  868. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  869. if (htmlBridge) {
  870. htmlBridge.style.top = pos.top + "px";
  871. htmlBridge.style.left = pos.left + "px";
  872. htmlBridge.style.width = pos.width + "px";
  873. htmlBridge.style.height = pos.height + "px";
  874. htmlBridge.style.zIndex = pos.zIndex + 1;
  875. }
  876. _setSize(pos.width, pos.height);
  877. }
  878. };
  879. var _setSize = function(width, height) {
  880. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  881. if (htmlBridge) {
  882. htmlBridge.style.width = width + "px";
  883. htmlBridge.style.height = height + "px";
  884. }
  885. };
  886. ZeroClipboard.emit = function(event) {
  887. var eventType, eventObj, performCallbackAsync, clients, i, len, eventCopy, returnVal, tmp;
  888. if (typeof event === "string" && event) {
  889. eventType = event;
  890. }
  891. if (typeof event === "object" && event && typeof event.type === "string" && event.type) {
  892. eventType = event.type;
  893. eventObj = event;
  894. }
  895. if (!eventType) {
  896. return;
  897. }
  898. event = _createEvent(eventType, eventObj);
  899. _preprocessEvent(event);
  900. if (event.type === "ready" && _flashState.overdue === true) {
  901. return ZeroClipboard.emit({
  902. type: "error",
  903. name: "flash-overdue"
  904. });
  905. }
  906. performCallbackAsync = !/^(before)?copy$/.test(event.type);
  907. if (event.client) {
  908. _dispatchClientCallbacks.call(event.client, event, performCallbackAsync);
  909. } else {
  910. clients = event.target && event.target !== window && _globalConfig.autoActivate === true ? _getAllClientsClippedToElement(event.target) : _getAllClients();
  911. for (i = 0, len = clients.length; i < len; i++) {
  912. eventCopy = _extend({}, event, {
  913. client: clients[i]
  914. });
  915. _dispatchClientCallbacks.call(clients[i], eventCopy, performCallbackAsync);
  916. }
  917. }
  918. if (event.type === "copy") {
  919. tmp = _mapClipDataToFlash(_clipData);
  920. returnVal = tmp.data;
  921. _clipDataFormatMap = tmp.formatMap;
  922. }
  923. return returnVal;
  924. };
  925. var _dispatchClientCallbacks = function(event, async) {
  926. var handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers[event.type];
  927. if (handlers && handlers.length) {
  928. var i, len, func, context, originalContext = this;
  929. for (i = 0, len = handlers.length; i < len; i++) {
  930. func = handlers[i];
  931. context = originalContext;
  932. if (typeof func === "string" && typeof window[func] === "function") {
  933. func = window[func];
  934. }
  935. if (typeof func === "object" && func && typeof func.handleEvent === "function") {
  936. context = func;
  937. func = func.handleEvent;
  938. }
  939. if (typeof func === "function") {
  940. _dispatchCallback(func, context, [ event ], async);
  941. }
  942. }
  943. }
  944. return this;
  945. };
  946. var _eventMessages = {
  947. ready: "Flash communication is established",
  948. error: {
  949. "flash-disabled": "Flash is disabled or not installed",
  950. "flash-outdated": "Flash is too outdated to support ZeroClipboard",
  951. "flash-unavailable": "Flash is unable to communicate bidirectionally with JavaScript",
  952. "flash-deactivated": "Flash is too outdated for your browser and/or is configured as click-to-activate",
  953. "flash-overdue": "Flash communication was established but NOT within the acceptable time limit"
  954. }
  955. };
  956. var _createEvent = function(eventType, event) {
  957. if (!(eventType || event && event.type)) {
  958. return;
  959. }
  960. event = event || {};
  961. eventType = (eventType || event.type).toLowerCase();
  962. _extend(event, {
  963. type: eventType,
  964. target: event.target || _currentElement || null,
  965. relatedTarget: event.relatedTarget || null,
  966. currentTarget: _flashState && _flashState.bridge || null
  967. });
  968. var msg = _eventMessages[event.type];
  969. if (event.type === "error" && event.name && msg) {
  970. msg = msg[event.name];
  971. }
  972. if (msg) {
  973. event.message = msg;
  974. }
  975. if (event.type === "ready") {
  976. _extend(event, {
  977. target: null,
  978. version: _flashState.version
  979. });
  980. }
  981. if (event.type === "error") {
  982. event.target = null;
  983. if (/^flash-(outdated|unavailable|deactivated|overdue)$/.test(event.name)) {
  984. _extend(event, {
  985. version: _flashState.version,
  986. minimumVersion: "11.0.0"
  987. });
  988. }
  989. }
  990. if (event.type === "copy") {
  991. event.clipboardData = {
  992. setData: ZeroClipboard.setData,
  993. clearData: ZeroClipboard.clearData
  994. };
  995. }
  996. if (event.type === "aftercopy") {
  997. event = _mapClipResultsFromFlash(event, _clipDataFormatMap);
  998. }
  999. if (event.target && !event.relatedTarget) {
  1000. event.relatedTarget = _getRelatedTarget(event.target);
  1001. }
  1002. return event;
  1003. };
  1004. var _getRelatedTarget = function(targetEl) {
  1005. var relatedTargetId = targetEl && targetEl.getAttribute && targetEl.getAttribute("data-clipboard-target");
  1006. return relatedTargetId ? document.getElementById(relatedTargetId) : null;
  1007. };
  1008. var _preprocessEvent = function(event) {
  1009. var element = event.target || _currentElement;
  1010. switch (event.type) {
  1011. case "error":
  1012. if (_inArray(event.name, [ "flash-disabled", "flash-outdated", "flash-deactivated", "flash-overdue" ])) {
  1013. _extend(_flashState, {
  1014. disabled: event.name === "flash-disabled",
  1015. outdated: event.name === "flash-outdated",
  1016. unavailable: event.name === "flash-unavailable",
  1017. deactivated: event.name === "flash-deactivated",
  1018. overdue: event.name === "flash-overdue",
  1019. ready: false
  1020. });
  1021. }
  1022. break;
  1023. case "ready":
  1024. var wasDeactivated = _flashState.deactivated === true;
  1025. _extend(_flashState, {
  1026. disabled: false,
  1027. outdated: false,
  1028. unavailable: false,
  1029. deactivated: false,
  1030. overdue: wasDeactivated,
  1031. ready: !wasDeactivated
  1032. });
  1033. break;
  1034. case "copy":
  1035. var textContent, htmlContent, targetEl = event.relatedTarget;
  1036. if (!(_clipData["text/html"] || _clipData["text/plain"]) && targetEl && (htmlContent = targetEl.value || targetEl.outerHTML || targetEl.innerHTML) && (textContent = targetEl.value || targetEl.textContent || targetEl.innerText)) {
  1037. event.clipboardData.clearData();
  1038. event.clipboardData.setData("text/plain", textContent);
  1039. if (htmlContent !== textContent) {
  1040. event.clipboardData.setData("text/html", htmlContent);
  1041. }
  1042. } else if (!_clipData["text/plain"] && event.target && (textContent = event.target.getAttribute("data-clipboard-text"))) {
  1043. event.clipboardData.clearData();
  1044. event.clipboardData.setData("text/plain", textContent);
  1045. }
  1046. break;
  1047. case "aftercopy":
  1048. ZeroClipboard.clearData();
  1049. if (element && element !== _safeActiveElement() && element.focus) {
  1050. element.focus();
  1051. }
  1052. break;
  1053. case "mouseover":
  1054. _addClass(element, _globalConfig.hoverClass);
  1055. break;
  1056. case "mouseout":
  1057. if (_globalConfig.autoActivate === true) {
  1058. ZeroClipboard.deactivate();
  1059. }
  1060. break;
  1061. case "mousedown":
  1062. _addClass(element, _globalConfig.activeClass);
  1063. break;
  1064. case "mouseup":
  1065. _removeClass(element, _globalConfig.activeClass);
  1066. break;
  1067. }
  1068. };
  1069. ZeroClipboard.prototype.on = function(eventName, func) {
  1070. var i, len, events, added = {}, handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers;
  1071. if (typeof eventName === "string" && eventName) {
  1072. events = eventName.toLowerCase().split(/\s+/);
  1073. } else if (typeof eventName === "object" && eventName && typeof func === "undefined") {
  1074. for (i in eventName) {
  1075. if (eventName.hasOwnProperty(i) && typeof i === "string" && i && typeof eventName[i] === "function") {
  1076. this.on(i, eventName[i]);
  1077. }
  1078. }
  1079. }
  1080. if (events && events.length) {
  1081. for (i = 0, len = events.length; i < len; i++) {
  1082. eventName = events[i].replace(/^on/, "");
  1083. added[eventName] = true;
  1084. if (!handlers[eventName]) {
  1085. handlers[eventName] = [];
  1086. }
  1087. handlers[eventName].push(func);
  1088. }
  1089. if (added.ready && _flashState.ready) {
  1090. ZeroClipboard.emit({
  1091. type: "ready",
  1092. client: this
  1093. });
  1094. }
  1095. if (added.error) {
  1096. var errorTypes = [ "disabled", "outdated", "unavailable", "deactivated", "overdue" ];
  1097. for (i = 0, len = errorTypes.length; i < len; i++) {
  1098. if (_flashState[errorTypes[i]]) {
  1099. ZeroClipboard.emit({
  1100. type: "error",
  1101. name: "flash-" + errorTypes[i],
  1102. client: this
  1103. });
  1104. break;
  1105. }
  1106. }
  1107. }
  1108. }
  1109. return this;
  1110. };
  1111. ZeroClipboard.prototype.off = function(eventName, func) {
  1112. var i, len, foundIndex, events, perEventHandlers, handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers;
  1113. if (arguments.length === 0) {
  1114. events = _objectKeys(handlers);
  1115. } else if (typeof eventName === "string" && eventName) {
  1116. events = eventName.split(/\s+/);
  1117. } else if (typeof eventName === "object" && eventName && typeof func === "undefined") {
  1118. for (i in eventName) {
  1119. if (eventName.hasOwnProperty(i) && typeof i === "string" && i && typeof eventName[i] === "function") {
  1120. this.off(i, eventName[i]);
  1121. }
  1122. }
  1123. }
  1124. if (events && events.length) {
  1125. for (i = 0, len = events.length; i < len; i++) {
  1126. eventName = events[i].toLowerCase().replace(/^on/, "");
  1127. perEventHandlers = handlers[eventName];
  1128. if (perEventHandlers && perEventHandlers.length) {
  1129. if (func) {
  1130. foundIndex = _inArray(func, perEventHandlers);
  1131. while (foundIndex !== -1) {
  1132. perEventHandlers.splice(foundIndex, 1);
  1133. foundIndex = _inArray(func, perEventHandlers, foundIndex);
  1134. }
  1135. } else {
  1136. handlers[eventName].length = 0;
  1137. }
  1138. }
  1139. }
  1140. }
  1141. return this;
  1142. };
  1143. ZeroClipboard.prototype.handlers = function(eventName) {
  1144. var prop, copy = null, handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers;
  1145. if (handlers) {
  1146. if (typeof eventName === "string" && eventName) {
  1147. return handlers[eventName] ? handlers[eventName].slice(0) : null;
  1148. }
  1149. copy = {};
  1150. for (prop in handlers) {
  1151. if (handlers.hasOwnProperty(prop) && handlers[prop]) {
  1152. copy[prop] = handlers[prop].slice(0);
  1153. }
  1154. }
  1155. }
  1156. return copy;
  1157. };
  1158. ZeroClipboard.prototype.clip = function(elements) {
  1159. elements = _prepClip(elements);
  1160. for (var i = 0; i < elements.length; i++) {
  1161. if (elements.hasOwnProperty(i) && elements[i] && elements[i].nodeType === 1) {
  1162. if (!elements[i].zcClippingId) {
  1163. elements[i].zcClippingId = "zcClippingId_" + _elementIdCounter++;
  1164. _elementMeta[elements[i].zcClippingId] = [ this.id ];
  1165. if (_globalConfig.autoActivate === true) {
  1166. _addEventHandler(elements[i], "mouseover", _elementMouseOver);
  1167. }
  1168. } else if (_inArray(this.id, _elementMeta[elements[i].zcClippingId]) === -1) {
  1169. _elementMeta[elements[i].zcClippingId].push(this.id);
  1170. }
  1171. var clippedElements = _clientMeta[this.id].elements;
  1172. if (_inArray(elements[i], clippedElements) === -1) {
  1173. clippedElements.push(elements[i]);
  1174. }
  1175. }
  1176. }
  1177. return this;
  1178. };
  1179. ZeroClipboard.prototype.unclip = function(elements) {
  1180. var meta = _clientMeta[this.id];
  1181. if (!meta) {
  1182. return this;
  1183. }
  1184. var clippedElements = meta.elements;
  1185. var arrayIndex;
  1186. if (typeof elements === "undefined") {
  1187. elements = clippedElements.slice(0);
  1188. } else {
  1189. elements = _prepClip(elements);
  1190. }
  1191. for (var i = elements.length; i--; ) {
  1192. if (elements.hasOwnProperty(i) && elements[i] && elements[i].nodeType === 1) {
  1193. arrayIndex = 0;
  1194. while ((arrayIndex = _inArray(elements[i], clippedElements, arrayIndex)) !== -1) {
  1195. clippedElements.splice(arrayIndex, 1);
  1196. }
  1197. var clientIds = _elementMeta[elements[i].zcClippingId];
  1198. if (clientIds) {
  1199. arrayIndex = 0;
  1200. while ((arrayIndex = _inArray(this.id, clientIds, arrayIndex)) !== -1) {
  1201. clientIds.splice(arrayIndex, 1);
  1202. }
  1203. if (clientIds.length === 0) {
  1204. if (_globalConfig.autoActivate === true) {
  1205. _removeEventHandler(elements[i], "mouseover", _elementMouseOver);
  1206. }
  1207. delete elements[i].zcClippingId;
  1208. }
  1209. }
  1210. }
  1211. }
  1212. return this;
  1213. };
  1214. ZeroClipboard.prototype.elements = function() {
  1215. var meta = _clientMeta[this.id];
  1216. return meta && meta.elements ? meta.elements.slice(0) : [];
  1217. };
  1218. var _getAllClientsClippedToElement = function(element) {
  1219. var elementMetaId, clientIds, i, len, client, clients = [];
  1220. if (element && element.nodeType === 1 && (elementMetaId = element.zcClippingId) && _elementMeta.hasOwnProperty(elementMetaId)) {
  1221. clientIds = _elementMeta[elementMetaId];
  1222. if (clientIds && clientIds.length) {
  1223. for (i = 0, len = clientIds.length; i < len; i++) {
  1224. client = _clientMeta[clientIds[i]].instance;
  1225. if (client && client instanceof ZeroClipboard) {
  1226. clients.push(client);
  1227. }
  1228. }
  1229. }
  1230. }
  1231. return clients;
  1232. };
  1233. _globalConfig.hoverClass = "zeroclipboard-is-hover";
  1234. _globalConfig.activeClass = "zeroclipboard-is-active";
  1235. if (typeof define === "function" && define.amd) {
  1236. define(function() {
  1237. return ZeroClipboard;
  1238. });
  1239. } else if (typeof module === "object" && module && typeof module.exports === "object" && module.exports) {
  1240. module.exports = ZeroClipboard;
  1241. } else {
  1242. window.ZeroClipboard = ZeroClipboard;
  1243. }
  1244. })(function() {
  1245. return this;
  1246. }());