jsonp
authorMarcin Koziej <marcin@lolownia.org>
Thu, 17 May 2012 11:19:30 +0000 (13:19 +0200)
committerMarcin Koziej <marcin@lolownia.org>
Thu, 17 May 2012 11:19:30 +0000 (13:19 +0200)
apps/wolnelektury_core/static/js/search.js
apps/wolnelektury_core/static/js/widget.js
apps/wolnelektury_core/static/js/widgetInit.js [deleted file]

index 3b6ea40..0b8dd39 100644 (file)
@@ -11,12 +11,23 @@ var __bind = function (self, fn) {
         },
 
        _create: function() {
+            console.log("dataType: " + this.options.dataType);
+            var url = this.element.data('source');
            var opts = { 
                minLength: this.options.minLength,
                select: __bind(this, this.enter),
                focus: function() { return false; },
-               source: this.element.data('source'),
-               dataType: options.dataType,
+               source: function(req, cb) {
+                    $.ajax({url: url,
+                            dataType: "jsonp",
+                            type: "GET",
+                            success: function(data) {
+                                cb(data);
+                            },
+                            error: function() { cb([]); }
+
+                });
+                },
            };
 
            this.element.autocomplete($.extend(opts, this.options))
index 275e9f5..48eeb87 100644 (file)
@@ -60,7 +60,7 @@ scriptUI.onreadystatechange = function() { if (scriptUI.readyState == 'complete'
 
 scriptSearch.onload = function() {
        var s = $('#id_qq');
-       s.search({source: s.attr('data-source')});
+       s.search({source: s.attr('data-source'), dataType: "jsonp"});
 }
 scriptSearch.onreadystatechange = function() { if (scriptSearch.readyState == 'complete') { scriptSearch.onload(); } };
 
diff --git a/apps/wolnelektury_core/static/js/widgetInit.js b/apps/wolnelektury_core/static/js/widgetInit.js
deleted file mode 100644 (file)
index 4cfa85a..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-
-var wl_scripts_loaded = {};
-
-function wl_load_search_if_ready(id) {
-    wl_scripts_loaded[id] = true;
-    if (wl_scripts_loaded['wl-search-script'] &&
-       wl_scripts_loaded['wl-jquery-ui-script']) 
-    {
-       var s = $('#id_qq');
-       s.search({source: s.attr('data-source')});
-    }
-}
-
-$('#wl-search-script').ready(function(){wl_load_search_if_ready('wl-search-script');});
-$('#wl-jquery-ui-script').ready(function(){wl_load_search_if_ready('wl-jquery-ui-script');});
-
-/*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_qq").val(ui.item.value);
-                $("#wl-form").submit();
-            }                  
-               });
-       });
-*/