From 2e7619a7bc917eb1a5514af07ce4258e461f74ec Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Thu, 17 May 2012 13:19:30 +0200 Subject: [PATCH] jsonp --- apps/wolnelektury_core/static/js/search.js | 15 ++++++- apps/wolnelektury_core/static/js/widget.js | 2 +- .../wolnelektury_core/static/js/widgetInit.js | 45 ------------------- 3 files changed, 14 insertions(+), 48 deletions(-) delete mode 100644 apps/wolnelektury_core/static/js/widgetInit.js diff --git a/apps/wolnelektury_core/static/js/search.js b/apps/wolnelektury_core/static/js/search.js index 3b6ea4043..0b8dd394a 100644 --- a/apps/wolnelektury_core/static/js/search.js +++ b/apps/wolnelektury_core/static/js/search.js @@ -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)) diff --git a/apps/wolnelektury_core/static/js/widget.js b/apps/wolnelektury_core/static/js/widget.js index 275e9f525..48eeb874d 100644 --- a/apps/wolnelektury_core/static/js/widget.js +++ b/apps/wolnelektury_core/static/js/widget.js @@ -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 index 4cfa85a26..000000000 --- a/apps/wolnelektury_core/static/js/widgetInit.js +++ /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(); - } - }); - }); -*/ -- 2.20.1