aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/captions.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/captions.js')
-rw-r--r--src/js/captions.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/js/captions.js b/src/js/captions.js
index 6682d6f0..24962387 100644
--- a/src/js/captions.js
+++ b/src/js/captions.js
@@ -7,7 +7,7 @@ import controls from './controls';
import i18n from './i18n';
import support from './support';
import browser from './utils/browser';
-import { createElement, emptyElement, getAttributesFromSelector, insertAfter, removeElement, toggleClass } from './utils/elements';
+import { createElement, emptyElement, getAttributesFromSelector, insertAfter, removeElement, toggleClass, toggleState } from './utils/elements';
import { on, triggerEvent } from './utils/events';
import fetch from './utils/fetch';
import is from './utils/is';
@@ -128,6 +128,28 @@ const captions = {
}
},
+ toggle(input) {
+ // If there's no full support
+ if (!this.supported.ui) {
+ return;
+ }
+
+ // If the method is called without parameter, toggle based on current value
+ const active = is.boolean(input) ? input : !this.elements.container.classList.contains(this.config.classNames.captions.active);
+
+ // Toggle state
+ toggleState(this.elements.buttons.captions, active);
+
+ // Add class hook
+ toggleClass(this.elements.container, this.config.classNames.captions.active, active);
+
+ // Update state and trigger event
+ if (active !== this.captions.active) {
+ this.captions.active = active;
+ triggerEvent.call(this, this.media, this.captions.active ? 'captionsenabled' : 'captionsdisabled');
+ }
+ },
+
set(index, setLanguage = true, show = true) {
const tracks = captions.getTracks.call(this);