2016-04-07 21:12:59 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// fix iterating over NodeList in Chrome and Opera
|
|
|
|
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
|
2016-04-08 13:17:00 +02:00
|
|
|
|
2016-06-08 22:37:59 +02:00
|
|
|
NodeList.prototype.querySelector = function(...args) {
|
|
|
|
for (let node of this) {
|
|
|
|
if (node.nodeType === 3) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const result = node.querySelector(...args);
|
|
|
|
if (result) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2016-06-12 22:10:20 +02:00
|
|
|
};
|
2016-06-08 22:37:59 +02:00
|
|
|
|
2016-04-08 13:17:00 +02:00
|
|
|
// non standard
|
2016-04-12 23:49:46 +02:00
|
|
|
Node.prototype.prependChild = function(child) {
|
|
|
|
if (this.firstChild) {
|
|
|
|
this.insertBefore(child, this.firstChild);
|
|
|
|
} else {
|
|
|
|
this.appendChild(child);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-20 23:10:45 +02:00
|
|
|
// non standard
|
2016-04-08 13:17:00 +02:00
|
|
|
Promise.prototype.always = function(onResolveOrReject) {
|
|
|
|
return this.then(
|
|
|
|
onResolveOrReject,
|
|
|
|
reason => {
|
|
|
|
onResolveOrReject(reason);
|
|
|
|
throw reason;
|
|
|
|
});
|
|
|
|
};
|
2016-04-10 10:23:27 +02:00
|
|
|
|
2016-05-20 23:10:45 +02:00
|
|
|
// non standard
|
2016-05-15 11:24:52 +02:00
|
|
|
Number.prototype.between = function(a, b, inclusive) {
|
|
|
|
const min = Math.min(a, b);
|
|
|
|
const max = Math.max(a, b);
|
|
|
|
return inclusive ?
|
|
|
|
this >= min && this <= max :
|
|
|
|
this > min && this < max;
|
|
|
|
};
|