Index: openacs-4/packages/acs-templating/www/resources/xinha-nightly/plugins/CharCounter/char-counter.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/resources/xinha-nightly/plugins/CharCounter/char-counter.js,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-templating/www/resources/xinha-nightly/plugins/CharCounter/char-counter.js 4 Jun 2006 00:45:49 -0000 1.3 +++ openacs-4/packages/acs-templating/www/resources/xinha-nightly/plugins/CharCounter/char-counter.js 2 Feb 2007 21:04:48 -0000 1.4 @@ -1,10 +1,15 @@ // Charcounter for HTMLArea-3.0 -// (c) Udo Schmal & L.N.Schaffrath NeueMedien +// (c) Udo Schmal & L.N.Schaffrath NeueMedien // Distributed under the same terms as HTMLArea itself. // This notice MUST stay intact for use (see license.txt). function CharCounter(editor) { - this.editor = editor; + this.editor = editor; + this._Chars = 0; + this._Words = 0; + this._HTML = 0; + this.maxHTML = 1024; + this.onKeyPress = this.__onKeyPress; } HTMLArea.Config.prototype.CharCounter = @@ -16,14 +21,14 @@ }; CharCounter._pluginInfo = { - name : "CharCounter", - version : "1.1", - developer : "Udo Schmal", - developer_url : "http://www.schaffrath-neuemedien.de", - sponsor : "L.N.Schaffrath NeueMedien", - sponsor_url : "http://www.schaffrath-neuemedien.de", - c_owner : "Udo Schmal & L.N.Schaffrath NeueMedien", - license : "htmlArea" + name : "CharCounter", + version : "1.3", + developer : "Udo Schmal", + developer_url : "http://www.schaffrath-neuemedien.de", + sponsor : "L.N.Schaffrath NeueMedien", + sponsor_url : "http://www.schaffrath-neuemedien.de", + c_owner : "Udo Schmal & L.N.Schaffrath NeueMedien", + license : "htmlArea" }; CharCounter.prototype._lc = function(string) { @@ -58,35 +63,27 @@ } }; -CharCounter.prototype.onUpdateToolbar = function() { - this.updateCharCount(); -}; - -CharCounter.prototype.onMode = function (mode) -{ - //Hide Chars in statusbar when switching into textmode - switch (mode) - { - case "textmode": - this.charCount.style.display = "none"; - break; - case "wysiwyg": - this.charCount.style.display = ""; - break; - default: - alert("Mode <" + mode + "> not defined!"); - return false; +CharCounter.prototype.__onKeyPress= function(ev) { + if ((ev.keyCode != 8) && (ev.keyCode !=46)) { // not backspace & delete + if (this.maxHTML!=-1) { + var contents = this.editor.getHTML(); + if (contents.length>=this.maxHTML) { + HTMLArea._stopEvent(ev); + return true; + } + } } -}; +} -CharCounter.prototype.updateCharCount = function(ev) { +CharCounter.prototype._updateCharCount= function() { var editor = this.editor; var cfg = editor.config; - var contents = editor.getHTML(); - var string = new Array(); + var contents = editor.getHTML(); + var string = new Array(); if (cfg.CharCounter.showHtml) { string[string.length] = this._lc("HTML") + ": " + contents.length; } + this._HTML = contents.length; if (cfg.CharCounter.showWord || cfg.CharCounter.showChar) { contents = contents.replace(/<\/?\s*!--[^-->]*-->/gi, "" ); contents = contents.replace(/<(.+?)>/g, '');//Don't count HTML tags @@ -97,18 +94,43 @@ contents = contents.replace(/^\s*|\s*$/g, '');//trim } if (cfg.CharCounter.showWord) { - var words=0; - for (var x=0;x=1) { words++; } - string[string.length] = this._lc("Words") + ": " + words; + if (this._Words >=1) { this._Words++; } + string[string.length] = this._lc("Words") + ": " + this._Words ; } - if (cfg.CharCounter.showChar) { string[string.length] = this._lc("Chars") + ": " + contents.length; + this._Chars = contents.length; } - this.charCount.innerHTML = string.join(cfg.CharCounter.separator); }; + +CharCounter.prototype.onUpdateToolbar = function() { + this.charCount.innerHTML = this._lc("... in progress"); + if(this._timeoutID) { + window.clearTimeout(this._timeoutID); + } + var e = this; + this._timeoutID = window.setTimeout(function() {e._updateCharCount();}, 1000); +}; + +CharCounter.prototype.onMode = function (mode) +{ + //Hide Chars in statusbar when switching into textmode + switch (mode) + { + case "textmode": + this.charCount.style.display = "none"; + break; + case "wysiwyg": + this.charCount.style.display = ""; + break; + default: + alert("Mode <" + mode + "> not defined!"); + return false; + } +};