From be833d80502f8b191c2d3e04dc57b1ed46a7e5d1 Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Sat, 27 Nov 2021 03:13:00 +0100 Subject: [PATCH 1/5] remove classlist polyfill see https://caniuse.com/?search=classlist --- js/bootstrap-select.js | 88 ------------------------------------------ 1 file changed, 88 deletions(-) diff --git a/js/bootstrap-select.js b/js/bootstrap-select.js index 84db03037..2dcf94485 100644 --- a/js/bootstrap-select.js +++ b/js/bootstrap-select.js @@ -143,94 +143,6 @@ return attributesObject; } - // Polyfill for browsers with no classList support - // Remove in v2 - if (!('classList' in document.createElement('_'))) { - (function (view) { - if (!('Element' in view)) return; - - var classListProp = 'classList', - protoProp = 'prototype', - elemCtrProto = view.Element[protoProp], - objCtr = Object, - classListGetter = function () { - var $elem = $(this); - - return { - add: function (classes) { - classes = Array.prototype.slice.call(arguments).join(' '); - return $elem.addClass(classes); - }, - remove: function (classes) { - classes = Array.prototype.slice.call(arguments).join(' '); - return $elem.removeClass(classes); - }, - toggle: function (classes, force) { - return $elem.toggleClass(classes, force); - }, - contains: function (classes) { - return $elem.hasClass(classes); - } - }; - }; - - if (objCtr.defineProperty) { - var classListPropDesc = { - get: classListGetter, - enumerable: true, - configurable: true - }; - try { - objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc); - } catch (ex) { // IE 8 doesn't support enumerable:true - // adding undefined to fight this issue https://github.com/eligrey/classList.js/issues/36 - // modernie IE8-MSW7 machine has IE8 8.0.6001.18702 and is affected - if (ex.number === undefined || ex.number === -0x7FF5EC54) { - classListPropDesc.enumerable = false; - objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc); - } - } - } else if (objCtr[protoProp].__defineGetter__) { - elemCtrProto.__defineGetter__(classListProp, classListGetter); - } - }(window)); - } - - var testElement = document.createElement('_'); - - testElement.classList.add('c1', 'c2'); - - if (!testElement.classList.contains('c2')) { - var _add = DOMTokenList.prototype.add, - _remove = DOMTokenList.prototype.remove; - - DOMTokenList.prototype.add = function () { - Array.prototype.forEach.call(arguments, _add.bind(this)); - }; - - DOMTokenList.prototype.remove = function () { - Array.prototype.forEach.call(arguments, _remove.bind(this)); - }; - } - - testElement.classList.toggle('c3', false); - - // Polyfill for IE 10 and Firefox <24, where classList.toggle does not - // support the second argument. - if (testElement.classList.contains('c3')) { - var _toggle = DOMTokenList.prototype.toggle; - - DOMTokenList.prototype.toggle = function (token, force) { - if (1 in arguments && !this.contains(token) === !force) { - return force; - } else { - return _toggle.call(this, token); - } - }; - } - - testElement = null; - // shallow array comparison function isEqual (array1, array2) { return array1.length === array2.length && array1.every(function (element, index) { From bea7d6c526a30a1d8246da3a91294b90dba0025b Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Sat, 27 Nov 2021 03:14:14 +0100 Subject: [PATCH 2/5] remove startswith polyfill See https://caniuse.com/?search=startswith --- js/bootstrap-select.js | 47 ------------------------------------------ 1 file changed, 47 deletions(-) diff --git a/js/bootstrap-select.js b/js/bootstrap-select.js index 2dcf94485..41d035231 100644 --- a/js/bootstrap-select.js +++ b/js/bootstrap-select.js @@ -150,53 +150,6 @@ }); }; - // - if (!String.prototype.startsWith) { - (function () { - 'use strict'; // needed to support `apply`/`call` with `undefined`/`null` - var toString = {}.toString; - var startsWith = function (search) { - if (this == null) { - throw new TypeError(); - } - var string = String(this); - if (search && toString.call(search) == '[object RegExp]') { - throw new TypeError(); - } - var stringLength = string.length; - var searchString = String(search); - var searchLength = searchString.length; - var position = arguments.length > 1 ? arguments[1] : undefined; - // `ToInteger` - var pos = position ? Number(position) : 0; - if (pos != pos) { // better `isNaN` - pos = 0; - } - var start = Math.min(Math.max(pos, 0), stringLength); - // Avoid the `indexOf` call if no match is possible - if (searchLength + start > stringLength) { - return false; - } - var index = -1; - while (++index < searchLength) { - if (string.charCodeAt(start + index) != searchString.charCodeAt(index)) { - return false; - } - } - return true; - }; - if (Object.defineProperty) { - Object.defineProperty(String.prototype, 'startsWith', { - 'value': startsWith, - 'configurable': true, - 'writable': true - }); - } else { - String.prototype.startsWith = startsWith; - } - }()); - } - function getSelectedOptions () { var selectedOptions = this.selectpicker.main.data.filter(function (item) { if (item.selected) { From 03066a9714b45de5cec675a5bad0647157dcb67d Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Sat, 27 Nov 2021 03:22:43 +0100 Subject: [PATCH 3/5] assume Event is supported See https://caniuse.com/?search=Event --- js/bootstrap-select.js | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/js/bootstrap-select.js b/js/bootstrap-select.js index 41d035231..cccf6bfdd 100644 --- a/js/bootstrap-select.js +++ b/js/bootstrap-select.js @@ -209,35 +209,11 @@ var changedArguments = null; - var EventIsSupported = (function () { - try { - new Event('change'); - return true; - } catch (e) { - return false; - } - })(); - $.fn.triggerNative = function (eventName) { - var el = this[0], - event; - - if (el.dispatchEvent) { // for modern browsers & IE9+ - if (EventIsSupported) { - // For modern browsers - event = new Event(eventName, { - bubbles: true - }); - } else { - // For IE since it doesn't support Event constructor - event = document.createEvent('Event'); - event.initEvent(eventName, true, false); - } - - el.dispatchEvent(event); - } + const el = this[0]; + const event = new Event(eventName, { bubbles: true }); + el.dispatchEvent(event); }; - // function stringSearch (li, searchString, method, normalize) { var stringTypes = [ From 6ae4a80e8305026a5eb70737848185e634fb2ba0 Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Sat, 27 Nov 2021 03:24:19 +0100 Subject: [PATCH 4/5] remove IE code --- js/bootstrap-select.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/js/bootstrap-select.js b/js/bootstrap-select.js index cccf6bfdd..3378bddec 100644 --- a/js/bootstrap-select.js +++ b/js/bootstrap-select.js @@ -2480,11 +2480,6 @@ var target = e.target, clearButton = that.$clearButton[0]; - // IE doesn't support event listeners on child elements of buttons - if (/MSIE|Trident/.test(window.navigator.userAgent)) { - target = document.elementFromPoint(e.clientX, e.clientY); - } - if (target === clearButton || target.parentElement === clearButton) { e.stopImmediatePropagation(); clearSelection(e); From 85052b6447bf6361e20a39fcfa2f541f45b4030f Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Sat, 27 Nov 2021 03:28:50 +0100 Subject: [PATCH 5/5] use es6 in eslint config --- js/.eslintrc.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/.eslintrc.json b/js/.eslintrc.json index 3620db1e0..c8265a79d 100644 --- a/js/.eslintrc.json +++ b/js/.eslintrc.json @@ -1,7 +1,8 @@ { "env": { "browser": true, - "jquery": true + "jquery": true, + "es6": true }, "globals": { @@ -9,6 +10,9 @@ "navigator": false, "window": false }, + "parserOptions": { + "ecmaVersion": 2017 + }, "rules": { "accessor-pairs": "error",