| author | veltr |
| Fri, 07 Sep 2012 17:50:17 +0200 | |
| changeset 39 | 84eea249ce7e |
| parent 37 | db991a757015 |
| child 42 | 48d825187d67 |
| permissions | -rw-r--r-- |
| 34 | 1 |
Rkns.Wikipedia = { |
2 |
} |
|
3 |
||
4 |
Rkns.Wikipedia.Search = function(_renkan, _opts) { |
|
5 |
this.renkan = _renkan; |
|
6 |
this.lang = _opts.lang || "en"; |
|
7 |
} |
|
| 24 | 8 |
|
| 34 | 9 |
Rkns.Wikipedia.Search.prototype.getBgClass = function() { |
10 |
return "Rk-Wikipedia-Search-Icon Rk-Wikipedia-Lang-" + this.lang; |
|
11 |
} |
|
12 |
||
13 |
Rkns.Wikipedia.Search.prototype.getSearchTitle = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
14 |
return ( this.renkan.l10n["wiki_" + this.lang] || this.renkan.l10n.wiki_) ; |
| 34 | 15 |
} |
16 |
||
17 |
Rkns.Wikipedia.Search.prototype.search = function(_q) { |
|
18 |
this.renkan.tabs.push( |
|
19 |
new Rkns.Wikipedia.Bin(this.renkan, { |
|
20 |
lang: this.lang, |
|
21 |
search: _q |
|
22 |
}) |
|
23 |
); |
|
24 |
} |
|
25 |
||
26 |
Rkns.Wikipedia.Bin = Rkns.Utils.inherit(Rkns._BaseBin); |
|
27 |
||
28 |
Rkns.Wikipedia.Bin.prototype.resultTemplate = Rkns._.template( |
|
| 24 | 29 |
'<li class="Rk-Wikipedia-Result Rk-Bin-Item" data-uri="<%=wpurl%>" ' |
| 37 | 30 |
+ 'data-title="Wikipedia: <%=result.title%>" data-description="<%=wpdesc%>" data-image="img/wikipedia.png">' |
31 |
+ '<img class="Rk-Wikipedia-Icon" src="img/wikipedia.png"></div><h4 class="Rk-Wikipedia-Title"><a href="<%=wpurl%>" target="_blank"><%=highlightedtitle%></a></h4>' |
|
| 24 | 32 |
+ '<p class="Rk-Wikipedia-Snippet"><%=result.snippet%></p></li>' |
33 |
); |
|
34 |
||
| 34 | 35 |
Rkns.Wikipedia.Bin.prototype._init = function(_renkan, _opts) { |
| 24 | 36 |
this.search = _opts.search; |
37 |
this.lang = _opts.lang || "en"; |
|
| 34 | 38 |
this.title_icon_$.addClass('Rk-Wikipedia-Title-Icon Rk-Wikipedia-Lang-' + this.lang); |
39 |
this.title_$.html(this.search).addClass("Rk-Wikipedia-Title"); |
|
| 24 | 40 |
var _this = this; |
41 |
Rkns.$.getJSON( |
|
42 |
"http://" + _this.lang + ".wikipedia.org/w/api.php?action=query&list=search&srsearch=" + encodeURIComponent(this.search) + "&format=json&callback=?", |
|
43 |
function(_data) { |
|
44 |
var _rgxp = new RegExp('('+_this.search.replace(/(\W)/g,'\\$1')+')','gi'), |
|
45 |
_html = Rkns._(_data.query.search).map(function(_result) { |
|
46 |
return _this.resultTemplate({ |
|
47 |
result: _result, |
|
| 25 | 48 |
wpurl: "http://" + _this.lang + ".wikipedia.org/wiki/" + encodeURI(_result.title.replace(/ /g,"_")), |
| 24 | 49 |
highlightedtitle: _result.title.replace(_rgxp, "<span class='searchmatch'>$1</span>"), |
50 |
wpdesc: Rkns.$('<div>').html(_result.snippet).text() |
|
51 |
}); |
|
52 |
}).join(""); |
|
53 |
_this.main_$.html(_html); |
|
| 26 | 54 |
_renkan.resizeBins(); |
| 24 | 55 |
} |
56 |
); |
|
57 |
} |