| author | Raphael Velt <raph.velt@gmail.com> |
| Mon, 21 May 2012 18:18:08 +0200 | |
| changeset 620 | 953c68b4da79 |
| parent 618 | f65c1c3f77ea |
| child 621 | 44f90de0016f |
| 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) { |
|
8 |
if (_msg.data.type === "hashchange") { |
|
9 |
document.location.hash = _msg.data.hash; |
|
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 |
||
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
25 |
IriSP.Widgets.Mediafragment.prototype.getLastHash = function() { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
26 |
var _tab = document.location.hash.replace(/^#/,'').split('&'); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
27 |
_tab = IriSP._(_tab).filter(function(_el) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
28 |
return _el && !/^(id|t)=/.test(_el); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
29 |
}); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
30 |
if (this.last_hash_key) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
31 |
_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
|
32 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
33 |
return '#' + _tab.join('&'); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
34 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
35 |
|
| 598 | 36 |
IriSP.Widgets.Mediafragment.prototype.goToHash = function() { |
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
37 |
if (document.location.hash !== this.getLastHash()) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
38 |
var _tab = document.location.hash.replace(/^#/,'').split('&'); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
39 |
for (var _i = 0; _i < _tab.length; _i++) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
40 |
var _subtab = _tab[_i].split("="); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
41 |
if (_subtab[0] == "id" || _subtab[0] == "t") { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
42 |
this.last_hash_key = _subtab[0]; |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
43 |
this.last_hash_value = _subtab[1]; |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
44 |
if (this.last_hash_key == "id") { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
45 |
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
|
46 |
if (typeof _annotation !== "undefined") { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
47 |
this.player.popcorn.currentTime(_annotation.begin.getSeconds()); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
48 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
49 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
50 |
if (this.last_hash_key == "t") { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
51 |
this.player.popcorn.currentTime(this.last_hash_value); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
52 |
} |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
53 |
break; |
| 598 | 54 |
} |
55 |
} |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) { |
|
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
60 |
this.setHash( 'id', this.source.unNamespace(_annotationId) ); |
| 598 | 61 |
} |
62 |
||
63 |
IriSP.Widgets.Mediafragment.prototype.setHashToTime = function(_time) { |
|
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
64 |
if (_time !== NaN) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
65 |
this.setHash( 't', this.player.popcorn.currentTime() ); |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
66 |
} |
| 598 | 67 |
} |
68 |
||
|
618
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
69 |
IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) { |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
70 |
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
|
71 |
this.last_hash_key = _key; |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
72 |
this.last_hash_value = _value; |
|
f65c1c3f77ea
corrected metadataplayer for mediafragment bug
Raphael Velt <raph.velt@gmail.com>
parents:
598
diff
changeset
|
73 |
var _hash = this.getLastHash(); |
| 598 | 74 |
document.location.hash = _hash; |
75 |
if (window.parent !== window) { |
|
76 |
window.parent.postMessage({ |
|
77 |
type: "hashchange", |
|
78 |
hash: _hash |
|
|
620
953c68b4da79
Added Edito 24.05 + embed code now relaying mediafragment
Raphael Velt <raph.velt@gmail.com>
parents:
618
diff
changeset
|
79 |
},"*") |
| 598 | 80 |
} |
81 |
this.block(); |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
IriSP.Widgets.Mediafragment.prototype.unblock = function() { |
|
86 |
if (typeof this.blockTimeout !== "undefined") { |
|
87 |
window.clearTimeout(this.blockTimeout); |
|
88 |
} |
|
89 |
this.blockTimeout = undefined; |
|
90 |
this.blocked = false; |
|
91 |
} |
|
92 |
||
93 |
IriSP.Widgets.Mediafragment.prototype.block = function() { |
|
94 |
if (typeof this.blockTimeout !== "undefined") { |
|
95 |
window.clearTimeout(this.blockTimeout); |
|
96 |
} |
|
97 |
this.blocked = true; |
|
98 |
this.blockTimeout = window.setTimeout(this.functionWrapper("unblock"), 1000); |
|
99 |
} |