Skip to content

Commit

Permalink
fix(controls): Added missing workflow for mobile devices to avoid hid…
Browse files Browse the repository at this point in the history
…ing controls
  • Loading branch information
rafa8626 committed May 9, 2018
1 parent d239ecd commit 8689291
Showing 1 changed file with 49 additions and 44 deletions.
93 changes: 49 additions & 44 deletions src/js/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Volume from './controls/volume';
import PlayerComponent from './interfaces/component';
import EventsList from './interfaces/events-list';
import Player from './player';
import { IS_ANDROID, IS_IOS } from './utils/constants';
import { addEvent } from './utils/events';
import { isVideo } from './utils/general';

Expand Down Expand Up @@ -159,44 +160,46 @@ class Controls implements PlayerComponent {
this.controls.className = 'om-controls';
this.player.getContainer().appendChild(this.controls);

this.events.mouse.mouseenter = () => {
if (isMediaVideo) {
this._stopControlTimer();
this.player.getContainer().classList.remove('om-controls--hidden');
this._startControlTimer(2500);
}
};
this.events.mouse.mousemove = () => {
if (isMediaVideo) {
if (!IS_ANDROID && !IS_IOS) {
this.events.mouse.mouseenter = () => {
if (isMediaVideo) {
this._stopControlTimer();
this.player.getContainer().classList.remove('om-controls--hidden');
this._startControlTimer(2500);
}
};
this.events.mouse.mousemove = () => {
if (isMediaVideo) {
this.player.getContainer().classList.remove('om-controls--hidden');
this._startControlTimer(2500);
}
};
this.events.mouse.mouseleave = () => {
if (isMediaVideo) {
this._startControlTimer(1000);
}
};
this.events.media.pause = () => {
this.player.getContainer().classList.remove('om-controls--hidden');
this._startControlTimer(2500);
}
};
this.events.mouse.mouseleave = () => {
if (isMediaVideo) {
this._startControlTimer(1000);
}
};
this.events.media.pause = () => {
this.player.getContainer().classList.remove('om-controls--hidden');
this._stopControlTimer();
};
this.events.media.controlschanged = () => {
this.destroy();
this._setElements();
this.create();
};

Object.keys(this.events.media).forEach(event => {
this.player.getElement().addEventListener(event, this.events.media[event]);
});

Object.keys(this.events.mouse).forEach(event => {
this.player.getContainer().addEventListener(event, this.events.mouse[event]);
});

// Initial countdown to hide controls
this._startControlTimer(3000);
this._stopControlTimer();
};
this.events.media.controlschanged = () => {
this.destroy();
this._setElements();
this.create();
};

Object.keys(this.events.media).forEach(event => {
this.player.getElement().addEventListener(event, this.events.media[event]);
});

Object.keys(this.events.mouse).forEach(event => {
this.player.getContainer().addEventListener(event, this.events.mouse[event]);
});

// Initial countdown to hide controls
this._startControlTimer(3000);
}

this._buildElements();
}
Expand All @@ -207,15 +210,17 @@ class Controls implements PlayerComponent {
* @memberof Controls
*/
public destroy(): void {
Object.keys(this.events.mouse).forEach(event => {
this.player.getContainer().removeEventListener(event, this.events.mouse[event]);
});
if (!IS_ANDROID && !IS_IOS) {
Object.keys(this.events.mouse).forEach(event => {
this.player.getContainer().removeEventListener(event, this.events.mouse[event]);
});

Object.keys(this.events.media).forEach(event => {
this.player.getElement().removeEventListener(event, this.events.media[event]);
});
Object.keys(this.events.media).forEach(event => {
this.player.getElement().removeEventListener(event, this.events.media[event]);
});

this._stopControlTimer();
this._stopControlTimer();
}

this.items.forEach(item => {
item.destroy();
Expand Down

0 comments on commit 8689291

Please sign in to comment.