PageRenderTime 61ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/files/zeroclipboard/2.1.2/ZeroClipboard.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1521 lines | 1164 code | 12 blank | 345 comment | 428 complexity | aca0990b412f9002dbffb3adf4c13442 MD5 | raw file
  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.1.2
  8. */
  9. (function(window, undefined) {
  10. "use strict";
  11. /**
  12. * Store references to critically important global functions that may be
  13. * overridden on certain web pages.
  14. */
  15. var _window = window, _document = _window.document, _navigator = _window.navigator, _setTimeout = _window.setTimeout, _encodeURIComponent = _window.encodeURIComponent, _ActiveXObject = _window.ActiveXObject, _parseInt = _window.Number.parseInt || _window.parseInt, _parseFloat = _window.Number.parseFloat || _window.parseFloat, _isNaN = _window.Number.isNaN || _window.isNaN, _round = _window.Math.round, _now = _window.Date.now, _keys = _window.Object.keys, _defineProperty = _window.Object.defineProperty, _hasOwn = _window.Object.prototype.hasOwnProperty, _slice = _window.Array.prototype.slice;
  16. /**
  17. * Convert an `arguments` object into an Array.
  18. *
  19. * @returns The arguments as an Array
  20. * @private
  21. */
  22. var _args = function(argumentsObj) {
  23. return _slice.call(argumentsObj, 0);
  24. };
  25. /**
  26. * Shallow-copy the owned, enumerable properties of one object over to another, similar to jQuery's `$.extend`.
  27. *
  28. * @returns The target object, augmented
  29. * @private
  30. */
  31. var _extend = function() {
  32. var i, len, arg, prop, src, copy, args = _args(arguments), target = args[0] || {};
  33. for (i = 1, len = args.length; i < len; i++) {
  34. if ((arg = args[i]) != null) {
  35. for (prop in arg) {
  36. if (_hasOwn.call(arg, prop)) {
  37. src = target[prop];
  38. copy = arg[prop];
  39. if (target !== copy && copy !== undefined) {
  40. target[prop] = copy;
  41. }
  42. }
  43. }
  44. }
  45. }
  46. return target;
  47. };
  48. /**
  49. * Return a deep copy of the source object or array.
  50. *
  51. * @returns Object or Array
  52. * @private
  53. */
  54. var _deepCopy = function(source) {
  55. var copy, i, len, prop;
  56. if (typeof source !== "object" || source == null) {
  57. copy = source;
  58. } else if (typeof source.length === "number") {
  59. copy = [];
  60. for (i = 0, len = source.length; i < len; i++) {
  61. if (_hasOwn.call(source, i)) {
  62. copy[i] = _deepCopy(source[i]);
  63. }
  64. }
  65. } else {
  66. copy = {};
  67. for (prop in source) {
  68. if (_hasOwn.call(source, prop)) {
  69. copy[prop] = _deepCopy(source[prop]);
  70. }
  71. }
  72. }
  73. return copy;
  74. };
  75. /**
  76. * Makes a shallow copy of `obj` (like `_extend`) but filters its properties based on a list of `keys` to keep.
  77. * The inverse of `_omit`, mostly. The big difference is that these properties do NOT need to be enumerable to
  78. * be kept.
  79. *
  80. * @returns A new filtered object.
  81. * @private
  82. */
  83. var _pick = function(obj, keys) {
  84. var newObj = {};
  85. for (var i = 0, len = keys.length; i < len; i++) {
  86. if (keys[i] in obj) {
  87. newObj[keys[i]] = obj[keys[i]];
  88. }
  89. }
  90. return newObj;
  91. };
  92. /**
  93. * Makes a shallow copy of `obj` (like `_extend`) but filters its properties based on a list of `keys` to omit.
  94. * The inverse of `_pick`.
  95. *
  96. * @returns A new filtered object.
  97. * @private
  98. */
  99. var _omit = function(obj, keys) {
  100. var newObj = {};
  101. for (var prop in obj) {
  102. if (keys.indexOf(prop) === -1) {
  103. newObj[prop] = obj[prop];
  104. }
  105. }
  106. return newObj;
  107. };
  108. /**
  109. * Remove all owned, enumerable properties from an object.
  110. *
  111. * @returns The original object without its owned, enumerable properties.
  112. * @private
  113. */
  114. var _deleteOwnProperties = function(obj) {
  115. if (obj) {
  116. for (var prop in obj) {
  117. if (_hasOwn.call(obj, prop)) {
  118. delete obj[prop];
  119. }
  120. }
  121. }
  122. return obj;
  123. };
  124. /**
  125. * Determine if an element is contained within another element.
  126. *
  127. * @returns Boolean
  128. * @private
  129. */
  130. var _containedBy = function(el, ancestorEl) {
  131. if (el && el.nodeType === 1 && el.ownerDocument && ancestorEl && (ancestorEl.nodeType === 1 && ancestorEl.ownerDocument && ancestorEl.ownerDocument === el.ownerDocument || ancestorEl.nodeType === 9 && !ancestorEl.ownerDocument && ancestorEl === el.ownerDocument)) {
  132. do {
  133. if (el === ancestorEl) {
  134. return true;
  135. }
  136. el = el.parentNode;
  137. } while (el);
  138. }
  139. return false;
  140. };
  141. /**
  142. * Keep track of the state of the Flash object.
  143. * @private
  144. */
  145. var _flashState = {
  146. bridge: null,
  147. version: "0.0.0",
  148. pluginType: "unknown",
  149. disabled: null,
  150. outdated: null,
  151. unavailable: null,
  152. deactivated: null,
  153. overdue: null,
  154. ready: null
  155. };
  156. /**
  157. * The minimum Flash Player version required to use ZeroClipboard completely.
  158. * @readonly
  159. * @private
  160. */
  161. var _minimumFlashVersion = "11.0.0";
  162. /**
  163. * Keep track of all event listener registrations.
  164. * @private
  165. */
  166. var _handlers = {};
  167. /**
  168. * Keep track of the currently activated element.
  169. * @private
  170. */
  171. var _currentElement;
  172. /**
  173. * Keep track of data for the pending clipboard transaction.
  174. * @private
  175. */
  176. var _clipData = {};
  177. /**
  178. * Keep track of data formats for the pending clipboard transaction.
  179. * @private
  180. */
  181. var _clipDataFormatMap = null;
  182. /**
  183. * The `message` store for events
  184. * @private
  185. */
  186. var _eventMessages = {
  187. ready: "Flash communication is established",
  188. error: {
  189. "flash-disabled": "Flash is disabled or not installed",
  190. "flash-outdated": "Flash is too outdated to support ZeroClipboard",
  191. "flash-unavailable": "Flash is unable to communicate bidirectionally with JavaScript",
  192. "flash-deactivated": "Flash is too outdated for your browser and/or is configured as click-to-activate",
  193. "flash-overdue": "Flash communication was established but NOT within the acceptable time limit"
  194. }
  195. };
  196. /**
  197. * The presumed location of the "ZeroClipboard.swf" file, based on the location
  198. * of the executing JavaScript file (e.g. "ZeroClipboard.js", etc.).
  199. * @private
  200. */
  201. var _swfPath = function() {
  202. var i, jsDir, tmpJsPath, jsPath, swfPath = "ZeroClipboard.swf";
  203. if (!(_document.currentScript && (jsPath = _document.currentScript.src))) {
  204. var scripts = _document.getElementsByTagName("script");
  205. if ("readyState" in scripts[0]) {
  206. for (i = scripts.length; i--; ) {
  207. if (scripts[i].readyState === "interactive" && (jsPath = scripts[i].src)) {
  208. break;
  209. }
  210. }
  211. } else if (_document.readyState === "loading") {
  212. jsPath = scripts[scripts.length - 1].src;
  213. } else {
  214. for (i = scripts.length; i--; ) {
  215. tmpJsPath = scripts[i].src;
  216. if (!tmpJsPath) {
  217. jsDir = null;
  218. break;
  219. }
  220. tmpJsPath = tmpJsPath.split("#")[0].split("?")[0];
  221. tmpJsPath = tmpJsPath.slice(0, tmpJsPath.lastIndexOf("/") + 1);
  222. if (jsDir == null) {
  223. jsDir = tmpJsPath;
  224. } else if (jsDir !== tmpJsPath) {
  225. jsDir = null;
  226. break;
  227. }
  228. }
  229. if (jsDir !== null) {
  230. jsPath = jsDir;
  231. }
  232. }
  233. }
  234. if (jsPath) {
  235. jsPath = jsPath.split("#")[0].split("?")[0];
  236. swfPath = jsPath.slice(0, jsPath.lastIndexOf("/") + 1) + swfPath;
  237. }
  238. return swfPath;
  239. }();
  240. /**
  241. * ZeroClipboard configuration defaults for the Core module.
  242. * @private
  243. */
  244. var _globalConfig = {
  245. swfPath: _swfPath,
  246. trustedDomains: window.location.host ? [ window.location.host ] : [],
  247. cacheBust: true,
  248. forceEnhancedClipboard: false,
  249. flashLoadTimeout: 3e4,
  250. autoActivate: true,
  251. bubbleEvents: true,
  252. containerId: "global-zeroclipboard-html-bridge",
  253. containerClass: "global-zeroclipboard-container",
  254. swfObjectId: "global-zeroclipboard-flash-bridge",
  255. hoverClass: "zeroclipboard-is-hover",
  256. activeClass: "zeroclipboard-is-active",
  257. forceHandCursor: false,
  258. title: null,
  259. zIndex: 999999999
  260. };
  261. /**
  262. * The underlying implementation of `ZeroClipboard.config`.
  263. * @private
  264. */
  265. var _config = function(options) {
  266. if (typeof options === "object" && options !== null) {
  267. for (var prop in options) {
  268. if (_hasOwn.call(options, prop)) {
  269. if (/^(?:forceHandCursor|title|zIndex|bubbleEvents)$/.test(prop)) {
  270. _globalConfig[prop] = options[prop];
  271. } else if (_flashState.bridge == null) {
  272. if (prop === "containerId" || prop === "swfObjectId") {
  273. if (_isValidHtml4Id(options[prop])) {
  274. _globalConfig[prop] = options[prop];
  275. } else {
  276. throw new Error("The specified `" + prop + "` value is not valid as an HTML4 Element ID");
  277. }
  278. } else {
  279. _globalConfig[prop] = options[prop];
  280. }
  281. }
  282. }
  283. }
  284. }
  285. if (typeof options === "string" && options) {
  286. if (_hasOwn.call(_globalConfig, options)) {
  287. return _globalConfig[options];
  288. }
  289. return;
  290. }
  291. return _deepCopy(_globalConfig);
  292. };
  293. /**
  294. * The underlying implementation of `ZeroClipboard.state`.
  295. * @private
  296. */
  297. var _state = function() {
  298. return {
  299. browser: _pick(_navigator, [ "userAgent", "platform", "appName" ]),
  300. flash: _omit(_flashState, [ "bridge" ]),
  301. zeroclipboard: {
  302. version: ZeroClipboard.version,
  303. config: ZeroClipboard.config()
  304. }
  305. };
  306. };
  307. /**
  308. * The underlying implementation of `ZeroClipboard.isFlashUnusable`.
  309. * @private
  310. */
  311. var _isFlashUnusable = function() {
  312. return !!(_flashState.disabled || _flashState.outdated || _flashState.unavailable || _flashState.deactivated);
  313. };
  314. /**
  315. * The underlying implementation of `ZeroClipboard.on`.
  316. * @private
  317. */
  318. var _on = function(eventType, listener) {
  319. var i, len, events, added = {};
  320. if (typeof eventType === "string" && eventType) {
  321. events = eventType.toLowerCase().split(/\s+/);
  322. } else if (typeof eventType === "object" && eventType && typeof listener === "undefined") {
  323. for (i in eventType) {
  324. if (_hasOwn.call(eventType, i) && typeof i === "string" && i && typeof eventType[i] === "function") {
  325. ZeroClipboard.on(i, eventType[i]);
  326. }
  327. }
  328. }
  329. if (events && events.length) {
  330. for (i = 0, len = events.length; i < len; i++) {
  331. eventType = events[i].replace(/^on/, "");
  332. added[eventType] = true;
  333. if (!_handlers[eventType]) {
  334. _handlers[eventType] = [];
  335. }
  336. _handlers[eventType].push(listener);
  337. }
  338. if (added.ready && _flashState.ready) {
  339. ZeroClipboard.emit({
  340. type: "ready"
  341. });
  342. }
  343. if (added.error) {
  344. var errorTypes = [ "disabled", "outdated", "unavailable", "deactivated", "overdue" ];
  345. for (i = 0, len = errorTypes.length; i < len; i++) {
  346. if (_flashState[errorTypes[i]] === true) {
  347. ZeroClipboard.emit({
  348. type: "error",
  349. name: "flash-" + errorTypes[i]
  350. });
  351. break;
  352. }
  353. }
  354. }
  355. }
  356. return ZeroClipboard;
  357. };
  358. /**
  359. * The underlying implementation of `ZeroClipboard.off`.
  360. * @private
  361. */
  362. var _off = function(eventType, listener) {
  363. var i, len, foundIndex, events, perEventHandlers;
  364. if (arguments.length === 0) {
  365. events = _keys(_handlers);
  366. } else if (typeof eventType === "string" && eventType) {
  367. events = eventType.split(/\s+/);
  368. } else if (typeof eventType === "object" && eventType && typeof listener === "undefined") {
  369. for (i in eventType) {
  370. if (_hasOwn.call(eventType, i) && typeof i === "string" && i && typeof eventType[i] === "function") {
  371. ZeroClipboard.off(i, eventType[i]);
  372. }
  373. }
  374. }
  375. if (events && events.length) {
  376. for (i = 0, len = events.length; i < len; i++) {
  377. eventType = events[i].toLowerCase().replace(/^on/, "");
  378. perEventHandlers = _handlers[eventType];
  379. if (perEventHandlers && perEventHandlers.length) {
  380. if (listener) {
  381. foundIndex = perEventHandlers.indexOf(listener);
  382. while (foundIndex !== -1) {
  383. perEventHandlers.splice(foundIndex, 1);
  384. foundIndex = perEventHandlers.indexOf(listener, foundIndex);
  385. }
  386. } else {
  387. perEventHandlers.length = 0;
  388. }
  389. }
  390. }
  391. }
  392. return ZeroClipboard;
  393. };
  394. /**
  395. * The underlying implementation of `ZeroClipboard.handlers`.
  396. * @private
  397. */
  398. var _listeners = function(eventType) {
  399. var copy;
  400. if (typeof eventType === "string" && eventType) {
  401. copy = _deepCopy(_handlers[eventType]) || null;
  402. } else {
  403. copy = _deepCopy(_handlers);
  404. }
  405. return copy;
  406. };
  407. /**
  408. * The underlying implementation of `ZeroClipboard.emit`.
  409. * @private
  410. */
  411. var _emit = function(event) {
  412. var eventCopy, returnVal, tmp;
  413. event = _createEvent(event);
  414. if (!event) {
  415. return;
  416. }
  417. if (_preprocessEvent(event)) {
  418. return;
  419. }
  420. if (event.type === "ready" && _flashState.overdue === true) {
  421. return ZeroClipboard.emit({
  422. type: "error",
  423. name: "flash-overdue"
  424. });
  425. }
  426. eventCopy = _extend({}, event);
  427. _dispatchCallbacks.call(this, eventCopy);
  428. if (event.type === "copy") {
  429. tmp = _mapClipDataToFlash(_clipData);
  430. returnVal = tmp.data;
  431. _clipDataFormatMap = tmp.formatMap;
  432. }
  433. return returnVal;
  434. };
  435. /**
  436. * The underlying implementation of `ZeroClipboard.create`.
  437. * @private
  438. */
  439. var _create = function() {
  440. if (typeof _flashState.ready !== "boolean") {
  441. _flashState.ready = false;
  442. }
  443. if (!ZeroClipboard.isFlashUnusable() && _flashState.bridge === null) {
  444. var maxWait = _globalConfig.flashLoadTimeout;
  445. if (typeof maxWait === "number" && maxWait >= 0) {
  446. _setTimeout(function() {
  447. if (typeof _flashState.deactivated !== "boolean") {
  448. _flashState.deactivated = true;
  449. }
  450. if (_flashState.deactivated === true) {
  451. ZeroClipboard.emit({
  452. type: "error",
  453. name: "flash-deactivated"
  454. });
  455. }
  456. }, maxWait);
  457. }
  458. _flashState.overdue = false;
  459. _embedSwf();
  460. }
  461. };
  462. /**
  463. * The underlying implementation of `ZeroClipboard.destroy`.
  464. * @private
  465. */
  466. var _destroy = function() {
  467. ZeroClipboard.clearData();
  468. ZeroClipboard.blur();
  469. ZeroClipboard.emit("destroy");
  470. _unembedSwf();
  471. ZeroClipboard.off();
  472. };
  473. /**
  474. * The underlying implementation of `ZeroClipboard.setData`.
  475. * @private
  476. */
  477. var _setData = function(format, data) {
  478. var dataObj;
  479. if (typeof format === "object" && format && typeof data === "undefined") {
  480. dataObj = format;
  481. ZeroClipboard.clearData();
  482. } else if (typeof format === "string" && format) {
  483. dataObj = {};
  484. dataObj[format] = data;
  485. } else {
  486. return;
  487. }
  488. for (var dataFormat in dataObj) {
  489. if (typeof dataFormat === "string" && dataFormat && _hasOwn.call(dataObj, dataFormat) && typeof dataObj[dataFormat] === "string" && dataObj[dataFormat]) {
  490. _clipData[dataFormat] = dataObj[dataFormat];
  491. }
  492. }
  493. };
  494. /**
  495. * The underlying implementation of `ZeroClipboard.clearData`.
  496. * @private
  497. */
  498. var _clearData = function(format) {
  499. if (typeof format === "undefined") {
  500. _deleteOwnProperties(_clipData);
  501. _clipDataFormatMap = null;
  502. } else if (typeof format === "string" && _hasOwn.call(_clipData, format)) {
  503. delete _clipData[format];
  504. }
  505. };
  506. /**
  507. * The underlying implementation of `ZeroClipboard.getData`.
  508. * @private
  509. */
  510. var _getData = function(format) {
  511. if (typeof format === "undefined") {
  512. return _deepCopy(_clipData);
  513. } else if (typeof format === "string" && _hasOwn.call(_clipData, format)) {
  514. return _clipData[format];
  515. }
  516. };
  517. /**
  518. * The underlying implementation of `ZeroClipboard.focus`/`ZeroClipboard.activate`.
  519. * @private
  520. */
  521. var _focus = function(element) {
  522. if (!(element && element.nodeType === 1)) {
  523. return;
  524. }
  525. if (_currentElement) {
  526. _removeClass(_currentElement, _globalConfig.activeClass);
  527. if (_currentElement !== element) {
  528. _removeClass(_currentElement, _globalConfig.hoverClass);
  529. }
  530. }
  531. _currentElement = element;
  532. _addClass(element, _globalConfig.hoverClass);
  533. var newTitle = element.getAttribute("title") || _globalConfig.title;
  534. if (typeof newTitle === "string" && newTitle) {
  535. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  536. if (htmlBridge) {
  537. htmlBridge.setAttribute("title", newTitle);
  538. }
  539. }
  540. var useHandCursor = _globalConfig.forceHandCursor === true || _getStyle(element, "cursor") === "pointer";
  541. _setHandCursor(useHandCursor);
  542. _reposition();
  543. };
  544. /**
  545. * The underlying implementation of `ZeroClipboard.blur`/`ZeroClipboard.deactivate`.
  546. * @private
  547. */
  548. var _blur = function() {
  549. var htmlBridge = _getHtmlBridge(_flashState.bridge);
  550. if (htmlBridge) {
  551. htmlBridge.removeAttribute("title");
  552. htmlBridge.style.left = "0px";
  553. htmlBridge.style.top = "-9999px";
  554. htmlBridge.style.width = "1px";
  555. htmlBridge.style.top = "1px";
  556. }
  557. if (_currentElement) {
  558. _removeClass(_currentElement, _globalConfig.hoverClass);
  559. _removeClass(_currentElement, _globalConfig.activeClass);
  560. _currentElement = null;
  561. }
  562. };
  563. /**
  564. * The underlying implementation of `ZeroClipboard.activeElement`.
  565. * @private
  566. */
  567. var _activeElement = function() {
  568. return _currentElement || null;
  569. };
  570. /**
  571. * Check if a value is a valid HTML4 `ID` or `Name` token.
  572. * @private
  573. */
  574. var _isValidHtml4Id = function(id) {
  575. return typeof id === "string" && id && /^[A-Za-z][A-Za-z0-9_:\-\.]*$/.test(id);
  576. };
  577. /**
  578. * Create or update an `event` object, based on the `eventType`.
  579. * @private
  580. */
  581. var _createEvent = function(event) {
  582. var eventType;
  583. if (typeof event === "string" && event) {
  584. eventType = event;
  585. event = {};
  586. } else if (typeof event === "object" && event && typeof event.type === "string" && event.type) {
  587. eventType = event.type;
  588. }
  589. if (!eventType) {
  590. return;
  591. }
  592. _extend(event, {
  593. type: eventType.toLowerCase(),
  594. target: event.target || _currentElement || null,
  595. relatedTarget: event.relatedTarget || null,
  596. currentTarget: _flashState && _flashState.bridge || null,
  597. timeStamp: event.timeStamp || _now() || null
  598. });
  599. var msg = _eventMessages[event.type];
  600. if (event.type === "error" && event.name && msg) {
  601. msg = msg[event.name];
  602. }
  603. if (msg) {
  604. event.message = msg;
  605. }
  606. if (event.type === "ready") {
  607. _extend(event, {
  608. target: null,
  609. version: _flashState.version
  610. });
  611. }
  612. if (event.type === "error") {
  613. if (/^flash-(disabled|outdated|unavailable|deactivated|overdue)$/.test(event.name)) {
  614. _extend(event, {
  615. target: null,
  616. minimumVersion: _minimumFlashVersion
  617. });
  618. }
  619. if (/^flash-(outdated|unavailable|deactivated|overdue)$/.test(event.name)) {
  620. _extend(event, {
  621. version: _flashState.version
  622. });
  623. }
  624. }
  625. if (event.type === "copy") {
  626. event.clipboardData = {
  627. setData: ZeroClipboard.setData,
  628. clearData: ZeroClipboard.clearData
  629. };
  630. }
  631. if (event.type === "aftercopy") {
  632. event = _mapClipResultsFromFlash(event, _clipDataFormatMap);
  633. }
  634. if (event.target && !event.relatedTarget) {
  635. event.relatedTarget = _getRelatedTarget(event.target);
  636. }
  637. event = _addMouseData(event);
  638. return event;
  639. };
  640. /**
  641. * Get a relatedTarget from the target's `data-clipboard-target` attribute
  642. * @private
  643. */
  644. var _getRelatedTarget = function(targetEl) {
  645. var relatedTargetId = targetEl && targetEl.getAttribute && targetEl.getAttribute("data-clipboard-target");
  646. return relatedTargetId ? _document.getElementById(relatedTargetId) : null;
  647. };
  648. /**
  649. * Add element and position data to `MouseEvent` instances
  650. * @private
  651. */
  652. var _addMouseData = function(event) {
  653. if (event && /^_(?:click|mouse(?:over|out|down|up|move))$/.test(event.type)) {
  654. var srcElement = event.target;
  655. var fromElement = event.type === "_mouseover" && event.relatedTarget ? event.relatedTarget : undefined;
  656. var toElement = event.type === "_mouseout" && event.relatedTarget ? event.relatedTarget : undefined;
  657. var pos = _getDOMObjectPosition(srcElement);
  658. var screenLeft = _window.screenLeft || _window.screenX || 0;
  659. var screenTop = _window.screenTop || _window.screenY || 0;
  660. var scrollLeft = _document.body.scrollLeft + _document.documentElement.scrollLeft;
  661. var scrollTop = _document.body.scrollTop + _document.documentElement.scrollTop;
  662. var pageX = pos.left + (typeof event._stageX === "number" ? event._stageX : 0);
  663. var pageY = pos.top + (typeof event._stageY === "number" ? event._stageY : 0);
  664. var clientX = pageX - scrollLeft;
  665. var clientY = pageY - scrollTop;
  666. var screenX = screenLeft + clientX;
  667. var screenY = screenTop + clientY;
  668. var moveX = typeof event.movementX === "number" ? event.movementX : 0;
  669. var moveY = typeof event.movementY === "number" ? event.movementY : 0;
  670. delete event._stageX;
  671. delete event._stageY;
  672. _extend(event, {
  673. srcElement: srcElement,
  674. fromElement: fromElement,
  675. toElement: toElement,
  676. screenX: screenX,
  677. screenY: screenY,
  678. pageX: pageX,
  679. pageY: pageY,
  680. clientX: clientX,
  681. clientY: clientY,
  682. x: clientX,
  683. y: clientY,
  684. movementX: moveX,
  685. movementY: moveY,
  686. offsetX: 0,
  687. offsetY: 0,
  688. layerX: 0,
  689. layerY: 0
  690. });
  691. }
  692. return event;
  693. };
  694. /**
  695. * Determine if an event's registered handlers should be execute synchronously or asynchronously.
  696. *
  697. * @returns {boolean}
  698. * @private
  699. */
  700. var _shouldPerformAsync = function(event) {
  701. var eventType = event && typeof event.type === "string" && event.type || "";
  702. return !/^(?:(?:before)?copy|destroy)$/.test(eventType);
  703. };
  704. /**
  705. * Control if a callback should be executed asynchronously or not.
  706. *
  707. * @returns `undefined`
  708. * @private
  709. */
  710. var _dispatchCallback = function(func, context, args, async) {
  711. if (async) {
  712. _setTimeout(function() {
  713. func.apply(context, args);
  714. }, 0);
  715. } else {
  716. func.apply(context, args);
  717. }
  718. };
  719. /**
  720. * Handle the actual dispatching of events to client instances.
  721. *
  722. * @returns `undefined`
  723. * @private
  724. */
  725. var _dispatchCallbacks = function(event) {
  726. if (!(typeof event === "object" && event && event.type)) {
  727. return;
  728. }
  729. var async = _shouldPerformAsync(event);
  730. var wildcardTypeHandlers = _handlers["*"] || [];
  731. var specificTypeHandlers = _handlers[event.type] || [];
  732. var handlers = wildcardTypeHandlers.concat(specificTypeHandlers);
  733. if (handlers && handlers.length) {
  734. var i, len, func, context, eventCopy, originalContext = this;
  735. for (i = 0, len = handlers.length; i < len; i++) {
  736. func = handlers[i];
  737. context = originalContext;
  738. if (typeof func === "string" && typeof _window[func] === "function") {
  739. func = _window[func];
  740. }
  741. if (typeof func === "object" && func && typeof func.handleEvent === "function") {
  742. context = func;
  743. func = func.handleEvent;
  744. }
  745. if (typeof func === "function") {
  746. eventCopy = _extend({}, event);
  747. _dispatchCallback(func, context, [ eventCopy ], async);
  748. }
  749. }
  750. }
  751. return this;
  752. };
  753. /**
  754. * Preprocess any special behaviors, reactions, or state changes after receiving this event.
  755. * Executes only once per event emitted, NOT once per client.
  756. * @private
  757. */
  758. var _preprocessEvent = function(event) {
  759. var element = event.target || _currentElement || null;
  760. var sourceIsSwf = event._source === "swf";
  761. delete event._source;
  762. var flashErrorNames = [ "flash-disabled", "flash-outdated", "flash-unavailable", "flash-deactivated", "flash-overdue" ];
  763. switch (event.type) {
  764. case "error":
  765. if (flashErrorNames.indexOf(event.name) !== -1) {
  766. _extend(_flashState, {
  767. disabled: event.name === "flash-disabled",
  768. outdated: event.name === "flash-outdated",
  769. unavailable: event.name === "flash-unavailable",
  770. deactivated: event.name === "flash-deactivated",
  771. overdue: event.name === "flash-overdue",
  772. ready: false
  773. });
  774. }
  775. break;
  776. case "ready":
  777. var wasDeactivated = _flashState.deactivated === true;
  778. _extend(_flashState, {
  779. disabled: false,
  780. outdated: false,
  781. unavailable: false,
  782. deactivated: false,
  783. overdue: wasDeactivated,
  784. ready: !wasDeactivated
  785. });
  786. break;
  787. case "copy":
  788. var textContent, htmlContent, targetEl = event.relatedTarget;
  789. if (!(_clipData["text/html"] || _clipData["text/plain"]) && targetEl && (htmlContent = targetEl.value || targetEl.outerHTML || targetEl.innerHTML) && (textContent = targetEl.value || targetEl.textContent || targetEl.innerText)) {
  790. event.clipboardData.clearData();
  791. event.clipboardData.setData("text/plain", textContent);
  792. if (htmlContent !== textContent) {
  793. event.clipboardData.setData("text/html", htmlContent);
  794. }
  795. } else if (!_clipData["text/plain"] && event.target && (textContent = event.target.getAttribute("data-clipboard-text"))) {
  796. event.clipboardData.clearData();
  797. event.clipboardData.setData("text/plain", textContent);
  798. }
  799. break;
  800. case "aftercopy":
  801. ZeroClipboard.clearData();
  802. if (element && element !== _safeActiveElement() && element.focus) {
  803. element.focus();
  804. }
  805. break;
  806. case "_mouseover":
  807. ZeroClipboard.focus(element);
  808. if (_globalConfig.bubbleEvents === true && sourceIsSwf) {
  809. if (element && element !== event.relatedTarget && !_containedBy(event.relatedTarget, element)) {
  810. _fireMouseEvent(_extend({}, event, {
  811. type: "mouseenter",
  812. bubbles: false,
  813. cancelable: false
  814. }));
  815. }
  816. _fireMouseEvent(_extend({}, event, {
  817. type: "mouseover"
  818. }));
  819. }
  820. break;
  821. case "_mouseout":
  822. ZeroClipboard.blur();
  823. if (_globalConfig.bubbleEvents === true && sourceIsSwf) {
  824. if (element && element !== event.relatedTarget && !_containedBy(event.relatedTarget, element)) {
  825. _fireMouseEvent(_extend({}, event, {
  826. type: "mouseleave",
  827. bubbles: false,
  828. cancelable: false
  829. }));
  830. }
  831. _fireMouseEvent(_extend({}, event, {
  832. type: "mouseout"
  833. }));
  834. }
  835. break;
  836. case "_mousedown":
  837. _addClass(element, _globalConfig.activeClass);
  838. if (_globalConfig.bubbleEvents === true && sourceIsSwf) {
  839. _fireMouseEvent(_extend({}, event, {
  840. type: event.type.slice(1)
  841. }));
  842. }
  843. break;
  844. case "_mouseup":
  845. _removeClass(element, _globalConfig.activeClass);
  846. if (_globalConfig.bubbleEvents === true && sourceIsSwf) {
  847. _fireMouseEvent(_extend({}, event, {
  848. type: event.type.slice(1)
  849. }));
  850. }
  851. break;
  852. case "_click":
  853. case "_mousemove":
  854. if (_globalConfig.bubbleEvents === true && sourceIsSwf) {
  855. _fireMouseEvent(_extend({}, event, {
  856. type: event.type.slice(1)
  857. }));
  858. }
  859. break;
  860. }
  861. if (/^_(?:click|mouse(?:over|out|down|up|move))$/.test(event.type)) {
  862. return true;
  863. }
  864. };
  865. /**
  866. * Dispatch a synthetic MouseEvent.
  867. *
  868. * @returns `undefined`
  869. * @private
  870. */
  871. var _fireMouseEvent = function(event) {
  872. if (!(event && typeof event.type === "string" && event)) {
  873. return;
  874. }
  875. var e, target = event.target || null, doc = target && target.ownerDocument || _document, defaults = {
  876. view: doc.defaultView || _window,
  877. canBubble: true,
  878. cancelable: true,
  879. detail: event.type === "click" ? 1 : 0,
  880. button: typeof event.which === "number" ? event.which - 1 : typeof event.button === "number" ? event.button : doc.createEvent ? 0 : 1
  881. }, args = _extend(defaults, event);
  882. if (!target) {
  883. return;
  884. }
  885. if (doc.createEvent && target.dispatchEvent) {
  886. args = [ args.type, args.canBubble, args.cancelable, args.view, args.detail, args.screenX, args.screenY, args.clientX, args.clientY, args.ctrlKey, args.altKey, args.shiftKey, args.metaKey, args.button, args.relatedTarget ];
  887. e = doc.createEvent("MouseEvents");
  888. if (e.initMouseEvent) {
  889. e.initMouseEvent.apply(e, args);
  890. e._source = "js";
  891. target.dispatchEvent(e);
  892. }
  893. }
  894. };
  895. /**
  896. * Create the HTML bridge element to embed the Flash object into.
  897. * @private
  898. */
  899. var _createHtmlBridge = function() {
  900. var container = _document.createElement("div");
  901. container.id = _globalConfig.containerId;
  902. container.className = _globalConfig.containerClass;
  903. container.style.position = "absolute";
  904. container.style.left = "0px";
  905. container.style.top = "-9999px";
  906. container.style.width = "1px";
  907. container.style.height = "1px";
  908. container.style.zIndex = "" + _getSafeZIndex(_globalConfig.zIndex);
  909. return container;
  910. };
  911. /**
  912. * Get the HTML element container that wraps the Flash bridge object/element.
  913. * @private
  914. */
  915. var _getHtmlBridge = function(flashBridge) {
  916. var htmlBridge = flashBridge && flashBridge.parentNode;
  917. while (htmlBridge && htmlBridge.nodeName === "OBJECT" && htmlBridge.parentNode) {
  918. htmlBridge = htmlBridge.parentNode;
  919. }
  920. return htmlBridge || null;
  921. };
  922. /**
  923. * Create the SWF object.
  924. *
  925. * @returns The SWF object reference.
  926. * @private
  927. */
  928. var _embedSwf = function() {
  929. var len, flashBridge = _flashState.bridge, container = _getHtmlBridge(flashBridge);
  930. if (!flashBridge) {
  931. var allowScriptAccess = _determineScriptAccess(_window.location.host, _globalConfig);
  932. var allowNetworking = allowScriptAccess === "never" ? "none" : "all";
  933. var flashvars = _vars(_globalConfig);
  934. var swfUrl = _globalConfig.swfPath + _cacheBust(_globalConfig.swfPath, _globalConfig);
  935. container = _createHtmlBridge();
  936. var divToBeReplaced = _document.createElement("div");
  937. container.appendChild(divToBeReplaced);
  938. _document.body.appendChild(container);
  939. var tmpDiv = _document.createElement("div");
  940. var oldIE = _flashState.pluginType === "activex";
  941. tmpDiv.innerHTML = '<object id="' + _globalConfig.swfObjectId + '" name="' + _globalConfig.swfObjectId + '" ' + '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>";
  942. flashBridge = tmpDiv.firstChild;
  943. tmpDiv = null;
  944. flashBridge.ZeroClipboard = ZeroClipboard;
  945. container.replaceChild(flashBridge, divToBeReplaced);
  946. }
  947. if (!flashBridge) {
  948. flashBridge = _document[_globalConfig.swfObjectId];
  949. if (flashBridge && (len = flashBridge.length)) {
  950. flashBridge = flashBridge[len - 1];
  951. }
  952. if (!flashBridge && container) {
  953. flashBridge = container.firstChild;
  954. }
  955. }
  956. _flashState.bridge = flashBridge || null;
  957. return flashBridge;
  958. };
  959. /**
  960. * Destroy the SWF object.
  961. * @private
  962. */
  963. var _unembedSwf = function() {
  964. var flashBridge = _flashState.bridge;
  965. if (flashBridge) {
  966. var htmlBridge = _getHtmlBridge(flashBridge);
  967. if (htmlBridge) {
  968. if (_flashState.pluginType === "activex" && "readyState" in flashBridge) {
  969. flashBridge.style.display = "none";
  970. (function removeSwfFromIE() {
  971. if (flashBridge.readyState === 4) {
  972. for (var prop in flashBridge) {
  973. if (typeof flashBridge[prop] === "function") {
  974. flashBridge[prop] = null;
  975. }
  976. }
  977. if (flashBridge.parentNode) {
  978. flashBridge.parentNode.removeChild(flashBridge);
  979. }
  980. if (htmlBridge.parentNode) {
  981. htmlBridge.parentNode.removeChild(htmlBridge);
  982. }
  983. } else {
  984. _setTimeout(removeSwfFromIE, 10);
  985. }
  986. })();
  987. } else {
  988. if (flashBridge.parentNode) {
  989. flashBridge.parentNode.removeChild(flashBridge);
  990. }
  991. if (htmlBridge.parentNode) {
  992. htmlBridge.parentNode.removeChild(htmlBridge);
  993. }
  994. }
  995. }
  996. _flashState.ready = null;
  997. _flashState.bridge = null;
  998. _flashState.deactivated = null;
  999. }
  1000. };
  1001. /**
  1002. * Map the data format names of the "clipData" to Flash-friendly names.
  1003. *
  1004. * @returns A new transformed object.
  1005. * @private
  1006. */
  1007. var _mapClipDataToFlash = function(clipData) {
  1008. var newClipData = {}, formatMap = {};
  1009. if (!(typeof clipData === "object" && clipData)) {
  1010. return;
  1011. }
  1012. for (var dataFormat in clipData) {
  1013. if (dataFormat && _hasOwn.call(clipData, dataFormat) && typeof clipData[dataFormat] === "string" && clipData[dataFormat]) {
  1014. switch (dataFormat.toLowerCase()) {
  1015. case "text/plain":
  1016. case "text":
  1017. case "air:text":
  1018. case "flash:text":
  1019. newClipData.text = clipData[dataFormat];
  1020. formatMap.text = dataFormat;
  1021. break;
  1022. case "text/html":
  1023. case "html":
  1024. case "air:html":
  1025. case "flash:html":
  1026. newClipData.html = clipData[dataFormat];
  1027. formatMap.html = dataFormat;
  1028. break;
  1029. case "application/rtf":
  1030. case "text/rtf":
  1031. case "rtf":
  1032. case "richtext":
  1033. case "air:rtf":
  1034. case "flash:rtf":
  1035. newClipData.rtf = clipData[dataFormat];
  1036. formatMap.rtf = dataFormat;
  1037. break;
  1038. default:
  1039. break;
  1040. }
  1041. }
  1042. }
  1043. return {
  1044. data: newClipData,
  1045. formatMap: formatMap
  1046. };
  1047. };
  1048. /**
  1049. * Map the data format names from Flash-friendly names back to their original "clipData" names (via a format mapping).
  1050. *
  1051. * @returns A new transformed object.
  1052. * @private
  1053. */
  1054. var _mapClipResultsFromFlash = function(clipResults, formatMap) {
  1055. if (!(typeof clipResults === "object" && clipResults && typeof formatMap === "object" && formatMap)) {
  1056. return clipResults;
  1057. }
  1058. var newResults = {};
  1059. for (var prop in clipResults) {
  1060. if (_hasOwn.call(clipResults, prop)) {
  1061. if (prop !== "success" && prop !== "data") {
  1062. newResults[prop] = clipResults[prop];
  1063. continue;
  1064. }
  1065. newResults[prop] = {};
  1066. var tmpHash = clipResults[prop];
  1067. for (var dataFormat in tmpHash) {
  1068. if (dataFormat && _hasOwn.call(tmpHash, dataFormat) && _hasOwn.call(formatMap, dataFormat)) {
  1069. newResults[prop][formatMap[dataFormat]] = tmpHash[dataFormat];
  1070. }
  1071. }
  1072. }
  1073. }
  1074. return newResults;
  1075. };
  1076. /**
  1077. * Will look at a path, and will create a "?noCache={time}" or "&noCache={time}"
  1078. * query param string to return. Does NOT append that string to the original path.
  1079. * This is useful because ExternalInterface often breaks when a Flash SWF is cached.
  1080. *
  1081. * @returns The `noCache` query param with necessary "?"/"&" prefix.
  1082. * @private
  1083. */
  1084. var _cacheBust = function(path, options) {
  1085. var cacheBust = options == null || options && options.cacheBust === true;
  1086. if (cacheBust) {
  1087. return (path.indexOf("?") === -1 ? "?" : "&") + "noCache=" + _now();
  1088. } else {
  1089. return "";
  1090. }
  1091. };
  1092. /**
  1093. * Creates a query string for the FlashVars param.
  1094. * Does NOT include the cache-busting query param.
  1095. *
  1096. * @returns FlashVars query string
  1097. * @private
  1098. */
  1099. var _vars = function(options) {
  1100. var i, len, domain, domains, str = "", trustedOriginsExpanded = [];
  1101. if (options.trustedDomains) {
  1102. if (typeof options.trustedDomains === "string") {
  1103. domains = [ options.trustedDomains ];
  1104. } else if (typeof options.trustedDomains === "object" && "length" in options.trustedDomains) {
  1105. domains = options.trustedDomains;
  1106. }
  1107. }
  1108. if (domains && domains.length) {
  1109. for (i = 0, len = domains.length; i < len; i++) {
  1110. if (_hasOwn.call(domains, i) && domains[i] && typeof domains[i] === "string") {
  1111. domain = _extractDomain(domains[i]);
  1112. if (!domain) {
  1113. continue;
  1114. }
  1115. if (domain === "*") {
  1116. trustedOriginsExpanded.length = 0;
  1117. trustedOriginsExpanded.push(domain);
  1118. break;
  1119. }
  1120. trustedOriginsExpanded.push.apply(trustedOriginsExpanded, [ domain, "//" + domain, _window.location.protocol + "//" + domain ]);
  1121. }
  1122. }
  1123. }
  1124. if (trustedOriginsExpanded.length) {
  1125. str += "trustedOrigins=" + _encodeURIComponent(trustedOriginsExpanded.join(","));
  1126. }
  1127. if (options.forceEnhancedClipboard === true) {
  1128. str += (str ? "&" : "") + "forceEnhancedClipboard=true";
  1129. }
  1130. if (typeof options.swfObjectId === "string" && options.swfObjectId) {
  1131. str += (str ? "&" : "") + "swfObjectId=" + _encodeURIComponent(options.swfObjectId);
  1132. }
  1133. return str;
  1134. };
  1135. /**
  1136. * Extract the domain (e.g. "github.com") from an origin (e.g. "https://github.com") or
  1137. * URL (e.g. "https://github.com/zeroclipboard/zeroclipboard/").
  1138. *
  1139. * @returns the domain
  1140. * @private
  1141. */
  1142. var _extractDomain = function(originOrUrl) {
  1143. if (originOrUrl == null || originOrUrl === "") {
  1144. return null;
  1145. }
  1146. originOrUrl = originOrUrl.replace(/^\s+|\s+$/g, "");
  1147. if (originOrUrl === "") {
  1148. return null;
  1149. }
  1150. var protocolIndex = originOrUrl.indexOf("//");
  1151. originOrUrl = protocolIndex === -1 ? originOrUrl : originOrUrl.slice(protocolIndex + 2);
  1152. var pathIndex = originOrUrl.indexOf("/");
  1153. originOrUrl = pathIndex === -1 ? originOrUrl : protocolIndex === -1 || pathIndex === 0 ? null : originOrUrl.slice(0, pathIndex);
  1154. if (originOrUrl && originOrUrl.slice(-4).toLowerCase() === ".swf") {
  1155. return null;
  1156. }
  1157. return originOrUrl || null;
  1158. };
  1159. /**
  1160. * Set `allowScriptAccess` based on `trustedDomains` and `window.location.host` vs. `swfPath`.
  1161. *
  1162. * @returns The appropriate script access level.
  1163. * @private
  1164. */
  1165. var _determineScriptAccess = function() {
  1166. var _extractAllDomains = function(origins) {
  1167. var i, len, tmp, resultsArray = [];
  1168. if (typeof origins === "string") {
  1169. origins = [ origins ];
  1170. }
  1171. if (!(typeof origins === "object" && origins && typeof origins.length === "number")) {
  1172. return resultsArray;
  1173. }
  1174. for (i = 0, len = origins.length; i < len; i++) {
  1175. if (_hasOwn.call(origins, i) && (tmp = _extractDomain(origins[i]))) {
  1176. if (tmp === "*") {
  1177. resultsArray.length = 0;
  1178. resultsArray.push("*");
  1179. break;
  1180. }
  1181. if (resultsArray.indexOf(tmp) === -1) {
  1182. resultsArray.push(tmp);
  1183. }
  1184. }
  1185. }
  1186. return resultsArray;
  1187. };
  1188. return function(currentDomain, configOptions) {
  1189. var swfDomain = _extractDomain(configOptions.swfPath);
  1190. if (swfDomain === null) {
  1191. swfDomain = currentDomain;
  1192. }
  1193. var trustedDomains = _extractAllDomains(configOptions.trustedDomains);
  1194. var len = trustedDomains.length;
  1195. if (len > 0) {
  1196. if (len === 1 && trustedDomains[0] === "*") {
  1197. return "always";
  1198. }
  1199. if (trustedDomains.indexOf(currentDomain) !== -1) {
  1200. if (len === 1 && currentDomain === swfDomain) {
  1201. return "sameDomain";
  1202. }
  1203. return "always";
  1204. }
  1205. }
  1206. return "never";
  1207. };
  1208. }();
  1209. /**
  1210. * Get the currently active/focused DOM element.
  1211. *
  1212. * @returns the currently active/focused element, or `null`
  1213. * @private
  1214. */
  1215. var _safeActiveElement = function() {
  1216. try {
  1217. return _document.activeElement;
  1218. } catch (err) {
  1219. return null;
  1220. }
  1221. };
  1222. /**
  1223. * Add a class to an element, if it doesn't already have it.
  1224. *
  1225. * @returns The element, with its new class added.
  1226. * @private
  1227. */
  1228. var _addClass = function(element, value) {
  1229. if (!element || element.nodeType !== 1) {
  1230. return element;
  1231. }
  1232. if (element.classList) {
  1233. if (!element.classList.contains(value)) {
  1234. element.classList.add(value);
  1235. }
  1236. return element;
  1237. }
  1238. if (value && typeof value === "string") {
  1239. var classNames = (value || "").split(/\s+/);
  1240. if (element.nodeType === 1) {
  1241. if (!element.className) {
  1242. element.className = value;
  1243. } else {
  1244. var className = " " + element.className + " ", setClass = element.className;
  1245. for (var c = 0, cl = classNames.length; c < cl; c++) {
  1246. if (className.indexOf(" " + classNames[c] + " ") < 0) {
  1247. setClass += " " + classNames[c];
  1248. }
  1249. }
  1250. element.className = setClass.replace(/^\s+|\s+$/g, "");
  1251. }
  1252. }
  1253. }
  1254. return element;
  1255. };
  1256. /**
  1257. * Remove a class from an element, if it has it.
  1258. *
  1259. * @returns The element, with its class removed.
  1260. * @private
  1261. */
  1262. var _removeClass = function(element, value) {
  1263. if (!element || element.nodeType !== 1) {
  1264. return element;
  1265. }
  1266. if (element.classList) {
  1267. if (element.classList.contains(value)) {
  1268. element.classList.remove(value);
  1269. }
  1270. return element;
  1271. }
  1272. if (typeof value === "string" && value) {
  1273. var classNames = value.split(/\s+/);
  1274. if (element.nodeType === 1 && element.className) {
  1275. var className = (" " + element.className + " ").replace(/[\n\t]/g, " ");
  1276. for (var c = 0, cl = classNames.length; c < cl; c++) {
  1277. className = className.replace(" " + classNames[c] + " ", " ");
  1278. }
  1279. element.className = className.replace(/^\s+|\s+$/g, "");
  1280. }
  1281. }
  1282. return element;
  1283. };
  1284. /**
  1285. * Attempt to interpret the element's CSS styling. If `prop` is `"cursor"`,
  1286. * then we assume that it should be a hand ("pointer") cursor if the element
  1287. * is an anchor element ("a" tag).
  1288. *
  1289. * @returns The computed style property.
  1290. * @private
  1291. */
  1292. var _getStyle = function(el, prop) {
  1293. var value = _window.getComputedStyle(el, null).getPropertyValue(prop);
  1294. if (prop === "cursor") {
  1295. if (!value || value === "auto") {
  1296. if (el.nodeName === "A") {
  1297. return "pointer";
  1298. }
  1299. }
  1300. }
  1301. return value;
  1302. };
  1303. /**
  1304. * Get the zoom factor of the browser. Always returns `1.0`, except at
  1305. * non-default zoom levels in IE<8 and some older versions of WebKit.
  1306. *
  1307. * @returns Floating unit percentage of the zoom factor (e.g. 150% = `1.5`).
  1308. * @private
  1309. */
  1310. var _getZoomFactor = function() {
  1311. var rect, physicalWidth, logicalWidth, zoomFactor = 1;
  1312. if (typeof _document.body.getBoundingClientRect === "function") {
  1313. rect = _document.body.getBoundingClientRect();
  1314. physicalWidth = rect.right - rect.left;
  1315. logicalWidth = _document.body.offsetWidth;
  1316. zoomFactor = _round(physicalWidth / logicalWidth * 100) / 100;
  1317. }
  1318. return zoomFactor;
  1319. };
  1320. /**
  1321. * Get the DOM positioning info of an element.
  1322. *
  1323. * @returns Object containing the element's position, width, and height.
  1324. * @private
  1325. */
  1326. var _getDOMObjectPosition = function(obj) {
  1327. var info = {
  1328. left: 0,
  1329. top: 0,
  1330. width: 0,
  1331. height: 0
  1332. };
  1333. if (obj.getBoundingClientRect) {
  1334. var rect = obj.getBoundingClientRect();
  1335. var pageXOffset, pageYOffset, zoomFactor;
  1336. if ("pageXOffset" in _window && "pageYOffset" in _window) {
  1337. pageXOffset = _window.pageXOffset;
  1338. pageYOffset = _window.pageYOffset;
  1339. } else {
  1340. zoomFactor = _getZoomFactor();
  1341. pageXOffset = _round(_document.documentElement.scrollLeft / zoomFactor);
  1342. pageYOffset = _round(_document.documentElement.scrollTop / zoomFactor);
  1343. }
  1344. var leftBorderWidth = _document.documentElement.clientLeft || 0;
  1345. var topBorderWidth = _document.documentElement.clientTop || 0;
  1346. info.left = rect.left + pageXOffset - leftBorderWidth;
  1347. info.top = rect.top + pageYOffset - topBorderWidth;
  1348. info.width = "width" in rect ? rect.width : rect.right - rect.left;
  1349. info.height = "height" in rect ? rect.height : rect.bottom - rect.top;
  1350. }
  1351. return info;
  1352. };
  1353. /**
  1354. * Reposition the Flash object to cover the currently activated element.
  1355. *
  1356. * @returns `undefined`
  1357. * @private
  1358. */
  1359. var _reposition = function() {
  1360. var htmlBridge;
  1361. if (_currentElement && (htmlBridge = _getHtmlBridge(_flashState.bridge))) {
  1362. var pos = _getDOMObjectPosition(_currentElement);
  1363. _extend(htmlBridge.style, {
  1364. width: pos.width + "px",
  1365. height: pos.height + "px",
  1366. top: pos.top + "px",
  1367. left: pos.left + "px",
  1368. zIndex: "" + _getSafeZIndex(_globalConfig.zIndex)
  1369. });
  1370. }
  1371. };
  1372. /**
  1373. * Sends a signal to the Flash object to display the hand cursor if `true`.
  1374. *
  1375. * @returns `undefined`
  1376. * @private
  1377. */
  1378. var _setHandCursor = function(enabled) {
  1379. if (_flashState.ready === true) {
  1380. if (_flashState.bridge && typeof _flashState.bridge.setHandCursor === "function") {
  1381. _flashState.bridge.setHandCursor(enabled);
  1382. } else {
  1383. _flashState.ready = false;
  1384. }
  1385. }
  1386. };
  1387. /**
  1388. * Get a safe value for `zIndex`
  1389. *
  1390. * @returns an integer, or "auto"
  1391. * @private
  1392. */
  1393. var _getSafeZIndex = function(val) {
  1394. if (/^(?:auto|inherit)$/.test(val)) {
  1395. return val;
  1396. }
  1397. var zIndex;
  1398. if (typeof val === "number" && !_isNaN(val)) {
  1399. zIndex = val;
  1400. } else if (typeof val === "string") {
  1401. zIndex = _getSafeZIndex(_parseInt(val, 10));
  1402. }
  1403. return typeof zIndex === "number" ? zIndex : "auto";
  1404. };
  1405. /**
  1406. * Detect the Flash Player status, version, and plugin type.
  1407. *
  1408. * @see {@link https://code.google.com/p/doctype-mirror/wiki/ArticleDetectFlash#The_code}
  1409. * @see {@link http://stackoverflow.com/questions/12866060/detecting-pepper-ppapi-flash-with-javascript}
  1410. *
  1411. * @returns `undefined`
  1412. * @private
  1413. */
  1414. var _detectFlashSupport = function(ActiveXObject) {
  1415. var plugin, ax, mimeType, hasFlash = false, isActiveX = false, isPPAPI = false, flashVersion = "";
  1416. /**
  1417. * Derived from Apple's suggested sniffer.
  1418. * @param {String} desc e.g. "Shockwave Flash 7.0 r61"
  1419. * @returns {String} "7.0.61"
  1420. * @private
  1421. */
  1422. function parseFlashVersion(desc) {
  1423. var matches = desc.match(/[\d]+/g);
  1424. matches.length = 3;
  1425. return matches.join(".");
  1426. }
  1427. function isPepperFlash(flashPlayerFileName) {
  1428. return !!flashPlayerFileName && (flashPlayerFileName = flashPlayerFileName.toLowerCase()) && (/^(pepflashplayer\.dll|libpepflashplayer\.so|pepperflashplayer\.plugin)$/.test(flashPlayerFileName) || flashPlayerFileName.slice(-13) === "chrome.plugin");
  1429. }
  1430. function inspectPlugin(plugin) {
  1431. if (plugin) {
  1432. hasFlash = true;
  1433. if (plugin.version) {
  1434. flashVersion = parseFlashVersion(plugin.version);
  1435. }
  1436. if (!flashVersion && plugin.description) {
  1437. flashVersion = parseFlashVersion(plugin.description);
  1438. }
  1439. if (plugin.filename) {
  1440. isPPAPI = isPepperFlash(plugin.filename);
  1441. }
  1442. }
  1443. }
  1444. if (_navigator.plugins && _navigator.plugins.length) {
  1445. plugin = _navigator.plugins["Shockwave Flash"];
  1446. inspectPlugin(plugin);
  1447. if (_navigator.plugins["Shockwave Flash 2.0"]) {
  1448. hasFlash = true;
  1449. flashVersion = "2.0.0.11";
  1450. }
  1451. } else if (_navigator.mimeTypes && _navigator.mimeTypes.length) {
  1452. mimeType = _navigator.mimeTypes["application/x-shockwave-flash"];
  1453. plugin = mimeType && mimeType.enabledPlugin;
  1454. inspectPlugin(plugin);
  1455. } else if (typeof ActiveXObject !== "undefined") {
  1456. isActiveX = true;
  1457. try {
  1458. ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
  1459. hasFlash = true;
  1460. flashVersion = parseFlashVersion(ax.GetVariable("$version"));
  1461. } catch (e1) {
  1462. try {
  1463. ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
  1464. hasFlash = true;
  1465. flashVersion = "6.0.21";
  1466. } catch (e2) {
  1467. try {
  1468. ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
  1469. hasFlash = true;
  1470. flashVersion = parseFlashVersion(ax.GetVariable("$version"));
  1471. } catch (e3) {
  1472. isActiveX = false;
  1473. }
  1474. }
  1475. }
  1476. }
  1477. _flashState.disabled = hasFlash !== true;
  1478. _flashState.outdated = flashVersion && _parseFloat(flashVersion) < _parseFloat(_minimumFlashVersion);
  1479. _flashState.version = flashVersion || "0.0.0";
  1480. _flashState.pluginType = isPPAPI ? "pepper" : isActiveX ? "activex" : hasFlash ? "netscape" : "unknown";
  1481. };
  1482. /**
  1483. * Invoke the Flash detection algorithms immediately upon inclusion so we're not waiting later.
  1484. */
  1485. _detectFlashSupport(_ActiveXObject);
  1486. /**
  1487. * A shell constructor for `ZeroClipboard` client instances.
  1488. *
  1489. * @constructor
  1490. */
  1491. var ZeroClipboard = function() {
  1492. if (!(this instanceof ZeroClipboard)) {
  1493. return new ZeroClipboard();
  1494. }
  1495. if (typeof ZeroClipboard._createClient === "function") {
  1496. ZeroClipboard._createClient.apply(this, _args(arguments));
  1497. }
  1498. };
  1499. /**
  1500. * The ZeroClipboard library's version number.
  1501. *
  1502. * @static
  1503. * @readonly
  1504. * @property {string}
  1505. */
  1506. _defineProperty(ZeroClipboard, "version", {
  1507. value: "2.1.2",
  1508. writable: false,
  1509. configurable: true,