164 } |
164 } |
165 |
165 |
166 if (!this.options.search.length) { |
166 if (!this.options.search.length) { |
167 this.$.find(".Rk-Web-Search-Form").detach(); |
167 this.$.find(".Rk-Web-Search-Form").detach(); |
168 } else { |
168 } else { |
169 var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
169 var _tmpl = _.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
170 _select = this.$.find(".Rk-Search-List"), |
170 _select = this.$.find(".Rk-Search-List"), |
171 _input = this.$.find(".Rk-Web-Search-Input"), |
171 _input = this.$.find(".Rk-Web-Search-Input"), |
172 _form = this.$.find(".Rk-Web-Search-Form"); |
172 _form = this.$.find(".Rk-Web-Search-Form"); |
173 Rkns._(this.options.search).each(function(_search, _key) { |
173 _(this.options.search).each(function(_search, _key) { |
174 if (Rkns[_search.type] && Rkns[_search.type].Search) { |
174 if (Rkns[_search.type] && Rkns[_search.type].Search) { |
175 _this.search_engines.push(new Rkns[_search.type].Search(_this, _search)); |
175 _this.search_engines.push(new Rkns[_search.type].Search(_this, _search)); |
176 } |
176 } |
177 }); |
177 }); |
178 _select.html( |
178 _select.html( |
179 Rkns._(this.search_engines).map(function(_search, _key) { |
179 _(this.search_engines).map(function(_search, _key) { |
180 return _tmpl({ |
180 return _tmpl({ |
181 key: _key, |
181 key: _key, |
182 title: _search.getSearchTitle(), |
182 title: _search.getSearchTitle(), |
183 className: _search.getBgClass() |
183 className: _search.getBgClass() |
184 }); |
184 }); |
202 this.$.find(".Rk-Search-Select").mouseleave( |
202 this.$.find(".Rk-Search-Select").mouseleave( |
203 function() { _select.hide(); } |
203 function() { _select.hide(); } |
204 ); |
204 ); |
205 this.setSearchEngine(0); |
205 this.setSearchEngine(0); |
206 } |
206 } |
207 Rkns._(this.options.bins).each(function(_bin) { |
207 _(this.options.bins).each(function(_bin) { |
208 if (Rkns[_bin.type] && Rkns[_bin.type].Bin) { |
208 if (Rkns[_bin.type] && Rkns[_bin.type].Bin) { |
209 _this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin)); |
209 _this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin)); |
210 } |
210 } |
211 }); |
211 }); |
212 |
212 |
227 var _t = Rkns.$(this); |
227 var _t = Rkns.$(this); |
228 if (_t && $(_t).attr("data-uri")) { |
228 if (_t && $(_t).attr("data-uri")) { |
229 var _models = _this.project.get("nodes").where({ |
229 var _models = _this.project.get("nodes").where({ |
230 uri: $(_t).attr("data-uri") |
230 uri: $(_t).attr("data-uri") |
231 }); |
231 }); |
232 Rkns._(_models).each(function(_model) { |
232 _(_models).each(function(_model) { |
233 _this.renderer.highlightModel(_model); |
233 _this.renderer.highlightModel(_model); |
234 }); |
234 }); |
235 } |
235 } |
236 }).mouseout(function() { |
236 }).mouseout(function() { |
237 _this.renderer.unhighlightAll(); |
237 _this.renderer.unhighlightAll(); |
279 |
279 |
280 Rkns.$(window).resize(function() { |
280 Rkns.$(window).resize(function() { |
281 _this.resizeBins(); |
281 _this.resizeBins(); |
282 }); |
282 }); |
283 |
283 |
|
284 var lastsearch = false, lastval = ''; |
|
285 |
284 this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() { |
286 this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() { |
285 var val = Rkns.$(this).val(); |
287 var val = Rkns.$(this).val(); |
286 Rkns._(_this.tabs).each(function(tab) { |
288 if (val === lastval) { |
287 tab.render(val); |
289 return; |
288 }); |
290 } |
|
291 var search = Rkns.Utils.regexpFromTextOrArray(val.length > 1 ? val: null); |
|
292 if (search.source === lastsearch) { |
|
293 return; |
|
294 } |
|
295 lastsearch = search.source; |
|
296 _(_this.tabs).each(function(tab) { |
|
297 tab.render(search); |
|
298 }); |
|
299 |
289 }); |
300 }); |
290 this.$.find(".Rk-Bins-Search-Form").submit(function() { |
301 this.$.find(".Rk-Bins-Search-Form").submit(function() { |
291 return false; |
302 return false; |
292 }); |
303 }); |
293 |
304 |
294 }; |
305 }; |
295 |
306 |
296 Renkan.prototype.template = Rkns._.template( |
307 Renkan.prototype.template = _.template( |
297 '<% if (options.show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>' |
308 '<% if (options.show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>' |
298 + '<form class="Rk-Web-Search-Form Rk-Search-Form"><input class="Rk-Web-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search the Web") %>" />' |
309 + '<form class="Rk-Web-Search-Form Rk-Search-Form"><input class="Rk-Web-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search the Web") %>" />' |
299 + '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
310 + '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
300 + '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" title="<%- translate("Search the Web") %>" /></form>' |
311 + '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" title="<%- translate("Search the Web") %>" /></form>' |
301 + '<form class="Rk-Bins-Search-Form Rk-Search-Form"><input class="Rk-Bins-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search in Bins") %>" />' |
312 + '<form class="Rk-Bins-Search-Form Rk-Search-Form"><input class="Rk-Bins-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search in Bins") %>" />' |
334 }; |
345 }; |
335 |
346 |
336 /* Utility functions */ |
347 /* Utility functions */ |
337 |
348 |
338 Rkns.Utils = { |
349 Rkns.Utils = { |
339 _ID_AUTO_INCREMENT : 0, |
350 getUID : (function() { |
340 _ID_BASE : (function(_d) { |
351 function pad(n){ |
341 |
352 return n<10 ? '0'+n : n; |
342 function pad(n){return n<10 ? '0'+n : n;} |
353 } |
343 function fillrand(n) { |
354 function fillrand(n) { |
344 var _res = ''; |
355 var _res = ''; |
345 for (var i=0; i<n; i++) { |
356 for (var i=0; i<n; i++) { |
346 _res += Math.floor(16*Math.random()).toString(16); |
357 _res += Math.floor(16*Math.random()).toString(16); |
347 } |
358 } |
348 return _res; |
359 return _res; |
349 } |
360 } |
350 return _d.getUTCFullYear() + '-' |
361 var _d = new Date(), |
|
362 ID_AUTO_INCREMENT = 0, |
|
363 ID_BASE = _d.getUTCFullYear() + '-' |
351 + pad(_d.getUTCMonth()+1) + '-' |
364 + pad(_d.getUTCMonth()+1) + '-' |
352 + pad(_d.getUTCDate()) + '-' |
365 + pad(_d.getUTCDate()) + '-' |
353 + fillrand(16); |
366 + fillrand(16); |
354 |
367 return function(_base) { |
355 })(new Date()), |
368 var _n = (++ID_AUTO_INCREMENT).toString(16), |
356 getUID : function(_base) { |
369 _base = (typeof _base === "undefined" ? "" : _base + "-" ); |
357 |
370 while (_n.length < 4) { _n = '0' + _n; } |
358 var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
371 return _base + this._ID_BASE + '-' + _n; |
359 _base = (typeof _base === "undefined" ? "" : _base + "-" ); |
372 } |
360 while (_n.length < 4) { |
373 })(), |
361 _n = '0' + _n; |
|
362 } |
|
363 return _base + this._ID_BASE + '-' + _n; |
|
364 |
|
365 }, |
|
366 getFullURL : function(url) { |
374 getFullURL : function(url) { |
367 |
375 |
368 if(typeof(url) == 'undefined' || url == null ) { |
376 if(typeof(url) == 'undefined' || url == null ) { |
369 return ""; |
377 return ""; |
370 } |
378 } |
388 if (typeof this._init == "function" && !this._initialized) { |
396 if (typeof this._init == "function" && !this._initialized) { |
389 this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
397 this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
390 this._initialized = true; |
398 this._initialized = true; |
391 } |
399 } |
392 }; |
400 }; |
393 Rkns._(_class.prototype).extend(_baseClass.prototype); |
401 _(_class.prototype).extend(_baseClass.prototype); |
394 return _class; |
402 return _class; |
395 |
403 |
396 } |
404 }, |
|
405 regexpFromTextOrArray: (function() { |
|
406 var charsub = [ |
|
407 '[aáàâä]', |
|
408 '[cç]', |
|
409 '[eéèêë]', |
|
410 '[iíìîï]', |
|
411 '[oóòôö]', |
|
412 '[uùûü]' |
|
413 ], |
|
414 removeChars = [ |
|
415 String.fromCharCode(768), String.fromCharCode(769), String.fromCharCode(770), String.fromCharCode(771), String.fromCharCode(807), |
|
416 "{", "}", "(", ")", "[", "]", "【", "】", "、", "・", "‥", "。", "「", "」", "『", "』", "〜", ":", "!", "?", " ", |
|
417 ",", " ", ";", "(", ")", ".", "*", "+", "\\", "?", "|", "{", "}", "[", "]", "^", "#", "/" |
|
418 ], |
|
419 remsrc = "[\\" + removeChars.join("\\") + "]", |
|
420 remrx = new RegExp(remsrc, "gm"), |
|
421 charsrx = _(charsub).map(function(c) { |
|
422 return new RegExp(c); |
|
423 }); |
|
424 |
|
425 function replaceText(_text) { |
|
426 var txt = _text.toLowerCase().replace(remrx,""), src = ""; |
|
427 for (var j = 0; j < txt.length; j++) { |
|
428 if (j) { |
|
429 src += remsrc + "*"; |
|
430 } |
|
431 var l = txt[j]; |
|
432 _(charsub).each(function(v, k) { |
|
433 l = l.replace(charsrx[k], v); |
|
434 }); |
|
435 src += l; |
|
436 } |
|
437 return src; |
|
438 } |
|
439 |
|
440 function getSource(inp) { |
|
441 switch (typeof inp) { |
|
442 case "string": |
|
443 return replaceText(inp); |
|
444 case "object": |
|
445 var src = ''; |
|
446 _(inp).each(function(v) { |
|
447 var res = getSource(v); |
|
448 if (res) { |
|
449 if (src) { |
|
450 src += '|'; |
|
451 } |
|
452 src += res; |
|
453 } |
|
454 }); |
|
455 return src; |
|
456 } |
|
457 return ''; |
|
458 } |
|
459 |
|
460 return function(_textOrArray) { |
|
461 var source = getSource(_textOrArray); |
|
462 if (source) { |
|
463 var testrx = new RegExp( source, "im"), |
|
464 replacerx = new RegExp( '(' + source + ')', "igm") |
|
465 return { |
|
466 isempty: false, |
|
467 source: source, |
|
468 test: function(_t) { return testrx.test(_t) }, |
|
469 replace: function(_text, _replace) { return _text.replace(replacerx, _replace); } |
|
470 } |
|
471 } else { |
|
472 return { |
|
473 isempty: true, |
|
474 source: '', |
|
475 test: function() { return true }, |
|
476 replace: function(_text) { return text } |
|
477 } |
|
478 } |
|
479 } |
|
480 })() |
397 }; |
481 }; |
398 })(window); |
482 })(window); |
399 |
483 |
400 /* END main.js */ |
484 /* END main.js */ |