diff options
author | Johann-S <johann.servoire@gmail.com> | 2017-09-05 15:35:52 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2019-02-20 23:05:45 +0300 |
commit | 9f9712b98c92678c709b2ad0adfa954e3c120911 (patch) | |
tree | e868e4dc7b23bf32b20f5d3db3f791b32326e75c /js/src | |
parent | 44f38e41280c12b5bfb25ad1134a9a9f83c23786 (diff) |
Add Manipulator object to add shortcuts for dom manipulations
Diffstat (limited to 'js/src')
-rw-r--r-- | js/src/button.js | 3 | ||||
-rw-r--r-- | js/src/dom/eventHandler.js | 2 | ||||
-rw-r--r-- | js/src/dom/manipulator.js | 24 |
3 files changed, 27 insertions, 2 deletions
diff --git a/js/src/button.js b/js/src/button.js index 410da06cb3..acba736af4 100644 --- a/js/src/button.js +++ b/js/src/button.js @@ -7,6 +7,7 @@ import Data from './dom/data' import EventHandler from './dom/eventHandler' +import Manipulator from './dom/manipulator' import SelectorEngine from './dom/selectorEngine' /** @@ -93,7 +94,7 @@ class Button { rootElement.classList.contains('disabled')) { return } - input.checked = !this._element.classList.contains(ClassName.ACTIVE) + Manipulator.setChecked(input, !this._element.classList.contains(ClassName.ACTIVE)) EventHandler.trigger(input, 'change') } diff --git a/js/src/dom/eventHandler.js b/js/src/dom/eventHandler.js index 476f7af26f..746f84bcb5 100644 --- a/js/src/dom/eventHandler.js +++ b/js/src/dom/eventHandler.js @@ -85,7 +85,7 @@ const nativeEvents = [ 'orientationchange', 'touchstart', 'touchmove', 'touchend', 'touchcancel', 'gesturestart', 'gesturechange', 'gestureend', - 'focus', 'blur', 'change', 'reset', 'select', 'submit', + 'focus', 'blur', 'change', 'reset', 'select', 'submit', 'focusin', 'focusout', 'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange', 'error', 'abort', 'scroll' ] diff --git a/js/src/dom/manipulator.js b/js/src/dom/manipulator.js new file mode 100644 index 0000000000..c124802349 --- /dev/null +++ b/js/src/dom/manipulator.js @@ -0,0 +1,24 @@ +/** + * -------------------------------------------------------------------------- + * Bootstrap (v4.0.0-beta): dom/manipulator.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * -------------------------------------------------------------------------- + */ + +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') + } +} + +export default Manipulator |