ZeroClipboard.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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. }
  429. return null;
  430. };
  431. var _pick = function (obj, keys) {
  432. var newObj = {};
  433. for (var i = 0, len = keys.length; i < len; i++) {
  434. if (keys[i] in obj) {
  435. newObj[keys[i]] = obj[keys[i]];
  436. }
  437. }
  438. return newObj;
  439. };
  440. var _omit = function (obj, keys) {
  441. var newObj = {};
  442. for (var prop in obj) {
  443. if (_inArray(prop, keys) === -1) {
  444. newObj[prop] = obj[prop];
  445. }
  446. }
  447. return newObj;
  448. };
  449. var _mapClipDataToFlash = function (clipData) {
  450. var newClipData = {}, formatMap = {};
  451. if (!(typeof clipData === "object" && clipData)) {
  452. return;
  453. }
  454. for (var dataFormat in clipData) {
  455. if (dataFormat && clipData.hasOwnProperty(dataFormat) && typeof clipData[dataFormat] === "string" && clipData[dataFormat]) {
  456. switch (dataFormat.toLowerCase()) {
  457. case "text/plain":
  458. case "text":
  459. case "air:text":
  460. case "flash:text":
  461. newClipData.text = clipData[dataFormat];
  462. formatMap.text = dataFormat;
  463. break;
  464. case "text/html":
  465. case "html":
  466. case "air:html":
  467. case "flash:html":
  468. newClipData.html = clipData[dataFormat];
  469. formatMap.html = dataFormat;
  470. break;
  471. case "application/rtf":
  472. case "text/rtf":
  473. case "rtf":
  474. case "richtext":
  475. case "air:rtf":
  476. case "flash:rtf":
  477. newClipData.rtf = clipData[dataFormat];
  478. formatMap.rtf = dataFormat;
  479. break;
  480. default:
  481. break;
  482. }
  483. }
  484. }
  485. return {
  486. data: newClipData,
  487. formatMap: formatMap
  488. };
  489. };
  490. var _mapClipResultsFromFlash = function (clipResults, formatMap) {
  491. if (!(typeof clipResults === "object" && clipResults && typeof formatMap === "object" && formatMap)) {
  492. return clipResults;
  493. }
  494. var newResults = {};
  495. for (var prop in clipResults) {
  496. if (clipResults.hasOwnProperty(prop)) {
  497. if (prop !== "success" && prop !== "data") {
  498. newResults[prop] = clipResults[prop];
  499. continue;
  500. }
  501. newResults[prop] = {};
  502. var tmpHash = clipResults[prop];
  503. for (var dataFormat in tmpHash) {
  504. if (dataFormat && tmpHash.hasOwnProperty(dataFormat) && formatMap.hasOwnProperty(dataFormat)) {
  505. newResults[prop][formatMap[dataFormat]] = tmpHash[dataFormat];
  506. }
  507. }
  508. }
  509. }
  510. return newResults;
  511. };
  512. var _args = function (arraySlice) {
  513. return function (args) {
  514. return arraySlice.call(args, 0);
  515. };
  516. }(window.Array.prototype.slice);
  517. var _detectFlashSupport = function () {
  518. var plugin, ax, mimeType, hasFlash = false, isActiveX = false, isPPAPI = false, flashVersion = "";
  519. function parseFlashVersion(desc) {
  520. var matches = desc.match(/[\d]+/g);
  521. matches.length = 3;
  522. return matches.join(".");
  523. }
  524. function isPepperFlash(flashPlayerFileName) {
  525. return !!flashPlayerFileName && (flashPlayerFileName = flashPlayerFileName.toLowerCase()) && (/^(pepflashplayer\.dll|libpepflashplayer\.so|pepperflashplayer\.plugin)$/.test(flashPlayerFileName) || flashPlayerFileName.slice(-13) === "chrome.plugin");
  526. }
  527. function inspectPlugin(plugin) {
  528. if (plugin) {
  529. hasFlash = true;
  530. if (plugin.version) {
  531. flashVersion = parseFlashVersion(plugin.version);
  532. }
  533. if (!flashVersion && plugin.description) {
  534. flashVersion = parseFlashVersion(plugin.description);
  535. }
  536. if (plugin.filename) {
  537. isPPAPI = isPepperFlash(plugin.filename);
  538. }
  539. }
  540. }
  541. if (navigator.plugins && navigator.plugins.length) {
  542. plugin = navigator.plugins["Shockwave Flash"];
  543. inspectPlugin(plugin);
  544. if (navigator.plugins["Shockwave Flash 2.0"]) {
  545. hasFlash = true;
  546. flashVersion = "2.0.0.11";
  547. }
  548. } else if (navigator.mimeTypes && navigator.mimeTypes.length) {
  549. mimeType = navigator.mimeTypes["application/x-shockwave-flash"];
  550. plugin = mimeType && mimeType.enabledPlugin;
  551. inspectPlugin(plugin);
  552. } else if (typeof ActiveXObject !== "undefined") {
  553. isActiveX = true;
  554. try {
  555. ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
  556. hasFlash = true;
  557. flashVersion = parseFlashVersion(ax.GetVariable("$version"));
  558. } catch (e1) {
  559. try {
  560. ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
  561. hasFlash = true;
  562. flashVersion = "6.0.21";
  563. } catch (e2) {
  564. try {
  565. ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
  566. hasFlash = true;
  567. flashVersion = parseFlashVersion(ax.GetVariable("$version"));
  568. } catch (e3) {
  569. isActiveX = false;
  570. }
  571. }
  572. }
  573. }
  574. _flashState.disabled = hasFlash !== true;
  575. _flashState.outdated = flashVersion && parseFloat(flashVersion) < 11;
  576. _flashState.version = flashVersion || "0.0.0";
  577. _flashState.pluginType = isPPAPI ? "pepper" : isActiveX ? "activex" : hasFlash ? "netscape" : "unknown";
  578. };
  579. _detectFlashSupport();
  580. var ZeroClipboard = function (elements) {
  581. if (!(this instanceof ZeroClipboard)) {
  582. return new ZeroClipboard(elements);
  583. }
  584. this.id = "" + _clientIdCounter++;
  585. _clientMeta[this.id] = {
  586. instance: this,
  587. elements: [],
  588. handlers: {}
  589. };
  590. if (elements) {
  591. this.clip(elements);
  592. }
  593. if (typeof _flashState.ready !== "boolean") {
  594. _flashState.ready = false;
  595. }
  596. if (!ZeroClipboard.isFlashUnusable() && _flashState.bridge === null) {
  597. var _client = this;
  598. var maxWait = _globalConfig.flashLoadTimeout;
  599. if (typeof maxWait === "number" && maxWait >= 0) {
  600. setTimeout(function () {
  601. if (typeof _flashState.deactivated !== "boolean") {
  602. _flashState.deactivated = true;
  603. }
  604. if (_flashState.deactivated === true) {
  605. ZeroClipboard.emit({
  606. type: "error",
  607. name: "flash-deactivated",
  608. client: _client
  609. });
  610. }
  611. }, maxWait);
  612. }
  613. _flashState.overdue = false;
  614. _bridge();
  615. }
  616. };
  617. ZeroClipboard.prototype.setText = function (text) {
  618. ZeroClipboard.setData("text/plain", text);
  619. return this;
  620. };
  621. ZeroClipboard.prototype.setHtml = function (html) {
  622. ZeroClipboard.setData("text/html", html);
  623. return this;
  624. };
  625. ZeroClipboard.prototype.setRichText = function (richText) {
  626. ZeroClipboard.setData("application/rtf", richText);
  627. return this;
  628. };
  629. ZeroClipboard.prototype.setData = function () {
  630. ZeroClipboard.setData.apply(ZeroClipboard, _args(arguments));
  631. return this;
  632. };
  633. ZeroClipboard.prototype.clearData = function () {
  634. ZeroClipboard.clearData.apply(ZeroClipboard, _args(arguments));
  635. return this;
  636. };
  637. ZeroClipboard.prototype.setSize = function (width, height) {
  638. _setSize(width, height);
  639. return this;
  640. };
  641. var _setHandCursor = function (enabled) {
  642. if (_flashState.ready === true && _flashState.bridge && typeof _flashState.bridge.setHandCursor === "function") {
  643. _flashState.bridge.setHandCursor(enabled);
  644. } else {
  645. _flashState.ready = false;
  646. }
  647. };
  648. ZeroClipboard.prototype.destroy = function () {
  649. this.unclip();
  650. this.off();
  651. delete _clientMeta[this.id];
  652. };
  653. var _getAllClients = function () {
  654. var i, len, client, clients = [], clientIds = _objectKeys(_clientMeta);
  655. for (i = 0, len = clientIds.length; i < len; i++) {
  656. client = _clientMeta[clientIds[i]].instance;
  657. if (client && client instanceof ZeroClipboard) {
  658. clients.push(client);
  659. }
  660. }
  661. return clients;
  662. };
  663. ZeroClipboard.version = "2.0.0-beta.5";
  664. var _globalConfig = {
  665. swfPath: _swfPath,
  666. trustedDomains: window.location.host ? [window.location.host] : [],
  667. cacheBust: true,
  668. forceHandCursor: false,
  669. forceEnhancedClipboard: false,
  670. zIndex: 999999999,
  671. debug: false,
  672. title: null,
  673. autoActivate: true,
  674. flashLoadTimeout: 3e4
  675. };
  676. ZeroClipboard.isFlashUnusable = function () {
  677. return !!(_flashState.disabled || _flashState.outdated || _flashState.unavailable || _flashState.deactivated);
  678. };
  679. ZeroClipboard.config = function (options) {
  680. if (typeof options === "object" && options !== null) {
  681. _extend(_globalConfig, options);
  682. }
  683. if (typeof options === "string" && options) {
  684. if (_globalConfig.hasOwnProperty(options)) {
  685. return _globalConfig[options];
  686. }
  687. return;
  688. }
  689. var copy = {};
  690. for (var prop in _globalConfig) {
  691. if (_globalConfig.hasOwnProperty(prop)) {
  692. if (typeof _globalConfig[prop] === "object" && _globalConfig[prop] !== null) {
  693. if ("length" in _globalConfig[prop]) {
  694. copy[prop] = _globalConfig[prop].slice(0);
  695. } else {
  696. copy[prop] = _extend({}, _globalConfig[prop]);
  697. }
  698. } else {
  699. copy[prop] = _globalConfig[prop];
  700. }
  701. }
  702. }
  703. return copy;
  704. };
  705. ZeroClipboard.destroy = function () {
  706. ZeroClipboard.deactivate();
  707. for (var clientId in _clientMeta) {
  708. if (_clientMeta.hasOwnProperty(clientId) && _clientMeta[clientId]) {
  709. var client = _clientMeta[clientId].instance;
  710. if (client && typeof client.destroy === "function") {
  711. client.destroy();
  712. }
  713. }
  714. }
  715. var flashBridge = _flashState.bridge;
  716. if (flashBridge) {
  717. var htmlBridge = _getHtmlBridge(flashBridge);
  718. if (htmlBridge) {
  719. if (_flashState.pluginType === "activex" && "readyState" in flashBridge) {
  720. flashBridge.style.display = "none";
  721. (function removeSwfFromIE() {
  722. if (flashBridge.readyState === 4) {
  723. for (var prop in flashBridge) {
  724. if (typeof flashBridge[prop] === "function") {
  725. flashBridge[prop] = null;
  726. }
  727. }
  728. flashBridge.parentNode.removeChild(flashBridge);
  729. if (htmlBridge.parentNode) {
  730. htmlBridge.parentNode.removeChild(htmlBridge);
  731. }
  732. } else {
  733. setTimeout(removeSwfFromIE, 10);
  734. }
  735. })();
  736. } else {
  737. flashBridge.parentNode.removeChild(flashBridge);
  738. if (htmlBridge.parentNode) {
  739. htmlBridge.parentNode.removeChild(htmlBridge);
  740. }
  741. }
  742. }
  743. _flashState.ready = null;
  744. _flashState.bridge = null;
  745. _flashState.deactivated = null;
  746. }
  747. ZeroClipboard.clearData();
  748. };
  749. ZeroClipboard.activate = function (element) {
  750. if (_currentElement) {
  751. _removeClass(_currentElement, _globalConfig.hoverClass);
  752. _removeClass(_currentElement, _globalConfig.activeClass);
  753. }
  754. _currentElement = element;
  755. _addClass(element, _globalConfig.hoverClass);
  756. _reposition();
  757. var newTitle = _globalConfig.title || element.getAttribute("title");
  758. if (newTitle) {
  759. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  760. if (htmlBridge) {
  761. htmlBridge.setAttribute("title", newTitle);
  762. }
  763. }
  764. var useHandCursor = _globalConfig.forceHandCursor === true || _getStyle(element, "cursor") === "pointer";
  765. _setHandCursor(useHandCursor);
  766. };
  767. ZeroClipboard.deactivate = function () {
  768. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  769. if (htmlBridge) {
  770. htmlBridge.removeAttribute("title");
  771. htmlBridge.style.left = "0px";
  772. htmlBridge.style.top = "-9999px";
  773. _setSize(1, 1);
  774. }
  775. if (_currentElement) {
  776. _removeClass(_currentElement, _globalConfig.hoverClass);
  777. _removeClass(_currentElement, _globalConfig.activeClass);
  778. _currentElement = null;
  779. }
  780. };
  781. ZeroClipboard.state = function () {
  782. return {
  783. browser: _pick(window.navigator, ["userAgent", "platform", "appName"]),
  784. flash: _omit(_flashState, ["bridge"]),
  785. zeroclipboard: {
  786. version: ZeroClipboard.version,
  787. config: ZeroClipboard.config()
  788. }
  789. };
  790. };
  791. ZeroClipboard.setData = function (format, data) {
  792. var dataObj;
  793. if (typeof format === "object" && format && typeof data === "undefined") {
  794. dataObj = format;
  795. ZeroClipboard.clearData();
  796. } else if (typeof format === "string" && format) {
  797. dataObj = {};
  798. dataObj[format] = data;
  799. } else {
  800. return;
  801. }
  802. for (var dataFormat in dataObj) {
  803. if (dataFormat && dataObj.hasOwnProperty(dataFormat) && typeof dataObj[dataFormat] === "string" && dataObj[dataFormat]) {
  804. _clipData[dataFormat] = dataObj[dataFormat];
  805. }
  806. }
  807. };
  808. ZeroClipboard.clearData = function (format) {
  809. if (typeof format === "undefined") {
  810. _deleteOwnProperties(_clipData);
  811. _clipDataFormatMap = null;
  812. } else if (typeof format === "string" && _clipData.hasOwnProperty(format)) {
  813. delete _clipData[format];
  814. }
  815. };
  816. var _bridge = function () {
  817. var flashBridge, len;
  818. var container = document.getElementById("global-zeroclipboard-html-bridge");
  819. if (!container) {
  820. var allowScriptAccess = _determineScriptAccess(window.location.host, _globalConfig);
  821. var allowNetworking = allowScriptAccess === "never" ? "none" : "all";
  822. var flashvars = _vars(_globalConfig);
  823. var swfUrl = _globalConfig.swfPath + _cacheBust(_globalConfig.swfPath, _globalConfig);
  824. container = _createHtmlBridge();
  825. var divToBeReplaced = document.createElement("div");
  826. container.appendChild(divToBeReplaced);
  827. document.body.appendChild(container);
  828. var tmpDiv = document.createElement("div");
  829. var oldIE = _flashState.pluginType === "activex";
  830. 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>";
  831. flashBridge = tmpDiv.firstChild;
  832. tmpDiv = null;
  833. flashBridge.ZeroClipboard = ZeroClipboard;
  834. container.replaceChild(flashBridge, divToBeReplaced);
  835. }
  836. if (!flashBridge) {
  837. flashBridge = document["global-zeroclipboard-flash-bridge"];
  838. if (flashBridge && (len = flashBridge.length)) {
  839. flashBridge = flashBridge[len - 1];
  840. }
  841. if (!flashBridge) {
  842. flashBridge = container.firstChild;
  843. }
  844. }
  845. _flashState.bridge = flashBridge || null;
  846. };
  847. var _createHtmlBridge = function () {
  848. var container = document.createElement("div");
  849. container.id = "global-zeroclipboard-html-bridge";
  850. container.className = "global-zeroclipboard-container";
  851. container.style.position = "absolute";
  852. container.style.left = "0px";
  853. container.style.top = "-9999px";
  854. container.style.width = "1px";
  855. container.style.height = "1px";
  856. container.style.zIndex = "" + _getSafeZIndex(_globalConfig.zIndex);
  857. return container;
  858. };
  859. var _getHtmlBridge = function (flashBridge) {
  860. var htmlBridge = flashBridge && flashBridge.parentNode;
  861. while (htmlBridge && htmlBridge.nodeName === "OBJECT" && htmlBridge.parentNode) {
  862. htmlBridge = htmlBridge.parentNode;
  863. }
  864. return htmlBridge || null;
  865. };
  866. var _reposition = function () {
  867. if (_currentElement) {
  868. var pos = _getDOMObjectPosition(_currentElement, _globalConfig.zIndex);
  869. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  870. if (htmlBridge) {
  871. htmlBridge.style.top = pos.top + "px";
  872. htmlBridge.style.left = pos.left + "px";
  873. htmlBridge.style.width = pos.width + "px";
  874. htmlBridge.style.height = pos.height + "px";
  875. htmlBridge.style.zIndex = pos.zIndex + 1;
  876. }
  877. _setSize(pos.width, pos.height);
  878. }
  879. };
  880. var _setSize = function (width, height) {
  881. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  882. if (htmlBridge) {
  883. htmlBridge.style.width = width + "px";
  884. htmlBridge.style.height = height + "px";
  885. }
  886. };
  887. ZeroClipboard.emit = function (event) {
  888. var eventType, eventObj, performCallbackAsync, clients, i, len, eventCopy, returnVal, tmp;
  889. if (typeof event === "string" && event) {
  890. eventType = event;
  891. }
  892. if (typeof event === "object" && event && typeof event.type === "string" && event.type) {
  893. eventType = event.type;
  894. eventObj = event;
  895. }
  896. if (!eventType) {
  897. return;
  898. }
  899. event = _createEvent(eventType, eventObj);
  900. _preprocessEvent(event);
  901. if (event.type === "ready" && _flashState.overdue === true) {
  902. return ZeroClipboard.emit({
  903. type: "error",
  904. name: "flash-overdue"
  905. });
  906. }
  907. performCallbackAsync = !/^(before)?copy$/.test(event.type);
  908. if (event.client) {
  909. _dispatchClientCallbacks.call(event.client, event, performCallbackAsync);
  910. } else {
  911. clients = event.target && event.target !== window && _globalConfig.autoActivate === true ? _getAllClientsClippedToElement(event.target) : _getAllClients();
  912. for (i = 0, len = clients.length; i < len; i++) {
  913. eventCopy = _extend({}, event, {
  914. client: clients[i]
  915. });
  916. _dispatchClientCallbacks.call(clients[i], eventCopy, performCallbackAsync);
  917. }
  918. }
  919. if (event.type === "copy") {
  920. tmp = _mapClipDataToFlash(_clipData);
  921. returnVal = tmp.data;
  922. _clipDataFormatMap = tmp.formatMap;
  923. }
  924. return returnVal;
  925. };
  926. var _dispatchClientCallbacks = function (event, async) {
  927. var handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers[event.type];
  928. if (handlers && handlers.length) {
  929. var i, len, func, context, originalContext = this;
  930. for (i = 0, len = handlers.length; i < len; i++) {
  931. func = handlers[i];
  932. context = originalContext;
  933. if (typeof func === "string" && typeof window[func] === "function") {
  934. func = window[func];
  935. }
  936. if (typeof func === "object" && func && typeof func.handleEvent === "function") {
  937. context = func;
  938. func = func.handleEvent;
  939. }
  940. if (typeof func === "function") {
  941. _dispatchCallback(func, context, [event], async);
  942. }
  943. }
  944. }
  945. return this;
  946. };
  947. var _eventMessages = {
  948. ready: "Flash communication is established",
  949. error: {
  950. "flash-disabled": "Flash is disabled or not installed",
  951. "flash-outdated": "Flash is too outdated to support ZeroClipboard",
  952. "flash-unavailable": "Flash is unable to communicate bidirectionally with JavaScript",
  953. "flash-deactivated": "Flash is too outdated for your browser and/or is configured as click-to-activate",
  954. "flash-overdue": "Flash communication was established but NOT within the acceptable time limit"
  955. }
  956. };
  957. var _createEvent = function (eventType, event) {
  958. if (!(eventType || event && event.type)) {
  959. return;
  960. }
  961. event = event || {};
  962. eventType = (eventType || event.type).toLowerCase();
  963. _extend(event, {
  964. type: eventType,
  965. target: event.target || _currentElement || null,
  966. relatedTarget: event.relatedTarget || null,
  967. currentTarget: _flashState && _flashState.bridge || null
  968. });
  969. var msg = _eventMessages[event.type];
  970. if (event.type === "error" && event.name && msg) {
  971. msg = msg[event.name];
  972. }
  973. if (msg) {
  974. event.message = msg;
  975. }
  976. if (event.type === "ready") {
  977. _extend(event, {
  978. target: null,
  979. version: _flashState.version
  980. });
  981. }
  982. if (event.type === "error") {
  983. event.target = null;
  984. if (/^flash-(outdated|unavailable|deactivated|overdue)$/.test(event.name)) {
  985. _extend(event, {
  986. version: _flashState.version,
  987. minimumVersion: "11.0.0"
  988. });
  989. }
  990. }
  991. if (event.type === "copy") {
  992. event.clipboardData = {
  993. setData: ZeroClipboard.setData,
  994. clearData: ZeroClipboard.clearData
  995. };
  996. }
  997. if (event.type === "aftercopy") {
  998. event = _mapClipResultsFromFlash(event, _clipDataFormatMap);
  999. }
  1000. if (event.target && !event.relatedTarget) {
  1001. event.relatedTarget = _getRelatedTarget(event.target);
  1002. }
  1003. return event;
  1004. };
  1005. var _getRelatedTarget = function (targetEl) {
  1006. var relatedTargetId = targetEl && targetEl.getAttribute && targetEl.getAttribute("data-clipboard-target");
  1007. return relatedTargetId ? document.getElementById(relatedTargetId) : null;
  1008. };
  1009. var _preprocessEvent = function (event) {
  1010. var element = event.target || _currentElement;
  1011. switch (event.type) {
  1012. case "error":
  1013. if (_inArray(event.name, ["flash-disabled", "flash-outdated", "flash-deactivated", "flash-overdue"])) {
  1014. _extend(_flashState, {
  1015. disabled: event.name === "flash-disabled",
  1016. outdated: event.name === "flash-outdated",
  1017. unavailable: event.name === "flash-unavailable",
  1018. deactivated: event.name === "flash-deactivated",
  1019. overdue: event.name === "flash-overdue",
  1020. ready: false
  1021. });
  1022. }
  1023. break;
  1024. case "ready":
  1025. var wasDeactivated = _flashState.deactivated === true;
  1026. _extend(_flashState, {
  1027. disabled: false,
  1028. outdated: false,
  1029. unavailable: false,
  1030. deactivated: false,
  1031. overdue: wasDeactivated,
  1032. ready: !wasDeactivated
  1033. });
  1034. break;
  1035. case "copy":
  1036. var textContent, htmlContent, targetEl = event.relatedTarget;
  1037. if (!(_clipData["text/html"] || _clipData["text/plain"]) && targetEl && (htmlContent = targetEl.value || targetEl.outerHTML || targetEl.innerHTML) && (textContent = targetEl.value || targetEl.textContent || targetEl.innerText)) {
  1038. event.clipboardData.clearData();
  1039. event.clipboardData.setData("text/plain", textContent);
  1040. if (htmlContent !== textContent) {
  1041. event.clipboardData.setData("text/html", htmlContent);
  1042. }
  1043. } else if (!_clipData["text/plain"] && event.target && (textContent = event.target.getAttribute("data-clipboard-text"))) {
  1044. event.clipboardData.clearData();
  1045. event.clipboardData.setData("text/plain", textContent);
  1046. }
  1047. break;
  1048. case "aftercopy":
  1049. ZeroClipboard.clearData();
  1050. if (element && element !== _safeActiveElement() && element.focus) {
  1051. element.focus();
  1052. }
  1053. break;
  1054. case "mouseover":
  1055. _addClass(element, _globalConfig.hoverClass);
  1056. break;
  1057. case "mouseout":
  1058. if (_globalConfig.autoActivate === true) {
  1059. ZeroClipboard.deactivate();
  1060. }
  1061. break;
  1062. case "mousedown":
  1063. _addClass(element, _globalConfig.activeClass);
  1064. break;
  1065. case "mouseup":
  1066. _removeClass(element, _globalConfig.activeClass);
  1067. break;
  1068. }
  1069. };
  1070. ZeroClipboard.prototype.on = function (eventName, func) {
  1071. var i, len, events, added = {}, handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers;
  1072. if (typeof eventName === "string" && eventName) {
  1073. events = eventName.toLowerCase().split(/\s+/);
  1074. } else if (typeof eventName === "object" && eventName && typeof func === "undefined") {
  1075. for (i in eventName) {
  1076. if (eventName.hasOwnProperty(i) && typeof i === "string" && i && typeof eventName[i] === "function") {
  1077. this.on(i, eventName[i]);
  1078. }
  1079. }
  1080. }
  1081. if (events && events.length) {
  1082. for (i = 0, len = events.length; i < len; i++) {
  1083. eventName = events[i].replace(/^on/, "");
  1084. added[eventName] = true;
  1085. if (!handlers[eventName]) {
  1086. handlers[eventName] = [];
  1087. }
  1088. handlers[eventName].push(func);
  1089. }
  1090. if (added.ready && _flashState.ready) {
  1091. ZeroClipboard.emit({
  1092. type: "ready",
  1093. client: this
  1094. });
  1095. }
  1096. if (added.error) {
  1097. var errorTypes = ["disabled", "outdated", "unavailable", "deactivated", "overdue"];
  1098. for (i = 0, len = errorTypes.length; i < len; i++) {
  1099. if (_flashState[errorTypes[i]]) {
  1100. ZeroClipboard.emit({
  1101. type: "error",
  1102. name: "flash-" + errorTypes[i],
  1103. client: this
  1104. });
  1105. break;
  1106. }
  1107. }
  1108. }
  1109. }
  1110. return this;
  1111. };
  1112. ZeroClipboard.prototype.off = function (eventName, func) {
  1113. var i, len, foundIndex, events, perEventHandlers,
  1114. handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers;
  1115. if (arguments.length === 0) {
  1116. events = _objectKeys(handlers);
  1117. } else if (typeof eventName === "string" && eventName) {
  1118. events = eventName.split(/\s+/);
  1119. } else if (typeof eventName === "object" && eventName && typeof func === "undefined") {
  1120. for (i in eventName) {
  1121. if (eventName.hasOwnProperty(i) && typeof i === "string" && i && typeof eventName[i] === "function") {
  1122. this.off(i, eventName[i]);
  1123. }
  1124. }
  1125. }
  1126. if (events && events.length) {
  1127. for (i = 0, len = events.length; i < len; i++) {
  1128. eventName = events[i].toLowerCase().replace(/^on/, "");
  1129. perEventHandlers = handlers[eventName];
  1130. if (perEventHandlers && perEventHandlers.length) {
  1131. if (func) {
  1132. foundIndex = _inArray(func, perEventHandlers);
  1133. while (foundIndex !== -1) {
  1134. perEventHandlers.splice(foundIndex, 1);
  1135. foundIndex = _inArray(func, perEventHandlers, foundIndex);
  1136. }
  1137. } else {
  1138. handlers[eventName].length = 0;
  1139. }
  1140. }
  1141. }
  1142. }
  1143. return this;
  1144. };
  1145. ZeroClipboard.prototype.handlers = function (eventName) {
  1146. var prop, copy = null, handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers;
  1147. if (handlers) {
  1148. if (typeof eventName === "string" && eventName) {
  1149. return handlers[eventName] ? handlers[eventName].slice(0) : null;
  1150. }
  1151. copy = {};
  1152. for (prop in handlers) {
  1153. if (handlers.hasOwnProperty(prop) && handlers[prop]) {
  1154. copy[prop] = handlers[prop].slice(0);
  1155. }
  1156. }
  1157. }
  1158. return copy;
  1159. };
  1160. ZeroClipboard.prototype.clip = function (elements) {
  1161. elements = _prepClip(elements);
  1162. for (var i = 0; i < elements.length; i++) {
  1163. if (elements.hasOwnProperty(i) && elements[i] && elements[i].nodeType === 1) {
  1164. if (!elements[i].zcClippingId) {
  1165. elements[i].zcClippingId = "zcClippingId_" + _elementIdCounter++;
  1166. _elementMeta[elements[i].zcClippingId] = [this.id];
  1167. if (_globalConfig.autoActivate === true) {
  1168. _addEventHandler(elements[i], "mouseover", _elementMouseOver);
  1169. }
  1170. } else if (_inArray(this.id, _elementMeta[elements[i].zcClippingId]) === -1) {
  1171. _elementMeta[elements[i].zcClippingId].push(this.id);
  1172. }
  1173. var clippedElements = _clientMeta[this.id].elements;
  1174. if (_inArray(elements[i], clippedElements) === -1) {
  1175. clippedElements.push(elements[i]);
  1176. }
  1177. }
  1178. }
  1179. return this;
  1180. };
  1181. ZeroClipboard.prototype.unclip = function (elements) {
  1182. var meta = _clientMeta[this.id];
  1183. if (!meta) {
  1184. return this;
  1185. }
  1186. var clippedElements = meta.elements;
  1187. var arrayIndex;
  1188. if (typeof elements === "undefined") {
  1189. elements = clippedElements.slice(0);
  1190. } else {
  1191. elements = _prepClip(elements);
  1192. }
  1193. for (var i = elements.length; i--;) {
  1194. if (elements.hasOwnProperty(i) && elements[i] && elements[i].nodeType === 1) {
  1195. arrayIndex = 0;
  1196. while ((arrayIndex = _inArray(elements[i], clippedElements, arrayIndex)) !== -1) {
  1197. clippedElements.splice(arrayIndex, 1);
  1198. }
  1199. var clientIds = _elementMeta[elements[i].zcClippingId];
  1200. if (clientIds) {
  1201. arrayIndex = 0;
  1202. while ((arrayIndex = _inArray(this.id, clientIds, arrayIndex)) !== -1) {
  1203. clientIds.splice(arrayIndex, 1);
  1204. }
  1205. if (clientIds.length === 0) {
  1206. if (_globalConfig.autoActivate === true) {
  1207. _removeEventHandler(elements[i], "mouseover", _elementMouseOver);
  1208. }
  1209. delete elements[i].zcClippingId;
  1210. }
  1211. }
  1212. }
  1213. }
  1214. return this;
  1215. };
  1216. ZeroClipboard.prototype.elements = function () {
  1217. var meta = _clientMeta[this.id];
  1218. return meta && meta.elements ? meta.elements.slice(0) : [];
  1219. };
  1220. var _getAllClientsClippedToElement = function (element) {
  1221. var elementMetaId, clientIds, i, len, client, clients = [];
  1222. if (element && element.nodeType === 1 && (elementMetaId = element.zcClippingId) && _elementMeta.hasOwnProperty(elementMetaId)) {
  1223. clientIds = _elementMeta[elementMetaId];
  1224. if (clientIds && clientIds.length) {
  1225. for (i = 0, len = clientIds.length; i < len; i++) {
  1226. client = _clientMeta[clientIds[i]].instance;
  1227. if (client && client instanceof ZeroClipboard) {
  1228. clients.push(client);
  1229. }
  1230. }
  1231. }
  1232. }
  1233. return clients;
  1234. };
  1235. _globalConfig.hoverClass = "zeroclipboard-is-hover";
  1236. _globalConfig.activeClass = "zeroclipboard-is-active";
  1237. if (typeof define === "function" && define.amd && false) {
  1238. define(function () {
  1239. return ZeroClipboard;
  1240. });
  1241. } else if (typeof module === "object" && module && typeof module.exports === "object" && module.exports) {
  1242. module.exports = ZeroClipboard;
  1243. } else {
  1244. window.ZeroClipboard = ZeroClipboard;
  1245. }
  1246. })(function () {
  1247. return this;
  1248. }());