-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove implicit dependencies on jQuery #55
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
@@ -65,7 +64,7 @@ export default Component.extend({ | |
didInsertElement() { | ||
this._super(...arguments); | ||
|
||
this.progressBarClick(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed |
||
this.addProgressBarClickHandler(); | ||
|
||
if (!this.get('lazyload') && this.get('ytid')) { | ||
// If "lazyload" is not enabled and we have an ID, we can start immediately. | ||
|
@@ -80,6 +79,9 @@ export default Component.extend({ | |
// clear the timer | ||
this.stopTimer(); | ||
|
||
// remove progress bar click handler | ||
this.removeProgressBarClickHandler(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here i remove the manual click handler event binding. |
||
|
||
// destroy video player | ||
const player = this.get('player'); | ||
if (player) { | ||
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since Under the hood, all jQuery |
||
ytScript.src = "https://www.youtube.com/iframe_api"; | ||
document.head.appendChild(ytScript); | ||
} | ||
}); | ||
}, | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without |
||
"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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the event handler wasn't removed previously, so now it is cleaned up when the component is removed from the DOM. |
||
this.element.removeEventListener( | ||
"click", | ||
this.progressBarClick.bind(this), | ||
false | ||
); | ||
}, | ||
|
||
actions: { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
byebye