Skip to content

Commit

Permalink
refactored the buttons to use buildCSSClass instead of className
Browse files Browse the repository at this point in the history
removing unnecessary localization

fixed the menu button css

Simplified controlText() and removed unnecessary override in MenuButton
  • Loading branch information
mmcc committed May 29, 2015
1 parent bcc5d4e commit 2979272
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/css/components/_big-play.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
font-size: 3em;
line-height: 1.5em;
height: 1.5em;
width: 3em; // Firefox bug
width: 3em; // Firefox bug: For some reason without width the icon wouldn't show up. Switched to using width and removed padding.
display: block;
z-index: 2;
position: absolute;
Expand Down
6 changes: 3 additions & 3 deletions src/css/components/_menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
overflow: auto;
}

.video-js .vjs-menu-button:hover .vjs-control-content .vjs-menu,
.video-js .vjs-control-content .vjs-menu.vjs-lock-showing {
.video-js .vjs-menu-button:hover .vjs-menu,
.video-js .vjs-menu.vjs-lock-showing {
display: block;
}
/* prevent menus from opening while scrubbing (FF, IE) */
.video-js.vjs-scrubbing .vjs-menu-button:hover .vjs-control-content .vjs-menu {
.video-js.vjs-scrubbing .vjs-menu-button:hover .vjs-menu {
display: none;
}
.video-js .vjs-menu-button ul li {
Expand Down
7 changes: 3 additions & 4 deletions src/js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ class Button extends Component {

el.appendChild(this.controlTextEl_);

this.controlText();
this.controlText(this.controlText_);

return el;
}

controlText(text) {
if (!text && (this.controlTextEl_ && this.controlTextEl_.innerHTML)) return this.controlText_ || 'Need Text';

if (text) this.controlText_ = text;
if (!text) return this.controlText_ || 'Need Text';

this.controlText_ = text;
this.controlTextEl_.innerHTML = this.localize(this.controlText_);

return this;
Expand Down
4 changes: 2 additions & 2 deletions src/js/control-bar/fullscreen-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class FullscreenToggle extends Button {
handleClick() {
if (!this.player_.isFullscreen()) {
this.player_.requestFullscreen();
this.controlText(this.localize('Non-Fullscreen'));
this.controlText('Non-Fullscreen');
} else {
this.player_.exitFullscreen();
this.controlText(this.localize('Fullscreen'));
this.controlText('Fullscreen');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/js/control-bar/play-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class PlayToggle extends Button {
handlePlay() {
this.removeClass('vjs-paused');
this.addClass('vjs-playing');
this.controlText(this.localize('Pause')); // change the button text to "Pause"
this.controlText('Pause'); // change the button text to "Pause"
}

// handlePause - Add the vjs-paused class to the element so it can change appearance
handlePause() {
this.removeClass('vjs-playing');
this.addClass('vjs-paused');
this.controlText(this.localize('Play')); // change the button text to "Play"
this.controlText('Play'); // change the button text to "Play"
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class PlaybackRateMenuButton extends MenuButton {
return el;
}

buildCSSClass() {
return `vjs-playback-rate ${super.buildCSSClass()}`;
}

// Menu creation
createMenu() {
let menu = new Menu(this.player());
Expand Down Expand Up @@ -102,7 +106,6 @@ class PlaybackRateMenuButton extends MenuButton {

}

PlaybackRateMenuButton.prototype.className = 'vjs-playback-rate';
PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate';

Component.registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton);
Expand Down
5 changes: 4 additions & 1 deletion src/js/control-bar/text-track-controls/captions-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class CaptionsButton extends TextTrackButton {
this.el_.setAttribute('aria-label','Captions Menu');
}

buildCSSClass() {
return `vjs-captions-button ${super.buildCSSClass()}`;
}

update() {
let threshold = 2;
super.update();
Expand Down Expand Up @@ -44,7 +48,6 @@ class CaptionsButton extends TextTrackButton {

CaptionsButton.prototype.kind_ = 'captions';
CaptionsButton.prototype.controlText_ = 'Captions';
CaptionsButton.prototype.className = 'vjs-captions-button';

Component.registerComponent('CaptionsButton', CaptionsButton);
export default CaptionsButton;
5 changes: 4 additions & 1 deletion src/js/control-bar/text-track-controls/chapters-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class ChaptersButton extends TextTrackButton {
this.el_.setAttribute('aria-label','Chapters Menu');
}

buildCSSClass() {
return `vjs-chapters-button ${super.buildCSSClass()}`;
}

// Create a menu item for each text track
createItems() {
let items = [];
Expand Down Expand Up @@ -106,7 +110,6 @@ class ChaptersButton extends TextTrackButton {

ChaptersButton.prototype.kind_ = 'chapters';
ChaptersButton.prototype.controlText_ = 'Chapters';
ChaptersButton.prototype.className = 'vjs-chapters-button';

Component.registerComponent('ChaptersButton', ChaptersButton);
export default ChaptersButton;
5 changes: 4 additions & 1 deletion src/js/control-bar/text-track-controls/subtitles-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ class SubtitlesButton extends TextTrackButton {
this.el_.setAttribute('aria-label','Subtitles Menu');
}

buildCSSClass() {
return `vjs-subtitles-button ${super.buildCSSClass()}`;
}

}

SubtitlesButton.prototype.kind_ = 'subtitles';
SubtitlesButton.prototype.controlText_ = 'Subtitles';
SubtitlesButton.prototype.className = 'vjs-subtitles-button';

Component.registerComponent('SubtitlesButton', SubtitlesButton);
export default SubtitlesButton;
2 changes: 1 addition & 1 deletion src/js/control-bar/volume-menu-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class VolumeMenuButton extends MenuButton {
}

VolumeMenuButton.prototype.volumeUpdate = MuteToggle.prototype.update;
VolumeMenuButton.prototype.contentText_ = 'Mute';
VolumeMenuButton.prototype.controlText_ = 'Mute';

Component.registerComponent('VolumeMenuButton', VolumeMenuButton);
export default VolumeMenuButton;
17 changes: 1 addition & 16 deletions src/js/menu/menu-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ class MenuButton extends Button {
*/
createItems(){}

// createEl() {
// return super.createEl('div', {
// className: this.buildCSSClass(),
// innerHTML: `<span class="vjs-control-text">${this.localize(this.buttonText())}</span>`
// });
// }
createEl() {
return super.createEl('div', {
className: this.buildCSSClass()
Expand All @@ -90,16 +84,7 @@ class MenuButton extends Button {

/** @inheritDoc */
buildCSSClass() {
return `${this.className} vjs-menu-button ${super.buildCSSClass()}`;
}

controlText(text) {
if (!text) return super.controlText();

this.controlText_ = text;
this.el().children[0].children[0].innerHTML = this.controlText_;

return this;
return `vjs-menu-button ${super.buildCSSClass()}`;
}

// Focus - Add keyboard functionality to element
Expand Down

0 comments on commit 2979272

Please sign in to comment.