corrected metadataplayer for mediafragment bug V01.81
authorRaphael Velt <raph.velt@gmail.com>
Mon, 21 May 2012 12:15:21 +0200
changeset 618 f65c1c3f77ea
parent 617 3d071f445560
child 619 170f46b3b318
corrected metadataplayer for mediafragment bug
web/jenkins/config.php
web/res/metadataplayer/Mediafragment.js
web/res/metadataplayer/Segments.js
--- a/web/jenkins/config.php	Wed May 16 12:40:35 2012 +0200
+++ b/web/jenkins/config.php	Mon May 21 12:15:21 2012 +0200
@@ -6,7 +6,7 @@
    	'place'   => 'Centre Pompidou, Grande Salle',
 
    	'title' => "Henry Jenkins, Transmedia 2.0",
-	'abstract'   => "Parole à la crtique<br />Vendredi 25 mai 2012, 19H<br/>Grande Salle, Centre Pompidou, Paris",
+	'abstract'   => "Parole à la critique<br />Vendredi 25 mai 2012, 19H<br/>Grande Salle, Centre Pompidou, Paris",
    	'description'=> "
 <p>
 Pionnier des études sur les fans, théoricien célébré de la culture de la convergence, Henry Jenkins a repensé l’écosystème médiatique
--- a/web/res/metadataplayer/Mediafragment.js	Wed May 16 12:40:35 2012 +0200
+++ b/web/res/metadataplayer/Mediafragment.js	Mon May 21 12:15:21 2012 +0200
@@ -1,6 +1,7 @@
 IriSP.Widgets.Mediafragment = function(player, config) {
     IriSP.Widgets.Widget.call(this, player, config);
-    this.last_hash = "";
+    this.last_hash_key = "";
+    this.last_hash_value = "";
     window.onhashchange = this.functionWrapper("goToHash");
     if (typeof window.addEventListener !== "undefined") {
         window.addEventListener('message', function(_msg) {
@@ -21,34 +22,55 @@
     this.goToHash();
 }
 
+IriSP.Widgets.Mediafragment.prototype.getLastHash = function() {
+    var _tab = document.location.hash.replace(/^#/,'').split('&');
+    _tab = IriSP._(_tab).filter(function(_el) {
+        return _el && !/^(id|t)=/.test(_el);
+    });
+    if (this.last_hash_key) {
+        _tab.push(this.last_hash_key + '=' + this.last_hash_value);
+    }
+    return '#' + _tab.join('&');
+}
+
 IriSP.Widgets.Mediafragment.prototype.goToHash = function() {
-    if (document.location.hash !== this.last_hash) {
-        this.last_hash = document.location.hash;
-        var _tab = this.last_hash.split("=");
-        if (_tab[0] === '#id') {
-            var _annotation = this.source.getElement(_tab[1]);
-            if (typeof _annotation !== "undefined") {
-                this.player.popcorn.currentTime(_annotation.begin.getSeconds());
+    if (document.location.hash !== this.getLastHash()) {
+        var _tab = document.location.hash.replace(/^#/,'').split('&');
+        for (var _i = 0; _i < _tab.length; _i++) {
+            var _subtab = _tab[_i].split("=");
+            if (_subtab[0] == "id" || _subtab[0] == "t") {
+                this.last_hash_key = _subtab[0];
+                this.last_hash_value = _subtab[1];
+                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());
+                    }
+                }
+                if (this.last_hash_key == "t") {
+                    this.player.popcorn.currentTime(this.last_hash_value);
+                }
+                break;
             }
         }
-        if (_tab[0] === '#t') {
-            this.player.popcorn.currentTime(_tab[1]);
-        }
     }
 }
 
 IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) {
-    this.setHash( '#id=' + this.source.unNamespace(_annotationId) );
+    this.setHash( 'id', this.source.unNamespace(_annotationId) );
 }
 
 IriSP.Widgets.Mediafragment.prototype.setHashToTime = function(_time) {
-    _time = (typeof _time !== "undefined" ? _time : this.player.popcorn.currentTime() );
-    this.setHash( '#t=' + _time );
+    if (_time !== NaN) {
+        this.setHash( 't', this.player.popcorn.currentTime() );
+    }
 }
 
-IriSP.Widgets.Mediafragment.prototype.setHash = function(_hash) {
-    if (!this.blocked && this.last_hash !== _hash) {
-        this.last_hash = _hash;
+IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) {
+    if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) {
+        this.last_hash_key = _key;
+        this.last_hash_value = _value;
+        var _hash = this.getLastHash();
         document.location.hash = _hash;
         if (window.parent !== window) {
             window.parent.postMessage({
--- a/web/res/metadataplayer/Segments.js	Wed May 16 12:40:35 2012 +0200
+++ b/web/res/metadataplayer/Segments.js	Mon May 21 12:15:21 2012 +0200
@@ -42,9 +42,10 @@
         segments : _list.map(function(_annotation, _k) {
             var _left = _annotation.begin * _scale,
                 _width = ( _annotation.end - _annotation.begin ) * _scale,
-                _center = _left + _width / 2;
+                _center = _left + _width / 2,
+                _fulltext = _annotation.title + ( _annotation.description ? ( '<br/>' + _annotation.description ) : '' );
             return {
-                text : _annotation.title + ( _annotation.description ? '<br />' + _annotation.description.replace(/(^.{120,140})[\s].+$/,'$1&hellip;') : ''),
+                text : _fulltext.replace(/(^.{120,140})[\s].+$/,'$1&hellip;'),
                 color : ( typeof _annotation.color !== "undefined" && _annotation.color ? _annotation.color : _this.colors[_k % _this.colors.length] ),
                 beginseconds : _annotation.begin.getSeconds() ,
                 left : Math.floor( _left ),