summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/mx/primitives/mx.vimeo.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/mx/primitives/mx.vimeo.js')
-rw-r--r--public/assets/javascripts/mx/primitives/mx.vimeo.js43
1 files changed, 36 insertions, 7 deletions
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')
+ }
}
})