Ignore:
Timestamp:
02/10/07 13:22:42 (13 years ago)
Author:
ray
Message:

SaveSubmit? update

  • improved detection of changed state
  • improved handling of shortcut key
  • reset changed state on udo
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/SaveSubmit/save-submit.js

    r681 r727  
    99function SaveSubmit(editor) { 
    1010        this.editor = editor; 
    11         this.initial_html = null; 
    1211        this.changed = false; 
    1312        var self = this; 
     
    1514        this.textarea = this.editor._textArea; 
    1615 
    17         this.imgage_changed = _editor_url+"plugins/SaveSubmit/img/ed_save_red.gif"; 
    18         this.imgage_unchanged = _editor_url+"plugins/SaveSubmit/img/ed_save_green.gif"; 
     16        this.image_changed = _editor_url+"plugins/SaveSubmit/img/ed_save_red.gif"; 
     17        this.image_unchanged = _editor_url+"plugins/SaveSubmit/img/ed_save_green.gif"; 
    1918        cfg.registerButton({ 
    2019        id       : "savesubmit", 
    2120        tooltip  : self._lc("Save"), 
    22         image    : this.imgage_unchanged, 
     21        image    : this.image_unchanged, 
    2322        textMode : false, 
    2423        action   :  function(editor) { 
     
    4443} 
    4544 
    46 SaveSubmit.prototype.onGenerate = function() { 
    47         var self = this; 
    48         var doc = this.editordoc = this.editor._iframe.contentWindow.document; 
    49         Xinha._addEvents(doc, ["mouseup","keyup","keypress","keydown"], 
    50                             function (event) { 
    51                             return self.onEvent(Xinha.is_ie ? self.editor._iframe.contentWindow.event : event); 
    52                             }); 
     45SaveSubmit.prototype.onGenerateOnce = function() { 
     46        this.initial_html = this.editor.getInnerHTML(); 
    5347} 
    5448 
    55 SaveSubmit.prototype.onEvent = function(ev) { 
    56  
    57         var keyEvent = (Xinha.is_ie && ev.type == "keydown") || (!Xinha.is_ie && ev.type == "keypress"); 
    58  
    59         if (keyEvent && ev.ctrlKey && String.fromCharCode(Xinha.is_ie ? ev.keyCode : ev.charCode).toLowerCase() == 's') { 
     49SaveSubmit.prototype.onKeyPress = function(ev) { 
     50        if ( ev.ctrlKey && this.editor.getKey(ev) == 's') { 
    6051                        this.save(this.editor); 
     52                        Xinha._stopEvent(ev); 
     53                        return true; 
    6154        } 
    6255        else { 
    6356                if (!this.changed) { 
    6457                        if (this.getChanged()) this.setChanged(); 
     58                        return false; 
    6559                } 
    6660        } 
    6761} 
    68  
     62SaveSubmit.prototype.onExecCommand = function (cmd) { 
     63        if (this.changed && cmd == 'undo') {  
     64                if (this.initial_html == this.editor.getInnerHTML()) this.setUnChanged(); 
     65                return false; 
     66        } 
     67} 
     68SaveSubmit.prototype.onUpdateToolbar = function () { 
     69        if (!this.changed) { 
     70                if (this.getChanged()) this.setChanged(); 
     71                return false; 
     72        }        
     73} 
    6974SaveSubmit.prototype.getChanged = function() { 
    70         if (this.initial_html == null) this.initial_html = this.editor.getHTML(); 
    71         if (this.initial_html != this.editor.getHTML() && this.changed == false) { 
    72  
     75        if (this.initial_html === null) this.initial_html = this.editor.getInnerHTML(); 
     76        if (this.initial_html != this.editor.getInnerHTML() && this.changed == false) { 
    7377                this.changed = true; 
    7478                return true; 
     
    7781} 
    7882SaveSubmit.prototype.setChanged = function() { 
    79         toolbar_objects = this.editor._toolbarObjects; 
    80         for (var i in toolbar_objects) { 
    81                 var btn = toolbar_objects[i]; 
    82                 if (btn.name == 'savesubmit') { 
    83                         btn.swapImage(this.imgage_changed); 
    84                 } 
    85         } 
     83        this.editor._toolbarObjects.savesubmit.swapImage(this.image_changed); 
    8684        this.editor.updateToolbar(); 
    8785} 
     86SaveSubmit.prototype.setUnChanged = function() { 
     87        this.changed = false; 
     88        this.editor._toolbarObjects.savesubmit.swapImage(this.image_unchanged); 
     89} 
    8890SaveSubmit.prototype.changedReset = function() { 
    89         this.changed = false; 
    9091        this.initial_html = null; 
    91         toolbar_objects = this.editor._toolbarObjects; 
    92         for (var i in toolbar_objects) { 
    93                 var btn = toolbar_objects[i]; 
    94                 if (btn.name == 'savesubmit') { 
    95                         btn.swapImage(this.imgage_unchanged); 
    96                 } 
    97         } 
     92        this.setUnChanged(); 
    9893} 
    9994 
     
    120115                removeMessage = function() { self.removeMessage()} ; 
    121116                window.setTimeout("removeMessage()",1000); 
    122  
    123117        }); 
    124118} 
     
    126120SaveSubmit.prototype.setMessage = function(string) { 
    127121  var textarea = this.textarea; 
    128   if ( !document.getElementById("message_sub_" + textarea.name)) { return ; } 
    129   var elt = document.getElementById("message_sub_" + textarea.name); 
     122  if ( !document.getElementById("message_sub_" + textarea.id)) { return ; } 
     123  var elt = document.getElementById("message_sub_" + textarea.id); 
    130124  elt.innerHTML = Xinha._lc(string, 'SaveSubmit'); 
    131125} 
     
    133127SaveSubmit.prototype.removeMessage = function() { 
    134128  var textarea = this.textarea; 
    135   if (!document.getElementById("message_" + textarea.name)) { return ; } 
    136   document.body.removeChild(document.getElementById("message_" + textarea.name)); 
     129  if (!document.getElementById("message_" + textarea.id)) { return ; } 
     130  document.body.removeChild(document.getElementById("message_" + textarea.id)); 
    137131} 
    138132 
     
    143137        var htmlarea = this.editor._htmlArea; 
    144138        var loading_message = document.createElement("div"); 
    145         loading_message.id = "message_" + textarea.name; 
     139        loading_message.id = "message_" + textarea.id; 
    146140        loading_message.className = "loading"; 
    147141        loading_message.style.width    = htmlarea.offsetWidth +'px' ;//(this.editor._iframe.offsetWidth != 0) ? this.editor._iframe.offsetWidth +'px' : this.editor._initial_ta_size.w; 
     
    152146        var loading_main = document.createElement("div"); 
    153147        loading_main.className = "loading_main"; 
    154         loading_main.id = "loading_main_" + textarea.name; 
     148        loading_main.id = "loading_main_" + textarea.id; 
    155149        loading_main.appendChild(document.createTextNode(this._lc("Saving..."))); 
    156150 
    157151        var loading_sub = document.createElement("div"); 
    158152        loading_sub.className = "loading_sub"; 
    159         loading_sub.id = "message_sub_" + textarea.name; 
     153        loading_sub.id = "message_sub_" + textarea.id; 
    160154        loading_sub.appendChild(document.createTextNode(this._lc("in progress"))); 
    161155        loading_message.appendChild(loading_main); 
Note: See TracChangeset for help on using the changeset viewer.