Detect PHP flexibly, assert wland configuration
[infodrom/musiikki-web.git] / html / musiikki.js
1 // Script to open and close sidebar
2 var page_callbacks = [];
3 function w3_open()
4 {
5     $('#mySidebar').css('display', 'block');
6     $('#myOverlay').css('display', 'block');
7 }
8
9 function w3_close()
10 {
11     $('#mySidebar').hide();
12     $('#myOverlay').hide();
13 }
14
15 function register_callback(page, callback)
16 {
17     page_callbacks[page] = callback;
18 }
19
20 function open_page(page) {
21     w3_close();
22     $('div.w3-container').hide();
23
24     if ($('div.w3-container#'+page + '[data-fetch="true"]').length)
25         $.post('index.php',
26                'action=get'+page,
27                function(data){
28                    if (typeof data == 'object') {
29                        if (page in page_callbacks) {
30                            page_callbacks[page](data);
31                        } else {
32                            for (name in data) {
33                                obj = $('div.w3-container#'+page + ' [name="'+name+'"]');
34                                if (obj.length)
35                                    obj.val(data[name]);
36                            }
37                        }
38                    }
39                });
40     $('div.w3-container#'+page).show();
41 }
42
43 function response(text, stay)
44 {
45     $('div.w3-container').hide();
46     $('div.w3-container#response #msg').html(text);
47     $('div.w3-container#response').show();
48     if (!stay)
49         setTimeout(function(){
50             open_page('home');
51         }, 5000);
52 }
53
54 $(function(){
55     $('div.w3-container').hide();
56     $('div.w3-container#home').show();
57 });