diff options
author | Albin Larsson <mail@albinlarsson.com> | 2018-05-27 05:08:18 +0200 |
---|---|---|
committer | Albin Larsson <mail@albinlarsson.com> | 2018-05-28 05:44:54 +0200 |
commit | 7aad747c25b07fedf4a4fc75095c560ea3c9899c (patch) | |
tree | 26e05dde93ce7fb04355250111cfde98913d7e3d /src/js/plyr.js | |
parent | e9684c20217300c15fc92a71c4c4a640c4784083 (diff) | |
download | plyr-7aad747c25b07fedf4a4fc75095c560ea3c9899c.tar.lz plyr-7aad747c25b07fedf4a4fc75095c560ea3c9899c.tar.xz plyr-7aad747c25b07fedf4a4fc75095c560ea3c9899c.zip |
Optimize captions code reused and ensure captionsenabled/captionsdisabled
will be sent on initial setup
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r-- | src/js/plyr.js | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index 34b618bd..061225f8 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -838,24 +838,19 @@ class Plyr { } // If the method is called without parameter, toggle based on current value - const show = utils.is.boolean(input) ? input : !this.elements.container.classList.contains(this.config.classNames.captions.active); - - // Nothing to change... - if (this.captions.active === show) { - return; - } - - // Set global - this.captions.active = show; + const active = utils.is.boolean(input) ? input : !this.elements.container.classList.contains(this.config.classNames.captions.active); // Toggle state - utils.toggleState(this.elements.buttons.captions, this.captions.active); + utils.toggleState(this.elements.buttons.captions, active); // Add class hook - utils.toggleClass(this.elements.container, this.config.classNames.captions.active, this.captions.active); + utils.toggleClass(this.elements.container, this.config.classNames.captions.active, active); - // Trigger an event - utils.dispatchEvent.call(this, this.media, this.captions.active ? 'captionsenabled' : 'captionsdisabled'); + // Update state and trigger event + if (active !== this.captions.active) { + this.captions.active = active; + utils.dispatchEvent.call(this, this.media, this.captions.active ? 'captionsenabled' : 'captionsdisabled'); + } } /** |