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