src/widgets/Mediafragment.js
branchnew-model
changeset 910 b9f1bd52df9a
parent 906 4b6e154ae8de
child 916 ec6849bbbdcc
equal deleted inserted replaced
909:aa0e42229784 910:b9f1bd52df9a
     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         window.addEventListener('message', function(_msg) {
     7         window.addEventListener('message', function(_msg) {
     8             if (/^#/.test(_msg.data)) {
     8             if (/^#/.test(_msg.data)) {
     9                 document.location.hash = _msg.data;
     9                 this.setWindowHash(_msg.data);
    10             }
    10             }
    11         })
    11         })
    12     };
    12     };
    13     this.bindPopcorn("pause","setHashToTime");
    13     this.bindPopcorn("pause","setHashToTime");
    14     this.bindPopcorn("seeked","setHashToTime");
    14     this.bindPopcorn("seeked","setHashToTime");
    18 
    18 
    19 IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget();
    19 IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget();
    20 
    20 
    21 IriSP.Widgets.Mediafragment.prototype.draw = function() {
    21 IriSP.Widgets.Mediafragment.prototype.draw = function() {
    22     this.goToHash();
    22     this.goToHash();
       
    23 }
       
    24 
       
    25 IriSP.Widgets.Mediafragment.prototype.setWindowHash = function(_hash) {
       
    26     if (typeof window.history !== "undefined" && typeof window.history.replaceState !== "undefined") {
       
    27         window.history.replaceState({}, "", _hash);
       
    28     } else {
       
    29         document.location.hash = _hash;
       
    30     }
    23 }
    31 }
    24 
    32 
    25 IriSP.Widgets.Mediafragment.prototype.getLastHash = function() {
    33 IriSP.Widgets.Mediafragment.prototype.getLastHash = function() {
    26     var _tab = document.location.hash.replace(/^#/,'').split('&');
    34     var _tab = document.location.hash.replace(/^#/,'').split('&');
    27     _tab = IriSP._(_tab).filter(function(_el) {
    35     _tab = IriSP._(_tab).filter(function(_el) {
    69 IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) {
    77 IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) {
    70     if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) {
    78     if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) {
    71         this.last_hash_key = _key;
    79         this.last_hash_key = _key;
    72         this.last_hash_value = _value;
    80         this.last_hash_value = _value;
    73         var _hash = this.getLastHash();
    81         var _hash = this.getLastHash();
    74         document.location.hash = _hash;
    82         this.setWindowHash(_hash);
    75         if (window.parent !== window) {
    83         if (window.parent !== window) {
    76             window.parent.postMessage(_hash,"*")
    84             window.parent.postMessage(_hash,"*")
    77         }
    85         }
    78         this.block();
    86         this.block();
    79     }
    87     }