Działający edytor CodeMirror.
[redakcja.git] / project / static / js / editor.js
index 7951ee7..d81a7b0 100644 (file)
@@ -92,7 +92,8 @@ Panel.prototype.unload = function(event, data) {
         $(this.contentDiv).html('');
 
         // disconnect the toolbar
-        $('div.panel-toolbar span.panel-toolbar-extra', this.wrap).empty();
+        $('div.panel-toolbar span.panel-toolbar-extra', this.wrap).html(
+            '<span />');
         
         this.callHook('unload');
         this.hooks = null; // flush the hooks
@@ -149,10 +150,9 @@ Panel.prototype.connectToolbar = function()
     if(toolbar.length === 0) return;
 
     // move the extra
-    var extra_buttons = $('span.panel-toolbar-extra', toolbar);
-    var placeholder = $('div.panel-toolbar span.panel-toolbar-extra', this.wrap);
-    placeholder.replaceWith(extra_buttons);
-    placeholder.hide();
+    var extra_buttons = $('span.panel-toolbar-extra button', toolbar);
+    var placeholder = $('div.panel-toolbar span.panel-toolbar-extra > span', this.wrap);
+    placeholder.replaceWith(extra_buttons);    
 
     var action_buttons = $('button', extra_buttons);
 
@@ -253,7 +253,9 @@ Panel.prototype.isHotkey = function(event) {
     if(event.ctrlKey) code = code | 0x200;
     if(event.shiftKey) code = code | 0x400;
 
-    if(this.hotkeys[code] !== null) {
+    $.log(event.character, this.hotkeys[code]);
+
+    if(this.hotkeys[code]) {
         return true;
     }
     return false;
@@ -301,6 +303,10 @@ Editor.prototype.loadConfig = function() {
     
     this.fileOptions = this.options;
     var self = this;
+
+    if(!this.options.recentFiles)
+        this.options.recentFiles = [];
+
     $.each(this.options.recentFiles, function(index) {
         if (fileId == self.options.recentFiles[index].fileId) {
             $.log('Found options for', fileId);
@@ -316,30 +322,30 @@ Editor.prototype.loadConfig = function() {
 };
 
 Editor.prototype.loadPanelOptions = function() {
-    var self = this;
-    var totalWidth = 0;
-    
-    $('.panel-wrap', self.rootDiv).each(function(index) {
-        var panelWidth = self.fileOptions.panels[index].ratio * self.rootDiv.width();
-        if ($(this).hasClass('last-panel')) {
-            $(this).css({
-                left: totalWidth,
-                right: 0
-            });
-        } else {
-            $(this).css({
-                left: totalWidth,
-                width: panelWidth
-            });
-            totalWidth += panelWidth;               
-        }
-        $.log('panel:', this, $(this).css('left'));
-        $('.panel-toolbar option', this).each(function() {
-            if ($(this).attr('p:panel-name') == self.fileOptions.panels[index].name) {
-                $(this).parent('select').val($(this).attr('value'));
-            }
-        });
-    });   
+    // var self = this;
+    // var totalWidth = 0;
+    // 
+    // $('.panel-wrap', self.rootDiv).each(function(index) {
+    //     var panelWidth = self.fileOptions.panels[index].ratio * self.rootDiv.width();
+    //     if ($(this).hasClass('last-panel')) {
+    //         $(this).css({
+    //             left: totalWidth,
+    //             right: 0
+    //         });
+    //     } else {
+    //         $(this).css({
+    //             left: totalWidth,
+    //             width: panelWidth
+    //         });
+    //         totalWidth += panelWidth;               
+    //     }
+    //     $.log('panel:', this, $(this).css('left'));
+    //     $('.panel-toolbar option', this).each(function() {
+    //         if ($(this).attr('p:panel-name') == self.fileOptions.panels[index].name) {
+    //             $(this).parent('select').val($(this).attr('value'));
+    //         }
+    //     });
+    // });   
 };
 
 Editor.prototype.savePanelOptions = function() {
@@ -419,7 +425,7 @@ Editor.prototype.saveToBranch = function(msg)
                 if(self.autosaveTimer) {
                     clearTimeout(self.autosaveTimer);
                 }
-                if (data.warnings === null) {
+                if (data.warnings === null || data.warning === undefined) {
                     self.showPopup('save-successful');
                 } else {
                     self.showPopup('save-warn', data.warnings[0]);