|
34
|
1 |
Rkns.Wikipedia = { |
|
|
2 |
i18n: { |
|
|
3 |
en: { |
|
|
4 |
wiki_fr: "French Wikipedia", |
|
|
5 |
wiki_en: "English Wikipedia", |
|
|
6 |
wiki_ja: "Japanese Wikipedia", |
|
|
7 |
wiki_: "Wikipedia (Other Language)" |
|
|
8 |
} |
|
|
9 |
} |
|
|
10 |
} |
|
|
11 |
|
|
|
12 |
Rkns.Wikipedia.Search = function(_renkan, _opts) { |
|
|
13 |
this.renkan = _renkan; |
|
|
14 |
this.lang = _opts.lang || "en"; |
|
|
15 |
} |
|
24
|
16 |
|
|
34
|
17 |
Rkns.Wikipedia.Search.prototype.getBgClass = function() { |
|
|
18 |
return "Rk-Wikipedia-Search-Icon Rk-Wikipedia-Lang-" + this.lang; |
|
|
19 |
} |
|
|
20 |
|
|
|
21 |
Rkns.Wikipedia.Search.prototype.getSearchTitle = function() { |
|
|
22 |
var _lang = Rkns.Wikipedia.i18n[this.renkan.lang] || Rkns.Wikipedia.i18n['en']; |
|
|
23 |
return ( _lang["wiki_" + this.lang] || _lang.wiki_) ; |
|
|
24 |
} |
|
|
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 |
); |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
Rkns.Wikipedia.Bin = Rkns.Utils.inherit(Rkns._BaseBin); |
|
|
36 |
|
|
|
37 |
Rkns.Wikipedia.Bin.prototype.resultTemplate = Rkns._.template( |
|
24
|
38 |
'<li class="Rk-Wikipedia-Result Rk-Bin-Item" data-uri="<%=wpurl%>" ' |
|
|
39 |
+ 'data-title="Wikipedia: <%=result.title%>" data-description="<%=wpdesc%>">' |
|
26
|
40 |
+ '<div class="Rk-Wikipedia-Icon"></div><h4 class="Rk-Wikipedia-Title"><a href="<%=wpurl%>" target="_blank"><%=highlightedtitle%></a></h4>' |
|
24
|
41 |
+ '<p class="Rk-Wikipedia-Snippet"><%=result.snippet%></p></li>' |
|
|
42 |
); |
|
|
43 |
|
|
34
|
44 |
Rkns.Wikipedia.Bin.prototype._init = function(_renkan, _opts) { |
|
24
|
45 |
this.search = _opts.search; |
|
|
46 |
this.lang = _opts.lang || "en"; |
|
34
|
47 |
var _lang = Rkns.Wikipedia.i18n[this.renkan.lang] || Rkns.Wikipedia.i18n['en']; |
|
|
48 |
this.title_icon_$.addClass('Rk-Wikipedia-Title-Icon Rk-Wikipedia-Lang-' + this.lang); |
|
|
49 |
this.title_$.html(this.search).addClass("Rk-Wikipedia-Title"); |
|
24
|
50 |
var _this = this; |
|
|
51 |
Rkns.$.getJSON( |
|
|
52 |
"http://" + _this.lang + ".wikipedia.org/w/api.php?action=query&list=search&srsearch=" + encodeURIComponent(this.search) + "&format=json&callback=?", |
|
|
53 |
function(_data) { |
|
|
54 |
var _rgxp = new RegExp('('+_this.search.replace(/(\W)/g,'\\$1')+')','gi'), |
|
|
55 |
_html = Rkns._(_data.query.search).map(function(_result) { |
|
|
56 |
return _this.resultTemplate({ |
|
|
57 |
result: _result, |
|
25
|
58 |
wpurl: "http://" + _this.lang + ".wikipedia.org/wiki/" + encodeURI(_result.title.replace(/ /g,"_")), |
|
24
|
59 |
highlightedtitle: _result.title.replace(_rgxp, "<span class='searchmatch'>$1</span>"), |
|
|
60 |
wpdesc: Rkns.$('<div>').html(_result.snippet).text() |
|
|
61 |
}); |
|
|
62 |
}).join(""); |
|
|
63 |
_this.main_$.html(_html); |
|
26
|
64 |
_renkan.resizeBins(); |
|
24
|
65 |
} |
|
|
66 |
); |
|
|
67 |
} |