diff options
author | Sam Potts <sam@potts.es> | 2018-06-17 00:39:35 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-17 00:39:35 +1000 |
commit | de45de0e0bbfdea63977427d70fea503274e39b6 (patch) | |
tree | cb823756be086db5c220ceb1045b75540b62a4ca /src/js/controls.js | |
parent | d522e405942e060180c7f5b28c914028e94a917b (diff) | |
parent | 99c10aa1fc2010c659a412568096ee24900f0eac (diff) | |
download | plyr-de45de0e0bbfdea63977427d70fea503274e39b6.tar.lz plyr-de45de0e0bbfdea63977427d70fea503274e39b6.tar.xz plyr-de45de0e0bbfdea63977427d70fea503274e39b6.zip |
Merge pull request #1040 from friday/switches-get-stitches
Switches code optimizations
Diffstat (limited to 'src/js/controls.js')
-rw-r--r-- | src/js/controls.js | 89 |
1 files changed, 33 insertions, 56 deletions
diff --git a/src/js/controls.js b/src/js/controls.js index f091555f..19c531af 100644 --- a/src/js/controls.js +++ b/src/js/controls.js @@ -119,28 +119,17 @@ const controls = { }, // Create hidden text label - createLabel(type, attr) { - let text = i18n.get(type, this.config); - const attributes = Object.assign({}, attr); - - switch (type) { - case 'pip': - text = 'PIP'; - break; - - case 'airplay': - text = 'AirPlay'; - break; - - default: - break; - } + createLabel(type, attr = {}) { + // Skip i18n for abbreviations and brand names + const universals = { + pip: 'PIP', + airplay: 'AirPlay', + }; - if ('class' in attributes) { - attributes.class += ` ${this.config.classNames.hidden}`; - } else { - attributes.class = this.config.classNames.hidden; - } + const text = universals[type] || i18n.get(type, this.config); + const attributes = Object.assign({}, attr, { + class: [attr.class, this.config.classNames.hidden].filter(Boolean).join(' '), + }); return createElement('span', attributes, text); }, @@ -342,19 +331,12 @@ const controls = { if (type !== 'volume') { progress.appendChild(createElement('span', null, '0')); - let suffix = ''; - switch (type) { - case 'played': - suffix = i18n.get('played', this.config); - break; + const suffixKey = ({ + played: 'played', + buffer: 'buffered', + })[type]; - case 'buffer': - suffix = i18n.get('buffered', this.config); - break; - - default: - break; - } + const suffix = suffixKey ? i18n.get(suffixKey, this.config) : ''; progress.innerText = `% ${suffix.toLowerCase()}`; } @@ -724,32 +706,27 @@ const controls = { let value = null; let list = container; - switch (setting) { - case 'captions': - value = this.currentTrack; - break; - - default: - value = !is.empty(input) ? input : this[setting]; - - // Get default - if (is.empty(value)) { - value = this.config[setting].default; - } + if (setting === 'captions') { + value = this.currentTrack; + } else { + value = !is.empty(input) ? input : this[setting]; - // Unsupported value - if (!is.empty(this.options[setting]) && !this.options[setting].includes(value)) { - this.debug.warn(`Unsupported value of '${value}' for ${setting}`); - return; - } + // Get default + if (is.empty(value)) { + value = this.config[setting].default; + } - // Disabled value - if (!this.config[setting].options.includes(value)) { - this.debug.warn(`Disabled value of '${value}' for ${setting}`); - return; - } + // Unsupported value + if (!is.empty(this.options[setting]) && !this.options[setting].includes(value)) { + this.debug.warn(`Unsupported value of '${value}' for ${setting}`); + return; + } - break; + // Disabled value + if (!this.config[setting].options.includes(value)) { + this.debug.warn(`Disabled value of '${value}' for ${setting}`); + return; + } } // Get the list if we need to |