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