1 /* create basic elements */
 
   3 var widget      = document.getElementById(id);
 
   4 var linkLogo    = document.createElement('a');
 
   5 var logo        = document.createElement('img');
 
   6 var form        = document.createElement('form');
 
   7 var inputText   = document.createElement('input');
 
   8 var inputSubmit = document.createElement('input');
 
   9 var body        = document.getElementsByTagName('body')
 
  10 var stylesheet = document.createElement('link');
 
  11 var stylesheetJQUI = document.createElement('linl');
 
  13 var host = 'www.wolnelektury.pl';
 
  15 /* set attributes of created elements */
 
  16 stylesheet.setAttribute('type', 'text/css');
 
  17 stylesheet.setAttribute('rel', 'stylesheet');
 
  18 stylesheet.setAttribute('href', 'http://'+host+'/static/css/widget.css');
 
  19 stylesheetJQUI.setAttribute('type', 'text/css');
 
  20 stylesheetJQUI.setAttribute('rel', 'stylesheet');
 
  21 stylesheetJQUI.setAttribute('href', 'http://'+host+'/static/css/ui-lightness/jquery-ui-1.8.16.custom.css');
 
  22 linkLogo.setAttribute('href', 'http://'+host);
 
  23 logo.setAttribute('src', 'http://'+host+'/static/img/logo-bez.png');
 
  24 form.setAttribute('action', 'http://'+host+'/szukaj/');
 
  25 form.setAttribute('method', 'get');
 
  26 form.setAttribute('accept-charset', 'utf-8');
 
  27 form.setAttribute('id', 'wl-form');
 
  28 inputText.setAttribute('type', 'text');
 
  29 inputText.setAttribute('title', 'tytul, autor, motyw/temat, epoka, rodzaj, gatunek');
 
  30 inputText.setAttribute('value', '');
 
  31 inputText.setAttribute('name', 'q');
 
  32 inputText.setAttribute('id', 'id_qq');
 
  33 inputText.setAttribute('data-source', 'http://'+host+'/szukaj/hint');
 
  34 /*inputText.setAttribute('size', '13');*/
 
  35 inputSubmit.setAttribute('type', 'image');
 
  36 inputSubmit.setAttribute('src', 'http://'+host+'/static/img/search.png');
 
  37 /* inputSubmit.setAttribute('style', 'position:relative; top:5px; margin-left:5px');*/
 
  39 /* import jquery and autocomplete */
 
  40 var scriptJ = document.createElement('script');
 
  41 scriptJ.setAttribute('type', 'text/javascript');
 
  42 scriptJ.setAttribute('src', 'http://'+host+'/static/js/jquery.js');
 
  44 var scriptUI = document.createElement('script');
 
  45 scriptUI.setAttribute('type', 'text/javascript');
 
  46 scriptUI.setAttribute('src', 'http://'+host+'/static/js/jquery-ui-1.8.2.custom.min.js');
 
  47 scriptUI.setAttribute('id', 'wl-jquery-ui-script')
 
  49 var scriptSearch = document.createElement('script');
 
  50 scriptSearch.setAttribute('type', 'text/javascript');
 
  51 scriptSearch.setAttribute('src', 'http://'+host+'/static/js/search.js');
 
  52 scriptSearch.setAttribute('id', 'wl-search-script')
 
  54 body[0].appendChild(scriptJ);
 
  55 scriptJ.onload = function() { body[0].appendChild(scriptUI); };
 
  56 scriptJ.onreadystatechange = function() { if (scriptJ.readyState == 'complete') { scriptJ.onload(); } };
 
  58 scriptUI.onload = function() { body[0].appendChild(scriptSearch); };
 
  59 scriptUI.onreadystatechange = function() { if (scriptUI.readyState == 'complete') { scriptUI.onload(); } };
 
  61 scriptSearch.onload = function() {
 
  63         s.search({source: s.attr('data-source')});
 
  65 scriptSearch.onreadystatechange = function() { if (scriptSearch.readyState == 'complete') { scriptSearch.onload(); } };
 
  67 /* append elements to widget */
 
  68 widget.appendChild(stylesheet);
 
  69 //widget.appendChild(stylesheetJQUI);
 
  70 widget.appendChild(linkLogo);
 
  71 linkLogo.appendChild(logo);
 
  72 widget.appendChild(form);
 
  73 form.appendChild(inputText);
 
  74 form.appendChild(inputSubmit);
 
  76 /* ...and a little make-up */
 
  78 widget.style.borderColor = "#84BF2A";
 
  79 widget.style.borderWidth = "2px";
 
  80 widget.style.borderStyle = "solid";
 
  81 widget.style.width = "160px";
 
  82 widget.style.padding = "10px";
 
  83 widget.style.fontSize = "12px";
 
  84 form.style.paddingTop = "10px";
 
  87 /* resize - if needed */
 
  88 if(widget.getAttribute('width') == '140'){
 
  89     logo.setAttribute('width', '140');
 
  90     inputText.setAttribute('size', '10');
 
  91     widget.style.width = "140px";