Merge branch 'master' of https://github.com/fnp/wolnelektury
[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 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')
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
55 body[0].appendChild(scriptJ);
56 body[0].appendChild(scriptUI);
57 body[0].appendChild(scriptSearch);
58
59 /* append elements to widget */
60 widget.appendChild(stylesheet);
61 //widget.appendChild(stylesheetJQUI);
62 widget.appendChild(linkLogo);
63 linkLogo.appendChild(logo);
64 widget.appendChild(form);
65 form.appendChild(inputText);
66 form.appendChild(inputSubmit);
67
68 /* ...and a little make-up */
69 /*
70 widget.style.borderColor = "#84BF2A";
71 widget.style.borderWidth = "2px";
72 widget.style.borderStyle = "solid";
73 widget.style.width = "160px";
74 widget.style.padding = "10px";
75 widget.style.fontSize = "12px";
76 form.style.paddingTop = "10px";
77 */
78
79 /* resize - if needed */
80 if(widget.getAttribute('width') == '140'){
81     logo.setAttribute('width', '140');
82     inputText.setAttribute('size', '10');
83     widget.style.width = "140px";
84 }
85
86 var wl_loaded_scripts = {};
87
88 function wl_initialize_after_load(just_loaded) {
89     wl_loaded_scripts[just_loaded] = true;
90     if (wl_loaded_scripts.jquery 
91         && wl_loaded_scripts.ui 
92         && wl_loaded_scripts.search) {
93         var s = $('#id_qq');
94         s.search({source: s.attr('data-source')});
95     }
96 }
97
98 scriptJ.onload = function() { wl_initialize_after_load('jquery'); };
99 scriptUI.onload = function() { wl_initialize_after_load('ui'); };
100 scriptSearch.onload = function() { wl_initialize_after_load('search'); };