diff -r 919e362b9db1 -r 3ab36f402b0c src/widgets/Mediafragment.js --- a/src/widgets/Mediafragment.js Thu Aug 30 14:45:23 2012 +0200 +++ b/src/widgets/Mediafragment.js Thu Jan 02 16:40:25 2014 +0100 @@ -4,23 +4,33 @@ this.last_hash_value = ""; window.onhashchange = this.functionWrapper("goToHash"); if (typeof window.addEventListener !== "undefined") { + var _this = this; window.addEventListener('message', function(_msg) { if (/^#/.test(_msg.data)) { - this.setWindowHash(_msg.data); + _this.setWindowHash(_msg.data); } - }) + }); }; - this.bindPopcorn("pause","setHashToTime"); - this.bindPopcorn("seeked","setHashToTime"); - this.bindPopcorn("IriSP.Mediafragment.setHashToAnnotation","setHashToAnnotation"); + this.onMdpEvent("Mediafragment.setHashToAnnotation","setHashToAnnotation"); this.blocked = false; -} +}; IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget(); IriSP.Widgets.Mediafragment.prototype.draw = function() { - this.goToHash(); -} + this.onMediaEvent("setpause","setHashToTime"); + var _this = this; + this.getWidgetAnnotations().forEach(function(_annotation) { + _annotation.on("click", function() { + _this.setHashToAnnotation(_annotation.id); + }); + }); + if (this.media.loadedMetadata) { + this.goToHash(); + } else { + this.onMediaEvent("loadedmetadata","goToHash"); + } +}; IriSP.Widgets.Mediafragment.prototype.setWindowHash = function(_hash) { if (typeof window.history !== "undefined" && typeof window.history.replaceState !== "undefined") { @@ -28,7 +38,7 @@ } else { document.location.hash = _hash; } -} +}; IriSP.Widgets.Mediafragment.prototype.getLastHash = function() { var _tab = document.location.hash.replace(/^#/,'').split('&'); @@ -39,7 +49,7 @@ _tab.push(this.last_hash_key + '=' + this.last_hash_value); } return '#' + _tab.join('&'); -} +}; IriSP.Widgets.Mediafragment.prototype.goToHash = function() { if (document.location.hash !== this.getLastHash()) { @@ -52,27 +62,25 @@ if (this.last_hash_key == "id") { var _annotation = this.source.getElement(this.last_hash_value); if (typeof _annotation !== "undefined") { - this.player.popcorn.currentTime(_annotation.begin.getSeconds()); + this.media.setCurrentTime(_annotation.begin); } } if (this.last_hash_key == "t") { - this.player.popcorn.currentTime(this.last_hash_value); + this.media.setCurrentTime(1000*this.last_hash_value); } break; } } } -} +}; IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) { this.setHash( 'id', _annotationId ); -} +}; -IriSP.Widgets.Mediafragment.prototype.setHashToTime = function(_time) { - if (_time !== NaN) { - this.setHash( 't', this.player.popcorn.currentTime() ); - } -} +IriSP.Widgets.Mediafragment.prototype.setHashToTime = function() { + this.setHash( 't', this.media.getCurrentTime().getSeconds() ); +}; IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) { if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) { @@ -81,11 +89,11 @@ var _hash = this.getLastHash(); this.setWindowHash(_hash); if (window.parent !== window) { - window.parent.postMessage(_hash,"*") + window.parent.postMessage(_hash,"*"); } this.block(); } -} +}; IriSP.Widgets.Mediafragment.prototype.unblock = function() { if (typeof this.blockTimeout !== "undefined") { @@ -93,12 +101,12 @@ } this.blockTimeout = undefined; this.blocked = false; -} +}; IriSP.Widgets.Mediafragment.prototype.block = function() { if (typeof this.blockTimeout !== "undefined") { window.clearTimeout(this.blockTimeout); } this.blocked = true; - this.blockTimeout = window.setTimeout(this.functionWrapper("unblock"), 1000); -} + this.blockTimeout = window.setTimeout(this.functionWrapper("unblock"), 1500); +};