# HG changeset patch # User veltr # Date 1345559246 -7200 # Node ID 121a24be9da48cf2c7846d12bb70dda5591e9d43 # Parent 70c8af9b44eca4f16f4d2bc04d8627726c090b8f Added Wikipedia Search diff -r 70c8af9b44ec -r 121a24be9da4 client/css/renkan.css --- a/client/css/renkan.css Tue Aug 21 12:46:11 2012 +0200 +++ b/client/css/renkan.css Tue Aug 21 16:27:26 2012 +0200 @@ -114,11 +114,11 @@ } .Rk-Search-Input { - width: 180px; + width: 150px; } .Rk-Search-Select { - width: 100px; + width: 130px; } .Rk-Bin-Title { @@ -130,7 +130,7 @@ overflow: auto; } -.Rk-Twitter-Tweet { +.Rk-Twitter-Tweet, .Rk-Wikipedia-Result { padding: 2px; background: #f8f8f8; border-bottom: 1px solid #cccccc; min-height: 55px; } @@ -142,7 +142,7 @@ margin: 2px 0 2px 50px; } -.Rk-Twitter-TwTitle { +.Rk-Twitter-TwTitle, .Rk-Wikipedia-Title { font-size: 13px; font-weight: bold; } @@ -150,6 +150,10 @@ font-size: 11px; font-style: italic; } -.Rk-Twitter-TwText { +.Rk-Twitter-TwText, .Rk-Wikipedia-Snippet { font-size: 12px; -} \ No newline at end of file +} + +.Rk-Wikipedia-Result .searchmatch, .Rk-Twitter-TwText .searchmatch { + background: #ffff80; +} diff -r 70c8af9b44ec -r 121a24be9da4 client/js/full-json.js --- a/client/js/full-json.js Tue Aug 21 12:46:11 2012 +0200 +++ b/client/js/full-json.js Tue Aug 21 16:27:26 2012 +0200 @@ -7,48 +7,12 @@ } var _load = function() { Rkns.$.getJSON(_opts.url, function(_data) { - _proj.get("users").add(_data.users); - Rkns._(_data.nodes).each(function(_item) { - _proj.addNode(_item); - }); - Rkns._(_data.edges).each(function(_item) { - _proj.addEdge(_item); - }); + console.log("Setting data"); + _proj.set(_data); }); } var _save = function() { - var _data = { - users: _proj.get("users").map(function(_item) { - return { - id: _item.get("id"), - title: _item.get("title"), - uri: _item.get("uri"), - description: _item.get("description"), - color: _item.get("color") - } - }), - nodes: _proj.get("nodes").map(function(_item) { - return { - id: _item.get("id"), - title: _item.get("title"), - uri: _item.get("uri"), - description: _item.get("description"), - position: _item.get("position"), - created_by: _item.get("created_by").get("id") - } - }), - edges: _proj.get("edges").map(function(_item) { - return { - id: _item.get("id"), - title: _item.get("title"), - uri: _item.get("uri"), - description: _item.get("description"), - from: _item.get("from").get("id"), - to: _item.get("to").get("id"), - created_by: _item.get("created_by").get("id") - } - }) - }; + var _data = _proj.toJSON(); Rkns.$.ajax({ type: _opts.http_method, url: _opts.url, diff -r 70c8af9b44ec -r 121a24be9da4 client/js/main.js --- a/client/js/main.js Tue Aug 21 12:46:11 2012 +0200 +++ b/client/js/main.js Tue Aug 21 16:27:26 2012 +0200 @@ -84,24 +84,35 @@ if (!_opts.search.length) { this.$.find(".Rk-Search-Form").detach(); } else { - var _tmpl = Rkns._.template(''); - this.$.find(".Rk-Search-Select").html( - Rkns._(_opts.search).map(function(_name) { - return _tmpl({name:_name}); + var _tmpl = Rkns._.template(''), + _select = this.$.find(".Rk-Search-Select"), + _input = this.$.find(".Rk-Search-Input") + _form = this.$.find(".Rk-Search-Form"); + _select.html( + Rkns._(_opts.search).map(function(_value, _key) { + return _tmpl({ + key: _key, + value: _value + }); }).join("") - ); + ).change(function() { + _form.submit(); + }); + _form.submit(function() { + if (_input.val()) { + var _search = _opts.search[_select.val()]; + _this.tabs.push( + new _search.bin( + _this, + Rkns._({ search: _input.val() }).defaults(_search) + ) + ); + } + return false; + + }); } - this.$.find(".Rk-Search-Form").submit(function() { - _this.tabs.push( - new Rkns.Bins[_this.$.find(".Rk-Search-Select").val()]( - _this, - { - search: _this.$.find(".Rk-Search-Input").val() - } - ) - ); - return false; - }); + this.$.find(".Rk-Bins") .click(function(_e) { if (_e.target.className == "Rk-Bin-Title") { diff -r 70c8af9b44ec -r 121a24be9da4 client/js/models.js --- a/client/js/models.js Tue Aug 21 12:46:11 2012 +0200 +++ b/client/js/models.js Tue Aug 21 16:27:26 2012 +0200 @@ -54,8 +54,16 @@ prepare: function(options) { options.color = options.color || "#666666"; return options; - } - + }, + toJSON: function() { + return { + id: this.get("id"), + title: this.get("title"), + uri: this.get("uri"), + description: this.get("description"), + color: this.get("color"), + } + }, }); // NODE @@ -71,8 +79,17 @@ this.addReference(options, "created_by", project.get("users"), options.created_by, project.current_user); options.description = options.description || ""; return options; - } - + }, + toJSON: function() { + return { + id: this.get("id"), + title: this.get("title"), + uri: this.get("uri"), + description: this.get("description"), + position: this.get("position"), + created_by: this.get("created_by").get("id") + } + }, }); // EDGE @@ -101,7 +118,18 @@ this.addReference(options, "from", project.get("nodes"), options.from); this.addReference(options, "to", project.get("nodes"), options.to); return options; - } + }, + toJSON: function() { + return { + id: this.get("id"), + title: this.get("title"), + uri: this.get("uri"), + description: this.get("description"), + from: this.get("from").get("id"), + to: this.get("to").get("id"), + created_by: this.get("created_by").get("id"), + } + }, }); // PROJECT @@ -160,6 +188,18 @@ removeEdge: function(_model) { this.get("edges").remove(_model); }, + validate: function(options) { + var _project = this; + _(options.users).each(function(_item) { + _item.project = _project; + }); + _(options.nodes).each(function(_item) { + _item.project = _project; + }); + _(options.edges).each(function(_item) { + _item.project = _project; + }); + }, // Add event handler to remove edges when a node is removed initialize: function() { var _this = this; diff -r 70c8af9b44ec -r 121a24be9da4 client/js/twitter-bin.js --- a/client/js/twitter-bin.js Tue Aug 21 12:46:11 2012 +0200 +++ b/client/js/twitter-bin.js Tue Aug 21 16:27:26 2012 +0200 @@ -20,6 +20,10 @@ Rkns.$.getJSON( "http://search.twitter.com/search.json?q=" + encodeURIComponent(this.search) + "&callback=?", function(_data) { + var _rgxp = new RegExp('('+_this.search.replace(/(\W)/g,'\\$1')+')','gi'); + function highlight(_text) { + return _text.replace(_rgxp, "$1"); + } var _html = Rkns._(_data.results).map(function(_result) { var _entities = [], _users = _result.text.match(/@[\w_]+/gm), @@ -72,10 +76,10 @@ _entities = Rkns._(_entities).sortBy(function(a) { return a.start }); var _lastend = 0, _text = Rkns._(_entities).map(function(_e) { - var _txt = _result.text.substring(_lastend, _e.start) + _e.link + _e.text + ''; + var _txt = highlight(_result.text.substring(_lastend, _e.start)) + _e.link + highlight(_e.text) + ''; _lastend = _e.end; return _txt; - }).join("") + _result.text.substring(_lastend); + }).join("") + highlight(_result.text.substring(_lastend)); return _this.tweetTemplate({ tweet: _result, 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( + '
<%=result.snippet%>