| author | veltr |
| Thu, 04 Jul 2013 12:43:30 +0200 | |
| changeset 196 | 2a2fcec209d0 |
| parent 170 | 603ffa4c6fa5 |
| child 293 | fba23fde14ba |
| 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%>" ' |
|
139
9929b1447f69
- Clean template code for list bin
ymh <ymh.work@gmail.com>
parents:
132
diff
changeset
|
7 |
+ 'data-title="<%-title%>" data-description="<%-description%>" ' |
|
9929b1447f69
- Clean template code for list bin
ymh <ymh.work@gmail.com>
parents:
132
diff
changeset
|
8 |
+ '<% if (image) { %>data-image="<%- Rkns.Utils.getFullURL(image) %>"<% } else { %>data-image=""<% } %> >' |
|
9929b1447f69
- Clean template code for list bin
ymh <ymh.work@gmail.com>
parents:
132
diff
changeset
|
9 |
+ '<% if (image) { %><img class="Rk-ResourceList-Image" src="<%-image%>"/><% } %><h4 class="Rk-ResourceList-Title">' |
| 75 | 10 |
+ '<% 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
|
11 |
+ '<% if (description) { %><p class="Rk-ResourceList-Description"><%=hdescription%></p><% } %><% if (image) { %><div style="clear: both;"></div><% } %></li>' |
| 73 | 12 |
); |
13 |
||
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
14 |
Rkns.ResourceList.Bin.prototype._init = function(_renkan, _opts) { |
| 160 | 15 |
this.renkan = _renkan; |
| 73 | 16 |
this.title_$.html(_opts.title); |
17 |
if (_opts.list) { |
|
| 160 | 18 |
this.data = _opts.list; |
| 73 | 19 |
} |
20 |
this.refresh(); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
21 |
}; |
| 73 | 22 |
|
| 196 | 23 |
Rkns.ResourceList.Bin.prototype.render = function(searchbase) { |
24 |
var search = searchbase || Rkns.Utils.regexpFromTextOrArray(); |
|
| 73 | 25 |
function highlight(_text) { |
| 196 | 26 |
var _e = _(_text).escape(); |
27 |
return search.isempty ? _e : search.replace(_e, "<span class='searchmatch'>$1</span>"); |
|
| 73 | 28 |
} |
29 |
var _html = "", |
|
30 |
_this = this, |
|
31 |
count = 0; |
|
| 74 | 32 |
Rkns._(this.data).each(function(_item) { |
| 160 | 33 |
if (typeof _item === "string") { |
34 |
if (/^(https?:\/\/|www)/.test(_item)) { |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
35 |
var _element = { url: _item }; |
| 160 | 36 |
} else { |
37 |
var _element = { title: _item.replace(/[:,]?\s?(https?:\/\/|www)[\d\w\/.&?=#%-_]+\s?/,'').trim() }, |
|
38 |
_match = _item.match(/(https?:\/\/|www)[\d\w\/.&?=#%-_]+/); |
|
39 |
if (_match) { |
|
40 |
_element.url = _match[0]; |
|
41 |
} |
|
42 |
if (_element.title.length > 80) { |
|
43 |
_element.description = _element.title; |
|
44 |
_element.title = _element.title.replace(/^(.{30,60})\s.+$/,'$1…'); |
|
45 |
} |
|
46 |
} |
|
47 |
} else { |
|
48 |
var _element = _item; |
|
49 |
} |
|
| 75 | 50 |
var title = _element.title || (_element.url || "").replace(/^https?:\/\/(www\.)?/,'').replace(/^(.{40}).+$/,'$1…'), |
| 73 | 51 |
url = _element.url || "", |
52 |
description = _element.description || "", |
|
53 |
image = _element.image || ""; |
|
| 75 | 54 |
if (url && !/^https?:\/\//.test(url)) { |
| 160 | 55 |
url = 'http://' + url; |
| 75 | 56 |
} |
| 196 | 57 |
if (!search.isempty && !search.test(title) && !search.test(description)) { |
| 73 | 58 |
return; |
59 |
} |
|
60 |
count++; |
|
61 |
_html += _this.resultTemplate({ |
|
62 |
url: url, |
|
63 |
title: title, |
|
64 |
htitle: highlight(title), |
|
65 |
image: image, |
|
66 |
description: description, |
|
67 |
hdescription: highlight(description), |
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
78
diff
changeset
|
68 |
static_url: _this.renkan.options.static_url |
| 73 | 69 |
}); |
70 |
}); |
|
71 |
_this.main_$.html(_html); |
|
| 196 | 72 |
if (!search.isempty && count) { |
| 73 | 73 |
this.count_$.text(count).show(); |
74 |
} else { |
|
75 |
this.count_$.hide(); |
|
76 |
} |
|
| 196 | 77 |
if (!search.isempty && !count) { |
| 73 | 78 |
this.$.hide(); |
79 |
} else { |
|
80 |
this.$.show(); |
|
81 |
} |
|
82 |
this.renkan.resizeBins(); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
83 |
}; |
| 73 | 84 |
|
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
85 |
Rkns.ResourceList.Bin.prototype.refresh = function() { |
| 73 | 86 |
if (this.data) { |
| 160 | 87 |
this.render(); |
| 73 | 88 |
} |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
89 |
}; |