|
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%>">' |
|
75
|
6 |
+ '<% if (image) { %><img class="Rk-ListBin-Image" src="<%-image%>"><% } %></div><h4 class="Rk-ListBin-Title">' |
|
|
7 |
+ '<% if (url) { %><a href="<%-url%>" target="_blank"><% } %><%=htitle%><% if (url) { %></a><% } %></h4>' |
|
73
|
8 |
+ '<% if (description) { %><p class="Rk-ListBin-Description"><%=hdescription%></p><% } %><% if (image) { %><div style="clear: both;"></div><% } %></li>' |
|
|
9 |
); |
|
|
10 |
|
|
|
11 |
Rkns.ListBin.prototype._init = function(_renkan, _opts) { |
|
|
12 |
this.renkan = _renkan; |
|
|
13 |
this.title_$.html(_opts.title); |
|
|
14 |
if (_opts.list) { |
|
|
15 |
this.data = _opts.list; |
|
|
16 |
} |
|
|
17 |
this.refresh(); |
|
|
18 |
} |
|
|
19 |
|
|
|
20 |
Rkns.ListBin.prototype.render = function(searchstr) { |
|
|
21 |
if (searchstr) { |
|
|
22 |
var _rgxp = new RegExp('('+(searchstr).replace(/(\W)/g,'\\$1')+')','gi'), |
|
|
23 |
rxtest = new RegExp(searchstr.replace(/(\W)/g,'\\$1'),'i'); |
|
|
24 |
} |
|
|
25 |
function highlight(_text) { |
|
|
26 |
if (searchstr) { |
|
|
27 |
return _text.replace(_rgxp, "<span class='searchmatch'>$1</span>"); |
|
|
28 |
} else { |
|
|
29 |
return _text; |
|
|
30 |
} |
|
|
31 |
} |
|
|
32 |
var _html = "", |
|
|
33 |
_this = this, |
|
|
34 |
count = 0; |
|
74
|
35 |
Rkns._(this.data).each(function(_item) { |
|
75
|
36 |
if (typeof _item === "string") { |
|
|
37 |
if (/^(https?:\/\/|www)/.test(_item)) { |
|
|
38 |
var _element = { url: _item } |
|
|
39 |
} else { |
|
|
40 |
var _element = { title: _item.replace(/[:,]?\s?(https?:\/\/|www)[\d\w\/.&?=#%-_]+\s?/,'').trim() }, |
|
|
41 |
_match = _item.match(/(https?:\/\/|www)[\d\w\/.&?=#%-_]+/); |
|
|
42 |
if (_match) { |
|
|
43 |
_element.url = _match[0]; |
|
|
44 |
} |
|
|
45 |
if (_element.title.length > 80) { |
|
|
46 |
_element.description = _element.title; |
|
|
47 |
_element.title = _element.title.replace(/^(.{30,60})\s.+$/,'$1…'); |
|
|
48 |
} |
|
|
49 |
} |
|
|
50 |
} else { |
|
|
51 |
var _element = _item; |
|
|
52 |
} |
|
|
53 |
var title = _element.title || (_element.url || "").replace(/^https?:\/\/(www\.)?/,'').replace(/^(.{40}).+$/,'$1…'), |
|
73
|
54 |
url = _element.url || "", |
|
|
55 |
description = _element.description || "", |
|
|
56 |
image = _element.image || ""; |
|
75
|
57 |
if (url && !/^https?:\/\//.test(url)) { |
|
|
58 |
url = 'http://' + url; |
|
|
59 |
} |
|
73
|
60 |
if (searchstr && !rxtest.test(title) && !rxtest.test(description)) { |
|
|
61 |
return; |
|
|
62 |
} |
|
|
63 |
count++; |
|
|
64 |
_html += _this.resultTemplate({ |
|
|
65 |
url: url, |
|
|
66 |
title: title, |
|
|
67 |
htitle: highlight(title), |
|
|
68 |
image: image, |
|
|
69 |
description: description, |
|
|
70 |
hdescription: highlight(description), |
|
|
71 |
static_url: _this.renkan.static_url |
|
|
72 |
}); |
|
|
73 |
}); |
|
|
74 |
_this.main_$.html(_html); |
|
|
75 |
if (searchstr && count) { |
|
|
76 |
this.count_$.text(count).show(); |
|
|
77 |
} else { |
|
|
78 |
this.count_$.hide(); |
|
|
79 |
} |
|
|
80 |
if (searchstr && !count) { |
|
|
81 |
this.$.hide(); |
|
|
82 |
} else { |
|
|
83 |
this.$.show(); |
|
|
84 |
} |
|
|
85 |
this.renkan.resizeBins(); |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
Rkns.ListBin.prototype.refresh = function() { |
|
|
89 |
if (this.data) { |
|
|
90 |
this.render(); |
|
|
91 |
} |
|
|
92 |
} |