]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Remove IE support and button bsChecked hack
authorAlessandro Chitolina <alekitto@gmail.com>
Tue, 25 Sep 2018 18:06:09 +0000 (20:06 +0200)
committerXhmikosR <xhmikosr@gmail.com>
Wed, 20 Feb 2019 20:05:45 +0000 (22:05 +0200)
js/src/button.js
js/src/dom/manipulator.js
js/src/dom/polyfill.js
js/src/dom/selectorEngine.js
js/tests/browsers.js
js/tests/unit/button.js
js/tests/unit/dom/manipulator.js
js/tests/visual/button.html

index 8bdf9d5bd7d95d10e17650a5ea46f038e06b0361..2cb6acabaea4dbdb22ac3d7d56f82f9624079eca 100644 (file)
@@ -7,7 +7,6 @@
 
 import Data from './dom/data'
 import EventHandler from './dom/eventHandler'
-import Manipulator from './dom/manipulator'
 import SelectorEngine from './dom/selectorEngine'
 import Util from './util'
 
@@ -96,7 +95,8 @@ class Button {
             rootElement.classList.contains('disabled')) {
             return
           }
-          Manipulator.setChecked(input, !this._element.classList.contains(ClassName.ACTIVE))
+
+          input.checked = !this._element.classList.contains(ClassName.ACTIVE)
           EventHandler.trigger(input, 'change')
         }
 
index ad14e2914860af8fd1e2177eadaebfba30233318..b9135aa7910aef01f6f12bc52a587af1c3e3022b 100644 (file)
@@ -28,20 +28,6 @@ function normalizeDataKey(key) {
 }
 
 const Manipulator = {
-  setChecked(input, val) {
-    if (input instanceof HTMLInputElement) {
-      input.checked = val
-      input.bsChecked = val
-    }
-  },
-
-  isChecked(input) {
-    if (input instanceof HTMLInputElement) {
-      return input.bsChecked || input.checked
-    }
-    throw new Error('INPUT parameter is not an HTMLInputElement')
-  },
-
   setDataAttribute(element, key, value) {
     element.setAttribute(`data-${normalizeDataKey(key)}`, value)
   },
index ff7ba1d1792cf949232c3858a384cdbae07e180d..dd29b9dfb1017e4b4f7ba61981eb6ecefd91806f 100644 (file)
@@ -9,47 +9,6 @@ import Util from '../util'
 
 /* istanbul ignore next */
 const Polyfill = (() => {
-  // defaultPrevented is broken in IE
-  const workingDefaultPrevented = (() => {
-    const e = document.createEvent('CustomEvent')
-    e.initEvent('Bootstrap', true, true)
-    e.preventDefault()
-    return e.defaultPrevented
-  })()
-
-  if (!workingDefaultPrevented) {
-    const origPreventDefault = Event.prototype.preventDefault
-    Event.prototype.preventDefault = function () {
-      if (!this.cancelable) {
-        return
-      }
-
-      origPreventDefault.call(this)
-      Object.defineProperty(this, 'defaultPrevented', {
-        get() {
-          return true
-        },
-        configurable: true
-      })
-    }
-  }
-
-  // CustomEvent polyfill for IE (see: https://mzl.la/2v76Zvn)
-  if (typeof window.CustomEvent !== 'function') {
-    window.CustomEvent = (event, params) => {
-      params = params || {
-        bubbles: false,
-        cancelable: false,
-        detail: null
-      }
-      const evt = document.createEvent('CustomEvent')
-      evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
-      return evt
-    }
-
-    window.CustomEvent.prototype = window.Event.prototype
-  }
-
   // MSEdge resets defaultPrevented flag upon dispatchEvent call if at least one listener is attached
   const defaultPreventedPreservedOnDispatch = (() => {
     const e = new CustomEvent('Bootstrap', {
@@ -76,14 +35,6 @@ const Polyfill = (() => {
     window.Event.prototype = origEvent.prototype
   }
 
-  // matches polyfill (see: https://mzl.la/2ikXneG)
-  let matches = Element.prototype.matches
-  if (!matches) {
-    matches =
-      Element.prototype.msMatchesSelector ||
-      Element.prototype.webkitMatchesSelector
-  }
-
   // closest polyfill (see: https://mzl.la/2vXggaI)
   let closest
   if (!Element.prototype.closest) {
@@ -91,7 +42,7 @@ const Polyfill = (() => {
     closest = (element, selector) => {
       let ancestor = element
       do {
-        if (matches.call(ancestor, selector)) {
+        if (ancestor.matches(selector)) {
           return ancestor
         }
 
@@ -188,7 +139,6 @@ const Polyfill = (() => {
     defaultPreventedPreservedOnDispatch,
     focusIn: typeof window.onfocusin === 'undefined',
     closest,
-    matches,
     find,
     findOne
   }
index ee2f004850a983c9901132afd8d667b3507b0213..1da34331d7bea431465ac339390bae264b42e56c 100644 (file)
@@ -15,7 +15,7 @@ import Util from '../util'
  */
 
 const closest = Polyfill.closest
-const matchesFn = Polyfill.matches
+const matchesFn = Element.prototype.matches
 const find = Polyfill.find
 const findOne = Polyfill.findOne
 const nodeText = 3
index da36e497b9ee9d0a8c5f80930701ba5b28eb61ea..2341f58ab2eca9bd3153232770fb0bf7af5950ea 100644 (file)
@@ -30,13 +30,6 @@ const browsers = {
     browser: 'Edge',
     browser_version: 'latest'
   },
-  ie11Win10: {
-    base: 'BrowserStack',
-    os: 'Windows',
-    os_version: '10',
-    browser: 'IE',
-    browser_version: '11.0'
-  },
   chromeWin10: {
     base: 'BrowserStack',
     os: 'Windows',
@@ -51,13 +44,6 @@ const browsers = {
     browser: 'Firefox',
     browser_version: 'latest'
   },
-  ie10Win8: {
-    base: 'BrowserStack',
-    os: 'Windows',
-    os_version: '8',
-    browser: 'IE',
-    browser_version: '10.0'
-  },
   iphoneX: {
     base: 'BrowserStack',
     os: 'ios',
index e116730c2eeb8c79957498c831fab5a6b3c0c88f..a1d15116b1eb8c3de4362c2d6b43c36c3804e57f 100644 (file)
@@ -130,21 +130,21 @@ $(function () {
     assert.ok($btn1.hasClass('active'), 'btn1 has active class')
     assert.ok($btn1.find('input').prop('checked'), 'btn1 is checked')
     assert.ok(!$btn2.hasClass('active'), 'btn2 does not have active class')
-    assert.ok(!(inputBtn2.bsChecked || inputBtn2.checked), 'btn2 is not checked')
+    assert.ok(!inputBtn2.checked, 'btn2 is not checked')
 
     inputBtn2.dispatchEvent(new Event('click'))
 
     assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class')
     assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is not checked')
     assert.ok($btn2.hasClass('active'), 'btn2 has active class')
-    assert.ok(inputBtn2.bsChecked || inputBtn2.checked, 'btn2 is checked')
+    assert.ok(inputBtn2.checked, 'btn2 is checked')
 
     inputBtn2.dispatchEvent(new Event('click')) // clicking an already checked radio should not un-check it
 
     assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class')
     assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is not checked')
     assert.ok($btn2.hasClass('active'), 'btn2 has active class')
-    assert.ok(inputBtn2.bsChecked || inputBtn2.checked, 'btn2 is checked')
+    assert.ok(inputBtn2.checked, 'btn2 is checked')
   })
 
   QUnit.test('should only toggle selectable inputs', function (assert) {
index 19effa42316e35477e76c53e5c0706ed82f396b4..8a0be08ea7ea31a13a93ed979ef7fce6707c100f 100644 (file)
@@ -8,52 +8,6 @@ $(function () {
     assert.ok(Manipulator, 'Manipulator is defined')
   })
 
-  QUnit.test('should set checked for input', function (assert) {
-    assert.expect(2)
-
-    var $input = $('<input type="checkbox" />').appendTo('#qunit-fixture')
-    Manipulator.setChecked($input[0], true)
-
-    assert.ok($input[0].checked)
-
-    Manipulator.setChecked($input[0], false)
-
-    assert.ok(!$input[0].checked)
-  })
-
-  QUnit.test('should not set checked for non input element', function (assert) {
-    assert.expect(1)
-
-    var $div = $('<div />').appendTo('#qunit-fixture')
-    Manipulator.setChecked($div[0], true)
-
-    assert.ok(typeof $div[0].checked === 'undefined')
-  })
-
-  QUnit.test('should verify if an element is checked', function (assert) {
-    assert.expect(2)
-
-    var $input = $('<input type="checkbox" />').appendTo('#qunit-fixture')
-    Manipulator.setChecked($input[0], true)
-
-    assert.ok(Manipulator.isChecked($input[0]))
-
-    Manipulator.setChecked($input[0], false)
-
-    assert.ok(!Manipulator.isChecked($input[0]))
-  })
-
-  QUnit.test('should throw an error when the element is not an input', function (assert) {
-    assert.expect(1)
-
-    var $div = $('<div />').appendTo('#qunit-fixture')
-    try {
-      Manipulator.isChecked($div[0])
-    } catch (e) {
-      assert.strictEqual(e.message, 'INPUT parameter is not an HTMLInputElement')
-    }
-  })
-
   QUnit.test('should set data attribute', function (assert) {
     assert.expect(1)
 
index 428fd156f2fcfd081edc419de502286dbe5623a0..44a91a821a837875e60a3f347a9aecd19fabf0f3 100644 (file)
       </div>
     </div>
 
+    <script src="../../dist/util.js"></script>
     <script src="../../dist/dom/polyfill.js"></script>
     <script src="../../dist/dom/eventHandler.js"></script>
-    <script src="../../dist/dom/manipulator.js"></script>
     <script src="../../dist/dom/selectorEngine.js"></script>
     <script src="../../dist/dom/data.js"></script>
-    <script src="../../dist/util.js"></script>
     <script src="../../dist/button.js"></script>
   </body>
 </html>