|
24
|
1 |
Rkns.Bins.Wikipedia = Rkns.Utils.inherit(Rkns.Bins._Base); |
|
|
2 |
|
|
|
3 |
Rkns.Bins.Wikipedia.prototype.resultTemplate = Rkns._.template( |
|
|
4 |
'<li class="Rk-Wikipedia-Result Rk-Bin-Item" data-uri="<%=wpurl%>" ' |
|
|
5 |
+ 'data-title="Wikipedia: <%=result.title%>" data-description="<%=wpdesc%>">' |
|
|
6 |
+ '<h4 class="Rk-Wikipedia-Title"><a href="<%=wpurl%>" target="_blank"><%=highlightedtitle%></a></h4>' |
|
|
7 |
+ '<p class="Rk-Wikipedia-Snippet"><%=result.snippet%></p></li>' |
|
|
8 |
); |
|
|
9 |
|
|
|
10 |
Rkns.Bins.Wikipedia.prototype._init = function(_renkan, _opts) { |
|
|
11 |
this.search = _opts.search; |
|
|
12 |
this.lang = _opts.lang || "en"; |
|
|
13 |
this.title_$.html(_opts.title + ': "' + this.search + '"') |
|
|
14 |
var _this = this; |
|
|
15 |
Rkns.$.getJSON( |
|
|
16 |
"http://" + _this.lang + ".wikipedia.org/w/api.php?action=query&list=search&srsearch=" + encodeURIComponent(this.search) + "&format=json&callback=?", |
|
|
17 |
function(_data) { |
|
|
18 |
var _rgxp = new RegExp('('+_this.search.replace(/(\W)/g,'\\$1')+')','gi'), |
|
|
19 |
_html = Rkns._(_data.query.search).map(function(_result) { |
|
|
20 |
return _this.resultTemplate({ |
|
|
21 |
result: _result, |
|
25
|
22 |
wpurl: "http://" + _this.lang + ".wikipedia.org/wiki/" + encodeURI(_result.title.replace(/ /g,"_")), |
|
24
|
23 |
highlightedtitle: _result.title.replace(_rgxp, "<span class='searchmatch'>$1</span>"), |
|
|
24 |
wpdesc: Rkns.$('<div>').html(_result.snippet).text() |
|
|
25 |
}); |
|
|
26 |
}).join(""); |
|
|
27 |
_this.main_$.html(_html); |
|
|
28 |
} |
|
|
29 |
); |
|
|
30 |
} |