summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/mx
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/mx')
-rw-r--r--public/assets/javascripts/mx/primitives/mx.video.js12
-rw-r--r--public/assets/javascripts/mx/primitives/mx.vimeo.js43
-rw-r--r--public/assets/javascripts/mx/primitives/mx.youtube.js21
3 files changed, 60 insertions, 16 deletions
diff --git a/public/assets/javascripts/mx/primitives/mx.video.js b/public/assets/javascripts/mx/primitives/mx.video.js
index b1b9f6b..f92fe9f 100644
--- a/public/assets/javascripts/mx/primitives/mx.video.js
+++ b/public/assets/javascripts/mx/primitives/mx.video.js
@@ -28,8 +28,8 @@ MX.Video = MX.Object3D.extend({
this.paused = true
this.player = document.createElement('video')
- this.player.addEventListener("loadedmetadata", $.proxy(this.ready, this))
- this.player.addEventListener("error", $.proxy(this.error, this))
+ this.player.addEventListener("loadedmetadata", this.ready.bind(this))
+ this.player.addEventListener("error", this.error.bind(this))
this.player.width = this.width
this.player.height = this.height
this.player.src = this.media.url
@@ -62,7 +62,10 @@ MX.Video = MX.Object3D.extend({
},
seek: function(n){
- this.player.currentTime = n
+ if (n < 1) {
+ n = n * this.duration()
+ }
+ this.player.currentTime = n
},
duration: function(){
@@ -71,6 +74,9 @@ MX.Video = MX.Object3D.extend({
finished: function(){
console.log("video finished")
+ if (this.media.bound) {
+ $(".playButton").removeClass('playing')
+ }
},
diff --git a/public/assets/javascripts/mx/primitives/mx.vimeo.js b/public/assets/javascripts/mx/primitives/mx.vimeo.js
index e558bc3..5a373ff 100644
--- a/public/assets/javascripts/mx/primitives/mx.vimeo.js
+++ b/public/assets/javascripts/mx/primitives/mx.vimeo.js
@@ -26,30 +26,34 @@ MX.Vimeo = MX.Object3D.extend({
load: function (ops) {
var uid = 'player-' + Uid ()
- var preload = document.createElement("div")
+ var preload = document.createElement("iframe")
preload.id = uid
+ preload.setAttribute("src", "//player.vimeo.com/video/" + this.media.token + "?api=1&badge=0&controls=0branding=0&byline=0&player_id=" + uid)
preload.style.backgroundImage = "url(" + this.media.thumbnail + ")"
preload.style.width = this.media.width + "px"
preload.style.height = this.media.height + "px"
+ preload.style.border = "0"
preload.style.pointerEvents = "none"
preload.className = "preload"
this.el.appendChild(preload)
-
this.player = $f(preload)
- this.player.addEvent('ready', $.proxy(this.ready, this))
+
+ this.player.addEvent('ready', this.ready.bind(this))
},
ready: function(){
console.log("vimeo ready")
// wait until ready before binding events. other events: play, pause
- this.player.addEvent('finish', $.proxy(this.finished, this))
+ this.player.addEvent('play', this.onPlay.bind(this))
+ this.player.addEvent('pause', this.onPause.bind(this))
+ this.player.addEvent('finish', this.finished.bind(this))
// so annoying that this is async!!
- this.player.api('getDuration', $.proxy(function(n){
+ this.player.api('getDuration', function(n){
console.log("vimeo duration", n)
this.player.duration = n
- }, this))
+ }.bind(this))
},
@@ -68,14 +72,39 @@ MX.Vimeo = MX.Object3D.extend({
},
seek: function(n){
- this.player.api('seekTo', n)
+ if (n < 1) {
+ n = n * this.duration()
+ }
+ this.player.api('seekTo', max(0, n-1))
+ if (this.paused) {
+ this.paused = false
+ this.play()
+ setTimeout(function(){
+ this.pause()
+ }.bind(this), 1000)
+ }
},
duration: function(){
return this.player.duration
},
+ onPlay: function(){
+ if (this.paused) {
+ this.pause()
+ }
+ },
+
+ onPause: function(){
+ if (! this.paused) {
+ this.play()
+ }
+ },
+
finished: function(){
+ if (this.media.bound) {
+ $(".playButton").removeClass('playing')
+ }
}
})
diff --git a/public/assets/javascripts/mx/primitives/mx.youtube.js b/public/assets/javascripts/mx/primitives/mx.youtube.js
index cc0ec0a..a31a24d 100644
--- a/public/assets/javascripts/mx/primitives/mx.youtube.js
+++ b/public/assets/javascripts/mx/primitives/mx.youtube.js
@@ -56,9 +56,9 @@ MX.Youtube = MX.Object3D.extend({
width: this.width,
height: this.height,
events: {
- onReady: $.proxy(this.ready, this),
- onError: $.proxy(this.error, this),
- onStateChange: $.proxy(this.statechange, this),
+ onReady: this.ready.bind(this),
+ onError: this.error.bind(this),
+ onStateChange: this.statechange.bind(this),
},
playerVars: {
autohide: 1,
@@ -93,10 +93,11 @@ MX.Youtube = MX.Object3D.extend({
this.finished()
break
case 1: // play
- this.paused = false
+ if (this.paused) {
+ this.pause()
+ }
break
case 2: // pause
- this.paused = true
break
case 3: // buffering
break
@@ -106,15 +107,20 @@ MX.Youtube = MX.Object3D.extend({
},
play: function(){
+ this.paused = false
this.player.playVideo()
},
pause: function(){
+ this.paused = true
this.player.pauseVideo()
},
seek: function(n, allowSeekAhead){
- allowSeekAhead = typeof allowSeekAhead == "boolean" ? allowSeekAhead : true
+ if (n < 1) {
+ n = n * this.duration()
+ }
+ allowSeekAhead = typeof allowSeekAhead == "boolean" ? allowSeekAhead : true
this.player.seekTo(n, true) // set to false if seeking manually
},
@@ -124,6 +130,9 @@ MX.Youtube = MX.Object3D.extend({
finished: function(){
console.log("youtube finished")
+ if (this.media.bound) {
+ $(".playButton").removeClass('playing')
+ }
}
})