Podstawowe ładowanie i odładowywanie paneli przez AJAX (właściwie AJAH).
[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             $(target).html(data);
9             $(document).trigger('panel:unload', target);
10             $(document).trigger('panel:load', target);
11             // panel(target);
12         },
13         error: function(request, textStatus, errorThrown) {
14             $(document).trigger('panel:unload', target);
15             console.log('ajax', url, target, 'error:', textStatus, errorThrown);
16         }
17     });
18 }
19
20 $(function() {
21     // ========================
22     // = Resizable panels =
23     // ========================
24     function resizePanels() {
25         $('.panel').height($(window).height() - $('.panel').position().top);
26         $('#right-panel-wrap').width($(window).width() - $('#left-panel-wrap').outerWidth());
27     }
28     
29     $(window).resize(function() {
30         resizePanels();
31     })
32     
33     $('#left-panel-wrap').bind('resizable:resize', resizePanels)
34         .resizable('#slider', {minWidth: 8});
35     
36     resizePanels();
37     
38     $('.panel-toolbar select').change(function() {
39         loadPanel($('.panel-contents', $(this).parent().parent()), $(this).val())
40     });
41     // $('#id_folders').change(function() {
42     //     $('#images').load('{% url folder_image_ajax %}' + $('#id_folders').val() + '/', function() {
43     //         $('#images-wrap').data('lazyload:lastCheckedScrollTop', -10000);
44     //     });
45     // });
46     // 
47     //
48     
49     // var editor = CodeMirror.fromTextArea("id_text", {
50     //     parserfile: 'parsexml.js',
51     //     path: "/static/js/codemirror/",
52     //     stylesheet: "/static/css/xmlcolors.css",
53     //     parserConfig: {useHTMLKludges: false},
54     //     initCallback: function() {
55     //         $('#images').autoscroll('iframe');
56     //         $('.toggleAutoscroll').toggle(function() {
57     //             $(this).html('Synchronizuj przewijanie');
58     //             $('#images').disableAutoscroll();
59     //         }, function() {
60     //             $(this).html('Nie synchronizuj przewijania');
61     //             $('#images').enableAutoscroll();
62     //         })
63     //         
64     //         // Toolbar
65     //         $('#toolbar-tabs li').click(function() {
66     //             var id = $(this).attr('p:button-list');
67     //             $('#toolbar-tabs li').removeClass('active');
68     //             $(this).addClass('active');
69     //             if (!$('#' + id).is(':visible')) {
70     //                 $('#toolbar-buttons ol').not('#' + id).hide();
71     //                 $('#' + id).show();
72     //             }
73     //         })
74     // 
75     //         var keys = {};
76     //         $('#toolbar-buttons li').each(function() {
77     //             var tag = $(this).attr('p:tag');
78     //             var handler = function() {
79     //                 var text = editor.selection();
80     //                 editor.replaceSelection('<' + tag + '>' + text + '</' + tag + '>');
81     //                 if (text.length == 0) {
82     //                     var pos = editor.cursorPosition();
83     //                     editor.selectLines(pos.line, pos.character + tag.length + 2);
84     //                 }
85     //             }
86     //             if ($(this).attr('p:key')) {
87     //                 keys[$(this).attr('p:key')] = handler;
88     //             }
89     //             $(this).click(handler)
90     //         });
91     //         
92     //         editor.grabKeys(function(event) { 
93     //             if (keys[event.keyCode]) {
94     //                 keys[event.keyCode]();
95     //             }
96     //         }, function(event) {
97     //             return event.altKey && keys[event.keyCode];
98     //         });
99     //     }
100     // });
101     
102
103     
104
105     
106     // $('#toolbar-buttons li').wTooltip({
107     //     delay: 1000, 
108     //     style: {
109     //         border: "1px solid #7F7D67",
110     //         opacity: 0.9, 
111     //         background: "#FBFBC6", 
112     //         padding: "1px",
113     //         fontSize: "12px",
114     //     }});
115     
116     // $('#images-wrap').lazyload('.image-box', {threshold: 640 * 10, scrollTreshold: 640 * 5});
117 });