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