src/widgets/Mediafragment.js
branchnew-model
changeset 880 4c7b33bf2795
child 881 f11b234497f7
equal deleted inserted replaced
876:03967b6ada7c 880:4c7b33bf2795
       
     1 IriSP.Widgets.Mediafragment = function(player, config) {
       
     2     IriSP.Widgets.Widget.call(this, player, config);
       
     3     this.last_hash = "";
       
     4     window.onhashchange = this.functionWrapper("goToHash");
       
     5     this.player.bindPopcorn("pause","setHashToTime");
       
     6 }
       
     7 
       
     8 IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget();
       
     9 
       
    10 IriSP.Widgets.Mediafragment.prototype.draw = function() {
       
    11     this.goToHash();
       
    12 }
       
    13 
       
    14 IriSP.Widgets.Mediafragment.prototype.goToHash = function() {
       
    15     if (document.location.hash !== this.last_hash) {
       
    16         this.last_hash = document.location.hash;
       
    17         var _tab = this.last_hash.split("=");
       
    18         if (_tab[0] === '#id') {
       
    19             var _annotation = this.source.getElement(_tab[1]);
       
    20             if (typeof _annotation !== "undefined") {
       
    21                 this.player.popcorn.currentTime(_annotation.begin.getSeconds());
       
    22             }
       
    23         }
       
    24         if (_tab[0] === '#t') {
       
    25             this.player.popcorn.currentTime(_tab[1]);
       
    26         }
       
    27     }
       
    28 }
       
    29 
       
    30 IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) {
       
    31     this.last_hash = '#id=' + this.source.unNamespace(_annotationId);
       
    32     
       
    33 }
       
    34 
       
    35 IriSP.Widgets.Mediafragment.prototype.setHashToTime = function() {
       
    36     this.last_hash = '#t=' + this.source.popcorn.currentTime();
       
    37 }
       
    38 
       
    39 IriSP.Widgets.Mediafragment.prototype.setHash = function(_hash) {
       
    40     if (this.last_hash !== _hash) {
       
    41         this.last_hash = _hash;
       
    42         document.location.hash = _hash;
       
    43     }
       
    44 }