Skip to content

Commit

Permalink
fix(controls): Added new class to indicate position of the custom con…
Browse files Browse the repository at this point in the history
…trols; ensured that all items in right position are prepended rather than appended
  • Loading branch information
rafa8626 committed Jan 9, 2019
1 parent 088a6fd commit c3066ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
player.addControl({
icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Love_Heart_SVG.svg/32px-Love_Heart_SVG.svg.png',
title: 'Test',
position: 'left',
position: 'right',
click: function() {
alert('You clicked the new ' + id + ' control');
}
Expand Down
8 changes: 6 additions & 2 deletions dist/openplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4674,7 +4674,11 @@ var Controls = function () {
};
var customItems = this.player.getCustomControls();
customItems.forEach(function (item) {
_this4.items[item.position].push(item);
if (item.position === 'right') {
_this4.items[item.position].unshift(item);
} else {
_this4.items[item.position].push(item);
}
});

if (general_1.isVideo(this.player.getElement())) {
Expand Down Expand Up @@ -4715,7 +4719,7 @@ var Controls = function () {
value: function _createCustomControl(item) {
var control = document.createElement('button');
var key = item.title.toLowerCase().replace(' ', '-');
control.className = "op-controls__".concat(key);
control.className = "op-controls__".concat(key, " op-control__").concat(item.position);
control.tabIndex = 0;
control.title = item.title;
control.innerHTML = "<img src=\"".concat(item.icon, "\"> <span class=\"op-sr\">").concat(item.title, "</span>");
Expand Down
2 changes: 1 addition & 1 deletion dist/openplayer.min.js

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions src/js/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,16 @@ class Controls implements PlayerComponent {
],
};

// Append the custom items (if any)
// Append/prepend the custom items (if any) depending on their position:
// If position is right, always prepend so Settings and Fullscreen are the last items;
// otherwise, append new controls
const customItems = this.player.getCustomControls();
customItems.forEach(item => {
this.items[item.position].push(item);
if (item.position === 'right') {
this.items[item.position].unshift(item);
} else {
this.items[item.position].push(item);
}
});

// Make sure fullscreen is always the last one
Expand Down Expand Up @@ -387,7 +393,7 @@ class Controls implements PlayerComponent {
private _createCustomControl(item: ControlItem): void {
const control = document.createElement('button');
const key = item.title.toLowerCase().replace(' ', '-');
control.className = `op-controls__${key}`;
control.className = `op-controls__${key} op-control__${item.position}`;
control.tabIndex = 0;
control.title = item.title;
control.innerHTML = `<img src="${item.icon}"> <span class="op-sr">${item.title}</span>`;
Expand Down

0 comments on commit c3066ab

Please sign in to comment.