| author | cavaliet |
| Thu, 02 Jan 2014 16:40:25 +0100 | |
| branch | new-model |
| changeset 1019 | 3ab36f402b0c |
| parent 916 | ec6849bbbdcc |
| child 1020 | 198c2b79f5e1 |
| permissions | -rw-r--r-- |
| 880 | 1 |
IriSP.Widgets.Mediafragment = function(player, config) { |
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
| 905 | 3 |
this.last_hash_key = ""; |
4 |
this.last_hash_value = ""; |
|
| 880 | 5 |
window.onhashchange = this.functionWrapper("goToHash"); |
| 882 | 6 |
if (typeof window.addEventListener !== "undefined") { |
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
7 |
var _this = this; |
| 882 | 8 |
window.addEventListener('message', function(_msg) { |
| 906 | 9 |
if (/^#/.test(_msg.data)) { |
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
10 |
_this.setWindowHash(_msg.data); |
| 882 | 11 |
} |
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
12 |
}); |
| 882 | 13 |
}; |
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
14 |
this.onMdpEvent("Mediafragment.setHashToAnnotation","setHashToAnnotation"); |
| 881 | 15 |
this.blocked = false; |
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
16 |
}; |
| 880 | 17 |
|
18 |
IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget(); |
|
19 |
||
20 |
IriSP.Widgets.Mediafragment.prototype.draw = function() { |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
21 |
this.onMediaEvent("setpause","setHashToTime"); |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
22 |
var _this = this; |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
23 |
this.getWidgetAnnotations().forEach(function(_annotation) { |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
24 |
_annotation.on("click", function() { |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
25 |
_this.setHashToAnnotation(_annotation.id); |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
26 |
}); |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
27 |
}); |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
28 |
if (this.media.loadedMetadata) { |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
29 |
this.goToHash(); |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
30 |
} else { |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
31 |
this.onMediaEvent("loadedmetadata","goToHash"); |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
32 |
} |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
33 |
}; |
| 880 | 34 |
|
| 910 | 35 |
IriSP.Widgets.Mediafragment.prototype.setWindowHash = function(_hash) { |
36 |
if (typeof window.history !== "undefined" && typeof window.history.replaceState !== "undefined") { |
|
37 |
window.history.replaceState({}, "", _hash); |
|
38 |
} else { |
|
39 |
document.location.hash = _hash; |
|
40 |
} |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
41 |
}; |
| 910 | 42 |
|
| 905 | 43 |
IriSP.Widgets.Mediafragment.prototype.getLastHash = function() { |
44 |
var _tab = document.location.hash.replace(/^#/,'').split('&'); |
|
45 |
_tab = IriSP._(_tab).filter(function(_el) { |
|
46 |
return _el && !/^(id|t)=/.test(_el); |
|
47 |
}); |
|
48 |
if (this.last_hash_key) { |
|
49 |
_tab.push(this.last_hash_key + '=' + this.last_hash_value); |
|
50 |
} |
|
51 |
return '#' + _tab.join('&'); |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
52 |
}; |
| 905 | 53 |
|
| 880 | 54 |
IriSP.Widgets.Mediafragment.prototype.goToHash = function() { |
| 905 | 55 |
if (document.location.hash !== this.getLastHash()) { |
56 |
var _tab = document.location.hash.replace(/^#/,'').split('&'); |
|
57 |
for (var _i = 0; _i < _tab.length; _i++) { |
|
58 |
var _subtab = _tab[_i].split("="); |
|
59 |
if (_subtab[0] == "id" || _subtab[0] == "t") { |
|
60 |
this.last_hash_key = _subtab[0]; |
|
61 |
this.last_hash_value = _subtab[1]; |
|
62 |
if (this.last_hash_key == "id") { |
|
63 |
var _annotation = this.source.getElement(this.last_hash_value); |
|
64 |
if (typeof _annotation !== "undefined") { |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
65 |
this.media.setCurrentTime(_annotation.begin); |
| 905 | 66 |
} |
67 |
} |
|
68 |
if (this.last_hash_key == "t") { |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
69 |
this.media.setCurrentTime(1000*this.last_hash_value); |
| 905 | 70 |
} |
71 |
break; |
|
| 880 | 72 |
} |
73 |
} |
|
74 |
} |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
75 |
}; |
| 880 | 76 |
|
77 |
IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) { |
|
| 916 | 78 |
this.setHash( 'id', _annotationId ); |
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
79 |
}; |
| 880 | 80 |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
81 |
IriSP.Widgets.Mediafragment.prototype.setHashToTime = function() { |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
82 |
this.setHash( 't', this.media.getCurrentTime().getSeconds() ); |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
83 |
}; |
| 880 | 84 |
|
| 905 | 85 |
IriSP.Widgets.Mediafragment.prototype.setHash = function(_key, _value) { |
86 |
if (!this.blocked && (this.last_hash_key !== _key || this.last_hash_value !== _value)) { |
|
87 |
this.last_hash_key = _key; |
|
88 |
this.last_hash_value = _value; |
|
89 |
var _hash = this.getLastHash(); |
|
| 910 | 90 |
this.setWindowHash(_hash); |
| 882 | 91 |
if (window.parent !== window) { |
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
92 |
window.parent.postMessage(_hash,"*"); |
| 882 | 93 |
} |
| 881 | 94 |
this.block(); |
| 880 | 95 |
} |
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
96 |
}; |
| 881 | 97 |
|
98 |
IriSP.Widgets.Mediafragment.prototype.unblock = function() { |
|
99 |
if (typeof this.blockTimeout !== "undefined") { |
|
100 |
window.clearTimeout(this.blockTimeout); |
|
101 |
} |
|
102 |
this.blockTimeout = undefined; |
|
103 |
this.blocked = false; |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
104 |
}; |
| 881 | 105 |
|
106 |
IriSP.Widgets.Mediafragment.prototype.block = function() { |
|
107 |
if (typeof this.blockTimeout !== "undefined") { |
|
108 |
window.clearTimeout(this.blockTimeout); |
|
109 |
} |
|
110 |
this.blocked = true; |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
111 |
this.blockTimeout = window.setTimeout(this.functionWrapper("unblock"), 1500); |
|
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
916
diff
changeset
|
112 |
}; |