src/widgets/Mediafragment.js
branchnew-model
changeset 881 f11b234497f7
parent 880 4c7b33bf2795
child 882 61c384dda19e
equal deleted inserted replaced
880:4c7b33bf2795 881:f11b234497f7
     1 IriSP.Widgets.Mediafragment = function(player, config) {
     1 IriSP.Widgets.Mediafragment = function(player, config) {
     2     IriSP.Widgets.Widget.call(this, player, config);
     2     IriSP.Widgets.Widget.call(this, player, config);
     3     this.last_hash = "";
     3     this.last_hash = "";
     4     window.onhashchange = this.functionWrapper("goToHash");
     4     window.onhashchange = this.functionWrapper("goToHash");
     5     this.player.bindPopcorn("pause","setHashToTime");
     5     this.bindPopcorn("pause","setHashToTime");
       
     6     this.bindPopcorn("seeked","setHashToTime");
       
     7     this.bindPopcorn("IriSP.Mediafragment.setHashToAnnotation","setHashToAnnotation");
       
     8     this.blocked = false;
     6 }
     9 }
     7 
    10 
     8 IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget();
    11 IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget();
     9 
    12 
    10 IriSP.Widgets.Mediafragment.prototype.draw = function() {
    13 IriSP.Widgets.Mediafragment.prototype.draw = function() {
    26         }
    29         }
    27     }
    30     }
    28 }
    31 }
    29 
    32 
    30 IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) {
    33 IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) {
    31     this.last_hash = '#id=' + this.source.unNamespace(_annotationId);
    34     this.setHash( '#id=' + this.source.unNamespace(_annotationId) );
    32     
       
    33 }
    35 }
    34 
    36 
    35 IriSP.Widgets.Mediafragment.prototype.setHashToTime = function() {
    37 IriSP.Widgets.Mediafragment.prototype.setHashToTime = function(_time) {
    36     this.last_hash = '#t=' + this.source.popcorn.currentTime();
    38     _time = (typeof _time !== "undefined" ? _time : this.player.popcorn.currentTime() );
       
    39     this.setHash( '#t=' + _time );
    37 }
    40 }
    38 
    41 
    39 IriSP.Widgets.Mediafragment.prototype.setHash = function(_hash) {
    42 IriSP.Widgets.Mediafragment.prototype.setHash = function(_hash) {
    40     if (this.last_hash !== _hash) {
    43     if (!this.blocked && this.last_hash !== _hash) {
    41         this.last_hash = _hash;
    44         this.last_hash = _hash;
    42         document.location.hash = _hash;
    45         document.location.hash = _hash;
       
    46         this.block();
    43     }
    47     }
    44 }
    48 }
       
    49 
       
    50 IriSP.Widgets.Mediafragment.prototype.unblock = function() {
       
    51     if (typeof this.blockTimeout !== "undefined") {
       
    52         window.clearTimeout(this.blockTimeout);
       
    53     }
       
    54     this.blockTimeout = undefined;
       
    55     this.blocked = false;
       
    56 }
       
    57 
       
    58 IriSP.Widgets.Mediafragment.prototype.block = function() {
       
    59     if (typeof this.blockTimeout !== "undefined") {
       
    60         window.clearTimeout(this.blockTimeout);
       
    61     }
       
    62     this.blocked = true;
       
    63     this.blockTimeout = window.setTimeout(this.functionWrapper("unblock"), 1000);
       
    64 }