| author | ymh <ymh.work@gmail.com> |
| Sat, 25 Apr 2015 04:13:53 +0200 | |
| changeset 433 | e457ec945e50 |
| parent 426 | 05ed0d95a511 |
| child 647 | eaaa1efce396 |
| 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 |
|
|
426
05ed0d95a511
split templates in main, list-bin and wikipedia-bin
rougeronj
parents:
293
diff
changeset
|
5 |
Rkns.ResourceList.Bin.prototype.resultTemplate = renkanJST['templates/list-bin.html']; |
| 73 | 6 |
|
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
7 |
Rkns.ResourceList.Bin.prototype._init = function(_renkan, _opts) { |
| 160 | 8 |
this.renkan = _renkan; |
| 73 | 9 |
this.title_$.html(_opts.title); |
10 |
if (_opts.list) { |
|
| 160 | 11 |
this.data = _opts.list; |
| 73 | 12 |
} |
13 |
this.refresh(); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
14 |
}; |
| 73 | 15 |
|
| 196 | 16 |
Rkns.ResourceList.Bin.prototype.render = function(searchbase) { |
17 |
var search = searchbase || Rkns.Utils.regexpFromTextOrArray(); |
|
| 73 | 18 |
function highlight(_text) { |
| 196 | 19 |
var _e = _(_text).escape(); |
20 |
return search.isempty ? _e : search.replace(_e, "<span class='searchmatch'>$1</span>"); |
|
| 73 | 21 |
} |
22 |
var _html = "", |
|
23 |
_this = this, |
|
24 |
count = 0; |
|
| 433 | 25 |
Rkns._.each(this.data,function(_item) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
196
diff
changeset
|
26 |
var _element; |
| 160 | 27 |
if (typeof _item === "string") { |
28 |
if (/^(https?:\/\/|www)/.test(_item)) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
196
diff
changeset
|
29 |
_element = { url: _item }; |
| 160 | 30 |
} else { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
196
diff
changeset
|
31 |
_element = { title: _item.replace(/[:,]?\s?(https?:\/\/|www)[\d\w\/.&?=#%-_]+\s?/,'').trim() }; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
196
diff
changeset
|
32 |
var _match = _item.match(/(https?:\/\/|www)[\d\w\/.&?=#%-_]+/); |
| 160 | 33 |
if (_match) { |
34 |
_element.url = _match[0]; |
|
35 |
} |
|
36 |
if (_element.title.length > 80) { |
|
37 |
_element.description = _element.title; |
|
38 |
_element.title = _element.title.replace(/^(.{30,60})\s.+$/,'$1…'); |
|
39 |
} |
|
40 |
} |
|
41 |
} else { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
196
diff
changeset
|
42 |
_element = _item; |
| 160 | 43 |
} |
| 75 | 44 |
var title = _element.title || (_element.url || "").replace(/^https?:\/\/(www\.)?/,'').replace(/^(.{40}).+$/,'$1…'), |
| 73 | 45 |
url = _element.url || "", |
46 |
description = _element.description || "", |
|
47 |
image = _element.image || ""; |
|
| 75 | 48 |
if (url && !/^https?:\/\//.test(url)) { |
| 160 | 49 |
url = 'http://' + url; |
| 75 | 50 |
} |
| 196 | 51 |
if (!search.isempty && !search.test(title) && !search.test(description)) { |
| 73 | 52 |
return; |
53 |
} |
|
54 |
count++; |
|
55 |
_html += _this.resultTemplate({ |
|
56 |
url: url, |
|
57 |
title: title, |
|
58 |
htitle: highlight(title), |
|
59 |
image: image, |
|
60 |
description: description, |
|
61 |
hdescription: highlight(description), |
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
78
diff
changeset
|
62 |
static_url: _this.renkan.options.static_url |
| 73 | 63 |
}); |
64 |
}); |
|
65 |
_this.main_$.html(_html); |
|
| 196 | 66 |
if (!search.isempty && count) { |
| 73 | 67 |
this.count_$.text(count).show(); |
68 |
} else { |
|
69 |
this.count_$.hide(); |
|
70 |
} |
|
| 196 | 71 |
if (!search.isempty && !count) { |
| 73 | 72 |
this.$.hide(); |
73 |
} else { |
|
74 |
this.$.show(); |
|
75 |
} |
|
76 |
this.renkan.resizeBins(); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
77 |
}; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
196
diff
changeset
|
78 |
|
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
79 |
Rkns.ResourceList.Bin.prototype.refresh = function() { |
| 73 | 80 |
if (this.data) { |
| 160 | 81 |
this.render(); |
| 73 | 82 |
} |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
196
diff
changeset
|
83 |
}; |