src/widgets/Mediafragment.js
changeset 986 f9d51dd4a3fe
parent 964 d7d56ea2d0a6
child 987 7b65bf78873a
equal deleted inserted replaced
985:9859c4bae904 986:f9d51dd4a3fe
     2     IriSP.Widgets.Widget.call(this, player, config);
     2     IriSP.Widgets.Widget.call(this, player, config);
     3     this.last_hash_key = "";
     3     this.last_hash_key = "";
     4     this.last_hash_value = "";
     4     this.last_hash_value = "";
     5     window.onhashchange = this.functionWrapper("goToHash");
     5     window.onhashchange = this.functionWrapper("goToHash");
     6     if (typeof window.addEventListener !== "undefined") {
     6     if (typeof window.addEventListener !== "undefined") {
       
     7         var _this = this;
     7         window.addEventListener('message', function(_msg) {
     8         window.addEventListener('message', function(_msg) {
     8             if (/^#/.test(_msg.data)) {
     9             if (/^#/.test(_msg.data)) {
     9                 this.setWindowHash(_msg.data);
    10                 _this.setWindowHash(_msg.data);
    10             }
    11             }
    11         })
    12         })
    12     };
    13     };
    13     this.onMdpEvent("Mediafragment.setHashToAnnotation","setHashToAnnotation");
    14     this.onMdpEvent("Mediafragment.setHashToAnnotation","setHashToAnnotation");
    14     this.blocked = false;
    15     this.blocked = false;
    16 
    17 
    17 IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget();
    18 IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget();
    18 
    19 
    19 IriSP.Widgets.Mediafragment.prototype.draw = function() {
    20 IriSP.Widgets.Mediafragment.prototype.draw = function() {
    20     this.onMediaEvent("pause","setHashToTime");
    21     this.onMediaEvent("pause","setHashToTime");
    21     this.onMediaEvent("seeked","setHashToTime");
       
    22     this.goToHash();
       
    23     var _this = this;
    22     var _this = this;
    24     this.getWidgetAnnotations().forEach(function(_annotation) {
    23     this.getWidgetAnnotations().forEach(function(_annotation) {
    25         _annotation.on("click", function() {
    24         _annotation.on("click", function() {
    26             _this.setHashToAnnotation(_annotation.id);
    25             _this.setHashToAnnotation(_annotation.id);
    27         })
    26         })
    28     })
    27     });
       
    28     this.player.on("widgets-loaded", function() {
       
    29         _this.goToHash();
       
    30     });
    29 }
    31 }
    30 
    32 
    31 IriSP.Widgets.Mediafragment.prototype.setWindowHash = function(_hash) {
    33 IriSP.Widgets.Mediafragment.prototype.setWindowHash = function(_hash) {
    32     if (typeof window.history !== "undefined" && typeof window.history.replaceState !== "undefined") {
    34     if (typeof window.history !== "undefined" && typeof window.history.replaceState !== "undefined") {
    33         window.history.replaceState({}, "", _hash);
    35         window.history.replaceState({}, "", _hash);