implemented hashchange event handler. popcorn-port
authorhamidouk
Thu, 05 Jan 2012 14:58:56 +0100
branchpopcorn-port
changeset 587 cd051898866e
parent 586 a3705fc7e054
child 588 78cf49152d4a
implemented hashchange event handler.
src/js/modules/mediafragment.js
--- a/src/js/modules/mediafragment.js	Thu Jan 05 14:57:37 2012 +0100
+++ b/src/js/modules/mediafragment.js	Thu Jan 05 14:58:56 2012 +0100
@@ -5,14 +5,18 @@
 
   this.mutex = false; /* a mutex because we access the url from two different functions */
 
-  this._Popcorn.listen( "loadedmetadata", IriSP.wrap(this, IriSP.MediaFragment.advanceTime));
-  this._Popcorn.listen( "pause", IriSP.wrap(this, IriSP.MediaFragment.updateTime));
-  this._Popcorn.listen( "seeked", IriSP.wrap(this, IriSP.MediaFragment.updateTime));
-  this._Popcorn.listen( "IriSP.PolemicTweet.click", IriSP.wrap(this, IriSP.MediaFragment.updateAnnotation));
-  this._Popcorn.listen( "IriSP.SegmentsWidget.click", IriSP.wrap(this, IriSP.MediaFragment.updateAnnotation));
+  this._Popcorn.listen( "loadedmetadata", IriSP.wrap(this,this.advanceTime));
+  this._Popcorn.listen( "pause", IriSP.wrap(this,this.updateTime));
+  this._Popcorn.listen( "seeked", IriSP.wrap(this,this.updateTime));
+  this._Popcorn.listen( "IriSP.PolemicTweet.click", IriSP.wrap(this,this.updateAnnotation));
+  this._Popcorn.listen( "IriSP.SegmentsWidget.click", IriSP.wrap(this,this.updateAnnotation));
+  
+  window.onhashchange = IriSP.wrap(this, this.advanceTime);
 };
 
-IriSP.MediaFragment.advanceTime = function() {
+IriSP.MediaFragment.prototype = new IriSP.Module();
+
+IriSP.MediaFragment.prototype.advanceTime = function() {
              var url = window.location.href;
 
               if ( url.split( "#" )[ 1 ] != null ) {
@@ -31,13 +35,13 @@
                     // there's no better way than that because
                     // of possible race conditions
                     this._serializer.sync(IriSP.wrap(this, function() {
-                          IriSP.MediaFragment.lookupAnnotation.call(this, annotationId); 
+                          this.lookupAnnotation.call(this, annotationId); 
                           }));
                   }
               }
 };
 
-IriSP.MediaFragment.updateTime = function() {
+IriSP.MediaFragment.prototype.updateTime = function() {
   if (this.mutex === true) {
     return;
   }
@@ -52,7 +56,7 @@
 };
 
 
-IriSP.MediaFragment.updateAnnotation = function(annotationId) {
+IriSP.MediaFragment.prototype.updateAnnotation = function(annotationId) {
   var _this = this;
   this.mutex = true;
 
@@ -68,7 +72,10 @@
 };
 
 // lookup and seek to the beginning of an annotation
-IriSP.MediaFragment.lookupAnnotation = function(annotationId) {
+IriSP.MediaFragment.prototype.lookupAnnotation = function(annotationId) {
+  var _this = this;
+  this.mutex = true;
+
   var annotation = undefined;
   var annotations = this._serializer._data.annotations;
 
@@ -83,4 +90,6 @@
   if (typeof(annotation) !== "undefined") {
     this._Popcorn.currentTime(annotation.begin / 1000);
   }
+  
+  window.setTimeout(function() { _this.mutex = false }, 50);
 };