Dodanie panelu htmleditor.
[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         $('.panel').height($(window).height() - $('.panel').position().top);
51         $('.panel-contents').height($(window).height() - $('.panel-contents').position().top);
52         $('#right-panel-wrap').width($(window).width() - $('#left-panel-wrap').outerWidth());
53     }
54     
55     $(window).resize(function() {
56         resizePanels();
57     })
58     
59     $('#left-panel-wrap').bind('resizable:stop', resizePanels)
60         .resizable('#slider', {minWidth: 8});
61     
62     resizePanels();
63     
64     $('.panel-toolbar select').change(function() {
65         loadPanel($('.panel-contents', $(this).parent().parent()), $(this).val())
66     });
67     // $('#id_folders').change(function() {
68     //     $('#images').load('{% url folder_image_ajax %}' + $('#id_folders').val() + '/', function() {
69     //         $('#images-wrap').data('lazyload:lastCheckedScrollTop', -10000);
70     //     });
71     // });
72     // 
73     //
74     
75     // var editor = CodeMirror.fromTextArea("id_text", {
76     //     parserfile: 'parsexml.js',
77     //     path: "/static/js/codemirror/",
78     //     stylesheet: "/static/css/xmlcolors.css",
79     //     parserConfig: {useHTMLKludges: false},
80     //     initCallback: function() {
81     //         $('#images').autoscroll('iframe');
82     //         $('.toggleAutoscroll').toggle(function() {
83     //             $(this).html('Synchronizuj przewijanie');
84     //             $('#images').disableAutoscroll();
85     //         }, function() {
86     //             $(this).html('Nie synchronizuj przewijania');
87     //             $('#images').enableAutoscroll();
88     //         })
89     //         
90     //         // Toolbar
91     //         $('#toolbar-tabs li').click(function() {
92     //             var id = $(this).attr('p:button-list');
93     //             $('#toolbar-tabs li').removeClass('active');
94     //             $(this).addClass('active');
95     //             if (!$('#' + id).is(':visible')) {
96     //                 $('#toolbar-buttons ol').not('#' + id).hide();
97     //                 $('#' + id).show();
98     //             }
99     //         })
100     // 
101     //         var keys = {};
102     //         $('#toolbar-buttons li').each(function() {
103     //             var tag = $(this).attr('p:tag');
104     //             var handler = function() {
105     //                 var text = editor.selection();
106     //                 editor.replaceSelection('<' + tag + '>' + text + '</' + tag + '>');
107     //                 if (text.length == 0) {
108     //                     var pos = editor.cursorPosition();
109     //                     editor.selectLines(pos.line, pos.character + tag.length + 2);
110     //                 }
111     //             }
112     //             if ($(this).attr('p:key')) {
113     //                 keys[$(this).attr('p:key')] = handler;
114     //             }
115     //             $(this).click(handler)
116     //         });
117     //         
118     //         editor.grabKeys(function(event) { 
119     //             if (keys[event.keyCode]) {
120     //                 keys[event.keyCode]();
121     //             }
122     //         }, function(event) {
123     //             return event.altKey && keys[event.keyCode];
124     //         });
125     //     }
126     // });
127     
128
129     
130
131     
132     // $('#toolbar-buttons li').wTooltip({
133     //     delay: 1000, 
134     //     style: {
135     //         border: "1px solid #7F7D67",
136     //         opacity: 0.9, 
137     //         background: "#FBFBC6", 
138     //         padding: "1px",
139     //         fontSize: "12px",
140     //     }});
141     
142     // $('#images-wrap').lazyload('.image-box', {threshold: 640 * 10, scrollTreshold: 640 * 5});
143 });