-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the overflow menu to use components design.
Closes #1673. Change-Id: I030745def928796a6abc813a91fb163cb2d76175
- Loading branch information
Showing
13 changed files
with
1,453 additions
and
1,176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
/** | ||
* @license | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
goog.provide('shaka.ui.AudioLanguageSelection'); | ||
|
||
goog.require('shaka.ui.Element'); | ||
goog.require('shaka.ui.Enums'); | ||
goog.require('shaka.ui.LanguageUtils'); | ||
goog.require('shaka.ui.Locales'); | ||
goog.require('shaka.ui.Localization'); | ||
goog.require('shaka.ui.OverflowMenu'); | ||
|
||
|
||
/** | ||
* @extends {shaka.ui.Element} | ||
* @final | ||
* @export | ||
*/ | ||
shaka.ui.AudioLanguageSelection = class extends shaka.ui.Element { | ||
/** | ||
* @param {!HTMLElement} parent | ||
* @param {!shaka.ui.Controls} controls | ||
*/ | ||
constructor(parent, controls) { | ||
super(parent, controls); | ||
|
||
this.addLanguagesButton_(); | ||
|
||
this.addAudioLangMenu_(); | ||
|
||
this.eventManager.listen( | ||
this.localization, shaka.ui.Localization.LOCALE_UPDATED, () => { | ||
this.updateLocalizedStrings_(); | ||
// TODO: is there a more efficient way of updating just the strings | ||
// we need instead of running the whole language update? | ||
this.updateAudioLanguages_(); | ||
}); | ||
|
||
this.eventManager.listen( | ||
this.localization, shaka.ui.Localization.LOCALE_CHANGED, () => { | ||
this.updateLocalizedStrings_(); | ||
// TODO: is there a more efficient way of updating just the strings | ||
// we need instead of running the whole language update? | ||
this.updateAudioLanguages_(); | ||
}); | ||
|
||
|
||
this.eventManager.listen(this.player, 'trackschanged', () => { | ||
this.updateAudioLanguages_(); | ||
}); | ||
|
||
this.eventManager.listen(this.player, 'variantchanged', () => { | ||
this.updateAudioLanguages_(); | ||
}); | ||
|
||
this.eventManager.listen(this.languagesButton_, 'click', () => { | ||
this.onLanguagesClick_(); | ||
}); | ||
|
||
// Set up all the strings in the user's preferred language. | ||
this.updateLocalizedStrings_(); | ||
} | ||
|
||
|
||
/** | ||
* @private | ||
*/ | ||
addAudioLangMenu_() { | ||
/** @private {!HTMLElement} */ | ||
this.audioLangMenu_ = shaka.ui.Utils.createHTMLElement('div'); | ||
this.audioLangMenu_.classList.add('shaka-audio-languages'); | ||
this.audioLangMenu_.classList.add('shaka-no-propagation'); | ||
this.audioLangMenu_.classList.add('shaka-show-controls-on-mouse-over'); | ||
this.audioLangMenu_.classList.add('shaka-settings-menu'); | ||
|
||
/** @private {!HTMLElement} */ | ||
this.backFromLanguageButton_ = shaka.ui.Utils.createHTMLElement('button'); | ||
this.backFromLanguageButton_.classList.add('shaka-back-to-overflow-button'); | ||
this.audioLangMenu_.appendChild(this.backFromLanguageButton_); | ||
|
||
const backIcon = shaka.ui.Utils.createHTMLElement('i'); | ||
backIcon.classList.add('material-icons'); | ||
backIcon.textContent = shaka.ui.Enums.MaterialDesignIcons.BACK; | ||
this.backFromLanguageButton_.appendChild(backIcon); | ||
|
||
/** @private {!HTMLElement} */ | ||
this.backFromLanguageSpan_ = shaka.ui.Utils.createHTMLElement('span'); | ||
this.backFromLanguageButton_.appendChild(this.backFromLanguageSpan_); | ||
|
||
const controlsContainer = this.controls.getControlsContainer(); | ||
controlsContainer.appendChild(this.audioLangMenu_); | ||
} | ||
|
||
|
||
/** | ||
* @private | ||
*/ | ||
addLanguagesButton_() { | ||
/** @private {!HTMLElement} */ | ||
this.languagesButton_ = shaka.ui.Utils.createHTMLElement('button'); | ||
this.languagesButton_.classList.add('shaka-language-button'); | ||
|
||
const icon = shaka.ui.Utils.createHTMLElement('i'); | ||
icon.classList.add('material-icons'); | ||
icon.textContent = shaka.ui.Enums.MaterialDesignIcons.LANGUAGE; | ||
this.languagesButton_.appendChild(icon); | ||
|
||
const label = shaka.ui.Utils.createHTMLElement('label'); | ||
label.classList.add('shaka-overflow-button-label'); | ||
|
||
/** @private {!HTMLElement} */ | ||
this.languageNameSpan_ = shaka.ui.Utils.createHTMLElement('span'); | ||
this.languageNameSpan_.classList.add('languageSpan'); | ||
label.appendChild(this.languageNameSpan_); | ||
|
||
/** @private {!HTMLElement} */ | ||
this.currentAudioLanguage_ = shaka.ui.Utils.createHTMLElement('span'); | ||
this.currentAudioLanguage_.classList.add('shaka-current-selection-span'); | ||
const language = this.player.getConfiguration().preferredAudioLanguage; | ||
this.currentAudioLanguage_.textContent = | ||
shaka.ui.LanguageUtils.getLanguageName(language, this.localization); | ||
label.appendChild(this.currentAudioLanguage_); | ||
|
||
this.languagesButton_.appendChild(label); | ||
|
||
this.parent.appendChild(this.languagesButton_); | ||
} | ||
|
||
/** @private */ | ||
onLanguagesClick_() { | ||
this.controls.dispatchEvent(new shaka.util.FakeEvent('submenuopen')); | ||
shaka.ui.Utils.setDisplay(this.audioLangMenu_, true); | ||
// Focus on the currently selected language button. | ||
shaka.ui.Utils.focusOnTheChosenItem(this.audioLangMenu_); | ||
} | ||
|
||
/** @private */ | ||
updateAudioLanguages_() { | ||
const tracks = this.player.getVariantTracks(); | ||
|
||
const languagesAndRoles = this.player.getAudioLanguagesAndRoles(); | ||
const languages = languagesAndRoles.map((langAndRole) => { | ||
return langAndRole.language; | ||
}); | ||
|
||
shaka.ui.LanguageUtils.updateLanguages(tracks, this.audioLangMenu_, | ||
languages, | ||
this.onAudioLanguageSelected_.bind(this), /* updateChosen */ true, | ||
this.currentAudioLanguage_, | ||
this.localization); | ||
shaka.ui.Utils.focusOnTheChosenItem(this.audioLangMenu_); | ||
} | ||
|
||
|
||
/** | ||
* @param {string} language | ||
* @private | ||
*/ | ||
onAudioLanguageSelected_(language) { | ||
this.player.selectAudioLanguage(language); | ||
} | ||
|
||
|
||
/** | ||
* @private | ||
*/ | ||
updateLocalizedStrings_() { | ||
const LocIds = shaka.ui.Locales.Ids; | ||
|
||
this.backFromLanguageButton_.setAttribute(shaka.ui.Constants.ARIA_LABEL, | ||
this.localization.resolve(LocIds.ARIA_LABEL_BACK)); | ||
this.languagesButton_.setAttribute(shaka.ui.Constants.ARIA_LABEL, | ||
this.localization.resolve(LocIds.ARIA_LABEL_LANGUAGE)); | ||
this.languageNameSpan_.textContent = | ||
this.localization.resolve(LocIds.LABEL_LANGUAGE); | ||
this.backFromLanguageSpan_.textContent = | ||
this.localization.resolve(LocIds.LABEL_LANGUAGE); | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* @implements {shaka.extern.IUIElement.Factory} | ||
* @final | ||
*/ | ||
shaka.ui.AudioLanguageSelection.Factory = class { | ||
/** @override */ | ||
create(rootElement, controls) { | ||
return new shaka.ui.AudioLanguageSelection(rootElement, controls); | ||
} | ||
}; | ||
|
||
shaka.ui.OverflowMenu.registerElement( | ||
'language', new shaka.ui.AudioLanguageSelection.Factory()); |
Oops, something went wrong.