Ulepszone zmienianie rozmiaru. Fixes #58.
[redakcja.git] / project / static / js / panels.js
1 function loadPanel(target, url) {
2     console.log('ajax', url, 'into', target);
3     $(document).trigger('panel:unload', target);
4     $.ajax({
5         url: url,
6         dataType: 'html',
7         success: function(data, textStatus) {
8             console.log(target, 'ajax success');
9             $(target).html(data);
10             console.log(target, 'triggering panel:load');
11             $(document).trigger('panel:load', target);
12             // panel(target);
13         },
14         error: function(request, textStatus, errorThrown) {
15             console.log('ajax', url, target, 'error:', textStatus, errorThrown);
16         }
17     });
18 }
19
20 // Funkcja do tworzenia nowych paneli
21 function panel(load, unload) {
22     var self = null;
23     var eventId = Math.ceil(Math.random() * 1000000000);
24     
25     unloadHandler = function(event, panel) {
26         if (self && self == panel) {
27             console.log('Panel', panel, 'unloading');
28             $(document).unbind('panel:unload.' + eventId);
29             $(panel).html('');
30             unload(event, panel);
31             console.log('Panel', panel, 'unloaded');
32             return false;
33         }
34     };
35     
36     $(document).one('panel:load', function(event, panel) {
37         self = panel;
38         console.log('Panel', panel, 'loading');
39         $(document).bind('panel:unload.' + eventId, unloadHandler);
40         load(event, panel);
41         console.log('Panel', panel, 'loaded');
42     });
43 }
44
45 $(function() {
46     // ========================
47     // = Resizable panels =
48     // ========================
49 //    function resizePanels() {
50 //              // called on resize
51 //        $('.panel').height($(window).height() - $('.panel').position().top);
52 //        $('.panel-content').height($(window).height() - $('.panel-contents').position().top);
53 //        $('#right-panel-wrap').width($(window).width() - $('#left-panel-wrap').outerWidth());
54 //    }
55     
56 //    $(window).resize(function() {
57 //        resizePanels();
58 //    })
59
60     $('#panels').makeHorizPanel({});
61     $('#panels').css('top', ($('#header').outerHeight() ) + 'px');
62         
63 //    $('#left-panel-wrap').bind('resizable:stop', resizePanels)
64 //        .resizable({minWidth: 8});    
65 //    resizePanels();
66     
67     $('.panel-toolbar select').change(function() {
68         loadPanel($('.panel-content', $(this).parent().parent()), $(this).val())
69     });
70     // $('#id_folders').change(function() {
71     //     $('#images').load('{% url folder_image_ajax %}' + $('#id_folders').val() + '/', function() {
72     //         $('#images-wrap').data('lazyload:lastCheckedScrollTop', -10000);
73     //     });
74     // });
75     // 
76     //
77     
78     // var editor = CodeMirror.fromTextArea("id_text", {
79     //     parserfile: 'parsexml.js',
80     //     path: "/static/js/codemirror/",
81     //     stylesheet: "/static/css/xmlcolors.css",
82     //     parserConfig: {useHTMLKludges: false},
83     //     initCallback: function() {
84     //         $('#images').autoscroll('iframe');
85     //         $('.toggleAutoscroll').toggle(function() {
86     //             $(this).html('Synchronizuj przewijanie');
87     //             $('#images').disableAutoscroll();
88     //         }, function() {
89     //             $(this).html('Nie synchronizuj przewijania');
90     //             $('#images').enableAutoscroll();
91     //         })
92     //         
93     //         // Toolbar
94     //         $('#toolbar-tabs li').click(function() {
95     //             var id = $(this).attr('p:button-list');
96     //             $('#toolbar-tabs li').removeClass('active');
97     //             $(this).addClass('active');
98     //             if (!$('#' + id).is(':visible')) {
99     //                 $('#toolbar-buttons ol').not('#' + id).hide();
100     //                 $('#' + id).show();
101     //             }
102     //         })
103     // 
104     //         var keys = {};
105     //         $('#toolbar-buttons li').each(function() {
106     //             var tag = $(this).attr('p:tag');
107     //             var handler = function() {
108     //                 var text = editor.selection();
109     //                 editor.replaceSelection('<' + tag + '>' + text + '</' + tag + '>');
110     //                 if (text.length == 0) {
111     //                     var pos = editor.cursorPosition();
112     //                     editor.selectLines(pos.line, pos.character + tag.length + 2);
113     //                 }
114     //             }
115     //             if ($(this).attr('p:key')) {
116     //                 keys[$(this).attr('p:key')] = handler;
117     //             }
118     //             $(this).click(handler)
119     //         });
120     //         
121     //         editor.grabKeys(function(event) { 
122     //             if (keys[event.keyCode]) {
123     //                 keys[event.keyCode]();
124     //             }
125     //         }, function(event) {
126     //             return event.altKey && keys[event.keyCode];
127     //         });
128     //     }
129     // });
130     
131
132     
133
134     
135     // $('#toolbar-buttons li').wTooltip({
136     //     delay: 1000, 
137     //     style: {
138     //         border: "1px solid #7F7D67",
139     //         opacity: 0.9, 
140     //         background: "#FBFBC6", 
141     //         padding: "1px",
142     //         fontSize: "12px",
143     //     }});
144     
145     // $('#images-wrap').lazyload('.image-box', {threshold: 640 * 10, scrollTreshold: 640 * 5});
146 });