You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2581 lines
84 KiB
2581 lines
84 KiB
/*!
|
|
* ZeroClipboard
|
|
* The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.
|
|
* Copyright (c) 2009-2014 Jon Rohan, James M. Greene
|
|
* Licensed MIT
|
|
* http://zeroclipboard.org/
|
|
* v2.2.0
|
|
*/
|
|
(function(window, undefined) {
|
|
"use strict";
|
|
/**
|
|
* Store references to critically important global functions that may be
|
|
* overridden on certain web pages.
|
|
*/
|
|
var _window = window, _document = _window.document, _navigator = _window.navigator, _setTimeout = _window.setTimeout, _clearTimeout = _window.clearTimeout, _setInterval = _window.setInterval, _clearInterval = _window.clearInterval, _getComputedStyle = _window.getComputedStyle, _encodeURIComponent = _window.encodeURIComponent, _ActiveXObject = _window.ActiveXObject, _Error = _window.Error, _parseInt = _window.Number.parseInt || _window.parseInt, _parseFloat = _window.Number.parseFloat || _window.parseFloat, _isNaN = _window.Number.isNaN || _window.isNaN, _now = _window.Date.now, _keys = _window.Object.keys, _defineProperty = _window.Object.defineProperty, _hasOwn = _window.Object.prototype.hasOwnProperty, _slice = _window.Array.prototype.slice, _unwrap = function() {
|
|
var unwrapper = function(el) {
|
|
return el;
|
|
};
|
|
if (typeof _window.wrap === "function" && typeof _window.unwrap === "function") {
|
|
try {
|
|
var div = _document.createElement("div");
|
|
var unwrappedDiv = _window.unwrap(div);
|
|
if (div.nodeType === 1 && unwrappedDiv && unwrappedDiv.nodeType === 1) {
|
|
unwrapper = _window.unwrap;
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
return unwrapper;
|
|
}();
|
|
/**
|
|
* Convert an `arguments` object into an Array.
|
|
*
|
|
* @returns The arguments as an Array
|
|
* @private
|
|
*/
|
|
var _args = function(argumentsObj) {
|
|
return _slice.call(argumentsObj, 0);
|
|
};
|
|
/**
|
|
* Shallow-copy the owned, enumerable properties of one object over to another, similar to jQuery's `$.extend`.
|
|
*
|
|
* @returns The target object, augmented
|
|
* @private
|
|
*/
|
|
var _extend = function() {
|
|
var i, len, arg, prop, src, copy, args = _args(arguments), target = args[0] || {};
|
|
for (i = 1, len = args.length; i < len; i++) {
|
|
if ((arg = args[i]) != null) {
|
|
for (prop in arg) {
|
|
if (_hasOwn.call(arg, prop)) {
|
|
src = target[prop];
|
|
copy = arg[prop];
|
|
if (target !== copy && copy !== undefined) {
|
|
target[prop] = copy;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return target;
|
|
};
|
|
/**
|
|
* Return a deep copy of the source object or array.
|
|
*
|
|
* @returns Object or Array
|
|
* @private
|
|
*/
|
|
var _deepCopy = function(source) {
|
|
var copy, i, len, prop;
|
|
if (typeof source !== "object" || source == null || typeof source.nodeType === "number") {
|
|
copy = source;
|
|
} else if (typeof source.length === "number") {
|
|
copy = [];
|
|
for (i = 0, len = source.length; i < len; i++) {
|
|
if (_hasOwn.call(source, i)) {
|
|
copy[i] = _deepCopy(source[i]);
|
|
}
|
|
}
|
|
} else {
|
|
copy = {};
|
|
for (prop in source) {
|
|
if (_hasOwn.call(source, prop)) {
|
|
copy[prop] = _deepCopy(source[prop]);
|
|
}
|
|
}
|
|
}
|
|
return copy;
|
|
};
|
|
/**
|
|
* Makes a shallow copy of `obj` (like `_extend`) but filters its properties based on a list of `keys` to keep.
|
|
* The inverse of `_omit`, mostly. The big difference is that these properties do NOT need to be enumerable to
|
|
* be kept.
|
|
*
|
|
* @returns A new filtered object.
|
|
* @private
|
|
*/
|
|
var _pick = function(obj, keys) {
|
|
var newObj = {};
|
|
for (var i = 0, len = keys.length; i < len; i++) {
|
|
if (keys[i] in obj) {
|
|
newObj[keys[i]] = obj[keys[i]];
|
|
}
|
|
}
|
|
return newObj;
|
|
};
|
|
/**
|
|
* Makes a shallow copy of `obj` (like `_extend`) but filters its properties based on a list of `keys` to omit.
|
|
* The inverse of `_pick`.
|
|
*
|
|
* @returns A new filtered object.
|
|
* @private
|
|
*/
|
|
var _omit = function(obj, keys) {
|
|
var newObj = {};
|
|
for (var prop in obj) {
|
|
if (keys.indexOf(prop) === -1) {
|
|
newObj[prop] = obj[prop];
|
|
}
|
|
}
|
|
return newObj;
|
|
};
|
|
/**
|
|
* Remove all owned, enumerable properties from an object.
|
|
*
|
|
* @returns The original object without its owned, enumerable properties.
|
|
* @private
|
|
*/
|
|
var _deleteOwnProperties = function(obj) {
|
|
if (obj) {
|
|
for (var prop in obj) {
|
|
if (_hasOwn.call(obj, prop)) {
|
|
delete obj[prop];
|
|
}
|
|
}
|
|
}
|
|
return obj;
|
|
};
|
|
/**
|
|
* Determine if an element is contained within another element.
|
|
*
|
|
* @returns Boolean
|
|
* @private
|
|
*/
|
|
var _containedBy = function(el, ancestorEl) {
|
|
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)) {
|
|
do {
|
|
if (el === ancestorEl) {
|
|
return true;
|
|
}
|
|
el = el.parentNode;
|
|
} while (el);
|
|
}
|
|
return false;
|
|
};
|
|
/**
|
|
* Get the URL path's parent directory.
|
|
*
|
|
* @returns String or `undefined`
|
|
* @private
|
|
*/
|
|
var _getDirPathOfUrl = function(url) {
|
|
var dir;
|
|
if (typeof url === "string" && url) {
|
|
dir = url.split("#")[0].split("?")[0];
|
|
dir = url.slice(0, url.lastIndexOf("/") + 1);
|
|
}
|
|
return dir;
|
|
};
|
|
/**
|
|
* Get the current script's URL by throwing an `Error` and analyzing it.
|
|
*
|
|
* @returns String or `undefined`
|
|
* @private
|
|
*/
|
|
var _getCurrentScriptUrlFromErrorStack = function(stack) {
|
|
var url, matches;
|
|
if (typeof stack === "string" && stack) {
|
|
matches = stack.match(/^(?:|[^:@]*@|.+\)@(?=http[s]?|file)|.+?\s+(?: at |@)(?:[^:\(]+ )*[\(]?)((?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?/);
|
|
if (matches && matches[1]) {
|
|
url = matches[1];
|
|
} else {
|
|
matches = stack.match(/\)@((?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?/);
|
|
if (matches && matches[1]) {
|
|
url = matches[1];
|
|
}
|
|
}
|
|
}
|
|
return url;
|
|
};
|
|
/**
|
|
* Get the current script's URL by throwing an `Error` and analyzing it.
|
|
*
|
|
* @returns String or `undefined`
|
|
* @private
|
|
*/
|
|
var _getCurrentScriptUrlFromError = function() {
|
|
var url, err;
|
|
try {
|
|
throw new _Error();
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
if (err) {
|
|
url = err.sourceURL || err.fileName || _getCurrentScriptUrlFromErrorStack(err.stack);
|
|
}
|
|
return url;
|
|
};
|
|
/**
|
|
* Get the current script's URL.
|
|
*
|
|
* @returns String or `undefined`
|
|
* @private
|
|
*/
|
|
var _getCurrentScriptUrl = function() {
|
|
var jsPath, scripts, i;
|
|
if (_document.currentScript && (jsPath = _document.currentScript.src)) {
|
|
return jsPath;
|
|
}
|
|
scripts = _document.getElementsByTagName("script");
|
|
if (scripts.length === 1) {
|
|
return scripts[0].src || undefined;
|
|
}
|
|
if ("readyState" in scripts[0]) {
|
|
for (i = scripts.length; i--; ) {
|
|
if (scripts[i].readyState === "interactive" && (jsPath = scripts[i].src)) {
|
|
return jsPath;
|
|
}
|
|
}
|
|
}
|
|
if (_document.readyState === "loading" && (jsPath = scripts[scripts.length - 1].src)) {
|
|
return jsPath;
|
|
}
|
|
if (jsPath = _getCurrentScriptUrlFromError()) {
|
|
return jsPath;
|
|
}
|
|
return undefined;
|
|
};
|
|
/**
|
|
* Get the unanimous parent directory of ALL script tags.
|
|
* If any script tags are either (a) inline or (b) from differing parent
|
|
* directories, this method must return `undefined`.
|
|
*
|
|
* @returns String or `undefined`
|
|
* @private
|
|
*/
|
|
var _getUnanimousScriptParentDir = function() {
|
|
var i, jsDir, jsPath, scripts = _document.getElementsByTagName("script");
|
|
for (i = scripts.length; i--; ) {
|
|
if (!(jsPath = scripts[i].src)) {
|
|
jsDir = null;
|
|
break;
|
|
}
|
|
jsPath = _getDirPathOfUrl(jsPath);
|
|
if (jsDir == null) {
|
|
jsDir = jsPath;
|
|
} else if (jsDir !== jsPath) {
|
|
jsDir = null;
|
|
break;
|
|
}
|
|
}
|
|
return jsDir || undefined;
|
|
};
|
|
/**
|
|
* Get the presumed location of the "ZeroClipboard.swf" file, based on the location
|
|
* of the executing JavaScript file (e.g. "ZeroClipboard.js", etc.).
|
|
*
|
|
* @returns String
|
|
* @private
|
|
*/
|
|
var _getDefaultSwfPath = function() {
|
|
var jsDir = _getDirPathOfUrl(_getCurrentScriptUrl()) || _getUnanimousScriptParentDir() || "";
|
|
return jsDir + "ZeroClipboard.swf";
|
|
};
|
|
/**
|
|
* Keep track of if the page is framed (in an `iframe`). This can never change.
|
|
* @private
|
|
*/
|
|
var _pageIsFramed = function() {
|
|
return window.opener == null && (!!window.top && window != window.top || !!window.parent && window != window.parent);
|
|
}();
|
|
/**
|
|
* Keep track of the state of the Flash object.
|
|
* @private
|
|
*/
|
|
var _flashState = {
|
|
bridge: null,
|
|
version: "0.0.0",
|
|
pluginType: "unknown",
|
|
disabled: null,
|
|
outdated: null,
|
|
sandboxed: null,
|
|
unavailable: null,
|
|
degraded: null,
|
|
deactivated: null,
|
|
overdue: null,
|
|
ready: null
|
|
};
|
|
/**
|
|
* The minimum Flash Player version required to use ZeroClipboard completely.
|
|
* @readonly
|
|
* @private
|
|
*/
|
|
var _minimumFlashVersion = "11.0.0";
|
|
/**
|
|
* The ZeroClipboard library version number, as reported by Flash, at the time the SWF was compiled.
|
|
*/
|
|
var _zcSwfVersion;
|
|
/**
|
|
* Keep track of all event listener registrations.
|
|
* @private
|
|
*/
|
|
var _handlers = {};
|
|
/**
|
|
* Keep track of the currently activated element.
|
|
* @private
|
|
*/
|
|
var _currentElement;
|
|
/**
|
|
* Keep track of the element that was activated when a `copy` process started.
|
|
* @private
|
|
*/
|
|
var _copyTarget;
|
|
/**
|
|
* Keep track of data for the pending clipboard transaction.
|
|
* @private
|
|
*/
|
|
var _clipData = {};
|
|
/**
|
|
* Keep track of data formats for the pending clipboard transaction.
|
|
* @private
|
|
*/
|
|
var _clipDataFormatMap = null;
|
|
/**
|
|
* Keep track of the Flash availability check timeout.
|
|
* @private
|
|
*/
|
|
var _flashCheckTimeout = 0;
|
|
/**
|
|
* Keep track of SWF network errors interval polling.
|
|
* @private
|
|
*/
|
|
var _swfFallbackCheckInterval = 0;
|
|
/**
|
|
* The `message` store for events
|
|
* @private
|
|
*/
|
|
var _eventMessages = {
|
|
ready: "Flash communication is established",
|
|
error: {
|
|
"flash-disabled": "Flash is disabled or not installed. May also be attempting to run Flash in a sandboxed iframe, which is impossible.",
|
|
"flash-outdated": "Flash is too outdated to support ZeroClipboard",
|
|
"flash-sandboxed": "Attempting to run Flash in a sandboxed iframe, which is impossible",
|
|
"flash-unavailable": "Flash is unable to communicate bidirectionally with JavaScript",
|
|
"flash-degraded": "Flash is unable to preserve data fidelity when communicating with JavaScript",
|
|
"flash-deactivated": "Flash is too outdated for your browser and/or is configured as click-to-activate.\nThis may also mean that the ZeroClipboard SWF object could not be loaded, so please check your `swfPath` configuration and/or network connectivity.\nMay also be attempting to run Flash in a sandboxed iframe, which is impossible.",
|
|
"flash-overdue": "Flash communication was established but NOT within the acceptable time limit",
|
|
"version-mismatch": "ZeroClipboard JS version number does not match ZeroClipboard SWF version number",
|
|
"clipboard-error": "At least one error was thrown while ZeroClipboard was attempting to inject your data into the clipboard",
|
|
"config-mismatch": "ZeroClipboard configuration does not match Flash's reality",
|
|
"swf-not-found": "The ZeroClipboard SWF object could not be loaded, so please check your `swfPath` configuration and/or network connectivity"
|
|
}
|
|
};
|
|
/**
|
|
* The `name`s of `error` events that can only occur is Flash has at least
|
|
* been able to load the SWF successfully.
|
|
* @private
|
|
*/
|
|
var _errorsThatOnlyOccurAfterFlashLoads = [ "flash-unavailable", "flash-degraded", "flash-overdue", "version-mismatch", "config-mismatch", "clipboard-error" ];
|
|
/**
|
|
* The `name`s of `error` events that should likely result in the `_flashState`
|
|
* variable's property values being updated.
|
|
* @private
|
|
*/
|
|
var _flashStateErrorNames = [ "flash-disabled", "flash-outdated", "flash-sandboxed", "flash-unavailable", "flash-degraded", "flash-deactivated", "flash-overdue" ];
|
|
/**
|
|
* A RegExp to match the `name` property of `error` events related to Flash.
|
|
* @private
|
|
*/
|
|
var _flashStateErrorNameMatchingRegex = new RegExp("^flash-(" + _flashStateErrorNames.map(function(errorName) {
|
|
return errorName.replace(/^flash-/, "");
|
|
}).join("|") + ")$");
|
|
/**
|
|
* A RegExp to match the `name` property of `error` events related to Flash,
|
|
* which is enabled.
|
|
* @private
|
|
*/
|
|
var _flashStateEnabledErrorNameMatchingRegex = new RegExp("^flash-(" + _flashStateErrorNames.slice(1).map(function(errorName) {
|
|
return errorName.replace(/^flash-/, "");
|
|
}).join("|") + ")$");
|
|
/**
|
|
* ZeroClipboard configuration defaults for the Core module.
|
|
* @private
|
|
*/
|
|
var _globalConfig = {
|
|
swfPath: _getDefaultSwfPath(),
|
|
trustedDomains: window.location.host ? [ window.location.host ] : [],
|
|
cacheBust: true,
|
|
forceEnhancedClipboard: false,
|
|
flashLoadTimeout: 3e4,
|
|
autoActivate: true,
|
|
bubbleEvents: true,
|
|
containerId: "global-zeroclipboard-html-bridge",
|
|
containerClass: "global-zeroclipboard-container",
|
|
swfObjectId: "global-zeroclipboard-flash-bridge",
|
|
hoverClass: "zeroclipboard-is-hover",
|
|
activeClass: "zeroclipboard-is-active",
|
|
forceHandCursor: false,
|
|
title: null,
|
|
zIndex: 999999999
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.config`.
|
|
* @private
|
|
*/
|
|
var _config = function(options) {
|
|
if (typeof options === "object" && options !== null) {
|
|
for (var prop in options) {
|
|
if (_hasOwn.call(options, prop)) {
|
|
if (/^(?:forceHandCursor|title|zIndex|bubbleEvents)$/.test(prop)) {
|
|
_globalConfig[prop] = options[prop];
|
|
} else if (_flashState.bridge == null) {
|
|
if (prop === "containerId" || prop === "swfObjectId") {
|
|
if (_isValidHtml4Id(options[prop])) {
|
|
_globalConfig[prop] = options[prop];
|
|
} else {
|
|
throw new Error("The specified `" + prop + "` value is not valid as an HTML4 Element ID");
|
|
}
|
|
} else {
|
|
_globalConfig[prop] = options[prop];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (typeof options === "string" && options) {
|
|
if (_hasOwn.call(_globalConfig, options)) {
|
|
return _globalConfig[options];
|
|
}
|
|
return;
|
|
}
|
|
return _deepCopy(_globalConfig);
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.state`.
|
|
* @private
|
|
*/
|
|
var _state = function() {
|
|
_detectSandbox();
|
|
return {
|
|
browser: _pick(_navigator, [ "userAgent", "platform", "appName" ]),
|
|
flash: _omit(_flashState, [ "bridge" ]),
|
|
zeroclipboard: {
|
|
version: ZeroClipboard.version,
|
|
config: ZeroClipboard.config()
|
|
}
|
|
};
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.isFlashUnusable`.
|
|
* @private
|
|
*/
|
|
var _isFlashUnusable = function() {
|
|
return !!(_flashState.disabled || _flashState.outdated || _flashState.sandboxed || _flashState.unavailable || _flashState.degraded || _flashState.deactivated);
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.on`.
|
|
* @private
|
|
*/
|
|
var _on = function(eventType, listener) {
|
|
var i, len, events, added = {};
|
|
if (typeof eventType === "string" && eventType) {
|
|
events = eventType.toLowerCase().split(/\s+/);
|
|
} else if (typeof eventType === "object" && eventType && typeof listener === "undefined") {
|
|
for (i in eventType) {
|
|
if (_hasOwn.call(eventType, i) && typeof i === "string" && i && typeof eventType[i] === "function") {
|
|
ZeroClipboard.on(i, eventType[i]);
|
|
}
|
|
}
|
|
}
|
|
if (events && events.length) {
|
|
for (i = 0, len = events.length; i < len; i++) {
|
|
eventType = events[i].replace(/^on/, "");
|
|
added[eventType] = true;
|
|
if (!_handlers[eventType]) {
|
|
_handlers[eventType] = [];
|
|
}
|
|
_handlers[eventType].push(listener);
|
|
}
|
|
if (added.ready && _flashState.ready) {
|
|
ZeroClipboard.emit({
|
|
type: "ready"
|
|
});
|
|
}
|
|
if (added.error) {
|
|
for (i = 0, len = _flashStateErrorNames.length; i < len; i++) {
|
|
if (_flashState[_flashStateErrorNames[i].replace(/^flash-/, "")] === true) {
|
|
ZeroClipboard.emit({
|
|
type: "error",
|
|
name: _flashStateErrorNames[i]
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
if (_zcSwfVersion !== undefined && ZeroClipboard.version !== _zcSwfVersion) {
|
|
ZeroClipboard.emit({
|
|
type: "error",
|
|
name: "version-mismatch",
|
|
jsVersion: ZeroClipboard.version,
|
|
swfVersion: _zcSwfVersion
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return ZeroClipboard;
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.off`.
|
|
* @private
|
|
*/
|
|
var _off = function(eventType, listener) {
|
|
var i, len, foundIndex, events, perEventHandlers;
|
|
if (arguments.length === 0) {
|
|
events = _keys(_handlers);
|
|
} else if (typeof eventType === "string" && eventType) {
|
|
events = eventType.split(/\s+/);
|
|
} else if (typeof eventType === "object" && eventType && typeof listener === "undefined") {
|
|
for (i in eventType) {
|
|
if (_hasOwn.call(eventType, i) && typeof i === "string" && i && typeof eventType[i] === "function") {
|
|
ZeroClipboard.off(i, eventType[i]);
|
|
}
|
|
}
|
|
}
|
|
if (events && events.length) {
|
|
for (i = 0, len = events.length; i < len; i++) {
|
|
eventType = events[i].toLowerCase().replace(/^on/, "");
|
|
perEventHandlers = _handlers[eventType];
|
|
if (perEventHandlers && perEventHandlers.length) {
|
|
if (listener) {
|
|
foundIndex = perEventHandlers.indexOf(listener);
|
|
while (foundIndex !== -1) {
|
|
perEventHandlers.splice(foundIndex, 1);
|
|
foundIndex = perEventHandlers.indexOf(listener, foundIndex);
|
|
}
|
|
} else {
|
|
perEventHandlers.length = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return ZeroClipboard;
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.handlers`.
|
|
* @private
|
|
*/
|
|
var _listeners = function(eventType) {
|
|
var copy;
|
|
if (typeof eventType === "string" && eventType) {
|
|
copy = _deepCopy(_handlers[eventType]) || null;
|
|
} else {
|
|
copy = _deepCopy(_handlers);
|
|
}
|
|
return copy;
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.emit`.
|
|
* @private
|
|
*/
|
|
var _emit = function(event) {
|
|
var eventCopy, returnVal, tmp;
|
|
event = _createEvent(event);
|
|
if (!event) {
|
|
return;
|
|
}
|
|
if (_preprocessEvent(event)) {
|
|
return;
|
|
}
|
|
if (event.type === "ready" && _flashState.overdue === true) {
|
|
return ZeroClipboard.emit({
|
|
type: "error",
|
|
name: "flash-overdue"
|
|
});
|
|
}
|
|
eventCopy = _extend({}, event);
|
|
_dispatchCallbacks.call(this, eventCopy);
|
|
if (event.type === "copy") {
|
|
tmp = _mapClipDataToFlash(_clipData);
|
|
returnVal = tmp.data;
|
|
_clipDataFormatMap = tmp.formatMap;
|
|
}
|
|
return returnVal;
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.create`.
|
|
* @private
|
|
*/
|
|
var _create = function() {
|
|
var previousState = _flashState.sandboxed;
|
|
_detectSandbox();
|
|
if (typeof _flashState.ready !== "boolean") {
|
|
_flashState.ready = false;
|
|
}
|
|
if (_flashState.sandboxed !== previousState && _flashState.sandboxed === true) {
|
|
_flashState.ready = false;
|
|
ZeroClipboard.emit({
|
|
type: "error",
|
|
name: "flash-sandboxed"
|
|
});
|
|
} else if (!ZeroClipboard.isFlashUnusable() && _flashState.bridge === null) {
|
|
var maxWait = _globalConfig.flashLoadTimeout;
|
|
if (typeof maxWait === "number" && maxWait >= 0) {
|
|
_flashCheckTimeout = _setTimeout(function() {
|
|
if (typeof _flashState.deactivated !== "boolean") {
|
|
_flashState.deactivated = true;
|
|
}
|
|
if (_flashState.deactivated === true) {
|
|
ZeroClipboard.emit({
|
|
type: "error",
|
|
name: "flash-deactivated"
|
|
});
|
|
}
|
|
}, maxWait);
|
|
}
|
|
_flashState.overdue = false;
|
|
_embedSwf();
|
|
}
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.destroy`.
|
|
* @private
|
|
*/
|
|
var _destroy = function() {
|
|
ZeroClipboard.clearData();
|
|
ZeroClipboard.blur();
|
|
ZeroClipboard.emit("destroy");
|
|
_unembedSwf();
|
|
ZeroClipboard.off();
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.setData`.
|
|
* @private
|
|
*/
|
|
var _setData = function(format, data) {
|
|
var dataObj;
|
|
if (typeof format === "object" && format && typeof data === "undefined") {
|
|
dataObj = format;
|
|
ZeroClipboard.clearData();
|
|
} else if (typeof format === "string" && format) {
|
|
dataObj = {};
|
|
dataObj[format] = data;
|
|
} else {
|
|
return;
|
|
}
|
|
for (var dataFormat in dataObj) {
|
|
if (typeof dataFormat === "string" && dataFormat && _hasOwn.call(dataObj, dataFormat) && typeof dataObj[dataFormat] === "string" && dataObj[dataFormat]) {
|
|
_clipData[dataFormat] = dataObj[dataFormat];
|
|
}
|
|
}
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.clearData`.
|
|
* @private
|
|
*/
|
|
var _clearData = function(format) {
|
|
if (typeof format === "undefined") {
|
|
_deleteOwnProperties(_clipData);
|
|
_clipDataFormatMap = null;
|
|
} else if (typeof format === "string" && _hasOwn.call(_clipData, format)) {
|
|
delete _clipData[format];
|
|
}
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.getData`.
|
|
* @private
|
|
*/
|
|
var _getData = function(format) {
|
|
if (typeof format === "undefined") {
|
|
return _deepCopy(_clipData);
|
|
} else if (typeof format === "string" && _hasOwn.call(_clipData, format)) {
|
|
return _clipData[format];
|
|
}
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.focus`/`ZeroClipboard.activate`.
|
|
* @private
|
|
*/
|
|
var _focus = function(element) {
|
|
if (!(element && element.nodeType === 1)) {
|
|
return;
|
|
}
|
|
if (_currentElement) {
|
|
_removeClass(_currentElement, _globalConfig.activeClass);
|
|
if (_currentElement !== element) {
|
|
_removeClass(_currentElement, _globalConfig.hoverClass);
|
|
}
|
|
}
|
|
_currentElement = element;
|
|
_addClass(element, _globalConfig.hoverClass);
|
|
var newTitle = element.getAttribute("title") || _globalConfig.title;
|
|
if (typeof newTitle === "string" && newTitle) {
|
|
var htmlBridge = _getHtmlBridge(_flashState.bridge);
|
|
if (htmlBridge) {
|
|
htmlBridge.setAttribute("title", newTitle);
|
|
}
|
|
}
|
|
var useHandCursor = _globalConfig.forceHandCursor === true || _getStyle(element, "cursor") === "pointer";
|
|
_setHandCursor(useHandCursor);
|
|
_reposition();
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.blur`/`ZeroClipboard.deactivate`.
|
|
* @private
|
|
*/
|
|
var _blur = function() {
|
|
var htmlBridge = _getHtmlBridge(_flashState.bridge);
|
|
if (htmlBridge) {
|
|
htmlBridge.removeAttribute("title");
|
|
htmlBridge.style.left = "0px";
|
|
htmlBridge.style.top = "-9999px";
|
|
htmlBridge.style.width = "1px";
|
|
htmlBridge.style.height = "1px";
|
|
}
|
|
if (_currentElement) {
|
|
_removeClass(_currentElement, _globalConfig.hoverClass);
|
|
_removeClass(_currentElement, _globalConfig.activeClass);
|
|
_currentElement = null;
|
|
}
|
|
};
|
|
/**
|
|
* The underlying implementation of `ZeroClipboard.activeElement`.
|
|
* @private
|
|
*/
|
|
var _activeElement = function() {
|
|
return _currentElement || null;
|
|
};
|
|
/**
|
|
* Check if a value is a valid HTML4 `ID` or `Name` token.
|
|
* @private
|
|
*/
|
|
var _isValidHtml4Id = function(id) {
|
|
return typeof id === "string" && id && /^[A-Za-z][A-Za-z0-9_:\-\.]*$/.test(id);
|
|
};
|
|
/**
|
|
* Create or update an `event` object, based on the `eventType`.
|
|
* @private
|
|
*/
|
|
var _createEvent = function(event) {
|
|
var eventType;
|
|
if (typeof event === "string" && event) {
|
|
eventType = event;
|
|
event = {};
|
|
} else if (typeof event === "object" && event && typeof event.type === "string" && event.type) {
|
|
eventType = event.type;
|
|
}
|
|
if (!eventType) {
|
|
return;
|
|
}
|
|
eventType = eventType.toLowerCase();
|
|
if (!event.target && (/^(copy|aftercopy|_click)$/.test(eventType) || eventType === "error" && event.name === "clipboard-error")) {
|
|
event.target = _copyTarget;
|
|
}
|
|
_extend(event, {
|
|
type: eventType,
|
|
target: event.target || _currentElement || null,
|
|
relatedTarget: event.relatedTarget || null,
|
|
currentTarget: _flashState && _flashState.bridge || null,
|
|
timeStamp: event.timeStamp || _now() || null
|
|
});
|
|
var msg = _eventMessages[event.type];
|
|
if (event.type === "error" && event.name && msg) {
|
|
msg = msg[event.name];
|
|
}
|
|
if (msg) {
|
|
event.message = msg;
|
|
}
|
|
if (event.type === "ready") {
|
|
_extend(event, {
|
|
target: null,
|
|
version: _flashState.version
|
|
});
|
|
}
|
|
if (event.type === "error") {
|
|
if (_flashStateErrorNameMatchingRegex.test(event.name)) {
|
|
_extend(event, {
|
|
target: null,
|
|
minimumVersion: _minimumFlashVersion
|
|
});
|
|
}
|
|
if (_flashStateEnabledErrorNameMatchingRegex.test(event.name)) {
|
|
_extend(event, {
|
|
version: _flashState.version
|
|
});
|
|
}
|
|
}
|
|
if (event.type === "copy") {
|
|
event.clipboardData = {
|
|
setData: ZeroClipboard.setData,
|
|
clearData: ZeroClipboard.clearData
|
|
};
|
|
}
|
|
if (event.type === "aftercopy") {
|
|
event = _mapClipResultsFromFlash(event, _clipDataFormatMap);
|
|
}
|
|
if (event.target && !event.relatedTarget) {
|
|
event.relatedTarget = _getRelatedTarget(event.target);
|
|
}
|
|
return _addMouseData(event);
|
|
};
|
|
/**
|
|
* Get a relatedTarget from the target's `data-clipboard-target` attribute
|
|
* @private
|
|
*/
|
|
var _getRelatedTarget = function(targetEl) {
|
|
var relatedTargetId = targetEl && targetEl.getAttribute && targetEl.getAttribute("data-clipboard-target");
|
|
return relatedTargetId ? _document.getElementById(relatedTargetId) : null;
|
|
};
|
|
/**
|
|
* Add element and position data to `MouseEvent` instances
|
|
* @private
|
|
*/
|
|
var _addMouseData = function(event) {
|
|
if (event && /^_(?:click|mouse(?:over|out|down|up|move))$/.test(event.type)) {
|
|
var srcElement = event.target;
|
|
var fromElement = event.type === "_mouseover" && event.relatedTarget ? event.relatedTarget : undefined;
|
|
var toElement = event.type === "_mouseout" && event.relatedTarget ? event.relatedTarget : undefined;
|
|
var pos = _getElementPosition(srcElement);
|
|
var screenLeft = _window.screenLeft || _window.screenX || 0;
|
|
var screenTop = _window.screenTop || _window.screenY || 0;
|
|
var scrollLeft = _document.body.scrollLeft + _document.documentElement.scrollLeft;
|
|
var scrollTop = _document.body.scrollTop + _document.documentElement.scrollTop;
|
|
var pageX = pos.left + (typeof event._stageX === "number" ? event._stageX : 0);
|
|
var pageY = pos.top + (typeof event._stageY === "number" ? event._stageY : 0);
|
|
var clientX = pageX - scrollLeft;
|
|
var clientY = pageY - scrollTop;
|
|
var screenX = screenLeft + clientX;
|
|
var screenY = screenTop + clientY;
|
|
var moveX = typeof event.movementX === "number" ? event.movementX : 0;
|
|
var moveY = typeof event.movementY === "number" ? event.movementY : 0;
|
|
delete event._stageX;
|
|
delete event._stageY;
|
|
_extend(event, {
|
|
srcElement: srcElement,
|
|
fromElement: fromElement,
|
|
toElement: toElement,
|
|
screenX: screenX,
|
|
screenY: screenY,
|
|
pageX: pageX,
|
|
pageY: pageY,
|
|
clientX: clientX,
|
|
clientY: clientY,
|
|
x: clientX,
|
|
y: clientY,
|
|
movementX: moveX,
|
|
movementY: moveY,
|
|
offsetX: 0,
|
|
offsetY: 0,
|
|
layerX: 0,
|
|
layerY: 0
|
|
});
|
|
}
|
|
return event;
|
|
};
|
|
/**
|
|
* Determine if an event's registered handlers should be execute synchronously or asynchronously.
|
|
*
|
|
* @returns {boolean}
|
|
* @private
|
|
*/
|
|
var _shouldPerformAsync = function(event) {
|
|
var eventType = event && typeof event.type === "string" && event.type || "";
|
|
return !/^(?:(?:before)?copy|destroy)$/.test(eventType);
|
|
};
|
|
/**
|
|
* Control if a callback should be executed asynchronously or not.
|
|
*
|
|
* @returns `undefined`
|
|
* @private
|
|
*/
|
|
var _dispatchCallback = function(func, context, args, async) {
|
|
if (async) {
|
|
_setTimeout(function() {
|
|
func.apply(context, args);
|
|
}, 0);
|
|
} else {
|
|
func.apply(context, args);
|
|
}
|
|
};
|
|
/**
|
|
* Handle the actual dispatching of events to client instances.
|
|
*
|
|
* @returns `undefined`
|
|
* @private
|
|
*/
|
|
var _dispatchCallbacks = function(event) {
|
|
if (!(typeof event === "object" && event && event.type)) {
|
|
return;
|
|
}
|
|
var async = _shouldPerformAsync(event);
|
|
var wildcardTypeHandlers = _handlers["*"] || [];
|
|
var specificTypeHandlers = _handlers[event.type] || [];
|
|
var handlers = wildcardTypeHandlers.concat(specificTypeHandlers);
|
|
if (handlers && handlers.length) {
|
|
var i, len, func, context, eventCopy, originalContext = this;
|
|
for (i = 0, len = handlers.length; i < len; i++) {
|
|
func = handlers[i];
|
|
context = originalContext;
|
|
if (typeof func === "string" && typeof _window[func] === "function") {
|
|
func = _window[func];
|
|
}
|
|
if (typeof func === "object" && func && typeof func.handleEvent === "function") {
|
|
context = func;
|
|
func = func.handleEvent;
|
|
}
|
|
if (typeof func === "function") {
|
|
eventCopy = _extend({}, event);
|
|
_dispatchCallback(func, context, [ eventCopy ], async);
|
|
}
|
|
}
|
|
}
|
|
return this;
|
|
};
|
|
/**
|
|
* Check an `error` event's `name` property to see if Flash has
|
|
* already loaded, which rules out possible `iframe` sandboxing.
|
|
* @private
|
|
*/
|
|
var _getSandboxStatusFromErrorEvent = function(event) {
|
|
var isSandboxed = null;
|
|
if (_pageIsFramed === false || event && event.type === "error" && event.name && _errorsThatOnlyOccurAfterFlashLoads.indexOf(event.name) !== -1) {
|
|
isSandboxed = false;
|
|
}
|
|
return isSandboxed;
|
|
};
|
|
/**
|
|
* Preprocess any special behaviors, reactions, or state changes after receiving this event.
|
|
* Executes only once per event emitted, NOT once per client.
|
|
* @private
|
|
*/
|
|
var _preprocessEvent = function(event) {
|
|
var element = event.target || _currentElement || null;
|
|
var sourceIsSwf = event._source === "swf";
|
|
delete event._source;
|
|
switch (event.type) {
|
|
case "error":
|
|
var isSandboxed = event.name === "flash-sandboxed" || _getSandboxStatusFromErrorEvent(event);
|
|
if (typeof isSandboxed === "boolean") {
|
|
_flashState.sandboxed = isSandboxed;
|
|
}
|
|
if (_flashStateErrorNames.indexOf(event.name) !== -1) {
|
|
_extend(_flashState, {
|
|
disabled: event.name === "flash-disabled",
|
|
outdated: event.name === "flash-outdated",
|
|
unavailable: event.name === "flash-unavailable",
|
|
degraded: event.name === "flash-degraded",
|
|
deactivated: event.name === "flash-deactivated",
|
|
overdue: event.name === "flash-overdue",
|
|
ready: false
|
|
});
|
|
} else if (event.name === "version-mismatch") {
|
|
_zcSwfVersion = event.swfVersion;
|
|
_extend(_flashState, {
|
|
disabled: false,
|
|
outdated: false,
|
|
unavailable: false,
|
|
degraded: false,
|
|
deactivated: false,
|
|
overdue: false,
|
|
ready: false
|
|
});
|
|
}
|
|
_clearTimeoutsAndPolling();
|
|
break;
|
|
|
|
case "ready":
|
|
_zcSwfVersion = event.swfVersion;
|
|
var wasDeactivated = _flashState.deactivated === true;
|
|
_extend(_flashState, {
|
|
disabled: false,
|
|
outdated: false,
|
|
sandboxed: false,
|
|
unavailable: false,
|
|
degraded: false,
|
|
deactivated: false,
|
|
overdue: wasDeactivated,
|
|
ready: !wasDeactivated
|
|
});
|
|
_clearTimeoutsAndPolling();
|
|
break;
|
|
|
|
case "beforecopy":
|
|
_copyTarget = element;
|
|
break;
|
|
|
|
case "copy":
|
|
var textContent, htmlContent, targetEl = event.relatedTarget;
|
|
if (!(_clipData["text/html"] || _clipData["text/plain"]) && targetEl && (htmlContent = targetEl.value || targetEl.outerHTML || targetEl.innerHTML) && (textContent = targetEl.value || targetEl.textContent || targetEl.innerText)) {
|
|
event.clipboardData.clearData();
|
|
event.clipboardData.setData("text/plain", textContent);
|
|
if (htmlContent !== textContent) {
|
|
event.clipboardData.setData("text/html", htmlContent);
|
|
}
|
|
} else if (!_clipData["text/plain"] && event.target && (textContent = event.target.getAttribute("data-clipboard-text"))) {
|
|
event.clipboardData.clearData();
|
|
event.clipboardData.setData("text/plain", textContent);
|
|
}
|
|
break;
|
|
|
|
case "aftercopy":
|
|
_queueEmitClipboardErrors(event);
|
|
ZeroClipboard.clearData();
|
|
if (element && element !== _safeActiveElement() && element.focus) {
|
|
element.focus();
|
|
}
|
|
break;
|
|
|
|
case "_mouseover":
|
|
ZeroClipboard.focus(element);
|
|
if (_globalConfig.bubbleEvents === true && sourceIsSwf) {
|
|
if (element && element !== event.relatedTarget && !_containedBy(event.relatedTarget, element)) {
|
|
_fireMouseEvent(_extend({}, event, {
|
|
type: "mouseenter",
|
|
bubbles: false,
|
|
cancelable: false
|
|
}));
|
|
}
|
|