diff -r 70c8af9b44ec -r 121a24be9da4 client/js/wikipedia-bin.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/js/wikipedia-bin.js Tue Aug 21 16:27:26 2012 +0200 @@ -0,0 +1,30 @@ +Rkns.Bins.Wikipedia = Rkns.Utils.inherit(Rkns.Bins._Base); + +Rkns.Bins.Wikipedia.prototype.resultTemplate = Rkns._.template( + '
  • ' + + '

    <%=highlightedtitle%>

    ' + + '

    <%=result.snippet%>

  • ' +); + +Rkns.Bins.Wikipedia.prototype._init = function(_renkan, _opts) { + this.search = _opts.search; + this.lang = _opts.lang || "en"; + this.title_$.html(_opts.title + ': "' + this.search + '"') + var _this = this; + Rkns.$.getJSON( + "http://" + _this.lang + ".wikipedia.org/w/api.php?action=query&list=search&srsearch=" + encodeURIComponent(this.search) + "&format=json&callback=?", + function(_data) { + var _rgxp = new RegExp('('+_this.search.replace(/(\W)/g,'\\$1')+')','gi'), + _html = Rkns._(_data.query.search).map(function(_result) { + return _this.resultTemplate({ + result: _result, + wpurl: "http://" + this.lang + ".wikipedia.org/wiki/" + encodeURI(_result.title.replace(/ /g,"_")), + highlightedtitle: _result.title.replace(_rgxp, "$1"), + wpdesc: Rkns.$('
    ').html(_result.snippet).text() + }); + }).join(""); + _this.main_$.html(_html); + } + ); +} \ No newline at end of file