-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 2 issues breaking IE8 compatibility #764
Changes from 4 commits
711fd41
f38738e
83b67a1
f2df168
e01a12b
42be6b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,29 +525,70 @@ | |
return result; | ||
} | ||
|
||
/** | ||
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice | ||
* on host objects like NamedNodeMap, NodeList, and HTMLCollection | ||
* (technically, since host objects have been implementation-dependent, | ||
* at least before ES2015, IE hasn't needed to work this way). | ||
* Also works on strings, fixes IE < 9 to allow an explicit undefined | ||
* for the 2nd argument (as in Firefox), and prevents errors when | ||
* called on other DOM objects. | ||
*/ | ||
var _slice = (function() { | ||
var slice = Array.prototype.slice; | ||
|
||
try { | ||
// Can't be used with DOM elements in IE < 9 | ||
slice.call(document.documentElement); | ||
return Array.prototype.slice; | ||
} catch (e) { // Fails in IE < 9 | ||
|
||
// This will work for genuine arrays, array-like objects, | ||
// NamedNodeMap (attributes, entities, notations), | ||
// NodeList (e.g., getElementsByTagName), HTMLCollection (e.g., childNodes), | ||
// and will not fail on other DOM objects (as do DOM elements in IE < 9) | ||
slice = function() { | ||
var i = this.length, | ||
clone = []; | ||
return function(begin, end) { | ||
// IE < 9 gets unhappy with an undefined end argument | ||
end = (end !== undefined) ? end : this.length; | ||
|
||
// For native Array objects, we use the native slice function | ||
if (this.slice){ | ||
return slice.call(this, begin, end); | ||
} | ||
|
||
while (--i > 0) { | ||
clone[i] = this[i]; | ||
// For array like object we handle it ourselves. | ||
var i, cloned = [], size, len = this.length; | ||
|
||
// Handle negative value for "begin" | ||
var start = begin || 0; | ||
start = (start >= 0) ? start : Math.max(0, len + start); | ||
|
||
// Handle negative value for "end" | ||
var upTo = (typeof end == 'number') ? Math.min(end, len) : len; | ||
if (end < 0) { | ||
upTo = len + end; | ||
} | ||
return clone; | ||
|
||
// Actual expected size of the slice | ||
size = upTo - start; | ||
|
||
if (size > 0) { | ||
cloned = new Array(size); | ||
if (this.charAt) { | ||
for (i = 0; i < size; i++) { | ||
cloned[i] = this.charAt(start + i); | ||
} | ||
} else { | ||
for (i = 0; i < size; i++) { | ||
cloned[i] = this[start + i]; | ||
} | ||
} | ||
} | ||
|
||
return cloned; | ||
}; | ||
} | ||
return slice; | ||
})(); // TODO: IE8, Cache of Array.prototype.slice that works on IE8 | ||
})(); | ||
|
||
function sanitizeElements(elements) { | ||
/* Unwrap jQuery/Zepto objects. */ | ||
|
@@ -1447,7 +1488,7 @@ | |
getUnit: function(str, start) { | ||
var unit = (str.substr(start || 0, 5).match(/^[a-z%]+/) || [])[0] || ""; | ||
|
||
if (unit && CSS.Lists.units.indexOf(unit) >= 0) { | ||
if (unit && $.inArray(unit, CSS.Lists.units) >= 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gah - just had a look, and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll remove that from my branch. |
||
return unit; | ||
} | ||
return ""; | ||
|
@@ -3856,7 +3897,7 @@ | |
|
||
/* Find shorthand color properties that have been passed a hex string. */ | ||
/* Would be quicker to use CSS.Lists.colors.includes() if possible */ | ||
if (CSS.Lists.colors.indexOf(propertyName) >= 0) { | ||
if ($.inArray(propertyName, CSS.Lists.colors) >= 0) { | ||
/* Parse the value data for each shorthand. */ | ||
var endValue = valueData[0], | ||
easing = valueData[1], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're caching it above, so can save a few bytes by returning
slice
directlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I'll fix that.