Initial commit as of 2018-10-16
This commit is contained in:
63
assets/js/core/polyfill.js
Normal file
63
assets/js/core/polyfill.js
Normal file
@@ -0,0 +1,63 @@
|
||||
let elem = document.createElement('div');
|
||||
elem.classList.toggle('test-class', false);
|
||||
if (elem.classList.contains('test-class')) {
|
||||
let _toggle = DOMTokenList.prototype.toggle;
|
||||
DOMTokenList.prototype.toggle = function(token, force) {
|
||||
if (arguments.length > 1 && !this.contains(token) === !force) {
|
||||
return force;
|
||||
} else {
|
||||
return _toggle.call(this, token);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.startsWith) {
|
||||
String.prototype.startsWith = function(searchString, position){
|
||||
position = position || 0;
|
||||
return this.substr(position, searchString.length) === searchString;
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.endsWith) {
|
||||
String.prototype.endsWith = function(searchString, position) {
|
||||
var subjectString = this.toString();
|
||||
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
|
||||
position = subjectString.length;
|
||||
}
|
||||
position -= searchString.length;
|
||||
var lastIndex = subjectString.indexOf(searchString, position);
|
||||
return lastIndex !== -1 && lastIndex === position;
|
||||
};
|
||||
}
|
||||
|
||||
if (!Array.prototype.find) {
|
||||
Object.defineProperty(Array.prototype, "find", {
|
||||
value: function(predicate) {
|
||||
if (this === null) {
|
||||
throw new TypeError('Array.prototype.find called on null or undefined');
|
||||
}
|
||||
if (typeof predicate !== 'function') {
|
||||
throw new TypeError('predicate must be a function');
|
||||
}
|
||||
var list = Object(this);
|
||||
var length = list.length >>> 0;
|
||||
var thisArg = arguments[1];
|
||||
var value;
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
value = list[i];
|
||||
if (predicate.call(thisArg, value, i, list)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Disable resizing in Firefox
|
||||
document.execCommand("enableObjectResizing", false, false);
|
||||
// Disable automatic linkifying in IE11
|
||||
document.execCommand("autoUrlDetect", false, false);
|
||||
});
|
Reference in New Issue
Block a user