de30eb71475706b7f33cac5c70060711a0ac847e
[wolnelektury.git] / wolnelektury / static / js / widget.js
1 /* create basic elements */
2 var id          = "wl";
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
12 var host = 'www.wolnelektury.pl';
13
14 /* set attributes of created elements */
15 stylesheet.setAttribute('type', 'text/css');
16 stylesheet.setAttribute('rel', 'stylesheet');
17 stylesheet.setAttribute('href', 'http://'+host+'/static/css/widget.css');
18 linkLogo.setAttribute('href', 'http://'+host);
19 logo.setAttribute('src', 'http://'+host+'/static/img/logo.png');
20 form.setAttribute('action', 'http://'+host+'/szukaj/');
21 form.setAttribute('method', 'get');
22 form.setAttribute('accept-charset', 'utf-8');
23 form.setAttribute('id', 'wl-form');
24 inputText.setAttribute('type', 'text');
25 inputText.setAttribute('title', 'tytul, autor, motyw/temat, epoka, rodzaj, gatunek');
26 inputText.setAttribute('value', '');
27 inputText.setAttribute('name', 'q');
28 inputText.setAttribute('id', 'id_qq');
29 inputText.setAttribute('size', '13');
30 inputSubmit.setAttribute('type', 'image');
31 inputSubmit.setAttribute('src', 'http://'+host+'/static/img/search.png');
32 inputSubmit.setAttribute('style', 'position:relative; top:5px; margin-left:5px');
33
34 /* import jquery and autocomplete */
35 var scriptJ = document.createElement('script');
36 scriptJ.setAttribute('type', 'text/javascript');
37 scriptJ.setAttribute('src', 'http://'+host+'/static/js/jquery.js');
38
39 var scriptAutoComplete = document.createElement('script');
40 scriptAutoComplete.setAttribute('type', 'text/javascript');
41 scriptAutoComplete.setAttribute('src', 'http://'+host+'/static/js/jquery-ui-1.8.2.custom.min.js');
42
43 var scriptInit = document.createElement('script');
44 scriptInit.setAttribute('type', 'text/javascript');
45 scriptInit.setAttribute('src', 'http://'+host+'/static/js/widgetInit.js');
46
47 body[0].appendChild(scriptJ);
48 body[0].appendChild(scriptAutoComplete);
49 body[0].appendChild(scriptInit);
50
51 /* append elements to widget */
52 widget.appendChild(stylesheet);
53 widget.appendChild(linkLogo);
54 linkLogo.appendChild(logo);
55 widget.appendChild(form);
56 form.appendChild(inputText);
57 form.appendChild(inputSubmit);
58
59 /* ...and a little make-up */
60 widget.style.borderColor = "#84BF2A";
61 widget.style.borderWidth = "2px";
62 widget.style.borderStyle = "solid";
63 widget.style.width = "160px";
64 widget.style.padding = "10px";
65 widget.style.fontSize = "12px";
66 form.style.paddingTop = "10px";
67
68 /* resize - if needed */
69 if(widget.getAttribute('width') == '140'){
70     logo.setAttribute('width', '140');
71     inputText.setAttribute('size', '10');
72     widget.style.width = "140px";
73 }