-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two polyfills for nextElementSibling and previousElementSibling
I've added two new files polyfill files although they didn't come directly from polyfill.io they were based off a PR that was merged in the library but not included in the new polyfill-library repo. I've added comments pointing to the original pull request for the detection and for the polyfill.
- Loading branch information
Showing
3 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/vendor/polyfills/Element/prototype/nextElementSibling.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import '../../Object/defineProperty' | ||
import '../../Element' | ||
|
||
(function(undefined) { | ||
|
||
// Detection from https://github.com/Financial-Times/polyfill-service/pull/1062/files#diff-b09a5d2acf3314b46a6c8f8d0c31b85c | ||
var detect = ( | ||
'Element' in this && "nextElementSibling" in document.documentElement | ||
) | ||
|
||
if (detect) return | ||
|
||
|
||
(function (global) { | ||
var dpSupport = true; | ||
var defineGetter = function (object, name, fn, configurable) { | ||
if (Object.defineProperty) | ||
Object.defineProperty(object, name, { | ||
configurable: false === dpSupport ? true : !!configurable, | ||
get: fn | ||
}); | ||
|
||
else object.__defineGetter__(name, fn); | ||
}; | ||
/** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */ | ||
try { | ||
defineGetter({}, "support"); | ||
} | ||
catch (e) { | ||
dpSupport = false; | ||
} | ||
|
||
// Polyfill from https://github.com/Financial-Times/polyfill-service/pull/1062/files#diff-404b69b4750d18dea4174930a49170fd | ||
Object.defineProperty(Element.prototype, "nextElementSibling", { | ||
get: function(){ | ||
var el = this.nextSibling; | ||
while (el && el.nodeType !== 1) { el = el.nextSibling; } | ||
return (el.nodeType === 1) ? el : null; | ||
} | ||
}); | ||
|
||
}(this)); | ||
|
||
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); |
43 changes: 43 additions & 0 deletions
43
src/vendor/polyfills/Element/prototype/previousElementSibling.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import '../../Object/defineProperty' | ||
import '../../Element' | ||
|
||
(function(undefined) { | ||
|
||
// Detection from https://github.com/Financial-Times/polyfill-service/pull/1062/files#diff-a162235fbc9c0dd40d4032265f44942e | ||
var detect = ( | ||
'Element' in this && 'previousElementSibling' in document.documentElement | ||
) | ||
|
||
if (detect) return | ||
|
||
(function (global) { | ||
var dpSupport = true; | ||
var defineGetter = function (object, name, fn, configurable) { | ||
if (Object.defineProperty) | ||
Object.defineProperty(object, name, { | ||
configurable: false === dpSupport ? true : !!configurable, | ||
get: fn | ||
}); | ||
|
||
else object.__defineGetter__(name, fn); | ||
}; | ||
/** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */ | ||
try { | ||
defineGetter({}, "support"); | ||
} | ||
catch (e) { | ||
dpSupport = false; | ||
} | ||
|
||
// Polyfill from https://github.com/Financial-Times/polyfill-service/pull/1062/files#diff-b45a1197b842728cb76b624b6ba7d739 | ||
Object.defineProperty(Element.prototype, 'previousElementSibling', { | ||
get: function(){ | ||
var el = this.previousSibling; | ||
while (el && el.nodeType !== 1) { el = el.previousSibling; } | ||
return (el.nodeType === 1) ? el : null; | ||
} | ||
}); | ||
|
||
}(this)); | ||
|
||
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); |