| author | ymh <ymh.work@gmail.com> |
| Fri, 15 Sep 2017 14:11:36 +0200 | |
| changeset 658 | cac26275af31 |
| parent 647 | eaaa1efce396 |
| permissions | -rw-r--r-- |
| 195 | 1 |
(function(Rkns) { |
| 196 | 2 |
"use strict"; |
3 |
||
4 |
var _ = Rkns._; |
|
| 26 | 5 |
|
| 195 | 6 |
var Ldt = Rkns.Ldt = {}; |
7 |
||
8 |
var Bin = Ldt.Bin = function(_renkan, _opts) { |
|
| 160 | 9 |
if (_opts.ldt_type) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
10 |
var Resclass = Ldt[_opts.ldt_type+"Bin"]; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
11 |
if (Resclass) { |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
12 |
return new Resclass(_renkan, _opts); |
| 160 | 13 |
} |
14 |
} |
|
15 |
console.error("No such LDT Bin Type"); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
16 |
}; |
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
68
diff
changeset
|
17 |
|
| 195 | 18 |
var ProjectBin = Ldt.ProjectBin = Rkns.Utils.inherit(Rkns._BaseBin); |
| 34 | 19 |
|
| 26 | 20 |
|
| 195 | 21 |
ProjectBin.prototype._init = function(_renkan, _opts) { |
| 61 | 22 |
this.renkan = _renkan; |
|
647
eaaa1efce396
add examples for youtube node types, add a way to open node urls with a single click
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
23 |
this.tagTemplate = _renkan.options.templates['templates/ldtjson-bin/tagtemplate.html']; |
|
eaaa1efce396
add examples for youtube node types, add a way to open node urls with a single click
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
24 |
this.annotationTemplate = _renkan.options.templates['templates/ldtjson-bin/annotationtemplate.html']; |
| 26 | 25 |
this.proj_id = _opts.project_id; |
| 28 | 26 |
this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/"; |
| 26 | 27 |
this.title_$.html(_opts.title); |
| 64 | 28 |
this.title_icon_$.addClass('Rk-Ldt-Title-Icon'); |
| 42 | 29 |
this.refresh(); |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
30 |
}; |
| 42 | 31 |
|
| 196 | 32 |
ProjectBin.prototype.render = function(searchbase) { |
33 |
var search = searchbase || Rkns.Utils.regexpFromTextOrArray(); |
|
| 44 | 34 |
function highlight(_text) { |
| 196 | 35 |
var _e = _(_text).escape(); |
36 |
return search.isempty ? _e : search.replace(_e, "<span class='searchmatch'>$1</span>"); |
|
| 44 | 37 |
} |
| 26 | 38 |
function convertTC(_ms) { |
39 |
function pad(_n) { |
|
40 |
var _res = _n.toString(); |
|
41 |
while (_res.length < 2) { |
|
42 |
_res = '0' + _res; |
|
43 |
} |
|
44 |
return _res; |
|
45 |
} |
|
46 |
var _totalSeconds = Math.abs(Math.floor(_ms/1000)), |
|
47 |
_hours = Math.floor(_totalSeconds / 3600), |
|
48 |
_minutes = (Math.floor(_totalSeconds / 60) % 60), |
|
49 |
_seconds = _totalSeconds % 60, |
|
50 |
_res = ''; |
|
51 |
if (_hours) { |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
52 |
_res += pad(_hours) + ':'; |
| 26 | 53 |
} |
54 |
_res += pad(_minutes) + ':' + pad(_seconds); |
|
55 |
return _res; |
|
56 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
57 |
|
| 44 | 58 |
var _html = '<li><h3>Tags</h3></li>', |
59 |
_projtitle = this.data.meta["dc:title"], |
|
60 |
_this = this, |
|
61 |
count = 0; |
|
62 |
_this.title_$.text('LDT Project: "' + _projtitle + '"'); |
|
| 433 | 63 |
_.map(_this.data.tags,function(_tag) { |
| 44 | 64 |
var _title = _tag.meta["dc:title"]; |
| 196 | 65 |
if (!search.isempty && !search.test(_title)) { |
| 44 | 66 |
return; |
67 |
} |
|
68 |
count++; |
|
69 |
_html += _this.tagTemplate({ |
|
70 |
ldt_platform: _this.ldt_platform, |
|
71 |
title: _title, |
|
72 |
htitle: highlight(_title), |
|
| 58 | 73 |
encodedtitle : encodeURIComponent(_title), |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
74 |
static_url: _this.renkan.options.static_url |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
75 |
}); |
| 44 | 76 |
}); |
77 |
_html += '<li><h3>Annotations</h3></li>'; |
|
| 433 | 78 |
_.map(_this.data.annotations,function(_annotation) { |
| 44 | 79 |
var _description = _annotation.content.description, |
80 |
_title = _annotation.content.title.replace(_description,""); |
|
| 196 | 81 |
if (!search.isempty && !search.test(_title) && !search.test(_description)) { |
| 44 | 82 |
return; |
83 |
} |
|
84 |
count++; |
|
85 |
var _duration = _annotation.end - _annotation.begin, |
|
86 |
_img = ( |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
87 |
(_annotation.content && _annotation.content.img && _annotation.content.img.src) ? |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
88 |
_annotation.content.img.src : |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
89 |
( _duration ? _this.renkan.options.static_url+"img/ldt-segment.png" : _this.renkan.options.static_url+"img/ldt-point.png" ) |
| 44 | 90 |
); |
91 |
_html += _this.annotationTemplate({ |
|
92 |
ldt_platform: _this.ldt_platform, |
|
93 |
title: _title, |
|
94 |
htitle: highlight(_title), |
|
95 |
description: _description, |
|
96 |
hdescription: highlight(_description), |
|
97 |
start: convertTC(_annotation.begin), |
|
98 |
end: convertTC(_annotation.end), |
|
99 |
duration: convertTC(_duration), |
|
100 |
mediaid: _annotation.media, |
|
101 |
annotationid: _annotation.id, |
|
| 58 | 102 |
image: _img, |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
103 |
static_url: _this.renkan.options.static_url |
| 44 | 104 |
}); |
105 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
106 |
|
| 44 | 107 |
this.main_$.html(_html); |
| 196 | 108 |
if (!search.isempty && count) { |
| 44 | 109 |
this.count_$.text(count).show(); |
110 |
} else { |
|
111 |
this.count_$.hide(); |
|
112 |
} |
|
| 196 | 113 |
if (!search.isempty && !count) { |
| 44 | 114 |
this.$.hide(); |
115 |
} else { |
|
116 |
this.$.show(); |
|
117 |
} |
|
| 61 | 118 |
this.renkan.resizeBins(); |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
119 |
}; |
| 44 | 120 |
|
| 195 | 121 |
ProjectBin.prototype.refresh = function() { |
| 44 | 122 |
var _this = this; |
| 42 | 123 |
Rkns.$.ajax({ |
124 |
url: this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id, |
|
125 |
dataType: "jsonp", |
|
126 |
success: function(_data) { |
|
| 44 | 127 |
_this.data = _data; |
128 |
_this.render(); |
|
| 26 | 129 |
} |
| 42 | 130 |
}); |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
131 |
}; |
| 64 | 132 |
|
| 195 | 133 |
var Search = Ldt.Search = function(_renkan, _opts) { |
| 64 | 134 |
this.renkan = _renkan; |
135 |
this.lang = _opts.lang || "en"; |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
136 |
}; |
| 64 | 137 |
|
| 195 | 138 |
Search.prototype.getBgClass = function() { |
| 64 | 139 |
return "Rk-Ldt-Icon"; |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
140 |
}; |
| 64 | 141 |
|
| 195 | 142 |
Search.prototype.getSearchTitle = function() { |
| 66 | 143 |
return this.renkan.translate("Lignes de Temps"); |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
144 |
}; |
| 64 | 145 |
|
| 195 | 146 |
Search.prototype.search = function(_q) { |
| 64 | 147 |
this.renkan.tabs.push( |
| 195 | 148 |
new ResultsBin(this.renkan, { |
| 64 | 149 |
search: _q |
150 |
}) |
|
151 |
); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
152 |
}; |
| 64 | 153 |
|
| 195 | 154 |
var ResultsBin = Ldt.ResultsBin = Rkns.Utils.inherit(Rkns._BaseBin); |
| 64 | 155 |
|
156 |
||
| 195 | 157 |
ResultsBin.prototype._init = function(_renkan, _opts) { |
| 64 | 158 |
this.renkan = _renkan; |
|
647
eaaa1efce396
add examples for youtube node types, add a way to open node urls with a single click
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
159 |
this.segmentTemplate = _renkan.options.templates['templates/ldtjson-bin/segmenttemplate.html']; |
| 64 | 160 |
this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/"; |
161 |
this.max_results = _opts.max_results || 50; |
|
162 |
this.search = _opts.search; |
|
163 |
this.title_$.html('Lignes de Temps: "' + _opts.search + '"'); |
|
164 |
this.title_icon_$.addClass('Rk-Ldt-Title-Icon'); |
|
165 |
this.refresh(); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
166 |
}; |
| 64 | 167 |
|
| 196 | 168 |
ResultsBin.prototype.render = function(searchbase) { |
169 |
if (!this.data) { |
|
170 |
return; |
|
| 64 | 171 |
} |
| 196 | 172 |
var search = searchbase || Rkns.Utils.regexpFromTextOrArray(); |
173 |
var highlightrx = (search.isempty ? Rkns.Utils.regexpFromTextOrArray(this.search) : search); |
|
| 64 | 174 |
function highlight(_text) { |
| 196 | 175 |
return highlightrx.replace(_(_text).escape(), "<span class='searchmatch'>$1</span>"); |
| 64 | 176 |
} |
177 |
function convertTC(_ms) { |
|
178 |
function pad(_n) { |
|
179 |
var _res = _n.toString(); |
|
180 |
while (_res.length < 2) { |
|
181 |
_res = '0' + _res; |
|
182 |
} |
|
183 |
return _res; |
|
184 |
} |
|
185 |
var _totalSeconds = Math.abs(Math.floor(_ms/1000)), |
|
186 |
_hours = Math.floor(_totalSeconds / 3600), |
|
187 |
_minutes = (Math.floor(_totalSeconds / 60) % 60), |
|
188 |
_seconds = _totalSeconds % 60, |
|
189 |
_res = ''; |
|
190 |
if (_hours) { |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
191 |
_res += pad(_hours) + ':'; |
| 64 | 192 |
} |
193 |
_res += pad(_minutes) + ':' + pad(_seconds); |
|
194 |
return _res; |
|
195 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
196 |
|
| 64 | 197 |
var _html = '', |
198 |
_this = this, |
|
199 |
count = 0; |
|
| 433 | 200 |
_.each(this.data.objects,function(_segment) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
201 |
var _description = _segment.abstract, |
| 64 | 202 |
_title = _segment.title; |
| 196 | 203 |
if (!search.isempty && !search.test(_title) && !search.test(_description)) { |
| 64 | 204 |
return; |
205 |
} |
|
206 |
count++; |
|
207 |
var _duration = _segment.duration, |
|
208 |
_begin = _segment.start_ts, |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
209 |
_end = + _segment.duration + _begin, |
| 64 | 210 |
_img = ( |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
211 |
_duration ? |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
212 |
_this.renkan.options.static_url + "img/ldt-segment.png" : |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
213 |
_this.renkan.options.static_url + "img/ldt-point.png" |
| 64 | 214 |
); |
215 |
_html += _this.segmentTemplate({ |
|
216 |
ldt_platform: _this.ldt_platform, |
|
217 |
title: _title, |
|
218 |
htitle: highlight(_title), |
|
219 |
description: _description, |
|
220 |
hdescription: highlight(_description), |
|
221 |
start: convertTC(_begin), |
|
222 |
end: convertTC(_end), |
|
223 |
duration: convertTC(_duration), |
|
224 |
mediaid: _segment.iri_id, |
|
| 68 | 225 |
//projectid: _segment.project_id, |
226 |
//cuttingid: _segment.cutting_id, |
|
| 64 | 227 |
annotationid: _segment.element_id, |
228 |
image: _img |
|
229 |
}); |
|
230 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
211
diff
changeset
|
231 |
|
| 64 | 232 |
this.main_$.html(_html); |
| 196 | 233 |
if (!search.isempty && count) { |
| 64 | 234 |
this.count_$.text(count).show(); |
235 |
} else { |
|
236 |
this.count_$.hide(); |
|
237 |
} |
|
| 196 | 238 |
if (!search.isempty && !count) { |
| 64 | 239 |
this.$.hide(); |
240 |
} else { |
|
241 |
this.$.show(); |
|
242 |
} |
|
243 |
this.renkan.resizeBins(); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
244 |
}; |
| 64 | 245 |
|
| 195 | 246 |
ResultsBin.prototype.refresh = function() { |
| 64 | 247 |
var _this = this; |
248 |
Rkns.$.ajax({ |
|
249 |
url: this.ldt_platform + 'ldtplatform/api/ldt/1.0/segments/search/', |
|
250 |
data: { |
|
251 |
format: "jsonp", |
|
252 |
q: this.search, |
|
253 |
limit: this.max_results |
|
254 |
}, |
|
255 |
dataType: "jsonp", |
|
256 |
success: function(_data) { |
|
257 |
_this.data = _data; |
|
258 |
_this.render(); |
|
259 |
} |
|
260 |
}); |
|
| 195 | 261 |
}; |
262 |
||
263 |
})(window.Rkns); |