mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-03 06:22:25 +02:00
Autofix errors
This commit is contained in:
parent
364aca20a6
commit
0f81a03e19
|
@ -4,14 +4,14 @@
|
||||||
// Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from
|
// Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from
|
||||||
if (!Array.from) {
|
if (!Array.from) {
|
||||||
Array.from = (function() {
|
Array.from = (function() {
|
||||||
var toStr = Object.prototype.toString;
|
let toStr = Object.prototype.toString;
|
||||||
|
|
||||||
var isCallable = function(fn) {
|
let isCallable = function(fn) {
|
||||||
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
|
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
|
||||||
};
|
};
|
||||||
|
|
||||||
var toInteger = function(value) {
|
let toInteger = function(value) {
|
||||||
var number = Number(value);
|
let number = Number(value);
|
||||||
if (isNaN(number)) {
|
if (isNaN(number)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -21,29 +21,29 @@
|
||||||
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
|
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
|
||||||
};
|
};
|
||||||
|
|
||||||
var maxSafeInteger = Math.pow(2, 53) - 1;
|
let maxSafeInteger = Math.pow(2, 53) - 1;
|
||||||
|
|
||||||
var toLength = function(value) {
|
let toLength = function(value) {
|
||||||
var len = toInteger(value);
|
let len = toInteger(value);
|
||||||
return Math.min(Math.max(len, 0), maxSafeInteger);
|
return Math.min(Math.max(len, 0), maxSafeInteger);
|
||||||
};
|
};
|
||||||
|
|
||||||
// The length property of the from method is 1.
|
// The length property of the from method is 1.
|
||||||
return function from(arrayLike /*, mapFn, thisArg */ ) {
|
return function from(arrayLike /* , mapFn, thisArg */) {
|
||||||
// 1. Let C be the this value.
|
// 1. Let C be the this value.
|
||||||
var C = this;
|
let C = this;
|
||||||
|
|
||||||
// 2. Let items be ToObject(arrayLike).
|
// 2. Let items be ToObject(arrayLike).
|
||||||
var items = Object(arrayLike);
|
let items = Object(arrayLike);
|
||||||
|
|
||||||
// 3. ReturnIfAbrupt(items).
|
// 3. ReturnIfAbrupt(items).
|
||||||
if (arrayLike == null) {
|
if (arrayLike == null) {
|
||||||
throw new TypeError("Array.from requires an array-like object - not null or undefined");
|
throw new TypeError('Array.from requires an array-like object - not null or undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. If mapfn is undefined, then let mapping be false.
|
// 4. If mapfn is undefined, then let mapping be false.
|
||||||
var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
|
let mapFn = arguments.length > 1 ? arguments[1] : void undefined;
|
||||||
var T;
|
let T;
|
||||||
if (typeof mapFn !== 'undefined') {
|
if (typeof mapFn !== 'undefined') {
|
||||||
// 5. else
|
// 5. else
|
||||||
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
|
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
|
||||||
|
@ -59,17 +59,17 @@
|
||||||
|
|
||||||
// 10. Let lenValue be Get(items, "length").
|
// 10. Let lenValue be Get(items, "length").
|
||||||
// 11. Let len be ToLength(lenValue).
|
// 11. Let len be ToLength(lenValue).
|
||||||
var len = toLength(items.length);
|
let len = toLength(items.length);
|
||||||
|
|
||||||
// 13. If IsConstructor(C) is true, then
|
// 13. If IsConstructor(C) is true, then
|
||||||
// 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
|
// 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
|
||||||
// 14. a. Else, Let A be ArrayCreate(len).
|
// 14. a. Else, Let A be ArrayCreate(len).
|
||||||
var A = isCallable(C) ? Object(new C(len)) : new Array(len);
|
let A = isCallable(C) ? Object(new C(len)) : new Array(len);
|
||||||
|
|
||||||
// 16. Let k be 0.
|
// 16. Let k be 0.
|
||||||
var k = 0;
|
let k = 0;
|
||||||
// 17. Repeat, while k < len… (also steps a - h)
|
// 17. Repeat, while k < len… (also steps a - h)
|
||||||
var kValue;
|
let kValue;
|
||||||
while (k < len) {
|
while (k < len) {
|
||||||
kValue = items[k];
|
kValue = items[k];
|
||||||
if (mapFn) {
|
if (mapFn) {
|
||||||
|
@ -91,18 +91,19 @@
|
||||||
if (!Array.prototype.find) {
|
if (!Array.prototype.find) {
|
||||||
Array.prototype.find = function(predicate) {
|
Array.prototype.find = function(predicate) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
if (this == null) {
|
if (this == null) {
|
||||||
throw new TypeError('Array.prototype.find called on null or undefined');
|
throw new TypeError('Array.prototype.find called on null or undefined');
|
||||||
}
|
}
|
||||||
if (typeof predicate !== 'function') {
|
if (typeof predicate !== 'function') {
|
||||||
throw new TypeError('predicate must be a function');
|
throw new TypeError('predicate must be a function');
|
||||||
}
|
}
|
||||||
var list = Object(this);
|
let list = Object(this);
|
||||||
var length = list.length >>> 0;
|
let length = list.length >>> 0;
|
||||||
var thisArg = arguments[1];
|
let thisArg = arguments[1];
|
||||||
var value;
|
let value;
|
||||||
|
|
||||||
for (var i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
value = list[i];
|
value = list[i];
|
||||||
if (predicate.call(thisArg, value, i, list)) {
|
if (predicate.call(thisArg, value, i, list)) {
|
||||||
return value;
|
return value;
|
||||||
|
@ -114,16 +115,16 @@
|
||||||
|
|
||||||
function CustomEvent (event, params) {
|
function CustomEvent (event, params) {
|
||||||
params = params || {
|
params = params || {
|
||||||
bubbles: false,
|
bubbles: false,
|
||||||
cancelable: false,
|
cancelable: false,
|
||||||
detail: undefined
|
detail: undefined,
|
||||||
};
|
};
|
||||||
var evt = document.createEvent('CustomEvent');
|
let evt = document.createEvent('CustomEvent');
|
||||||
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
||||||
return evt;
|
return evt;
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomEvent.prototype = window.Event.prototype;
|
CustomEvent.prototype = window.Event.prototype;
|
||||||
|
|
||||||
window.CustomEvent = CustomEvent;
|
window.CustomEvent = CustomEvent;
|
||||||
})();
|
}());
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capitalises the first letter of each word in a string
|
* Capitalises the first letter of each word in a string
|
||||||
* @param {String} str String to capitalise
|
* @param {String} str String to capitalise
|
||||||
* @return {String} Capitalised string
|
* @return {String} Capitalised string
|
||||||
*/
|
*/
|
||||||
export const capitalise = function(str) {
|
export const capitalise = function(str) {
|
||||||
return str.replace(/\w\S*/g, function(txt) {
|
return str.replace(/\w\S*/g, txt => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
|
||||||
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,11 +14,11 @@ export const capitalise = function(str) {
|
||||||
* @param {Number} length Length of the string to generate
|
* @param {Number} length Length of the string to generate
|
||||||
* @return {String} String of random chars
|
* @return {String} String of random chars
|
||||||
*/
|
*/
|
||||||
export const generateChars = function (length) {
|
export const generateChars = function(length) {
|
||||||
var chars = '';
|
let chars = '';
|
||||||
|
|
||||||
for (var i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
var randomChar = getRandomNumber(0, 36);
|
const randomChar = getRandomNumber(0, 36);
|
||||||
chars += randomChar.toString(36);
|
chars += randomChar.toString(36);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +31,8 @@ export const generateChars = function (length) {
|
||||||
* @param {String} Prefix for the Id
|
* @param {String} Prefix for the Id
|
||||||
* @return {String} Unique Id
|
* @return {String} Unique Id
|
||||||
*/
|
*/
|
||||||
export const generateId = function (element, prefix) {
|
export const generateId = function(element, prefix) {
|
||||||
var id = element.id || (element.name && (element.name + '-' + generateChars(2))) || generateChars(4);
|
let id = element.id || (element.name && (`${element.name}-${generateChars(2)}`)) || generateChars(4);
|
||||||
id = id.replace(/(:|\.|\[|\]|,)/g, '');
|
id = id.replace(/(:|\.|\[|\]|,)/g, '');
|
||||||
id = prefix + id;
|
id = prefix + id;
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ export const getType = function(obj) {
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
export const isType = function(type, obj) {
|
export const isType = function(type, obj) {
|
||||||
var clas = getType(obj);
|
const clas = getType(obj);
|
||||||
return obj !== undefined && obj !== null && clas === type;
|
return obj !== undefined && obj !== null && clas === type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,24 +66,20 @@ export const isType = function(type, obj) {
|
||||||
* @param {Object} obj Object to be tested
|
* @param {Object} obj Object to be tested
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
export const isNode = (o) => {
|
export const isNode = o => (
|
||||||
return (
|
typeof Node === 'object' ? o instanceof Node :
|
||||||
typeof Node === "object" ? o instanceof Node :
|
o && typeof o === 'object' && typeof o.nodeType === 'number' && typeof o.nodeName === 'string'
|
||||||
o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName === "string"
|
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests to see if a passed object is an element
|
* Tests to see if a passed object is an element
|
||||||
* @param {Object} obj Object to be tested
|
* @param {Object} obj Object to be tested
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
export const isElement = (o) => {
|
export const isElement = o => (
|
||||||
return (
|
typeof HTMLElement === 'object' ? o instanceof HTMLElement : // DOM2
|
||||||
typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2
|
o && typeof o === 'object' && o !== null && o.nodeType === 1 && typeof o.nodeName === 'string'
|
||||||
o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName === "string"
|
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges unspecified amount of objects into new object
|
* Merges unspecified amount of objects into new object
|
||||||
|
@ -92,30 +87,30 @@ export const isElement = (o) => {
|
||||||
* @return {Object} Merged object of arguments
|
* @return {Object} Merged object of arguments
|
||||||
*/
|
*/
|
||||||
export const extend = function() {
|
export const extend = function() {
|
||||||
let extended = {};
|
const extended = {};
|
||||||
let length = arguments.length;
|
const length = arguments.length;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge one object into another
|
* Merge one object into another
|
||||||
* @param {Object} obj Object to merge into extended object
|
* @param {Object} obj Object to merge into extended object
|
||||||
*/
|
*/
|
||||||
let merge = function(obj) {
|
const merge = function(obj) {
|
||||||
for (let prop in obj) {
|
for (const prop in obj) {
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
||||||
// If deep merge and property is an object, merge properties
|
// If deep merge and property is an object, merge properties
|
||||||
if (isType('Object', obj[prop])) {
|
if (isType('Object', obj[prop])) {
|
||||||
extended[prop] = extend(true, extended[prop], obj[prop]);
|
extended[prop] = extend(true, extended[prop], obj[prop]);
|
||||||
} else {
|
} else {
|
||||||
extended[prop] = obj[prop];
|
extended[prop] = obj[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Loop through each passed argument
|
// Loop through each passed argument
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
// store argument at position i
|
// store argument at position i
|
||||||
let obj = arguments[i];
|
const obj = arguments[i];
|
||||||
|
|
||||||
// If we are in fact dealing with an object, merge it.
|
// If we are in fact dealing with an object, merge it.
|
||||||
if (isType('Object', obj)) {
|
if (isType('Object', obj)) {
|
||||||
|
@ -131,15 +126,15 @@ export const extend = function() {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
export const whichTransitionEvent = function() {
|
export const whichTransitionEvent = function() {
|
||||||
var t,
|
let t,
|
||||||
el = document.createElement('fakeelement');
|
el = document.createElement('fakeelement');
|
||||||
|
|
||||||
var transitions = {
|
const transitions = {
|
||||||
'transition': 'transitionend',
|
transition: 'transitionend',
|
||||||
'OTransition': 'oTransitionEnd',
|
OTransition: 'oTransitionEnd',
|
||||||
'MozTransition': 'transitionend',
|
MozTransition: 'transitionend',
|
||||||
'WebkitTransition': 'webkitTransitionEnd'
|
WebkitTransition: 'webkitTransitionEnd',
|
||||||
}
|
};
|
||||||
|
|
||||||
for (t in transitions) {
|
for (t in transitions) {
|
||||||
if (el.style[t] !== undefined) {
|
if (el.style[t] !== undefined) {
|
||||||
|
@ -153,14 +148,14 @@ export const whichTransitionEvent = function() {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
export const whichAnimationEvent = function() {
|
export const whichAnimationEvent = function() {
|
||||||
var t,
|
let t,
|
||||||
el = document.createElement('fakeelement');
|
el = document.createElement('fakeelement');
|
||||||
|
|
||||||
var animations = {
|
const animations = {
|
||||||
'animation': 'animationend',
|
animation: 'animationend',
|
||||||
'OAnimation': 'oAnimationEnd',
|
OAnimation: 'oAnimationEnd',
|
||||||
'MozAnimation': 'animationend',
|
MozAnimation: 'animationend',
|
||||||
'WebkitAnimation': 'webkitAnimationEnd'
|
WebkitAnimation: 'webkitAnimationEnd',
|
||||||
};
|
};
|
||||||
|
|
||||||
for (t in animations) {
|
for (t in animations) {
|
||||||
|
@ -179,14 +174,12 @@ export const whichAnimationEvent = function() {
|
||||||
* @return {Array} Array of parent elements
|
* @return {Array} Array of parent elements
|
||||||
*/
|
*/
|
||||||
export const getParentsUntil = function(elem, parent, selector) {
|
export const getParentsUntil = function(elem, parent, selector) {
|
||||||
var parents = [];
|
const parents = [];
|
||||||
// Get matches
|
// Get matches
|
||||||
for (; elem && elem !== document; elem = elem.parentNode) {
|
for (; elem && elem !== document; elem = elem.parentNode) {
|
||||||
|
|
||||||
// Check if parent has been reached
|
// Check if parent has been reached
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
const parentType = parent.charAt(0);
|
||||||
var parentType = parent.charAt(0);
|
|
||||||
|
|
||||||
// If parent is a class
|
// If parent is a class
|
||||||
if (parentType === '.') {
|
if (parentType === '.') {
|
||||||
|
@ -213,10 +206,9 @@ export const getParentsUntil = function(elem, parent, selector) {
|
||||||
if (elem.tagName.toLowerCase() === parent) {
|
if (elem.tagName.toLowerCase() === parent) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (selector) {
|
if (selector) {
|
||||||
var selectorType = selector.charAt(0);
|
const selectorType = selector.charAt(0);
|
||||||
|
|
||||||
// If selector is a class
|
// If selector is a class
|
||||||
if (selectorType === '.') {
|
if (selectorType === '.') {
|
||||||
|
@ -243,7 +235,6 @@ export const getParentsUntil = function(elem, parent, selector) {
|
||||||
if (elem.tagName.toLowerCase() === selector) {
|
if (elem.tagName.toLowerCase() === selector) {
|
||||||
parents.push(elem);
|
parents.push(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
parents.push(elem);
|
parents.push(elem);
|
||||||
}
|
}
|
||||||
|
@ -252,9 +243,8 @@ export const getParentsUntil = function(elem, parent, selector) {
|
||||||
// Return parents if any exist
|
// Return parents if any exist
|
||||||
if (parents.length === 0) {
|
if (parents.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
|
||||||
return parents;
|
|
||||||
}
|
}
|
||||||
|
return parents;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const wrap = function(element, wrapper) {
|
export const wrap = function(element, wrapper) {
|
||||||
|
@ -268,8 +258,8 @@ export const wrap = function(element, wrapper) {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSiblings = function(elem) {
|
export const getSiblings = function(elem) {
|
||||||
var siblings = [];
|
const siblings = [];
|
||||||
var sibling = elem.parentNode.firstChild;
|
let sibling = elem.parentNode.firstChild;
|
||||||
for (; sibling; sibling = sibling.nextSibling) {
|
for (; sibling; sibling = sibling.nextSibling) {
|
||||||
if (sibling.nodeType === 1 && sibling !== elem) {
|
if (sibling.nodeType === 1 && sibling !== elem) {
|
||||||
siblings.push(sibling);
|
siblings.push(sibling);
|
||||||
|
@ -317,15 +307,15 @@ export const findAncestorByAttrName = function(el, attr) {
|
||||||
* @return {Function} A function will be called after it stops being called for a given delay
|
* @return {Function} A function will be called after it stops being called for a given delay
|
||||||
*/
|
*/
|
||||||
export const debounce = function(func, wait, immediate) {
|
export const debounce = function(func, wait, immediate) {
|
||||||
var timeout;
|
let timeout;
|
||||||
return function() {
|
return function() {
|
||||||
var context = this,
|
let context = this,
|
||||||
args = arguments;
|
args = arguments;
|
||||||
var later = function() {
|
const later = function() {
|
||||||
timeout = null;
|
timeout = null;
|
||||||
if (!immediate) func.apply(context, args);
|
if (!immediate) func.apply(context, args);
|
||||||
};
|
};
|
||||||
var callNow = immediate && !timeout;
|
const callNow = immediate && !timeout;
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = setTimeout(later, wait);
|
timeout = setTimeout(later, wait);
|
||||||
if (callNow) func.apply(context, args);
|
if (callNow) func.apply(context, args);
|
||||||
|
@ -339,7 +329,7 @@ export const debounce = function(func, wait, immediate) {
|
||||||
* @return {Number} Elements Distance from top of page
|
* @return {Number} Elements Distance from top of page
|
||||||
*/
|
*/
|
||||||
export const getElemDistance = function(el) {
|
export const getElemDistance = function(el) {
|
||||||
var location = 0;
|
let location = 0;
|
||||||
if (el.offsetParent) {
|
if (el.offsetParent) {
|
||||||
do {
|
do {
|
||||||
location += el.offsetTop;
|
location += el.offsetTop;
|
||||||
|
@ -356,7 +346,7 @@ export const getElemDistance = function(el) {
|
||||||
* @return {Number} Height of element
|
* @return {Number} Height of element
|
||||||
*/
|
*/
|
||||||
export const getElementOffset = function(el, offset) {
|
export const getElementOffset = function(el, offset) {
|
||||||
var elOffset = offset;
|
let elOffset = offset;
|
||||||
if (elOffset > 1) elOffset = 1;
|
if (elOffset > 1) elOffset = 1;
|
||||||
if (elOffset > 0) elOffset = 0;
|
if (elOffset > 0) elOffset = 0;
|
||||||
|
|
||||||
|
@ -391,10 +381,9 @@ export const getScrollPosition = function(position) {
|
||||||
if (position === 'bottom') {
|
if (position === 'bottom') {
|
||||||
// Scroll position from the bottom of the viewport
|
// Scroll position from the bottom of the viewport
|
||||||
return Math.max((window.scrollY || window.pageYOffset) + (window.innerHeight || document.documentElement.clientHeight));
|
return Math.max((window.scrollY || window.pageYOffset) + (window.innerHeight || document.documentElement.clientHeight));
|
||||||
} else {
|
|
||||||
// Scroll position from the top of the viewport
|
|
||||||
return (window.scrollY || window.pageYOffset);
|
|
||||||
}
|
}
|
||||||
|
// Scroll position from the top of the viewport
|
||||||
|
return (window.scrollY || window.pageYOffset);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -405,7 +394,7 @@ export const getScrollPosition = function(position) {
|
||||||
*/
|
*/
|
||||||
export const isInView = function(el, position, offset) {
|
export const isInView = function(el, position, offset) {
|
||||||
// If the user has scrolled further than the distance from the element to the top of its parent
|
// If the user has scrolled further than the distance from the element to the top of its parent
|
||||||
return this.getScrollPosition(position) > (this.getElemDistance(el) + this.getElementOffset(el, offset)) ? true : false;
|
return this.getScrollPosition(position) > (this.getElemDistance(el) + this.getElementOffset(el, offset));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -437,9 +426,9 @@ export const isScrolledIntoView = (el, parent, direction = 1) => {
|
||||||
* @return {String} Sanitised string
|
* @return {String} Sanitised string
|
||||||
*/
|
*/
|
||||||
export const stripHTML = function(html) {
|
export const stripHTML = function(html) {
|
||||||
let el = document.createElement("DIV");
|
const el = document.createElement('DIV');
|
||||||
el.innerHTML = html;
|
el.innerHTML = html;
|
||||||
return el.textContent || el.innerText || "";
|
return el.textContent || el.innerText || '';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -449,9 +438,9 @@ export const stripHTML = function(html) {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
export const addAnimation = (el, animation) => {
|
export const addAnimation = (el, animation) => {
|
||||||
let animationEvent = whichAnimationEvent();
|
const animationEvent = whichAnimationEvent();
|
||||||
|
|
||||||
let removeAnimation = () => {
|
const removeAnimation = () => {
|
||||||
el.classList.remove(animation);
|
el.classList.remove(animation);
|
||||||
el.removeEventListener(animationEvent, removeAnimation, false);
|
el.removeEventListener(animationEvent, removeAnimation, false);
|
||||||
};
|
};
|
||||||
|
@ -477,9 +466,9 @@ export const getRandomNumber = function(min, max) {
|
||||||
* @return {HTMLElement} Converted node element
|
* @return {HTMLElement} Converted node element
|
||||||
*/
|
*/
|
||||||
export const strToEl = (function() {
|
export const strToEl = (function() {
|
||||||
let tmpEl = document.createElement('div');
|
const tmpEl = document.createElement('div');
|
||||||
return function(str) {
|
return function(str) {
|
||||||
let cleanedInput = str.trim();
|
const cleanedInput = str.trim();
|
||||||
let r;
|
let r;
|
||||||
tmpEl.innerHTML = cleanedInput;
|
tmpEl.innerHTML = cleanedInput;
|
||||||
r = tmpEl.children[0];
|
r = tmpEl.children[0];
|
||||||
|
@ -501,7 +490,7 @@ export const getWidthOfInput = (input) => {
|
||||||
let width = input.offsetWidth;
|
let width = input.offsetWidth;
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
const testEl = strToEl(`<span>${ value }</span>`);
|
const testEl = strToEl(`<span>${value}</span>`);
|
||||||
testEl.style.position = 'absolute';
|
testEl.style.position = 'absolute';
|
||||||
testEl.style.padding = '0';
|
testEl.style.padding = '0';
|
||||||
testEl.style.top = '-9999px';
|
testEl.style.top = '-9999px';
|
||||||
|
@ -560,9 +549,7 @@ export const sortByAlpha = (a, b) => {
|
||||||
* 1 for before,
|
* 1 for before,
|
||||||
* 0 for same location
|
* 0 for same location
|
||||||
*/
|
*/
|
||||||
export const sortByScore = (a, b) => {
|
export const sortByScore = (a, b) => a.score - b.score;
|
||||||
return a.score - b.score;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger native event
|
* Trigger native event
|
||||||
|
@ -575,7 +562,7 @@ export const triggerEvent = (element, type, customArgs = null) => {
|
||||||
const event = new CustomEvent(type, {
|
const event = new CustomEvent(type, {
|
||||||
detail: customArgs,
|
detail: customArgs,
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
cancelable: true
|
cancelable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return element.dispatchEvent(event);
|
return element.dispatchEvent(event);
|
||||||
|
@ -594,4 +581,4 @@ export const regexFilter = (value, regex) => {
|
||||||
|
|
||||||
const expression = new RegExp(regex.source, 'i');
|
const expression = new RegExp(regex.source, 'i');
|
||||||
return expression.test(value);
|
return expression.test(value);
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in a new issue