src/js/modules/embed.js
branchnew-model
changeset 882 61c384dda19e
parent 881 f11b234497f7
child 883 d35ad8111c5e
equal deleted inserted replaced
881:f11b234497f7 882:61c384dda19e
     1 /* embed module - listens and relay hash changes to a parent window. */
       
     2 
       
     3 IriSP.EmbedModule = function(Popcorn, config, Serializer) {
       
     4   IriSP.Module.call(this, Popcorn, config, Serializer);
       
     5 
       
     6   window.addEventListener('message', IriSP.wrap(this, this.handleMessages), false);
       
     7   this._Popcorn.listen("IriSP.Mediafragment.hashchange", IriSP.wrap(this, this.relayChanges));
       
     8 };
       
     9 
       
    10 IriSP.EmbedModule.prototype = new IriSP.Module();
       
    11 
       
    12 IriSP.EmbedModule.prototype.handleMessages = function(e) {
       
    13   if (e.data.type === "hashchange") {
       
    14     window.location.hash = e.data.value;    
       
    15   }  
       
    16 };
       
    17 
       
    18 IriSP.EmbedModule.prototype.relayChanges = function(newHash) {
       
    19   window.parent.postMessage({type: "hashchange", value: newHash}, "*"); 
       
    20   return;
       
    21 };