Merge branch 'master' of git@stigma:platforma
[redakcja.git] / project / static / js / panels.js
1 function loadPanel(target, url) {
2     $.log('ajax', url, 'into', target);
3     $('.change-notification', $(target).parent()).fadeOut();
4     $(document).trigger('panel:unload', target);
5     $.ajax({
6         url: url,
7         dataType: 'html',
8         success: function(data, textStatus) {
9             $(target).html(data);
10             $(document).trigger('panel:load', target);
11         },
12         error: function(request, textStatus, errorThrown) {
13             $.log('ajax', url, target, 'error:', textStatus, errorThrown);
14         }
15     });
16 }
17
18 // Funkcja do tworzenia nowych paneli
19 function panel(load, unload) {
20     var self = null;
21     var eventId = Math.ceil(Math.random() * 1000000000);
22     
23     unloadHandler = function(event, panel) {
24         if (self && self == panel) {
25             $(document).unbind('panel:unload.' + eventId);
26             $(panel).html('');
27             unload(event, panel);
28             return false;
29         }
30     };
31     
32     $(document).one('panel:load', function(event, panel) {
33         self = panel;
34         $(document).bind('panel:unload.' + eventId, unloadHandler);
35         load(event, panel);
36     });
37 }
38
39 $(function() {
40     $('#panels').makeHorizPanel({});
41     $('#panels').css('top', ($('#header').outerHeight() ) + 'px');
42         
43     $('.panel-toolbar select').change(function() {
44         loadPanel($('.panel-content', $(this).parent().parent()), $(this).val())
45     });
46 });