Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
Remove all utility methods only required for oldIE
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMGreene committed Jun 16, 2014
1 parent 6efa213 commit ed416a3
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 500 deletions.
141 changes: 27 additions & 114 deletions dist/ZeroClipboard.Core.js
Expand Up @@ -12,21 +12,7 @@
* 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, _parseInt = _window.Number.parseInt || _window.parseInt, _parseFloat = _window.Number.parseFloat || _window.parseFloat, _isNaN = _window.Number.isNaN || _window.isNaN, _encodeURIComponent = _window.encodeURIComponent, _Math = _window.Math, _Date = _window.Date, _ActiveXObject = _window.ActiveXObject, _slice = _window.Array.prototype.slice, _keys = _window.Object.keys, _hasOwn = _window.Object.prototype.hasOwnProperty, _defineProperty = function() {
if (typeof _window.Object.defineProperty === "function" && function() {
try {
var x = {};
_window.Object.defineProperty(x, "y", {
value: "z"
});
return x.y === "z";
} catch (e) {
return false;
}
}()) {
return _window.Object.defineProperty;
}
}();
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;
/**
* Convert an `arguments` object into an Array.
*
Expand All @@ -37,29 +23,6 @@
return _slice.call(argumentsObj, 0);
};
/**
* Get the index of an item in an Array.
*
* @returns The index of an item in the Array, or `-1` if not found.
* @private
*/
var _inArray = function(item, array, fromIndex) {
if (typeof array.indexOf === "function") {
return array.indexOf(item, fromIndex);
}
var i, len = array.length;
if (typeof fromIndex === "undefined") {
fromIndex = 0;
} else if (fromIndex < 0) {
fromIndex = len + fromIndex;
}
for (i = fromIndex; i < len; i++) {
if (_hasOwn.call(array, i) && array[i] === item) {
return i;
}
}
return -1;
};
/**
* Shallow-copy the owned, enumerable properties of one object over to another, similar to jQuery's `$.extend`.
*
* @returns The target object, augmented
Expand Down Expand Up @@ -139,34 +102,13 @@
var _omit = function(obj, keys) {
var newObj = {};
for (var prop in obj) {
if (_inArray(prop, keys) === -1) {
if (keys.indexOf(prop) === -1) {
newObj[prop] = obj[prop];
}
}
return newObj;
};
/**
* Get all of an object's owned, enumerable property names. Does NOT include prototype properties.
*
* @returns An Array of property names.
* @private
*/
var _objectKeys = function(obj) {
if (obj == null) {
return [];
}
if (_keys) {
return _keys(obj);
}
var keys = [];
for (var prop in obj) {
if (_hasOwn.call(obj, prop)) {
keys.push(prop);
}
}
return keys;
};
/**
* Remove all owned, enumerable properties from an object.
*
* @returns The original object without its owned, enumerable properties.
Expand All @@ -183,44 +125,13 @@
return obj;
};
/**
* Mark an existing property as read-only.
* @private
*/
var _makeReadOnly = function(obj, prop) {
if (prop in obj && typeof _defineProperty === "function") {
_defineProperty(obj, prop, {
value: obj[prop],
writable: false,
configurable: true,
enumerable: true
});
}
};
/**
* Get the current time in milliseconds since the epoch.
*
* @returns Number
* @private
*/
var _now = function(Date) {
return function() {
var time;
if (Date.now) {
time = Date.now();
} else {
time = new Date().getTime();
}
return time;
};
}(_Date);
/**
* Determine if an element is contained within another element.
*
* @returns Boolean
* @private
*/
var _containedBy = function(el, ancestorEl) {
if (el && el.nodeType === 1 && ancestorEl && (ancestorEl.nodeType === 1 || ancestorEl.nodeType === 9)) {
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;
Expand Down Expand Up @@ -454,7 +365,7 @@
var _off = function(eventType, listener) {
var i, len, foundIndex, events, perEventHandlers;
if (arguments.length === 0) {
events = _objectKeys(_handlers);
events = _keys(_handlers);
} else if (typeof eventType === "string" && eventType) {
events = eventType.split(/\s+/);
} else if (typeof eventType === "object" && eventType && typeof listener === "undefined") {
Expand All @@ -470,10 +381,10 @@
perEventHandlers = _handlers[eventType];
if (perEventHandlers && perEventHandlers.length) {
if (listener) {
foundIndex = _inArray(listener, perEventHandlers);
foundIndex = perEventHandlers.indexOf(listener);
while (foundIndex !== -1) {
perEventHandlers.splice(foundIndex, 1);
foundIndex = _inArray(listener, perEventHandlers, foundIndex);
foundIndex = perEventHandlers.indexOf(listener, foundIndex);
}
} else {
perEventHandlers.length = 0;
Expand Down Expand Up @@ -851,9 +762,10 @@
var element = event.target || _currentElement || null;
var sourceIsSwf = event._source === "swf";
delete event._source;
var flashErrorNames = [ "flash-disabled", "flash-outdated", "flash-unavailable", "flash-deactivated", "flash-overdue" ];
switch (event.type) {
case "error":
if (_inArray(event.name, [ "flash-disabled", "flash-outdated", "flash-deactivated", "flash-overdue" ])) {
if (flashErrorNames.indexOf(event.name) !== -1) {
_extend(_flashState, {
disabled: event.name === "flash-disabled",
outdated: event.name === "flash-outdated",
Expand Down Expand Up @@ -1215,7 +1127,8 @@
continue;
}
if (domain === "*") {
trustedOriginsExpanded = [ domain ];
trustedOriginsExpanded.length = 0;
trustedOriginsExpanded.push(domain);
break;
}
trustedOriginsExpanded.push.apply(trustedOriginsExpanded, [ domain, "//" + domain, _window.location.protocol + "//" + domain ]);
Expand Down Expand Up @@ -1264,16 +1177,13 @@
* @private
*/
var _determineScriptAccess = function() {
var _extractAllDomains = function(origins, resultsArray) {
var i, len, tmp;
if (origins == null || resultsArray[0] === "*") {
return;
}
var _extractAllDomains = function(origins) {
var i, len, tmp, resultsArray = [];
if (typeof origins === "string") {
origins = [ origins ];
}
if (!(typeof origins === "object" && typeof origins.length === "number")) {
return;
if (!(typeof origins === "object" && origins && typeof origins.length === "number")) {
return resultsArray;
}
for (i = 0, len = origins.length; i < len; i++) {
if (_hasOwn.call(origins, i) && (tmp = _extractDomain(origins[i]))) {
Expand All @@ -1282,26 +1192,25 @@
resultsArray.push("*");
break;
}
if (_inArray(tmp, resultsArray) === -1) {
if (resultsArray.indexOf(tmp) === -1) {
resultsArray.push(tmp);
}
}
}
return resultsArray;
};
return function(currentDomain, configOptions) {
var swfDomain = _extractDomain(configOptions.swfPath);
if (swfDomain === null) {
swfDomain = currentDomain;
}
var trustedDomains = [];
_extractAllDomains(configOptions.trustedOrigins, trustedDomains);
_extractAllDomains(configOptions.trustedDomains, trustedDomains);
var trustedDomains = _extractAllDomains(configOptions.trustedDomains);
var len = trustedDomains.length;
if (len > 0) {
if (len === 1 && trustedDomains[0] === "*") {
return "always";
}
if (_inArray(currentDomain, trustedDomains) !== -1) {
if (trustedDomains.indexOf(currentDomain) !== -1) {
if (len === 1 && currentDomain === swfDomain) {
return "sameDomain";
}
Expand Down Expand Up @@ -1418,7 +1327,7 @@
rect = _document.body.getBoundingClientRect();
physicalWidth = rect.right - rect.left;
logicalWidth = _document.body.offsetWidth;
zoomFactor = _Math.round(physicalWidth / logicalWidth * 100) / 100;
zoomFactor = _round(physicalWidth / logicalWidth * 100) / 100;
}
return zoomFactor;
};
Expand All @@ -1443,8 +1352,8 @@
pageYOffset = _window.pageYOffset;
} else {
zoomFactor = _getZoomFactor();
pageXOffset = _Math.round(_document.documentElement.scrollLeft / zoomFactor);
pageYOffset = _Math.round(_document.documentElement.scrollTop / zoomFactor);
pageXOffset = _round(_document.documentElement.scrollLeft / zoomFactor);
pageYOffset = _round(_document.documentElement.scrollTop / zoomFactor);
}
var leftBorderWidth = _document.documentElement.clientLeft || 0;
var topBorderWidth = _document.documentElement.clientTop || 0;
Expand Down Expand Up @@ -1608,8 +1517,12 @@
* @readonly
* @property {string}
*/
ZeroClipboard.version = "2.1.1";
_makeReadOnly(ZeroClipboard, "version");
_defineProperty(ZeroClipboard, "version", {
value: "2.1.1",
writable: false,
configurable: true,
enumerable: true
});
/**
* Update or get a copy of the ZeroClipboard global configuration.
* Returns a copy of the current/updated configuration.
Expand Down
2 changes: 1 addition & 1 deletion dist/ZeroClipboard.Core.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ZeroClipboard.Core.min.map

Large diffs are not rendered by default.

0 comments on commit ed416a3

Please sign in to comment.