Close #53 - add auto-completion to HDA Notices research
authorrougeronj
Wed, 11 Feb 2015 11:14:40 +0100
changeset 441 7eee076e994e
parent 440 4c4cfe573486
child 442 3d54acec55d6
Close #53 - add auto-completion to HDA Notices research
src/hdalab/static/hdalab/css/additionnal_renkan.css
src/hdalab/static/hdalab/js/hdalab-renkan-bins.js
--- a/src/hdalab/static/hdalab/css/additionnal_renkan.css	Thu Feb 05 13:18:29 2015 +0100
+++ b/src/hdalab/static/hdalab/css/additionnal_renkan.css	Wed Feb 11 11:14:40 2015 +0100
@@ -19,6 +19,11 @@
     position: relative;
     box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
 }
+
+.ui-autocomplete.ui-widget-content{
+	background: rgb(255, 255, 255);
+}
+
 .Rk-HdaNotices-Title-Icon {
     background: url("../img/page_icon.png") no-repeat -3px -5px;
     height: 20px;
--- a/src/hdalab/static/hdalab/js/hdalab-renkan-bins.js	Thu Feb 05 13:18:29 2015 +0100
+++ b/src/hdalab/static/hdalab/js/hdalab-renkan-bins.js	Wed Feb 11 11:14:40 2015 +0100
@@ -8,6 +8,29 @@
     this.lang = _opts.lang || "fr";
     this.image = _opts.image;
     this.url = _opts.url;
+    this.autoComplete();
+};
+
+Rkns.HdaNotices.Search.prototype.autoComplete = function() {
+    var _this = this;
+    this.renkan.$.find(".Rk-Web-Search-Input").on("change keyup paste", function() {
+        if (_this.renkan.$.find(".Rk-Search-Current").hasClass(_this.getBgClass())){
+	    	$.ajax({
+	            url: _this.url + "?q=" + _this.renkan.$.find(".Rk-Web-Search-Input").val() + "&format=json&limit=10",
+	            success: function(data){
+	            	var results = [];
+	            	if (typeof(data.results) != 'undefined'){
+	            		data.results.forEach(function(result){
+	                		results.push(result.title);
+	                	});
+	                  	_this.renkan.$.find(".Rk-Web-Search-Input").autocomplete({
+	                  		source: results
+	                  	});
+	            	}
+	            }
+	        });
+        }
+    });
 };
 
 Rkns.HdaNotices.Search.prototype.getBgClass = function() {