Ignore:
Timestamp:
12/09/05 12:11:52 (14 years ago)
Author:
gocher
Message:

Ticket #589 (assigned) Character counter not work

Not all changes made by mokhet in his version are good:
Preparing the contents of the editor twice wood make editing slow!

File:
1 edited

Legend:

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

    r419 r432  
    88} 
    99 
     10HTMLArea.Config.prototype.CharCounter = 
     11{ 
     12  'showChar': true, // show the characters count, 
     13  'showWord': true, // show the words count, 
     14  'showHtml': true, // show the exact html count 
     15  'separator': ' | ' // separator used to join informations 
     16}; 
     17 
    1018CharCounter._pluginInfo = { 
    1119    name : "CharCounter", 
    12     version : "1.0", 
     20    version : "1.1", 
    1321    developer : "Udo Schmal", 
    1422    developer_url : "http://www.schaffrath-neuemedien.de", 
     
    7381 
    7482CharCounter.prototype.updateCharCount = function(ev) { 
    75     editor = this.editor; 
     83  var editor = this.editor; 
     84  var cfg = editor.config; 
    7685    var contents = editor.getHTML(); 
     86        var string = new Array(); 
     87  if (cfg.CharCounter.showHtml) { 
     88    string[string.length] = this._lc("HTML") + ": " + contents.length; 
     89  } 
     90        if (cfg.CharCounter.showWord) { 
     91    contents = contents.replace(/<\/?\s*!--[^-->]*-->/gi, "" ); 
    7792    contents = contents.replace(/<(.+?)>/g, '');//Don't count HTML tags 
     93    contents = contents.replace(/&nbsp;/gi, ' '); 
    7894    contents = contents.replace(/([\n\r\t])/g, ' ');//convert newlines and tabs into space 
    7995    contents = contents.replace(/(  +)/g, ' ');//count spaces only once 
    8096    contents = contents.replace(/&(.*);/g, ' ');//Count htmlentities as one keystroke 
    8197    contents = contents.replace(/^\s*|\s*$/g, '');//trim 
    82 //    var words=0; 
    83 //    for (var x=0;x<contents.length;x++) { 
    84 //      if (contents.charAt(x) == " " )  {words++} 
    85 //    } 
    86 //    this.charCount.innerHTML = this._lc("Words") + ": " + words + " | " + this._lc("Chars") + ": " + contents.length; 
    87     this.charCount.innerHTML = this._lc("Chars") + ": " + contents.length; 
    88     return(contents.length); 
     98    var words=0; 
     99    for (var x=0;x<contents.length;x++) 
     100    { 
     101      if (contents.charAt(x) == " " ) {words++;} 
     102    } 
     103  if (words>=1) { words = words+1; } 
     104    string[string.length] = this._lc("Words") + ": " + words; 
     105  } 
     106 
     107  if (cfg.CharCounter.showChar) { 
     108    string[string.length] = this._lc("Chars") + ": " + contents.length; 
     109  } 
     110 
     111  this.charCount.innerHTML = string.join(cfg.CharCounter.separator); 
    89112}; 
Note: See TracChangeset for help on using the changeset viewer.