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