| author | Raphael Velt <raph.velt@gmail.com> |
| Wed, 20 Jun 2012 18:46:56 +0200 | |
| changeset 638 | e0d4e8431de3 |
| parent 621 | 44f90de0016f |
| child 694 | e9400c80e1e4 |
| permissions | -rw-r--r-- |
| 598 | 1 |
IriSP.Widgets.Mediafragment = function(player, config) { |
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
3 |
this.last_hash_key = ""; |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
4 |
this.last_hash_value = ""; |
| 598 | 5 |
window.onhashchange = this.functionWrapper("goToHash"); |
6 |
if (typeof window.addEventListener !== "undefined") { |
|
7 |
window.addEventListener('message', function(_msg) { |
|
| 621 | 8 |
if (/^#/.test(_msg.data)) { |
| 638 | 9 |
this.setWindowHash(_msg.data); |
| 598 | 10 |
} |
11 |
}) |
|
12 |
}; |
|
13 |
this.bindPopcorn("pause","setHashToTime"); |
|
14 |
this.bindPopcorn("seeked","setHashToTime"); |
|
15 |
this.bindPopcorn("IriSP.Mediafragment.setHashToAnnotation","setHashToAnnotation"); |
|
16 |
this.blocked = false; |
|
17 |
} |
|
18 |
||
19 |
IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget(); |
|
20 |
||
21 |
IriSP.Widgets.Mediafragment.prototype.draw = function() { |
|
22 |
this.goToHash(); |
|
23 |
} |
|
24 |
||
| 638 | 25 |
IriSP.Widgets.Mediafragment.prototype.setWindowHash = function(_hash) { |
26 |
if (typeof window.history !== "undefined" && typeof window.history.replaceState !== "undefined") { |
|
27 |
window.history.replaceState({}, "", _hash); |
|
28 |
} else { |
|
29 |
document.location.hash = _hash; |
|
30 |
} |
|
31 |
} |
|
32 |
||
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
33 |
IriSP.Widgets.Mediafragment.prototype.getLastHash = function() { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
34 |
var _tab = document.location.hash.replace(/^#/,'').split('&'); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
35 |
_tab = IriSP._(_tab).filter(function(_el) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
36 |
return _el && !/^(id|t)=/.test(_el); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
37 |
}); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
38 |
if (this.last_hash_key) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
39 |
_tab.push(this.last_hash_key + '=' + this.last_hash_value); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
40 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
41 |
return '#' + _tab.join('&'); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
42 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
43 |
|
| 598 | 44 |
IriSP.Widgets.Mediafragment.prototype.goToHash = function() { |
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
45 |
if (document.location.hash !== this.getLastHash()) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
46 |
var _tab = document.location.hash.replace(/^#/,'').split('&'); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
47 |
for (var _i = 0; _i < _tab.length; _i++) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
48 |
var _subtab = _tab[_i].split("="); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
49 |
if (_subtab[0] == "id" || _subtab[0] == "t") { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
50 |
this.last_hash_key = _subtab[0]; |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
51 |
this.last_hash_value = _subtab[1]; |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
52 |
if (this.last_hash_key == "id") { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
53 |
var _annotation = this.source.getElement(this.last_hash_value); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
54 |
if (typeof _annotation !== "undefined") { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
55 |
this.player.popcorn.currentTime(_annotation.begin.getSeconds()); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
56 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
57 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
58 |
if (this.last_hash_key == "t") { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
59 |
this.player.popcorn.currentTime(this.last_hash_value); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
60 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
61 |
break; |
| 598 | 62 |
} |
63 |
} |
|
64 |
} |
|
65 |
} |
|
66 |
||
67 |
IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) { |
|
| 638 | 68 |
this.setHash( 'id', _annotationId ); |
| 598 | 69 |
} |
70 |
||
71 |
IriSP.Widgets.Mediafragment.prototype.setHashToTime = function(_time) { |
|
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
72 |
if (_time !== NaN) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
73 |
this.setHash( 't', this.player.popcorn.currentTime() ); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
74 |
} |
| 598 | 75 |
} |
76 |
||
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
77 |
IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
78 |
if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
79 |
this.last_hash_key = _key; |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
80 |
this.last_hash_value = _value; |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
81 |
var _hash = this.getLastHash(); |
| 638 | 82 |
this.setWindowHash(_hash); |
| 598 | 83 |
if (window.parent !== window) { |
| 621 | 84 |
window.parent.postMessage(_hash,"*") |
| 598 | 85 |
} |
86 |
this.block(); |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
IriSP.Widgets.Mediafragment.prototype.unblock = function() { |
|
91 |
if (typeof this.blockTimeout !== "undefined") { |
|
92 |
window.clearTimeout(this.blockTimeout); |
|
93 |
} |
|
94 |
this.blockTimeout = undefined; |
|
95 |
this.blocked = false; |
|
96 |
} |
|
97 |
||
98 |
IriSP.Widgets.Mediafragment.prototype.block = function() { |
|
99 |
if (typeof this.blockTimeout !== "undefined") { |
|
100 |
window.clearTimeout(this.blockTimeout); |
|
101 |
} |
|
102 |
this.blocked = true; |
|
103 |
this.blockTimeout = window.setTimeout(this.functionWrapper("unblock"), 1000); |
|
104 |
} |