diff options
author | XhmikosR <xhmikosr@gmail.com> | 2020-07-08 20:09:39 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2020-09-21 14:58:34 +0300 |
commit | b31046aab36ea1e476ff384f585ef650c8158d1e (patch) | |
tree | 1f88c461bb248b1dd8876a106e16a52996329822 | |
parent | c86b74fe88318cd4483c148a560742b0d2ed6f65 (diff) |
Cache a few variables.
-rw-r--r-- | js/src/button.js | 5 | ||||
-rw-r--r-- | js/src/carousel.js | 3 | ||||
-rw-r--r-- | js/src/collapse.js | 8 | ||||
-rw-r--r-- | js/src/tooltip.js | 5 |
4 files changed, 12 insertions, 9 deletions
diff --git a/js/src/button.js b/js/src/button.js index b244c8df47..d793785829 100644 --- a/js/src/button.js +++ b/js/src/button.js @@ -111,11 +111,12 @@ class Button { static _jQueryInterface(config) { return this.each(function () { - let data = $(this).data(DATA_KEY) + const $element = $(this) + let data = $element.data(DATA_KEY) if (!data) { data = new Button(this) - $(this).data(DATA_KEY, data) + $element.data(DATA_KEY, data) } if (config === 'toggle') { diff --git a/js/src/carousel.js b/js/src/carousel.js index 8c03818ab0..62b4ce1e4d 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -129,10 +129,11 @@ class Carousel { } nextWhenVisible() { + const $element = $(this._element) // Don't call next when the page isn't visible // or the carousel or its parent isn't visible if (!document.hidden && - ($(this._element).is(':visible') && $(this._element).css('visibility') !== 'hidden')) { + ($element.is(':visible') && $element.css('visibility') !== 'hidden')) { this.next() } } diff --git a/js/src/collapse.js b/js/src/collapse.js index 04653b835e..6052995153 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -324,11 +324,11 @@ class Collapse { static _jQueryInterface(config) { return this.each(function () { - const $this = $(this) - let data = $this.data(DATA_KEY) + const $element = $(this) + let data = $element.data(DATA_KEY) const _config = { ...Default, - ...$this.data(), + ...$element.data(), ...typeof config === 'object' && config ? config : {} } @@ -338,7 +338,7 @@ class Collapse { if (!data) { data = new Collapse(this, _config) - $this.data(DATA_KEY, data) + $element.data(DATA_KEY, data) } if (typeof config === 'string') { diff --git a/js/src/tooltip.js b/js/src/tooltip.js index a1ce7ca87e..e2a554014d 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -735,7 +735,8 @@ class Tooltip { static _jQueryInterface(config) { return this.each(function () { - let data = $(this).data(DATA_KEY) + const $element = $(this) + let data = $element.data(DATA_KEY) const _config = typeof config === 'object' && config if (!data && /dispose|hide/.test(config)) { @@ -744,7 +745,7 @@ class Tooltip { if (!data) { data = new Tooltip(this, _config) - $(this).data(DATA_KEY, data) + $element.data(DATA_KEY, data) } if (typeof config === 'string') { |