X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/2c968d7bbf97b820439c6a997de08cc3411abb07..a5d0aab8bef13d4fd4ea19c6b08d703453f3f47d:/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 de30eb714..f9cf53e13 100644 --- a/apps/wolnelektury_core/static/js/widget.js +++ b/apps/wolnelektury_core/static/js/widget.js @@ -8,16 +8,20 @@ var inputText = document.createElement('input'); var inputSubmit = document.createElement('input'); var body = document.getElementsByTagName('body') var stylesheet = document.createElement('link'); +var stylesheetJQUI = document.createElement('linl'); -var host = 'www.wolnelektury.pl'; +var host = 'wolnelektury.pl'; /* set attributes of created elements */ stylesheet.setAttribute('type', 'text/css'); stylesheet.setAttribute('rel', 'stylesheet'); -stylesheet.setAttribute('href', 'http://'+host+'/static/css/widget.css'); -linkLogo.setAttribute('href', 'http://'+host); -logo.setAttribute('src', 'http://'+host+'/static/img/logo.png'); -form.setAttribute('action', 'http://'+host+'/szukaj/'); +stylesheet.setAttribute('href', '//'+host+'/static/css/widget.css'); +stylesheetJQUI.setAttribute('type', 'text/css'); +stylesheetJQUI.setAttribute('rel', 'stylesheet'); +stylesheetJQUI.setAttribute('href', '//'+host+'/static/css/ui-lightness/jquery-ui-1.8.16.custom.css'); +linkLogo.setAttribute('href', '//'+host); +logo.setAttribute('src', '//'+host+'/static/img/logo-bez.png'); +form.setAttribute('action', '//'+host+'/szukaj/'); form.setAttribute('method', 'get'); form.setAttribute('accept-charset', 'utf-8'); form.setAttribute('id', 'wl-form'); @@ -26,30 +30,55 @@ inputText.setAttribute('title', 'tytul, autor, motyw/temat, epoka, rodzaj, gatun inputText.setAttribute('value', ''); inputText.setAttribute('name', 'q'); inputText.setAttribute('id', 'id_qq'); -inputText.setAttribute('size', '13'); +inputText.setAttribute('data-source', '//'+host+'/szukaj/hint/'); +/*inputText.setAttribute('size', '13');*/ inputSubmit.setAttribute('type', 'image'); -inputSubmit.setAttribute('src', 'http://'+host+'/static/img/search.png'); -inputSubmit.setAttribute('style', 'position:relative; top:5px; margin-left:5px'); +inputSubmit.setAttribute('src', '//'+host+'/static/img/search.png'); +/* inputSubmit.setAttribute('style', 'position:relative; top:5px; margin-left:5px');*/ /* import jquery and autocomplete */ var scriptJ = document.createElement('script'); scriptJ.setAttribute('type', 'text/javascript'); -scriptJ.setAttribute('src', 'http://'+host+'/static/js/jquery.js'); +scriptJ.setAttribute('src', '//'+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'); +var scriptUI = document.createElement('script'); +scriptUI.setAttribute('type', 'text/javascript'); +scriptUI.setAttribute('src', '//'+host+'/static/js/jquery-ui-1.8.2.custom.min.js'); +scriptUI.setAttribute('id', 'wl-jquery-ui-script') -var scriptInit = document.createElement('script'); -scriptInit.setAttribute('type', 'text/javascript'); -scriptInit.setAttribute('src', 'http://'+host+'/static/js/widgetInit.js'); +var scriptSearch = document.createElement('script'); +scriptSearch.setAttribute('type', 'text/javascript'); +scriptSearch.setAttribute('src', '//'+host+'/static/js/search.js'); +scriptSearch.setAttribute('id', 'wl-search-script') body[0].appendChild(scriptJ); -body[0].appendChild(scriptAutoComplete); -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", + host: "//"+host}); +} +scriptSearch.onreadystatechange = function() { if (scriptSearch.readyState == 'complete') { scriptSearch.onload(); } }; /* append elements to widget */ widget.appendChild(stylesheet); +//widget.appendChild(stylesheetJQUI); widget.appendChild(linkLogo); linkLogo.appendChild(logo); widget.appendChild(form); @@ -57,6 +86,7 @@ form.appendChild(inputText); form.appendChild(inputSubmit); /* ...and a little make-up */ +/* widget.style.borderColor = "#84BF2A"; widget.style.borderWidth = "2px"; widget.style.borderStyle = "solid"; @@ -64,6 +94,7 @@ widget.style.width = "160px"; widget.style.padding = "10px"; widget.style.fontSize = "12px"; form.style.paddingTop = "10px"; +*/ /* resize - if needed */ if(widget.getAttribute('width') == '140'){ @@ -71,3 +102,6 @@ if(widget.getAttribute('width') == '140'){ inputText.setAttribute('size', '10'); widget.style.width = "140px"; } + + +