X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/4fb0bfd1b7351af7d83a2cc69e7fca666a359160..948866cb20453892f057d497b3abf6d4b0677d8e:/apps/wolnelektury_core/static/js/widget.js diff --git a/apps/wolnelektury_core/static/js/widget.js b/apps/wolnelektury_core/static/js/widget.js index 2d9a42bb3..abadfd9cf 100644 --- a/apps/wolnelektury_core/static/js/widget.js +++ b/apps/wolnelektury_core/static/js/widget.js @@ -10,7 +10,7 @@ var body = document.getElementsByTagName('body') var stylesheet = document.createElement('link'); var stylesheetJQUI = document.createElement('linl'); -var host = 'localhost:8000'; //'www.wolnelektury.pl'; +var host = 'wolnelektury.pl'; /* set attributes of created elements */ stylesheet.setAttribute('type', 'text/css'); @@ -51,10 +51,30 @@ scriptSearch.setAttribute('type', 'text/javascript'); scriptSearch.setAttribute('src', 'http://'+host+'/static/js/search.js'); scriptSearch.setAttribute('id', 'wl-search-script') - body[0].appendChild(scriptJ); -body[0].appendChild(scriptUI); -body[0].appendChild(scriptSearch); +scriptJ.onload = function() { body[0].appendChild(scriptUI); }; +scriptJ.onreadystatechange = function() { if (scriptJ.readyState == 'complete') { scriptJ.onload(); } }; + +scriptUI.onload = function() { body[0].appendChild(scriptSearch); }; +scriptUI.onreadystatechange = function() { if (scriptUI.readyState == 'complete') { scriptUI.onload(); } }; + +scriptSearch.onload = function() { + var s = $('#id_qq'); + var url = s.attr('data-source'); + s.search({source: + function(req, cb) { + $.ajax({url: url, + dataType: "jsonp", + data: { term: req.term }, + type: "GET", + success: function(data) { cb(data); }, + error: function() { cb([]); } + }); + }, + dataType: "jsonp", + host: "http://"+host}); +} +scriptSearch.onreadystatechange = function() { if (scriptSearch.readyState == 'complete') { scriptSearch.onload(); } }; /* append elements to widget */ widget.appendChild(stylesheet); @@ -83,18 +103,5 @@ if(widget.getAttribute('width') == '140'){ widget.style.width = "140px"; } -var wl_loaded_scripts = {}; -function wl_initialize_after_load(just_loaded) { - wl_loaded_scripts[just_loaded] = true; - if (wl_loaded_scripts.jquery - && wl_loaded_scripts.ui - && wl_loaded_scripts.search) { - var s = $('#id_qq'); - s.search({source: s.attr('data-source')}); - } -} -scriptJ.onload = function() { wl_initialize_after_load('jquery'); }; -scriptUI.onload = function() { wl_initialize_after_load('ui'); }; -scriptSearch.onload = function() { wl_initialize_after_load('search'); };