|
73
|
1 |
Rkns.ListBin = Rkns.Utils.inherit(Rkns._BaseBin); |
|
|
2 |
|
|
|
3 |
Rkns.ListBin.prototype.resultTemplate = Rkns._.template( |
|
|
4 |
'<li class="Rk-Bin-Item Rk-ListBin-Item" draggable="true" data-uri="<%-url%>" ' |
|
|
5 |
+ 'data-title="<%-title%>" data-description="<%-description%>" data-image="<%-image%>">' |
|
|
6 |
+ '<% if (image) { %><img class="Rk-ListBin-Image" src="<%-image%>"><% } %></div><h4 class="Rk-ListBin-Title"><a href="<%-url%>" target="_blank"><%=htitle%></a></h4>' |
|
|
7 |
+ '<% if (description) { %><p class="Rk-ListBin-Description"><%=hdescription%></p><% } %><% if (image) { %><div style="clear: both;"></div><% } %></li>' |
|
|
8 |
); |
|
|
9 |
|
|
|
10 |
Rkns.ListBin.prototype._init = function(_renkan, _opts) { |
|
|
11 |
this.renkan = _renkan; |
|
|
12 |
this.title_$.html(_opts.title); |
|
|
13 |
if (_opts.list) { |
|
|
14 |
this.data = _opts.list; |
|
|
15 |
} |
|
|
16 |
this.refresh(); |
|
|
17 |
} |
|
|
18 |
|
|
|
19 |
Rkns.ListBin.prototype.render = function(searchstr) { |
|
|
20 |
if (searchstr) { |
|
|
21 |
var _rgxp = new RegExp('('+(searchstr).replace(/(\W)/g,'\\$1')+')','gi'), |
|
|
22 |
rxtest = new RegExp(searchstr.replace(/(\W)/g,'\\$1'),'i'); |
|
|
23 |
} |
|
|
24 |
function highlight(_text) { |
|
|
25 |
if (searchstr) { |
|
|
26 |
return _text.replace(_rgxp, "<span class='searchmatch'>$1</span>"); |
|
|
27 |
} else { |
|
|
28 |
return _text; |
|
|
29 |
} |
|
|
30 |
} |
|
|
31 |
var _html = "", |
|
|
32 |
_this = this, |
|
|
33 |
count = 0; |
|
|
34 |
Rkns._(this.data).each(function(_element) { |
|
|
35 |
var title = _element.title || _element.url || "", |
|
|
36 |
url = _element.url || "", |
|
|
37 |
description = _element.description || "", |
|
|
38 |
image = _element.image || ""; |
|
|
39 |
if (searchstr && !rxtest.test(title) && !rxtest.test(description)) { |
|
|
40 |
return; |
|
|
41 |
} |
|
|
42 |
count++; |
|
|
43 |
_html += _this.resultTemplate({ |
|
|
44 |
url: url, |
|
|
45 |
title: title, |
|
|
46 |
htitle: highlight(title), |
|
|
47 |
image: image, |
|
|
48 |
description: description, |
|
|
49 |
hdescription: highlight(description), |
|
|
50 |
static_url: _this.renkan.static_url |
|
|
51 |
}); |
|
|
52 |
}); |
|
|
53 |
_this.main_$.html(_html); |
|
|
54 |
if (searchstr && count) { |
|
|
55 |
this.count_$.text(count).show(); |
|
|
56 |
} else { |
|
|
57 |
this.count_$.hide(); |
|
|
58 |
} |
|
|
59 |
if (searchstr && !count) { |
|
|
60 |
this.$.hide(); |
|
|
61 |
} else { |
|
|
62 |
this.$.show(); |
|
|
63 |
} |
|
|
64 |
this.renkan.resizeBins(); |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
Rkns.ListBin.prototype.refresh = function() { |
|
|
68 |
if (this.data) { |
|
|
69 |
this.render(); |
|
|
70 |
} |
|
|
71 |
} |