src/js/iframe_embed/embedder.js
author veltr
Wed, 30 May 2012 17:07:01 +0200
branchnew-model
changeset 908 f56199193fad
parent 906 4b6e154ae8de
child 910 b9f1bd52df9a
permissions -rw-r--r--
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent

/* This piece of code is directly requested by the page the player is embedded
   on. It creates the iframe the player is embedded in and it reflects changes
   to the iframe url in the page url.   
*/

if (typeof IriSP === "undefined") {
    IriSP = {};
}

IriSP.iFrameUpdater = function(_frameId) {
    
    var _frame = document.getElementById(_frameId),
        _blocked = false,
        _updater = function() {
            _blocked = true;
            window.setTimeout(function() {
                _blocked = false;
            }, 1000);
            _frame.contentWindow.postMessage(document.location.hash, "*");
        };
    
    window.onhashchange = _updater;
    
    window.addEventListener('message', function(_e) {
        if (/^#/.test(_e.data) && !_blocked) {
            document.location.hash = _e.data;
        }
    });
    
    window.setTimeout(_updater, 2000);
    
};