aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/controls.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-04-27 18:35:06 +1000
committerSam Potts <sam@potts.es>2018-04-27 18:35:06 +1000
commit24d833a5d1ad7c98bfce676c3aaf219381a4bdee (patch)
tree164e859f5ecb53fc416f0c1d29103f3f37dbda76 /src/js/controls.js
parente1183d604950163fd7a3bfb1a99573beeb89ec92 (diff)
parent44b30380f71f03c8944e42b24c7ce3e92a0f2eea (diff)
downloadplyr-24d833a5d1ad7c98bfce676c3aaf219381a4bdee.tar.lz
plyr-24d833a5d1ad7c98bfce676c3aaf219381a4bdee.tar.xz
plyr-24d833a5d1ad7c98bfce676c3aaf219381a4bdee.zip
Merge branch 'master' into develop
Diffstat (limited to 'src/js/controls.js')
-rw-r--r--src/js/controls.js94
1 files changed, 50 insertions, 44 deletions
diff --git a/src/js/controls.js b/src/js/controls.js
index 615da39e..4404da65 100644
--- a/src/js/controls.js
+++ b/src/js/controls.js
@@ -15,8 +15,6 @@ const browser = utils.getBrowser();
const controls = {
// Webkit polyfill for lower fill range
updateRangeFill(target) {
-
-
// Get range from event if event passed
const range = utils.is.event(target) ? target.target : target;
@@ -212,7 +210,6 @@ const controls = {
// Add aria attributes
attributes['aria-pressed'] = false;
- attributes['aria-label'] = i18n.get(label, this.config);
} else {
button.appendChild(controls.createIcon.call(this, icon));
button.appendChild(controls.createLabel.call(this, label));
@@ -329,22 +326,14 @@ const controls = {
// Create time display
createTime(type) {
- const container = utils.createElement('div', {
- class: 'plyr__time',
- });
+ const attributes = utils.getAttributesFromSelector(this.config.selectors.display[type]);
- container.appendChild(
- utils.createElement(
- 'span',
- {
- class: this.config.classNames.hidden,
- },
- i18n.get(type, this.config),
- ),
- );
-
- container.appendChild(utils.createElement('span', utils.getAttributesFromSelector(this.config.selectors.display[type]), '00:00'));
+ const container = utils.createElement('div', utils.extend(attributes, {
+ class: `plyr__time ${attributes.class}`,
+ 'aria-label': i18n.get(type, this.config),
+ }), '0:00');
+ // Reference for updates
this.elements.display[type] = container;
return container;
@@ -369,7 +358,7 @@ const controls = {
}),
);
- const faux = utils.createElement('span', { 'aria-hidden': true });
+ const faux = utils.createElement('span', { hidden: '' });
label.appendChild(radio);
label.appendChild(faux);
@@ -444,11 +433,7 @@ const controls = {
// Hide/show a tab
toggleTab(setting, toggle) {
- const tab = this.elements.settings.tabs[setting];
- const pane = this.elements.settings.panes[setting];
-
- utils.toggleHidden(tab, !toggle);
- utils.toggleHidden(pane, !toggle);
+ utils.toggleHidden(this.elements.settings.tabs[setting], !toggle);
},
// Set the quality menu
@@ -660,7 +645,6 @@ const controls = {
// Get current selected caption language
// TODO: rework this to user the getter in the API?
-
// Set a list of available captions languages
setCaptionsMenu() {
// TODO: Captions or language? Currently it's mixed
@@ -760,10 +744,6 @@ const controls = {
// Get the list to populate
const list = this.elements.settings.panes.speed.querySelector('ul');
- // Show the pane and tab
- utils.toggleHidden(this.elements.settings.tabs.speed, false);
- utils.toggleHidden(this.elements.settings.panes.speed, false);
-
// Empty the menu
utils.emptyElement(list);
@@ -794,7 +774,7 @@ const controls = {
return;
}
- const show = utils.is.boolean(event) ? event : utils.is.element(form) && form.getAttribute('aria-hidden') === 'true';
+ const show = utils.is.boolean(event) ? event : utils.is.element(form) && form.hasAttribute('hidden');
if (utils.is.event(event)) {
const isMenuItem = utils.is.element(form) && form.contains(event.target);
@@ -819,7 +799,7 @@ const controls = {
}
if (utils.is.element(form)) {
- form.setAttribute('aria-hidden', !show);
+ utils.toggleHidden(form, !show);
utils.toggleClass(this.elements.container, this.config.classNames.menu.open, show);
if (show) {
@@ -835,7 +815,7 @@ const controls = {
const clone = tab.cloneNode(true);
clone.style.position = 'absolute';
clone.style.opacity = 0;
- clone.setAttribute('aria-hidden', false);
+ clone.removeAttribute('hidden');
// Prevent input's being unchecked due to the name being identical
Array.from(clone.querySelectorAll('input[name]')).forEach(input => {
@@ -879,7 +859,7 @@ const controls = {
// Hide all other tabs
// Get other tabs
- const current = menu.querySelector('[role="tabpanel"][aria-hidden="false"]');
+ const current = menu.querySelector('[role="tabpanel"]:not([hidden])');
const container = current.parentNode;
// Set other toggles to be expanded false
@@ -923,11 +903,11 @@ const controls = {
}
// Set attributes on current tab
- current.setAttribute('aria-hidden', true);
+ utils.toggleHidden(current, true);
current.setAttribute('tabindex', -1);
// Set attributes on target
- pane.setAttribute('aria-hidden', !show);
+ utils.toggleHidden(pane, !show);
tab.setAttribute('aria-expanded', show);
pane.removeAttribute('tabindex');
@@ -1069,7 +1049,7 @@ const controls = {
const form = utils.createElement('form', {
class: 'plyr__menu__container',
id: `plyr-settings-${data.id}`,
- 'aria-hidden': true,
+ hidden: '',
'aria-labelled-by': `plyr-settings-toggle-${data.id}`,
role: 'tablist',
tabindex: -1,
@@ -1079,7 +1059,6 @@ const controls = {
const home = utils.createElement('div', {
id: `plyr-settings-${data.id}-home`,
- 'aria-hidden': false,
'aria-labelled-by': `plyr-settings-toggle-${data.id}`,
role: 'tabpanel',
});
@@ -1130,11 +1109,10 @@ const controls = {
this.config.settings.forEach(type => {
const pane = utils.createElement('div', {
id: `plyr-settings-${data.id}-${type}`,
- 'aria-hidden': true,
+ hidden: '',
'aria-labelled-by': `plyr-settings-${data.id}-${type}-tab`,
role: 'tabpanel',
tabindex: -1,
- hidden: '',
});
const back = utils.createElement(
@@ -1217,17 +1195,21 @@ const controls = {
let container = null;
this.elements.controls = null;
- // HTML or Element passed as the option
+ // Set template properties
+ const props = {
+ id: this.id,
+ seektime: this.config.seekTime,
+ title: this.config.title,
+ };
+ let update = true;
+
if (utils.is.string(this.config.controls) || utils.is.element(this.config.controls)) {
+ // String or HTMLElement passed as the option
container = this.config.controls;
} else if (utils.is.function(this.config.controls)) {
// A custom function to build controls
// The function can return a HTMLElement or String
- container = this.config.controls({
- id: this.id,
- seektime: this.config.seekTime,
- title: this.config.title,
- });
+ container = this.config.controls.call(this, props);
} else {
// Create controls
container = controls.create.call(this, {
@@ -1239,6 +1221,30 @@ const controls = {
// TODO: Looping
// loop: 'None',
});
+ update = false;
+ }
+
+ // Replace props with their value
+ const replace = input => {
+ let result = input;
+
+ Object.entries(props).forEach(([
+ key,
+ value,
+ ]) => {
+ result = utils.replaceAll(result, `{${key}}`, value);
+ });
+
+ return result;
+ };
+
+ // Update markup
+ if (update) {
+ if (utils.is.string(this.config.controls)) {
+ container = replace(container);
+ } else if (utils.is.element(container)) {
+ container.innerHTML = replace(container.innerHTML);
+ }
}
// Controls container