| author | veltr |
| Wed, 18 Apr 2012 18:58:44 +0200 | |
| branch | new-model |
| changeset 870 | 2c025db10a10 |
| parent 852 | eefb64f74a3f |
| child 872 | d777d05a16e4 |
| permissions | -rw-r--r-- |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
1 |
IriSP.AnnotationsListWidget = function(player, config) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
2 |
IriSP.Widget.call(this, player, config); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
3 |
this.bindPopcorn("IriSP.search", "searchHandler"); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
4 |
this.bindPopcorn("IriSP.search.closed", "searchHandler"); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
5 |
this.bindPopcorn("IriSP.search.cleared", "searchHandler"); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
6 |
this.searchString = false; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
7 |
this.lastIds = []; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
8 |
var _this = this; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
9 |
this.throttledRefresh = IriSP._.throttle(function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
10 |
_this.refresh(false); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
11 |
}, 1500); |
| 585 | 12 |
}; |
13 |
||
14 |
IriSP.AnnotationsListWidget.prototype = new IriSP.Widget(); |
|
15 |
||
16 |
IriSP.AnnotationsListWidget.prototype.clear = function() { |
|
17 |
}; |
|
18 |
||
| 588 | 19 |
IriSP.AnnotationsListWidget.prototype.clearWidget = function() { |
| 585 | 20 |
}; |
21 |
||
|
838
03b03865eb9b
Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents:
836
diff
changeset
|
22 |
IriSP.AnnotationsListWidget.prototype.searchHandler = function(searchString) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
23 |
this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
24 |
var _n = this.refresh(true); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
25 |
if (this.searchString) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
26 |
if (_n) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
27 |
this.player.popcorn.trigger("IriSP.search.matchFound"); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
28 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
29 |
this.player.popcorn.trigger("IriSP.search.noMatchFound"); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
30 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
31 |
} |
|
838
03b03865eb9b
Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents:
836
diff
changeset
|
32 |
} |
| 629 | 33 |
/** effectively redraw the widget - called by drawList */ |
34 |
IriSP.AnnotationsListWidget.prototype.do_redraw = function(list) { |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
35 |
/* var _html = IriSP.templToHTML(IriSP.annotationsListWidget_template, { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
36 |
annotations : list |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
37 |
}), _this = this; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
38 |
|
|
838
03b03865eb9b
Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents:
836
diff
changeset
|
39 |
this.selector.html(_html); |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
40 |
|
| 842 | 41 |
this.selector.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
42 |
_this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().trim()); |
| 842 | 43 |
}) |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
44 |
if(this.searchRe !== null) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
45 |
this.selector.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
46 |
var _$ = IriSP.jQuery(this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
47 |
_$.html(_$.text().trim().replace(_this.searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>')) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
48 |
}) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
49 |
} */ |
| 629 | 50 |
}; |
51 |
||
| 833 | 52 |
IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
53 |
/* var _this = this; |
| 833 | 54 |
return { |
55 |
"id" : a.id, |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
56 |
"title" : this.cinecast_version ? IriSP.get_aliased(a.meta, ['creator_name', 'creator']) : a.content.title, |
| 833 | 57 |
"desc" : this.cinecast_version ? a.content.data : a.content.description, |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
58 |
"begin" : IriSP.msToTime(a.begin), |
| 833 | 59 |
"end" : IriSP.msToTime(a.end), |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
60 |
"thumbnail" : ( typeof a.meta == "object" && typeof a.meta.thumbnail == "string") ? a.meta.thumbnail : this.default_thumbnail, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
61 |
"url" : ( typeof a.meta == "object" && typeof a.meta.url == "string") ? a.meta.url : null, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
62 |
"created_at" : ( typeof a.meta == "object" && typeof a.meta.created == "string") ? Date.parse(a.meta.created.replace(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}\:\d{2}\:\d{2}).*$/, "$2/$3/$1 $4 UTC+0000")) : null, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
63 |
"tags" : typeof a.tags == "object" ? IriSP.underscore(a.tags).chain().map(function(_t) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
64 |
if( typeof _t == "string") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
65 |
return _t.replace(/^.*:/, '#'); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
66 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
67 |
if( typeof _t['id-ref'] != "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
68 |
var _f = IriSP.underscore.find(_this._serializer._data.tags, function(_tag) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
69 |
return _tag.id == _t['id-ref']; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
70 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
71 |
if( typeof _f != "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
72 |
return IriSP.get_aliased(_f.meta, ['dc:title', 'title']); |
| 833 | 73 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
74 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
75 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
76 |
return null; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
77 |
}).filter(function(_t) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
78 |
return _t !== null && _t !== "" |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
79 |
}).value() : [] |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
80 |
} */ |
| 833 | 81 |
} |
| 599 | 82 |
/** draw the annotation list */ |
|
607
0b94ae49efbd
added an option to force the redraw of a list, even if the cached lists are the
hamidouk
parents:
605
diff
changeset
|
83 |
IriSP.AnnotationsListWidget.prototype.drawList = function(force_redraw) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
84 |
/* var _this = this; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
85 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
86 |
// var view_type = this._serializer.getContributions(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
87 |
var annotations = this._serializer._data.annotations; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
88 |
var currentTime = this.player.popcorn.currentTime(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
89 |
var list = []; |
| 588 | 90 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
91 |
for( i = 0; i < annotations.length; i++) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
92 |
var obj = this.transformAnnotation(annotations[i]); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
93 |
obj.iterator = i; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
94 |
obj.distance = Math.abs((annotations[i].end + annotations[i].begin) / 2000 - currentTime); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
95 |
if(!this.cinecast_version || annotations[i].type == "cinecast:UserAnnotation") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
96 |
list.push(obj); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
97 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
98 |
|
| 835 | 99 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
100 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
101 |
if(this.searchRe !== null) { |
|
838
03b03865eb9b
Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents:
836
diff
changeset
|
102 |
list = list.filter(function(_a) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
103 |
return (_this.searchRe.test(_a.desc) || _this.searchRe.test(_a.title)); |
|
838
03b03865eb9b
Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents:
836
diff
changeset
|
104 |
}); |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
105 |
if(list.length) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
106 |
this.player.popcorn.trigger("IriSP.search.matchFound"); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
107 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
108 |
this.player.popcorn.trigger("IriSP.search.noMatchFound"); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
109 |
} |
|
838
03b03865eb9b
Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents:
836
diff
changeset
|
110 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
111 |
list = IriSP.underscore(list).chain().sortBy(function(_o) { |
| 833 | 112 |
return _o.distance; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
113 |
}).first(10).sortBy(function(_o) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
114 |
return (_this.cinecast_version ? -_o.created_at : _o.iterator); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
115 |
}).value(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
116 |
var idList = IriSP.underscore.pluck(list, "id").sort(); |
| 642 | 117 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
118 |
if(!IriSP.underscore.isEqual(this.__oldList, idList) || this.lastSearch !== this.searchRe || typeof (force_redraw) !== "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
119 |
this.do_redraw(list); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
120 |
this.__oldList = idList; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
121 |
this.lastSearch = this.searchRe; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
122 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
123 |
/* save for next call */ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
124 |
|
| 599 | 125 |
}; |
126 |
||
| 674 | 127 |
IriSP.AnnotationsListWidget.prototype.ajaxRedraw = function(timecode) { |
| 748 | 128 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
129 |
/* the seeked signal sometimes passes an argument - depending on if we're using |
| 752 | 130 |
our popcorn lookalike or the real thing - if it's the case, use it as it's |
131 |
more precise than currentTime which sometimes contains the place we where at */ |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
132 |
if(IriSP.null_or_undefined(timecode) || typeof (timecode) != "number") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
133 |
var tcode = this.player.popcorn.currentTime(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
134 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
135 |
var tcode = timecode; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
136 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
137 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
138 |
/* the platform gives us a special url - of the type : http://path/{{media}}/{{begin}}/{{end}} |
| 748 | 139 |
we double the braces using regexps and we feed it to mustache to build the correct url |
140 |
we have to do that because the platform only knows at run time what view it's displaying. |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
141 |
*/ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
142 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
143 |
var media_id = this.currentMedia()["id"]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
144 |
var duration = this.getDuration(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
145 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
146 |
var begin_timecode = (Math.floor(tcode) - 300) * 1000; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
147 |
if(begin_timecode < 0) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
148 |
begin_timecode = 0; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
149 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
150 |
var end_timecode = (Math.floor(tcode) + 300) * 1000; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
151 |
if(end_timecode > duration) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
152 |
end_timecode = duration; |
| 748 | 153 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
154 |
var templ = Mustache.to_html(this.ajax_url, { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
155 |
media : media_id, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
156 |
begin : begin_timecode, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
157 |
end : end_timecode |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
158 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
159 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
160 |
/* we create on the fly a serializer to get the ajax */ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
161 |
var serializer = new IriSP.JSONSerializer(IriSP.__dataloader, templ); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
162 |
serializer.sync(IriSP.wrap(this, function(json) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
163 |
this.processJson(json, serializer) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
164 |
})); |
| 674 | 165 |
}; |
| 698 | 166 |
/** process the received json - it's a bit hackish */ |
167 |
IriSP.AnnotationsListWidget.prototype.processJson = function(json, serializer) { |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
168 |
/* FIXME: DRY the whole thing */ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
169 |
/* var annotations = serializer._data.annotations; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
170 |
if(IriSP.null_or_undefined(annotations)) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
171 |
return; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
172 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
173 |
/* |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
174 |
commented in case we wanted to discriminate against some annotation types. |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
175 |
var view_types = serializer.getIds("Contributions"); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
176 |
*/ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
177 |
var l = []; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
178 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
179 |
var media = this.currentMedia()["id"]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
180 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
181 |
for( i = 0; i < annotations.length; i++) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
182 |
var obj = this.transformAnnotation(annotations[i]) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
183 |
if( typeof obj.url == "undefined" || !obj.url) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
184 |
/* only if the annotation isn't present in the document create an |
| 836 | 185 |
external link */ |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
186 |
if(this.annotations_ids.indexOf(obj.id.toLowerCase()) == -1) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
187 |
// braindead url; jacques didn't want to create a new one in the platform, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
188 |
// so we append the cutting id to the url. |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
189 |
obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
190 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
191 |
// obj.url = document.location.href.split("#")[0] + "/" + annotation.meta.project; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
192 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
193 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
194 |
l.push(obj); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
195 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
196 |
this._ajax_cache = l; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
197 |
this.do_redraw(l); |
| 698 | 198 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
199 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
200 |
IriSP.AnnotationsListWidget.prototype.ajaxSource = function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
201 |
var _url = Mustache.to_html(this.ajax_url, { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
202 |
media : this.source.currentMedia.namespacedId.name, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
203 |
begin : 0, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
204 |
end : 0 |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
205 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
206 |
console.log(_url); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
207 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
208 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
209 |
IriSP.AnnotationsListWidget.prototype.refresh = function(_forceRedraw) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
210 |
if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
211 |
return 0; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
212 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
213 |
var _this = this, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
214 |
_list = undefined, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
215 |
_currentTime = this.player.popcorn.currentTime(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
216 |
if (typeof _currentTime == "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
217 |
_currentTime = 0; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
218 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
219 |
if (this.annotation_type) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
220 |
_list = this.currentSource.getAnnotationsByTypeTitle(this.annotation_type); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
221 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
222 |
if (typeof _list === "undefined") { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
223 |
_list = this.currentSource.getAnnotations(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
224 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
225 |
if (this.searchString) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
226 |
_list = _list.searchByTextFields(this.searchString); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
227 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
228 |
if (this.limit_count) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
229 |
_list = _list.sortBy(function(_annotation) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
230 |
return Math.abs(_annotation.begin.getSeconds() - _currentTime); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
231 |
}).slice(0, this.limit_count) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
232 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
233 |
if (this.newest_first) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
234 |
_list = _list.sortBy(function(_annotation) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
235 |
return -_annotation.created.valueOf(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
236 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
237 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
238 |
_list = _list.sortBy(function(_annotation) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
239 |
return _annotation.begin.milliseconds; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
240 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
241 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
242 |
var _ids = _list.idIndex; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
243 |
if (!_forceRedraw && IriSP._.isEqual(_ids, this.lastIds)) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
244 |
return _list.length; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
245 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
246 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
247 |
/* This part only gets executed if the list needs updating */ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
248 |
this.lastIds = _ids; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
249 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
250 |
var _html = IriSP.templToHTML( |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
251 |
IriSP.annotationsListWidget_template, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
252 |
{ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
253 |
annotations : _list.map(function(_annotation) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
254 |
var _res = { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
255 |
id : _annotation.id, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
256 |
title : _annotation.title.replace(_annotation.description,''), |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
257 |
description : _annotation.description, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
258 |
begin : _annotation.begin.toString(), |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
259 |
end : _annotation.end.toString(), |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
260 |
thumbnail : typeof _annotation.thumbnail !== "undefined" ? _annotation.thumbnail : _this.default_thumbnail, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
261 |
url : typeof _annotation.url !== "undefined" ? _annotation.thumbnail : '#' + _annotation.namespacedId.name, |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
262 |
tags : _annotation.getTagTexts() |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
263 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
264 |
return _res; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
265 |
}) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
266 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
267 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
268 |
this.$.html(_html); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
269 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
270 |
this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
271 |
_this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
272 |
}) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
273 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
274 |
if(this.searchString) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
275 |
var _searchRe = new RegExp('(' + this.searchString.replace(/(\W)/gm,'\\$1') + ')','gim'); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
276 |
this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
277 |
var _$ = IriSP.jQuery(this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
278 |
_$.html(_$.text().replace(/(^\s+|\s+$)/g,'').replace(_searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>')) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
279 |
}) |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
280 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
281 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
282 |
return _list.length; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
283 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
284 |
|
| 599 | 285 |
IriSP.AnnotationsListWidget.prototype.draw = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
286 |
var _this = this; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
287 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
288 |
if (this.ajax_url && this.ajax_granularity) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
289 |
this.ajaxSource(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
290 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
291 |
this.currentSource = this.source; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
292 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
293 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
294 |
if (this.refresh_interval) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
295 |
window.setInterval(function() { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
296 |
_this.currentSource.get() |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
297 |
}, this.refresh_interval); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
298 |
} |
| 674 | 299 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
300 |
var _events = [ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
301 |
"IriSP.createAnnotationWidget.addedAnnotation", |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
302 |
"timeupdate", |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
303 |
"seeked", |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
304 |
"loadedmetadata" |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
305 |
]; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
306 |
for (var _i = 0; _i < _events.length; _i++) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
307 |
this.player.popcorn.listen(_events[_i], this.throttledRefresh); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
308 |
} |
|
730
357fc047503b
redraw the widget after that an annotation has been added.
hamidouk
parents:
729
diff
changeset
|
309 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
310 |
this.throttledRefresh(); |
| 698 | 311 |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
852
diff
changeset
|
312 |
}; |