Changeset 619


Ignore:
Timestamp:
12/14/06 14:50:24 (11 years ago)
Author:
gocher
Message:

New version of the charcounter plugin with max HTML length

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/CharCounter/char-counter.js

    r512 r619  
    66function CharCounter(editor) { 
    77  this.editor = editor; 
     8  this._Chars = 0; 
     9  this._Words = 0; 
     10  this._HTML = 0; 
     11  this.maxHTML = 1024; 
     12  this.onKeyPress = this.__onKeyPress; 
    813} 
    914 
     
    1823CharCounter._pluginInfo = { 
    1924  name          : "CharCounter", 
    20   version       : "1.2", 
     25  version       : "1.3", 
    2126  developer     : "Udo Schmal", 
    2227  developer_url : "http://www.schaffrath-neuemedien.de", 
     
    5964}; 
    6065 
    61 CharCounter.prototype._updateCharCount = function() { 
     66CharCounter.prototype.__onKeyPress= function(ev) { 
     67  if ((ev.keyCode != 8) && (ev.keyCode !=46)) { // not backspace & delete 
     68    if (this.maxHTML!=-1) { 
     69      var contents = this.editor.getHTML(); 
     70      if (contents.length>=this.maxHTML) { 
     71        HTMLArea._stopEvent(ev); 
     72        return true; 
     73      } 
     74    } 
     75  } 
     76} 
     77 
     78CharCounter.prototype._updateCharCount= function() { 
    6279  var editor = this.editor; 
    6380  var cfg = editor.config; 
     
    6784    string[string.length] = this._lc("HTML") + ": " + contents.length; 
    6885  } 
     86  this._HTML = contents.length; 
    6987  if (cfg.CharCounter.showWord || cfg.CharCounter.showChar) { 
    7088    contents = contents.replace(/<\/?\s*!--[^-->]*-->/gi, "" ); 
     
    7795  } 
    7896  if (cfg.CharCounter.showWord) { 
    79     var words=0; 
     97    this._Words = 0; 
    8098    for (var x=0;x<contents.length;x++) 
    8199    { 
    82       if (contents.charAt(x) == " " ) {words++;} 
     100      if (contents.charAt(x) == " " ) {this._Words++;} 
    83101    } 
    84     if (words>=1) { words++; } 
    85     string[string.length] = this._lc("Words") + ": " + words; 
     102    if (this._Words >=1) { this._Words++; } 
     103    string[string.length] = this._lc("Words") + ": " + this._Words ; 
    86104  } 
    87  
    88105  if (cfg.CharCounter.showChar) { 
    89106    string[string.length] = this._lc("Chars") + ": " + contents.length; 
     107    this._Chars = contents.length; 
    90108  } 
    91  
    92109  this.charCount.innerHTML = string.join(cfg.CharCounter.separator); 
    93110}; 
Note: See TracChangeset for help on using the changeset viewer.