Skip to content

Commit

Permalink
fix(player): Added control position as part of each one of the contro…
Browse files Browse the repository at this point in the history
…ls class names to allow more advanced styling
  • Loading branch information
rafa8626 committed Nov 21, 2019
1 parent 8b77f0b commit 82a0634
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 61 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ Sometimes you need more flexibility instantiating the player (for example, addin

```javascript
var player = new OpenPlayer('[player ID]', [valid VAST/VPAID URL|List of VAST/VPAID URLs], [`true|false` for fullscreen effect by default], {
// Controls configuration by default; `levels` can be added as well since it's an optional feature
// Controls configuration by default; `levels` can be added as well since it's an optional feature;
// Each one of the items will have in their class name the `op-control__[left|middle|right]` according
// to the controls' structure listed below
controls: {
left: ['play', 'time', 'volume'],
middle: ['progress'],
Expand Down
5 changes: 1 addition & 4 deletions dist/openplayer.css
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,7 @@
}

/* === Time =================== */
.op-controls > time {
margin-top: 4px;
}
.op-controls__time-delimiter {
.op-controls > .op-controls-time {
margin: 4px 3px 0;
}

Expand Down
56 changes: 34 additions & 22 deletions dist/openplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,11 +1502,11 @@ var Player = function () {
volumeControl: 'Volume Control',
volumeSlider: 'Volume Slider'
},
onError: function onError() {},
showLoaderOnInit: false,
startTime: 0,
startVolume: 1,
step: 0,
onError: function onError() {}
step: 0
};
this.element = element instanceof HTMLMediaElement ? element : document.getElementById(element);

Expand Down Expand Up @@ -4775,7 +4775,7 @@ var Controls = function () {
return a.indexOf(v) === i;
}).forEach(function (el) {
var className = "".concat(el.charAt(0).toUpperCase()).concat(el.slice(1));
var item = new _this4.controlEls[className](_this4.player);
var item = new _this4.controlEls[className](_this4.player, position);

if (el === 'settings') {
_this4.settings = item;
Expand All @@ -4795,7 +4795,7 @@ var Controls = function () {
});

if (general_1.isVideo(this.player.getElement())) {
this.items.right.push(new fullscreen_1["default"](this.player));
this.items.right.push(new fullscreen_1["default"](this.player, 'right'));
}
}
}, {
Expand Down Expand Up @@ -4883,7 +4883,7 @@ var general_1 = __webpack_require__(2);
var time_1 = __webpack_require__(46);

var Captions = function () {
function Captions(player) {
function Captions(player, position) {
_classCallCheck(this, Captions);

this.events = {
Expand All @@ -4897,6 +4897,7 @@ var Captions = function () {
this.player = player;
this.labels = player.getOptions().labels;
this.detachMenu = player.getOptions().detachMenus;
this.position = position;
var trackList = this.player.getElement().textTracks;
var tracks = [];

Expand Down Expand Up @@ -4930,7 +4931,7 @@ var Captions = function () {
}

this.button = document.createElement('button');
this.button.className = 'op-controls__captions op-control__right';
this.button.className = "op-controls__captions op-control__".concat(this.position);
this.button.tabIndex = 0;
this.button.title = this.labels.toggleCaptions;
this.button.setAttribute('aria-controls', this.player.id);
Expand Down Expand Up @@ -5438,11 +5439,12 @@ Object.defineProperty(exports, "__esModule", {
var constants_1 = __webpack_require__(5);

var Fullscreen = function () {
function Fullscreen(player) {
function Fullscreen(player, position) {
_classCallCheck(this, Fullscreen);

this.player = player;
this.labels = player.getOptions().labels;
this.position = position;
this.isFullscreen = document.body.classList.contains('op-fullscreen__on');
var target = document;
this.fullScreenEnabled = !!(target.fullscreenEnabled || target.mozFullScreenEnabled || target.msFullscreenEnabled || target.webkitSupportsFullscreen || target.webkitFullscreenEnabled || document.createElement('video').webkitRequestFullScreen);
Expand All @@ -5456,7 +5458,7 @@ var Fullscreen = function () {

this.button = document.createElement('button');
this.button.type = 'button';
this.button.className = 'op-controls__fullscreen op-control__right';
this.button.className = "op-controls__fullscreen op-control__".concat(this.position);
this.button.tabIndex = 0;
this.button.title = this.labels.fullscreen;
this.button.setAttribute('aria-controls', this.player.id);
Expand Down Expand Up @@ -5653,7 +5655,7 @@ var events_1 = __webpack_require__(6);
var general_1 = __webpack_require__(2);

var Levels = function () {
function Levels(player) {
function Levels(player, position) {
_classCallCheck(this, Levels);

this.events = {
Expand All @@ -5665,6 +5667,7 @@ var Levels = function () {
this.player = player;
this.labels = player.getOptions().labels;
this.detachMenu = player.getOptions().detachMenus;
this.position = position;
return this;
}

Expand All @@ -5681,7 +5684,7 @@ var Levels = function () {
return items.key === _this["default"];
}).label : this.labels.auto;
this.button = document.createElement('button');
this.button.className = 'op-controls__levels op-control__right';
this.button.className = "op-controls__levels op-control__".concat(this.position);
this.button.tabIndex = 0;
this.button.title = this.labels.mediaLevels;
this.button.setAttribute('aria-controls', this.player.id);
Expand Down Expand Up @@ -5962,7 +5965,7 @@ var events_1 = __webpack_require__(6);
var general_1 = __webpack_require__(2);

var Play = function () {
function Play(player) {
function Play(player, position) {
_classCallCheck(this, Play);

this.events = {
Expand All @@ -5971,6 +5974,7 @@ var Play = function () {
};
this.player = player;
this.labels = this.player.getOptions().labels;
this.position = position;
return this;
}

Expand All @@ -5981,7 +5985,7 @@ var Play = function () {

this.button = document.createElement('button');
this.button.type = 'button';
this.button.className = 'op-controls__playpause';
this.button.className = "op-controls__playpause op-control__".concat(this.position);
this.button.tabIndex = 0;
this.button.title = this.labels.play;
this.button.setAttribute('aria-controls', this.player.id);
Expand Down Expand Up @@ -6175,7 +6179,7 @@ var general_1 = __webpack_require__(2);
var time_1 = __webpack_require__(46);

var Progress = function () {
function Progress(player) {
function Progress(player, position) {
_classCallCheck(this, Progress);

this.events = {
Expand All @@ -6188,6 +6192,7 @@ var Progress = function () {
this.player = player;
this.labels = player.getOptions().labels;
this.forcePause = false;
this.position = position;
return this;
}

Expand All @@ -6197,7 +6202,7 @@ var Progress = function () {
var _this = this;

this.progress = document.createElement('div');
this.progress.className = 'op-controls__progress';
this.progress.className = "op-controls__progress op-control__".concat(this.position);
this.progress.tabIndex = 0;
this.progress.setAttribute('aria-label', this.labels.progressSlider);
this.progress.setAttribute('aria-valuemin', '0');
Expand Down Expand Up @@ -6521,7 +6526,7 @@ Object.defineProperty(exports, "__esModule", {
var general_1 = __webpack_require__(2);

var Settings = function () {
function Settings(player) {
function Settings(player, position) {
_classCallCheck(this, Settings);

this.submenu = {};
Expand All @@ -6531,6 +6536,7 @@ var Settings = function () {
};
this.player = player;
this.labels = player.getOptions().labels;
this.position = position;
return this;
}

Expand All @@ -6540,7 +6546,7 @@ var Settings = function () {
var _this = this;

this.button = document.createElement('button');
this.button.className = 'op-controls__settings op-control__right';
this.button.className = "op-controls__settings op-control__".concat(this.position);
this.button.tabIndex = 0;
this.button.title = this.labels.settings;
this.button.setAttribute('aria-controls', this.player.id);
Expand Down Expand Up @@ -6791,7 +6797,7 @@ Object.defineProperty(exports, "__esModule", {
var time_1 = __webpack_require__(46);

var Time = function () {
function Time(player) {
function Time(player, position) {
_classCallCheck(this, Time);

this.events = {
Expand All @@ -6800,6 +6806,7 @@ var Time = function () {
};
this.player = player;
this.labels = player.getOptions().labels;
this.position = position;
return this;
}

Expand Down Expand Up @@ -6879,9 +6886,12 @@ var Time = function () {
});
this.player.getControls().getContainer().addEventListener('controlschanged', this.events.controls.controlschanged);
var controls = this.player.getControls().getContainer();
controls.appendChild(this.current);
controls.appendChild(this.delimiter);
controls.appendChild(this.duration);
this.container = document.createElement('span');
this.container.className = "op-controls-time op-control__".concat(this.position);
this.container.appendChild(this.current);
this.container.appendChild(this.delimiter);
this.container.appendChild(this.duration);
controls.appendChild(this.container);
}
}, {
key: "destroy",
Expand All @@ -6895,6 +6905,7 @@ var Time = function () {
this.current.remove();
this.delimiter.remove();
this.duration.remove();
this.container.remove();
}
}]);

Expand Down Expand Up @@ -6927,7 +6938,7 @@ var events_1 = __webpack_require__(6);
var general_1 = __webpack_require__(2);

var Volume = function () {
function Volume(player) {
function Volume(player, position) {
_classCallCheck(this, Volume);

this.events = {
Expand All @@ -6938,6 +6949,7 @@ var Volume = function () {
this.player = player;
this.labels = player.getOptions().labels;
this.volume = this.player.getMedia().volume;
this.position = position;
return this;
}

Expand All @@ -6947,7 +6959,7 @@ var Volume = function () {
var _this = this;

this.container = document.createElement('div');
this.container.className = 'op-controls__volume';
this.container.className = "op-controls__volume op-control__".concat(this.position);
this.container.tabIndex = 0;
this.container.setAttribute('aria-valuemin', '0');
this.container.setAttribute('aria-valuemax', '100');
Expand Down
2 changes: 1 addition & 1 deletion dist/openplayer.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/openplayer.min.js

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/css/player.css
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,7 @@
}

/* === Time =================== */
.op-controls > time {
margin-top: 4px;
}
.op-controls__time-delimiter {
.op-controls > .op-controls-time {
margin: 4px 3px 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/js/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class Controls implements PlayerComponent {
.filter((v: string, i: number, a: string[]) => a.indexOf(v) === i)
.forEach((el: string) => {
const className = `${el.charAt(0).toUpperCase()}${el.slice(1)}`;
const item = new this.controlEls[className](this.player);
const item = new this.controlEls[className](this.player, position);
if (el === 'settings') {
this.settings = item;
}
Expand All @@ -314,7 +314,7 @@ class Controls implements PlayerComponent {

// Make sure fullscreen is always the last one
if (isVideo(this.player.getElement())) {
this.items.right.push(new Fullscreen(this.player));
this.items.right.push(new Fullscreen(this.player, 'right'));
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/js/controls/captions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,27 @@ class Captions implements PlayerComponent {
*/
private labels: any;

/**
* Position of the button to be indicated as part of its class name
*
* @private
* @type {string}
* @memberof Captions
*/
private position: string;

/**
* Create an instance of Captions.
*
* @param {Player} player
* @memberof Captions
* @returns {Captions}
*/
constructor(player: Player) {
constructor(player: Player, position: string) {
this.player = player;
this.labels = player.getOptions().labels;
this.detachMenu = player.getOptions().detachMenus;
this.position = position;
const trackList = this.player.getElement().textTracks;

// Check that `trackList` matches with track tags (if any)
Expand Down Expand Up @@ -192,7 +202,7 @@ class Captions implements PlayerComponent {
}

this.button = document.createElement('button');
this.button.className = 'op-controls__captions op-control__right';
this.button.className = `op-controls__captions op-control__${this.position}`;
this.button.tabIndex = 0;
this.button.title = this.labels.toggleCaptions;
this.button.setAttribute('aria-controls', this.player.id);
Expand Down
16 changes: 13 additions & 3 deletions src/js/controls/fullscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,30 @@ class Fullscreen implements PlayerComponent {
*
* @private
* @type object
* @memberof Captions
* @memberof Fullscreen
*/
private labels: any;

/**
* Position of the button to be indicated as part of its class name
*
* @private
* @type {string}
* @memberof Fullscreen
*/
private position: string;

/**
* Create an instance of Fullscreen.
*
* @param {Player} player
* @returns {Fullscreen}
* @memberof Fullscreen
*/
constructor(player: Player) {
constructor(player: Player, position: string) {
this.player = player;
this.labels = player.getOptions().labels;
this.position = position;
this.isFullscreen = document.body.classList.contains('op-fullscreen__on');

const target = (document as any);
Expand All @@ -123,7 +133,7 @@ class Fullscreen implements PlayerComponent {
public create(): void {
this.button = document.createElement('button');
this.button.type = 'button';
this.button.className = 'op-controls__fullscreen op-control__right';
this.button.className = `op-controls__fullscreen op-control__${this.position}`;
this.button.tabIndex = 0;
this.button.title = this.labels.fullscreen;
this.button.setAttribute('aria-controls', this.player.id);
Expand Down

0 comments on commit 82a0634

Please sign in to comment.