123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- (function (arr) {
- arr.forEach(function (item) {
- if (item.hasOwnProperty('before')) {
- return;
- }
- Object.defineProperty(item, 'before', {
- configurable: true,
- enumerable: true,
- writable: true,
- value: function before() {
- var argArr = Array.prototype.slice.call(arguments),
- docFrag = document.createDocumentFragment();
- argArr.forEach(function (argItem) {
- var isNode = argItem instanceof Node;
- docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem)));
- });
- this.parentNode.insertBefore(docFrag, this);
- }
- });
- });
- })([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
- if (!String.prototype.startsWith) {
- Object.defineProperty(String.prototype, 'startsWith', {
- value: function(search, pos) {
- pos = !pos || pos < 0 ? 0 : +pos;
- return this.substring(pos, pos + search.length) === search;
- }
- });
- }
- if (!Element.prototype.matches) {
- Element.prototype.matches = Element.prototype.msMatchesSelector ||
- Element.prototype.webkitMatchesSelector;
- }
- if (new Set([0]).size === 0) {
-
- const BuiltinSet = Set;
- Set = function Set(iterable) {
- const set = new BuiltinSet();
- if (iterable) {
- iterable.forEach(set.add, set);
- }
- return set;
- };
- Set.prototype = BuiltinSet.prototype;
- Set.prototype.constructor = Set;
- }
- // Polyfill for using :scope in querySelector/querySelectorAll
- // from: https://github.com/lazd/scopedQuerySelectorShim
- // Copyright (C) 2015 Larry Davis
- // This software may be modified and distributed under the terms of the BSD license.
- (function() {
- if (!HTMLElement.prototype.querySelectorAll) {
- throw new Error("rootedQuerySelectorAll: This polyfill can only be used with browsers that support querySelectorAll");
- }
-
-
- var container = document.createElement("div");
-
- try {
-
- container.querySelectorAll(":scope *");
- } catch (e) {
-
- var scopeRE = /^\s*:scope/gi;
-
- function overrideNodeMethod(prototype, methodName) {
-
- var oldMethod = prototype[methodName];
-
- prototype[methodName] = function(query) {
- var nodeList, gaveId = false, gaveContainer = false;
- if (query.match(scopeRE)) {
-
- query = query.replace(scopeRE, "");
- if (!this.parentNode) {
-
- container.appendChild(this);
- gaveContainer = true;
- }
- parentNode = this.parentNode;
- if (!this.id) {
-
- this.id = "rootedQuerySelector_id_" + new Date().getTime();
- gaveId = true;
- }
-
- nodeList = oldMethod.call(parentNode, "#" + this.id + " " + query);
-
- if (gaveId) {
- this.id = "";
- }
-
- if (gaveContainer) {
- container.removeChild(this);
- }
- return nodeList;
- } else {
-
- return oldMethod.call(this, query);
- }
- };
- }
-
- overrideNodeMethod(HTMLElement.prototype, "querySelector");
- overrideNodeMethod(HTMLElement.prototype, "querySelectorAll");
- }
- })();
|