mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-07-03 14:10:32 +00:00
theme: end support for Internet Explorer 11 #584
This commit is contained in:
parent
77ed3f431a
commit
e952e148fc
22 changed files with 30 additions and 1525 deletions
static/js
|
@ -3,35 +3,6 @@ window.relearn = window.relearn || {};
|
|||
// we need to load this script in the html head to avoid flickering
|
||||
// on page load if the user has selected a non default variant
|
||||
|
||||
// polyfill this rotten piece of sh...oftware
|
||||
if( typeof NodeList !== "undefined" && NodeList.prototype && !NodeList.prototype.forEach ){
|
||||
NodeList.prototype.forEach = Array.prototype.forEach;
|
||||
}
|
||||
|
||||
if (!String.prototype.startsWith) {
|
||||
Object.defineProperty(String.prototype, 'startsWith', {
|
||||
value: function(search, rawPos) {
|
||||
var pos = rawPos > 0 ? rawPos|0 : 0;
|
||||
return this.substring(pos, pos + search.length) === search;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
"function"!=typeof Object.assign&&(Object.assign=function(n,t){"use strict";if(null==n)throw new TypeError("Cannot convert undefined or null to object");for(var r=Object(n),e=1;e<arguments.length;e++){var o=arguments[e];if(null!=o)for(var c in o)Object.prototype.hasOwnProperty.call(o,c)&&(r[c]=o[c])}return r});
|
||||
|
||||
if(!Array.prototype.find){Array.prototype.find=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+=1){value=list[i];if(predicate.call(thisArg,value,i,list)){return value}}return undefined}}
|
||||
|
||||
Array.from||(Array.from=function(){var r;try{r=Symbol.iterator?Symbol.iterator:"Symbol(Symbol.iterator)"}catch(t){r="Symbol(Symbol.iterator)"}var t=Object.prototype.toString,n=function(r){return"function"==typeof r||"[object Function]"===t.call(r)},o=Math.pow(2,53)-1,e=function(r){var t=function(r){var t=Number(r);return isNaN(t)?0:0!==t&&isFinite(t)?(t>0?1:-1)*Math.floor(Math.abs(t)):t}(r);return Math.min(Math.max(t,0),o)},a=function(t,n){var o=t&&n[r]();return function(r){return t?o.next():n[r]}},i=function(r,t,n,o,e,a){for(var i=0;i<n||e;){var u=o(i),f=e?u.value:u;if(e&&u.done)return t;t[i]=a?void 0===r?a(f,i):a.call(r,f,i):f,i+=1}if(e)throw new TypeError("Array.from: provided arrayLike or iterator has length more then 2 ** 52 - 1");return t.length=n,t};return function(t){var o=this,u=Object(t),f=n(u[r]);if(null==t&&!f)throw new TypeError("Array.from requires an array-like object or iterator - not null or undefined");var l,c=arguments.length>1?arguments[1]:void 0;if(void 0!==c){if(!n(c))throw new TypeError("Array.from: when provided, the second argument must be a function");arguments.length>2&&(l=arguments[2])}var y=e(u.length),h=n(o)?Object(new o(y)):new Array(y);return i(l,h,y,a(f,u),f,c)}}());
|
||||
|
||||
const ElementPrototype=window.Element.prototype;
|
||||
if(typeof ElementPrototype.matches!=='function'){ElementPrototype.matches=ElementPrototype.msMatchesSelector||ElementPrototype.mozMatchesSelector||ElementPrototype.webkitMatchesSelector||function matches(selector){let element=this;const elements=(element.document||element.ownerDocument).querySelectorAll(selector);let index=0;while(elements[index]&&elements[index]!==element){index+=1}return Boolean(elements[index])}}if(typeof ElementPrototype.closest!=='function'){ElementPrototype.closest=function closest(selector){let element=this;while(element&&element.nodeType===1){if(element.matches(selector)){return element}element=element.parentNode}return null}}
|
||||
|
||||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
||||
|
||||
function ready(fn) { if (document.readyState == 'complete') { fn(); } else { document.addEventListener('DOMContentLoaded',fn); } }
|
||||
|
||||
var variants = {
|
||||
|
@ -263,52 +234,34 @@ var variants = {
|
|||
this.download( style, 'text/css', 'theme-' + this.customvariantname + '.css' );
|
||||
},
|
||||
|
||||
adjustCSSRules: function(selector, props, sheets) {
|
||||
// get stylesheet(s)
|
||||
if (!sheets) sheets = [].concat(Array.from(document.styleSheets));else if (sheets.sup) {
|
||||
// sheets is a string
|
||||
var absoluteURL = new URL(sheets, document.baseURI).href;
|
||||
sheets = [].concat(document.styleSheets).filter(function (i) {
|
||||
return i.href == absoluteURL;
|
||||
});
|
||||
} else sheets = [sheets]; // sheets is a stylesheet
|
||||
// CSS (& HTML) reduce spaces in selector to one.
|
||||
adjustCSSRules: function(selector, props, sheets){
|
||||
// get stylesheet(s)
|
||||
if (!sheets) sheets = [...document.styleSheets];
|
||||
else if (sheets.sup){ // sheets is a string
|
||||
let absoluteURL = new URL(sheets, document.baseURI).href;
|
||||
sheets = [...document.styleSheets].filter(i => i.href == absoluteURL);
|
||||
}
|
||||
else sheets = [sheets]; // sheets is a stylesheet
|
||||
|
||||
selector = selector.replace(/\s+/g, ' ');
|
||||
// CSS (& HTML) reduce spaces in selector to one.
|
||||
selector = selector.replace(/\s+/g, ' ');
|
||||
const findRule = s => [...s.cssRules].reverse().find(i => i.selectorText == selector)
|
||||
let rule = sheets.map(findRule).filter(i=>i).pop()
|
||||
|
||||
var findRule = function findRule(s) {
|
||||
return [].concat(s.cssRules).reverse().find(function (i) {
|
||||
return i.selectorText == selector;
|
||||
});
|
||||
};
|
||||
const propsArr = props.sup
|
||||
? props.split(/\s*;\s*/).map(i => i.split(/\s*:\s*/)) // from string
|
||||
: Object.entries(props); // from Object
|
||||
|
||||
var rule = sheets.map(findRule).filter(function (i) {
|
||||
return i;
|
||||
}).pop();
|
||||
var propsArr = props.sup ? props.split(/\s*;\s*/).map(function (i) {
|
||||
return i.split(/\s*:\s*/);
|
||||
}) // from string
|
||||
: Object.entries(props); // from Object
|
||||
|
||||
if (rule) {
|
||||
for (var _iterator = _createForOfIteratorHelperLoose(propsArr), _step; !(_step = _iterator()).done;) {
|
||||
var _rule$style;
|
||||
var _step$value = _step.value,
|
||||
prop = _step$value[0],
|
||||
val = _step$value[1];
|
||||
// rule.style[prop] = val; is against the spec, and does not support !important.
|
||||
(_rule$style = rule.style).setProperty.apply(_rule$style, [prop].concat(val.split(/ *!(?=important)/)));
|
||||
}
|
||||
} else {
|
||||
sheet = sheets.pop();
|
||||
if (!props.sup) props = propsArr.reduce(function (str, _ref) {
|
||||
var k = _ref[0],
|
||||
v = _ref[1];
|
||||
return str + "; " + k + ": " + v;
|
||||
}, '');
|
||||
sheet.insertRule(selector + " { " + props + " }", sheet.cssRules.length);
|
||||
}
|
||||
},
|
||||
if (rule) for (let [prop, val] of propsArr){
|
||||
// rule.style[prop] = val; is against the spec, and does not support !important.
|
||||
rule.style.setProperty(prop, ...val.split(/ *!(?=important)/));
|
||||
}
|
||||
else {
|
||||
sheet = sheets.pop();
|
||||
if (!props.sup) props = propsArr.reduce((str, [k, v]) => `${str}; ${k}: ${v}`, '');
|
||||
sheet.insertRule(`${selector} { ${props} }`, sheet.cssRules.length);
|
||||
}
|
||||
},
|
||||
|
||||
normalizeColor: function( c ){
|
||||
if( !c || !c.trim ){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue