|
880
|
1 |
IriSP.Widgets.Mediafragment = function(player, config) { |
|
|
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
3 |
this.last_hash = ""; |
|
|
4 |
window.onhashchange = this.functionWrapper("goToHash"); |
|
881
|
5 |
this.bindPopcorn("pause","setHashToTime"); |
|
|
6 |
this.bindPopcorn("seeked","setHashToTime"); |
|
|
7 |
this.bindPopcorn("IriSP.Mediafragment.setHashToAnnotation","setHashToAnnotation"); |
|
|
8 |
this.blocked = false; |
|
880
|
9 |
} |
|
|
10 |
|
|
|
11 |
IriSP.Widgets.Mediafragment.prototype = new IriSP.Widgets.Widget(); |
|
|
12 |
|
|
|
13 |
IriSP.Widgets.Mediafragment.prototype.draw = function() { |
|
|
14 |
this.goToHash(); |
|
|
15 |
} |
|
|
16 |
|
|
|
17 |
IriSP.Widgets.Mediafragment.prototype.goToHash = function() { |
|
|
18 |
if (document.location.hash !== this.last_hash) { |
|
|
19 |
this.last_hash = document.location.hash; |
|
|
20 |
var _tab = this.last_hash.split("="); |
|
|
21 |
if (_tab[0] === '#id') { |
|
|
22 |
var _annotation = this.source.getElement(_tab[1]); |
|
|
23 |
if (typeof _annotation !== "undefined") { |
|
|
24 |
this.player.popcorn.currentTime(_annotation.begin.getSeconds()); |
|
|
25 |
} |
|
|
26 |
} |
|
|
27 |
if (_tab[0] === '#t') { |
|
|
28 |
this.player.popcorn.currentTime(_tab[1]); |
|
|
29 |
} |
|
|
30 |
} |
|
|
31 |
} |
|
|
32 |
|
|
|
33 |
IriSP.Widgets.Mediafragment.prototype.setHashToAnnotation = function(_annotationId) { |
|
881
|
34 |
this.setHash( '#id=' + this.source.unNamespace(_annotationId) ); |
|
880
|
35 |
} |
|
|
36 |
|
|
881
|
37 |
IriSP.Widgets.Mediafragment.prototype.setHashToTime = function(_time) { |
|
|
38 |
_time = (typeof _time !== "undefined" ? _time : this.player.popcorn.currentTime() ); |
|
|
39 |
this.setHash( '#t=' + _time ); |
|
880
|
40 |
} |
|
|
41 |
|
|
|
42 |
IriSP.Widgets.Mediafragment.prototype.setHash = function(_hash) { |
|
881
|
43 |
if (!this.blocked && this.last_hash !== _hash) { |
|
880
|
44 |
this.last_hash = _hash; |
|
|
45 |
document.location.hash = _hash; |
|
881
|
46 |
this.block(); |
|
880
|
47 |
} |
|
881
|
48 |
} |
|
|
49 |
|
|
|
50 |
IriSP.Widgets.Mediafragment.prototype.unblock = function() { |
|
|
51 |
if (typeof this.blockTimeout !== "undefined") { |
|
|
52 |
window.clearTimeout(this.blockTimeout); |
|
|
53 |
} |
|
|
54 |
this.blockTimeout = undefined; |
|
|
55 |
this.blocked = false; |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
IriSP.Widgets.Mediafragment.prototype.block = function() { |
|
|
59 |
if (typeof this.blockTimeout !== "undefined") { |
|
|
60 |
window.clearTimeout(this.blockTimeout); |
|
|
61 |
} |
|
|
62 |
this.blocked = true; |
|
|
63 |
this.blockTimeout = window.setTimeout(this.functionWrapper("unblock"), 1000); |
|
|
64 |
} |