| author | ymh <ymh.work@gmail.com> |
| Sun, 14 Jul 2024 22:00:08 +0200 | |
| changeset 666 | 9d6550026232 |
| parent 647 | eaaa1efce396 |
| permissions | -rw-r--r-- |
| 34 | 1 |
Rkns.Wikipedia = { |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
2 |
}; |
| 34 | 3 |
|
4 |
Rkns.Wikipedia.Search = function(_renkan, _opts) { |
|
5 |
this.renkan = _renkan; |
|
6 |
this.lang = _opts.lang || "en"; |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
7 |
}; |
| 24 | 8 |
|
| 34 | 9 |
Rkns.Wikipedia.Search.prototype.getBgClass = function() { |
10 |
return "Rk-Wikipedia-Search-Icon Rk-Wikipedia-Lang-" + this.lang; |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
11 |
}; |
| 34 | 12 |
|
13 |
Rkns.Wikipedia.Search.prototype.getSearchTitle = function() { |
|
| 160 | 14 |
var langs = { |
15 |
"fr": "French", |
|
16 |
"en": "English", |
|
17 |
"ja": "Japanese" |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
18 |
}; |
| 160 | 19 |
if (langs[this.lang]) { |
20 |
return this.renkan.translate("Wikipedia in ") + this.renkan.translate(langs[this.lang]); |
|
21 |
} else { |
|
22 |
return this.renkan.translate("Wikipedia") + " [" + this.lang + "]"; |
|
23 |
} |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
24 |
}; |
| 34 | 25 |
|
26 |
Rkns.Wikipedia.Search.prototype.search = function(_q) { |
|
27 |
this.renkan.tabs.push( |
|
28 |
new Rkns.Wikipedia.Bin(this.renkan, { |
|
29 |
lang: this.lang, |
|
30 |
search: _q |
|
31 |
}) |
|
32 |
); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
33 |
}; |
| 34 | 34 |
|
35 |
Rkns.Wikipedia.Bin = Rkns.Utils.inherit(Rkns._BaseBin); |
|
36 |
||
37 |
Rkns.Wikipedia.Bin.prototype._init = function(_renkan, _opts) { |
|
| 160 | 38 |
this.renkan = _renkan; |
| 24 | 39 |
this.search = _opts.search; |
|
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
|
40 |
this.resultTemplate = _renkan.options.templates['templates/wikipedia-bin/resulttemplate.html']; |
| 24 | 41 |
this.lang = _opts.lang || "en"; |
| 34 | 42 |
this.title_icon_$.addClass('Rk-Wikipedia-Title-Icon Rk-Wikipedia-Lang-' + this.lang); |
43 |
this.title_$.html(this.search).addClass("Rk-Wikipedia-Title"); |
|
| 42 | 44 |
this.refresh(); |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
45 |
}; |
| 42 | 46 |
|
| 196 | 47 |
Rkns.Wikipedia.Bin.prototype.render = function(searchbase) { |
48 |
var search = searchbase || Rkns.Utils.regexpFromTextOrArray(); |
|
49 |
var highlightrx = (search.isempty ? Rkns.Utils.regexpFromTextOrArray(this.search) : search); |
|
| 44 | 50 |
function highlight(_text) { |
| 196 | 51 |
return highlightrx.replace(_(_text).escape(), "<span class='searchmatch'>$1</span>"); |
| 44 | 52 |
} |
53 |
var _html = "", |
|
| 52 | 54 |
_this = this, |
55 |
count = 0; |
|
| 433 | 56 |
Rkns._.each(this.data.query.search, function(_result) { |
| 44 | 57 |
var title = _result.title, |
58 |
url = "http://" + _this.lang + ".wikipedia.org/wiki/" + encodeURI(title.replace(/ /g,"_")), |
|
59 |
description = Rkns.$('<div>').html(_result.snippet).text(); |
|
| 196 | 60 |
if (!search.isempty && !search.test(title) && !search.test(description)) { |
| 44 | 61 |
return; |
62 |
} |
|
63 |
count++; |
|
64 |
_html += _this.resultTemplate({ |
|
65 |
url: url, |
|
66 |
title: title, |
|
67 |
htitle: highlight(title), |
|
68 |
description: description, |
|
| 56 | 69 |
hdescription: highlight(description), |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
68
diff
changeset
|
70 |
static_url: _this.renkan.options.static_url |
| 44 | 71 |
}); |
72 |
}); |
|
73 |
_this.main_$.html(_html); |
|
| 196 | 74 |
if (!search.isempty && count) { |
| 44 | 75 |
this.count_$.text(count).show(); |
76 |
} else { |
|
77 |
this.count_$.hide(); |
|
78 |
} |
|
| 196 | 79 |
if (!search.isempty && !count) { |
| 44 | 80 |
this.$.hide(); |
81 |
} else { |
|
82 |
this.$.show(); |
|
83 |
} |
|
| 56 | 84 |
this.renkan.resizeBins(); |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
85 |
}; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
196
diff
changeset
|
86 |
|
| 42 | 87 |
Rkns.Wikipedia.Bin.prototype.refresh = function() { |
| 24 | 88 |
var _this = this; |
| 42 | 89 |
Rkns.$.ajax({ |
90 |
url: "http://" + _this.lang + ".wikipedia.org/w/api.php?action=query&list=search&srsearch=" + encodeURIComponent(this.search) + "&format=json", |
|
91 |
dataType: "jsonp", |
|
92 |
success: function(_data) { |
|
| 44 | 93 |
_this.data = _data; |
94 |
_this.render(); |
|
| 24 | 95 |
} |
| 42 | 96 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
196
diff
changeset
|
97 |
}; |