1 IriSP.Widgets.Mediafragment = function(player, config) { |
1 IriSP.Widgets.Mediafragment = function(player, config) { |
2 IriSP.Widgets.Widget.call(this, player, config); |
2 IriSP.Widgets.Widget.call(this, player, config); |
3 this.last_hash_key = ""; |
3 this.last_hash_key = ""; |
4 this.last_hash_value = ""; |
4 this.last_hash_value = ""; |
|
5 this.last_extra_key = ""; |
|
6 this.last_extra_value = ""; |
|
7 |
5 window.onhashchange = this.functionWrapper("goToHash"); |
8 window.onhashchange = this.functionWrapper("goToHash"); |
6 if (typeof window.addEventListener !== "undefined") { |
9 if (typeof window.addEventListener !== "undefined") { |
7 var _this = this; |
10 var _this = this; |
8 window.addEventListener('message', function(_msg) { |
11 window.addEventListener('message', function(_msg) { |
9 if (/^#/.test(_msg.data)) { |
12 if (/^#/.test(_msg.data)) { |
20 IriSP.Widgets.Mediafragment.prototype.draw = function() { |
23 IriSP.Widgets.Mediafragment.prototype.draw = function() { |
21 this.onMediaEvent("setpause","setHashToTime"); |
24 this.onMediaEvent("setpause","setHashToTime"); |
22 var _this = this; |
25 var _this = this; |
23 this.getWidgetAnnotations().forEach(function(_annotation) { |
26 this.getWidgetAnnotations().forEach(function(_annotation) { |
24 _annotation.on("click", function() { |
27 _annotation.on("click", function() { |
25 _this.setHashToAnnotation(_annotation.id); |
28 _this.setHashToAnnotation(_annotation); |
26 }); |
29 }); |
27 }); |
30 }); |
28 if (this.media.loadedMetadata) { |
31 if (this.media.loadedMetadata) { |
29 this.goToHash(); |
32 this.goToHash(); |
30 } else { |
33 } else { |
46 return _el && !/^(id|t)=/.test(_el); |
49 return _el && !/^(id|t)=/.test(_el); |
47 }); |
50 }); |
48 if (this.last_hash_key) { |
51 if (this.last_hash_key) { |
49 _tab.push(this.last_hash_key + '=' + this.last_hash_value); |
52 _tab.push(this.last_hash_key + '=' + this.last_hash_value); |
50 } |
53 } |
|
54 if (this.last_extra_key) { |
|
55 _tab.push(this.last_extra_key + '=' + this.last_extra_value); |
|
56 } |
51 return '#' + _tab.join('&'); |
57 return '#' + _tab.join('&'); |
52 }; |
58 }; |
53 |
59 |
54 IriSP.Widgets.Mediafragment.prototype.goToHash = function() { |
60 IriSP.Widgets.Mediafragment.prototype.goToHash = function() { |
55 if (document.location.hash !== this.getLastHash()) { |
61 if (document.location.hash !== this.getLastHash()) { |
61 this.last_hash_value = _subtab[1]; |
67 this.last_hash_value = _subtab[1]; |
62 if (this.last_hash_key == "id") { |
68 if (this.last_hash_key == "id") { |
63 var _annotation = this.source.getElement(this.last_hash_value); |
69 var _annotation = this.source.getElement(this.last_hash_value); |
64 if (typeof _annotation !== "undefined") { |
70 if (typeof _annotation !== "undefined") { |
65 this.media.setCurrentTime(_annotation.begin); |
71 this.media.setCurrentTime(_annotation.begin); |
|
72 } else { |
|
73 /* Proceed parsing elements, maybe a t was specified */ |
|
74 continue; |
66 } |
75 } |
67 } |
76 } |
68 if (this.last_hash_key == "t") { |
77 if (this.last_hash_key == "t") { |
69 this.media.setCurrentTime(1000*this.last_hash_value); |
78 this.media.setCurrentTime(1000 * this.last_hash_value); |
70 } |
79 } |
71 break; |
80 break; |
72 } |
81 } |
73 } |
82 } |
74 } |
83 } |
75 }; |
84 }; |
76 |
85 |
77 IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) { |
86 IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotation) { |
78 this.setHash( 'id', _annotationId ); |
87 this.setHash( 'id', _annotation.id, 't', _annotation.begin / 1000.0 ); |
79 }; |
88 }; |
80 |
89 |
81 IriSP.Widgets.Mediafragment.prototype.setHashToTime = function() { |
90 IriSP.Widgets.Mediafragment.prototype.setHashToTime = function() { |
82 this.setHash( 't', this.media.getCurrentTime().getSeconds() ); |
91 this.setHash( 't', this.media.getCurrentTime().getSeconds() ); |
83 }; |
92 }; |
84 |
93 |
85 IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) { |
94 IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value, _key2, _value2) { |
86 if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) { |
95 if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) { |
87 this.last_hash_key = _key; |
96 this.last_hash_key = _key; |
88 this.last_hash_value = _value; |
97 this.last_hash_value = _value; |
|
98 this.last_extra_key = _key2; |
|
99 this.last_extra_value = _value2; |
|
100 |
89 var _hash = this.getLastHash(); |
101 var _hash = this.getLastHash(); |
90 this.setWindowHash(_hash); |
102 this.setWindowHash(_hash); |
91 if (window.parent !== window) { |
103 if (window.parent !== window) { |
92 window.parent.postMessage(_hash,"*"); |
104 window.parent.postMessage(_hash,"*"); |
93 } |
105 } |