Search widget with JSONP support. Sample included.
[wolnelektury.git] / wolnelektury / static / js / widgetInit.js
diff --git a/wolnelektury/static/js/widgetInit.js b/wolnelektury/static/js/widgetInit.js
new file mode 100644 (file)
index 0000000..074dbeb
--- /dev/null
@@ -0,0 +1,29 @@
+       $(function() {          
+               $("#id_q").autocomplete({
+                       source: function(request, response) {
+                               $.ajax({
+                                       url: "http://www.wolnelektury.pl/katalog/jtags/",
+                                       dataType: "jsonp",
+                                       data: {
+                                               featureClass: "P",
+                                               style: "full",
+                                               maxRows: 10,
+                                               q: request.term
+                                       },
+                                       success: function(data) {
+                                               response($.map(data.matches, function(item) {
+                                                       return {
+                                                               label: item,
+                                                               value: item
+                                                       }
+                                               }))
+                                       },                                      
+                               })
+                       },
+                       minLength: 2,
+            select: function(event, ui) {
+                $("#id_q").val(ui.item.value);
+                $("#wl-form").submit();
+            }                  
+               });
+       });