X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/07a437ef67ffcad01b83255999d2d7744f994d7f..637f96b139a895372c2e90684858c07fb09a709f:/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 550bf2084..09476297f 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'); @@ -41,24 +41,39 @@ var scriptJ = document.createElement('script'); scriptJ.setAttribute('type', 'text/javascript'); scriptJ.setAttribute('src', 'http://'+host+'/static/js/jquery.js'); -var scriptAutoComplete = document.createElement('script'); -scriptAutoComplete.setAttribute('type', 'text/javascript'); -scriptAutoComplete.setAttribute('src', 'http://'+host+'/static/js/jquery-ui-1.8.2.custom.min.js'); -scriptAutoComplete.setAttribute('id', 'wl-jquery-ui-script') +var scriptUI = document.createElement('script'); +scriptUI.setAttribute('type', 'text/javascript'); +scriptUI.setAttribute('src', 'http://'+host+'/static/js/jquery-ui-1.8.2.custom.min.js'); +scriptUI.setAttribute('id', 'wl-jquery-ui-script') var scriptSearch = document.createElement('script'); scriptSearch.setAttribute('type', 'text/javascript'); scriptSearch.setAttribute('src', 'http://'+host+'/static/js/search.js'); scriptSearch.setAttribute('id', 'wl-search-script') -var scriptInit = document.createElement('script'); -scriptInit.setAttribute('type', 'text/javascript'); -scriptInit.setAttribute('src', 'http://'+host+'/static/js/widgetInit.js'); - body[0].appendChild(scriptJ); -body[0].appendChild(scriptAutoComplete); -body[0].appendChild(scriptSearch); -body[0].appendChild(scriptInit); +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"}); +} +scriptSearch.onreadystatechange = function() { if (scriptSearch.readyState == 'complete') { scriptSearch.onload(); } }; /* append elements to widget */ widget.appendChild(stylesheet); @@ -86,3 +101,6 @@ if(widget.getAttribute('width') == '140'){ inputText.setAttribute('size', '10'); widget.style.width = "140px"; } + + +