--- a/src/widgets/Mediafragment.js Fri May 18 18:23:51 2012 +0200
+++ b/src/widgets/Mediafragment.js Mon May 21 13:17:47 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,35 +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) {
if (_time !== NaN) {
- this.setHash( '#t=' + this.player.popcorn.currentTime() );
+ 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/src/widgets/Segments.js Fri May 18 18:23:51 2012 +0200
+++ b/src/widgets/Segments.js Mon May 21 13:17:47 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…') : ''),
+ text : _fulltext.replace(/(^.{120,140})[\s].+$/,'$1…'),
color : ( typeof _annotation.color !== "undefined" && _annotation.color ? _annotation.color : _this.colors[_k % _this.colors.length] ),
beginseconds : _annotation.begin.getSeconds() ,
left : Math.floor( _left ),