Skip to content

Commit

Permalink
Merge pull request #55 from mirai-audio/remove-jquery
Browse files Browse the repository at this point in the history
remove implicit dependencies on jQuery
  • Loading branch information
oskarrough authored May 6, 2019
2 parents 0ef7328 + ae03080 commit cc4878f
Show file tree
Hide file tree
Showing 3 changed files with 1,302 additions and 1,193 deletions.
44 changes: 31 additions & 13 deletions addon/components/ember-youtube.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global YT, window */

import $ from 'jquery';
import Component from '@ember/component';
import RSVP from 'rsvp'
import { computed, getProperties, setProperties, observer } from '@ember/object';
Expand Down Expand Up @@ -65,7 +64,7 @@ export default Component.extend({
didInsertElement() {
this._super(...arguments);

this.progressBarClick();
this.addProgressBarClickHandler();

if (!this.get('lazyload') && this.get('ytid')) {
// If "lazyload" is not enabled and we have an ID, we can start immediately.
Expand All @@ -80,6 +79,9 @@ export default Component.extend({
// clear the timer
this.stopTimer();

// remove progress bar click handler
this.removeProgressBarClickHandler();

// destroy video player
const player = this.get('player');
if (player) {
Expand Down Expand Up @@ -137,7 +139,9 @@ export default Component.extend({
// If already loaded, make sure not to load the script again.
resolve(window.YT);
} else {
$.getScript('https://www.youtube.com/iframe_api');
let ytScript = document.createElement("script");
ytScript.src = "https://www.youtube.com/iframe_api";
document.head.appendChild(ytScript);
}
});
},
Expand Down Expand Up @@ -325,17 +329,31 @@ export default Component.extend({

// OK, this is stupid but couldn't access the "event" inside
// an ember action so here's a manual click handler instead.
progressBarClick() {
addProgressBarClickHandler() {
this.element.addEventListener(
"click",
this.progressBarClick.bind(this),
false
);
},
progressBarClick(event) {
let self = this;
this.$().on('click', 'progress', function (event) {
// get the x position of the click inside our progress el
let x = event.pageX - $(this).position().left;
// convert it to a value relative to the duration (max)
let clickedValue = x * this.max / this.offsetWidth;
// 250 = 0.25 seconds into player
self.set("currentTime", clickedValue);
self.send('seekTo', clickedValue);
});
let element = event.srcElement;
if (element.tagName.toLowerCase() !== "progress") return;
// get the x position of the click inside our progress el
let x = event.pageX - element.getBoundingClientRect().x;
// convert it to a value relative to the duration (max)
let clickedValue = (x * element.max) / element.offsetWidth;
// 250 = 0.25 seconds into player
self.set("currentTime", clickedValue);
self.send("seekTo", clickedValue);
},
removeProgressBarClickHandler() {
this.element.removeEventListener(
"click",
this.progressBarClick.bind(this),
false
);
},

actions: {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^3.0.0",
"ember-cli": "~3.0.0",
"ember-cli-dependency-checker": "^2.0.0",
"ember-cli-eslint": "^4.2.1",
Expand Down
Loading

0 comments on commit cc4878f

Please sign in to comment.