widget
[wolnelektury.git] / apps / wolnelektury_core / 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 var stylesheetJQUI = document.createElement('linl');
12
13 var host = 'localhost:8000'; //'www.wolnelektury.pl';
14
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');*/
38
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');
43
44 var scriptAutoComplete = document.createElement('script');
45 scriptAutoComplete.setAttribute('type', 'text/javascript');
46 scriptAutoComplete.setAttribute('src', 'http://'+host+'/static/js/jquery-ui-1.8.2.custom.min.js');
47 scriptAutoComplete.setAttribute('id', 'wl-jquery-ui-script')
48
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')
53
54 var scriptInit = document.createElement('script');
55 scriptInit.setAttribute('type', 'text/javascript');
56 scriptInit.setAttribute('src', 'http://'+host+'/static/js/widgetInit.js');
57
58 body[0].appendChild(scriptJ);
59 body[0].appendChild(scriptAutoComplete);
60 body[0].appendChild(scriptSearch);
61 body[0].appendChild(scriptInit);
62
63 /* append elements to widget */
64 widget.appendChild(stylesheet);
65 //widget.appendChild(stylesheetJQUI);
66 widget.appendChild(linkLogo);
67 linkLogo.appendChild(logo);
68 widget.appendChild(form);
69 form.appendChild(inputText);
70 form.appendChild(inputSubmit);
71
72 /* ...and a little make-up */
73 /*
74 widget.style.borderColor = "#84BF2A";
75 widget.style.borderWidth = "2px";
76 widget.style.borderStyle = "solid";
77 widget.style.width = "160px";
78 widget.style.padding = "10px";
79 widget.style.fontSize = "12px";
80 form.style.paddingTop = "10px";
81 */
82
83 /* resize - if needed */
84 if(widget.getAttribute('width') == '140'){
85     logo.setAttribute('width', '140');
86     inputText.setAttribute('size', '10');
87     widget.style.width = "140px";
88 }