Changeset 512


Ignore:
Timestamp:
05/02/06 10:46:10 (8 years ago)
Author:
gocher
Message:

Ticket #655
Run the updateCharCount not every key press

Location:
trunk/plugins/CharCounter
Files:
2 edited

Legend:

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

    r433 r512  
    11// Charcounter for HTMLArea-3.0 
    2 // (c) Udo Schmal & L.N.Schaffrath NeueMedien  
     2// (c) Udo Schmal & L.N.Schaffrath NeueMedien 
    33// Distributed under the same terms as HTMLArea itself. 
    44// This notice MUST stay intact for use (see license.txt). 
    55 
    66function CharCounter(editor) { 
    7     this.editor = editor; 
     7  this.editor = editor; 
    88} 
    99 
     
    1717 
    1818CharCounter._pluginInfo = { 
    19     name          : "CharCounter", 
    20     version       : "1.1", 
    21     developer     : "Udo Schmal", 
    22     developer_url : "http://www.schaffrath-neuemedien.de", 
    23     sponsor       : "L.N.Schaffrath NeueMedien", 
    24     sponsor_url   : "http://www.schaffrath-neuemedien.de", 
    25     c_owner       : "Udo Schmal & L.N.Schaffrath NeueMedien", 
    26     license       : "htmlArea" 
     19  name          : "CharCounter", 
     20  version       : "1.2", 
     21  developer     : "Udo Schmal", 
     22  developer_url : "http://www.schaffrath-neuemedien.de", 
     23  sponsor       : "L.N.Schaffrath NeueMedien", 
     24  sponsor_url   : "http://www.schaffrath-neuemedien.de", 
     25  c_owner       : "Udo Schmal & L.N.Schaffrath NeueMedien", 
     26  license       : "htmlArea" 
    2727}; 
    2828 
     
    5959}; 
    6060 
     61CharCounter.prototype._updateCharCount = function() { 
     62  var editor = this.editor; 
     63  var cfg = editor.config; 
     64  var contents = editor.getHTML(); 
     65  var string = new Array(); 
     66  if (cfg.CharCounter.showHtml) { 
     67    string[string.length] = this._lc("HTML") + ": " + contents.length; 
     68  } 
     69  if (cfg.CharCounter.showWord || cfg.CharCounter.showChar) { 
     70    contents = contents.replace(/<\/?\s*!--[^-->]*-->/gi, "" ); 
     71    contents = contents.replace(/<(.+?)>/g, '');//Don't count HTML tags 
     72    contents = contents.replace(/&nbsp;/gi, ' '); 
     73    contents = contents.replace(/([\n\r\t])/g, ' ');//convert newlines and tabs into space 
     74    contents = contents.replace(/(  +)/g, ' ');//count spaces only once 
     75    contents = contents.replace(/&(.*);/g, ' ');//Count htmlentities as one keystroke 
     76    contents = contents.replace(/^\s*|\s*$/g, '');//trim 
     77  } 
     78  if (cfg.CharCounter.showWord) { 
     79    var words=0; 
     80    for (var x=0;x<contents.length;x++) 
     81    { 
     82      if (contents.charAt(x) == " " ) {words++;} 
     83    } 
     84    if (words>=1) { words++; } 
     85    string[string.length] = this._lc("Words") + ": " + words; 
     86  } 
     87 
     88  if (cfg.CharCounter.showChar) { 
     89    string[string.length] = this._lc("Chars") + ": " + contents.length; 
     90  } 
     91 
     92  this.charCount.innerHTML = string.join(cfg.CharCounter.separator); 
     93}; 
     94 
    6195CharCounter.prototype.onUpdateToolbar = function() { 
    62     this.updateCharCount(); 
     96  this.charCount.innerHTML = this._lc("... in progress"); 
     97  if(this._timeoutID) { 
     98    window.clearTimeout(this._timeoutID); 
     99  } 
     100  var e = this; 
     101  this._timeoutID = window.setTimeout(function() {e._updateCharCount();}, 1000); 
    63102}; 
    64103 
     
    79118  } 
    80119}; 
    81  
    82 CharCounter.prototype.updateCharCount = function(ev) { 
    83   var editor = this.editor; 
    84   var cfg = editor.config; 
    85     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 || cfg.CharCounter.showChar) { 
    91     contents = contents.replace(/<\/?\s*!--[^-->]*-->/gi, "" ); 
    92     contents = contents.replace(/<(.+?)>/g, '');//Don't count HTML tags 
    93     contents = contents.replace(/&nbsp;/gi, ' '); 
    94     contents = contents.replace(/([\n\r\t])/g, ' ');//convert newlines and tabs into space 
    95     contents = contents.replace(/(  +)/g, ' ');//count spaces only once 
    96     contents = contents.replace(/&(.*);/g, ' ');//Count htmlentities as one keystroke 
    97     contents = contents.replace(/^\s*|\s*$/g, '');//trim 
    98   } 
    99   if (cfg.CharCounter.showWord) { 
    100     var words=0; 
    101     for (var x=0;x<contents.length;x++)  
    102     { 
    103       if (contents.charAt(x) == " " ) {words++;} 
    104     } 
    105     if (words>=1) { words++; } 
    106     string[string.length] = this._lc("Words") + ": " + words; 
    107   } 
    108  
    109   if (cfg.CharCounter.showChar) { 
    110     string[string.length] = this._lc("Chars") + ": " + contents.length; 
    111   } 
    112  
    113   this.charCount.innerHTML = string.join(cfg.CharCounter.separator); 
    114 }; 
  • trunk/plugins/CharCounter/lang/de.js

    r383 r512  
    33// Author: Udo Schmal (gocher), http://www.schaffrath-neuemedien.de/, udo.schmal@t-online.de 
    44{ 
    5   "Chars": "Zeichen" 
     5  "Chars": "Zeichen", 
     6  "Words": "Worte", 
     7  "... in progress": "... in Bearbeitung" 
    68}; 
Note: See TracChangeset for help on using the changeset viewer.