diff options
| author | Johann-S <[email protected]> | 2017-08-21 09:11:37 +0200 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2019-02-20 22:05:45 +0200 |
| commit | 0b16c8c6d9a9690d537bd08eac8a8292ebf938cd (patch) | |
| tree | cf06827946db78c07a40d797a01fc5fd7a11e18d /js/src/dom/selectorEngine.js | |
| parent | 8d34bc136b54f4605595f228253463c90a3c5c97 (diff) | |
| download | bootstrap-0b16c8c6d9a9690d537bd08eac8a8292ebf938cd.tar.xz bootstrap-0b16c8c6d9a9690d537bd08eac8a8292ebf938cd.zip | |
alert without jquery
Diffstat (limited to 'js/src/dom/selectorEngine.js')
| -rw-r--r-- | js/src/dom/selectorEngine.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/js/src/dom/selectorEngine.js b/js/src/dom/selectorEngine.js new file mode 100644 index 000000000..f6bcf6da2 --- /dev/null +++ b/js/src/dom/selectorEngine.js @@ -0,0 +1,42 @@ +/** + * -------------------------------------------------------------------------- + * Bootstrap (v4.0.0-beta): dom/selectorEngine.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * -------------------------------------------------------------------------- + */ + +const SelectorEngine = { + matches: Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector, + + find(selector) { + if (typeof selector !== 'string') { + return null + } + + let selectorType = 'querySelectorAll' + if (selector.indexOf('#') === 0) { + selectorType = 'getElementById' + selector = selector.substr(1, selector.length) + } + return document[selectorType](selector) + }, + + closest(element, selector) { + let ancestor = element + if (!document.documentElement.contains(element)) { + return null + } + + do { + if (SelectorEngine.matches.call(ancestor, selector)) { + return ancestor + } + + ancestor = ancestor.parentElement + } while (ancestor !== null) + + return null + } +} + +export default SelectorEngine |
