diff --git a/plugins/s_textmetrics/editor_plugin.js b/plugins/s_textmetrics/editor_plugin.js
index 9bf4df5..7c5df0e 100644
--- a/plugins/s_textmetrics/editor_plugin.js
+++ b/plugins/s_textmetrics/editor_plugin.js
@@ -1,5 +1,5 @@
-(function(){tinymce.create('scriptito.plugins.TextMetrics',{block:0,tid:null,ccid:null,wcid:null,scid:null,pcid:null,init:function(ed,url){var t=this;t.editor=ed;t.tid=ed.id+"-metrics";t.ccid=ed.id+'-character-count';t.wcid=ed.id+'-word-count';t.scid=ed.id+'-sentence-count';t.pcid=ed.id+'-paragraph-count';t.state=ed.getParam('s_textmetrics_on');ed.addCommand("s_toggleMetrics",t._toggleMetrics,t);ed.addButton('toggle_metrics',{title:'s_textmetrics.button_title',cmd:'s_toggleMetrics'});ed.onPostRender.add(function(ed,cm){var row,id;id=ed.getParam('textmetrics_target_id');if(!id){row=tinymce.DOM.get(ed.id+'_path_row');if(row){tinymce.DOM.add(row.parentNode,'div',{'id':t.tid,'class':'metrics','style':'display:'+(t.state?"block;":"none;")},''+ed.getLang('s_textmetrics.characters','Characters: ')+'0'+''+ed.getLang('s_textmetrics.words','Words: ')+'0'+''+ed.getLang('s_textmetrics.sentences','Sentences: ')+'0'+''+ed.getLang('s_textmetrics.paragraphs','Paragraphs: ')+'0');}
-ed.controlManager.setActive('toggle_metrics',t.state);}
-else{tinymce.DOM.add(id,'span',{},'0');}});ed.onSetContent.add(function(ed){t._count(ed);});ed.onLoadContent.add(function(ed){t._count(ed);});ed.onUndo.add(function(ed){t._count(ed);});ed.onPaste.add(function(ed){t._count(ed);});ed.onKeyUp.add(function(ed,e){if(sTextUtils.isWhitespaceKeyCode(e.keyCode)||sTextUtils.isPunctuationKeyCode(e.keyCode)||8==e.keyCode||46==e.keyCode){t._count(ed);}});},_count:function(ed){var t=this,tc=0;if(!t.state||t.block)
-return;t.block=1;setTimeout(function(){var tx=ed.getContent({format:'raw'});if(tx){var d=tinymce.DOM;var m=sTextUtils.getMetricsForHtml(tx);d.setHTML(t.ccid,m.characterCount);d.setHTML(t.wcid,m.wordCount);d.setHTML(t.scid,m.sentenceCount);d.setHTML(t.pcid,m.paragraphCount);}
-t.block=0;},1);},_toggleMetrics:function(){var t=this,ed=t.editor;t.state=!t.state;ed.controlManager.setActive('toggle_metrics',t.state);tinymce.DOM.setStyle(t.tid,"display",t.state?"block":"none");if(t.state){t._count(ed);}},getInfo:function(){return{longname:'Text Metrics Plugin',author:'Scriptito, LLC',authorurl:'http://www.scriptito.com',infourl:'http://www.scriptito.com',version:"1.2"};}});tinymce.PluginManager.add('s_textmetrics',scriptito.plugins.TextMetrics);})();
\ No newline at end of file
+(function(){tinymce.create("scriptito.plugins.TextMetrics",{block:0,tid:null,ccid:null,wcid:null,scid:null,pcid:null,lcid:null,init:function(a,b){var c=this;c.editor=a;c.tid=a.id+"-metrics";c.ccid=a.id+"-character-count";c.wcid=a.id+"-word-count";c.scid=a.id+"-sentence-count";c.pcid=a.id+"-paragraph-count";c.lcid=a.id+"-line-count";c.state=a.getParam("s_textmetrics_on");a.addCommand("s_toggleMetrics",c._toggleMetrics,c);a.addButton("toggle_metrics",{title:"s_textmetrics.button_title",cmd:"s_toggleMetrics"});
+a.onPostRender.add(function(e,d){var f,g;g=e.getParam("textmetrics_target_id");if(!g){f=tinymce.DOM.get(e.id+"_path_row");if(f){tinymce.DOM.add(f.parentNode,"div",{id:c.tid,"class":"metrics",style:"display:"+(c.state?"block;":"none;")},e.getParam("s_textmetrics_template",function(h,i){return""+h.getLang("s_textmetrics.characters","Characters: ")+'0'+h.getLang("s_textmetrics.words","Words: ")+'0'+h.getLang("s_textmetrics.sentences","Sentences: ")+'0'+h.getLang("s_textmetrics.paragraphs","Paragraphs: ")+'0'+h.getLang("s_textmetrics.lines","Lines: ")+'0'
+})(e,c))}e.controlManager.setActive("toggle_metrics",c.state)}else{tinymce.DOM.add(g,"span",{},'0')}});a.onSetContent.add(function(d){c._count(d)});a.onLoadContent.add(function(d){c._count(d)});a.onUndo.add(function(d){c._count(d)});a.onPaste.add(function(d){c._count(d)});a.onKeyUp.add(function(d,f){if(sTextUtils.isWhitespaceKeyCode(f.keyCode)||sTextUtils.isPunctuationKeyCode(f.keyCode)||8==f.keyCode||46==f.keyCode){c._count(d)}})},_count:function(b){var c=this,a=0;if(!c.state||c.block){return
+}c.block=1;setTimeout(function(){var g=null;try{g=b.getContent({format:"raw"})}catch(h){}if(g){var j=tinymce.DOM;var f=sTextUtils.getMetricsForHtml(g,b.getParam("s_textmetrics_charsperline",80));var i=b.getParam("s_textmetrics_updater",function(k,l,e){l.setHTML(k.ccid,e.characterCount);l.setHTML(k.wcid,e.wordCount);l.setHTML(k.scid,e.sentenceCount);l.setHTML(k.pcid,e.paragraphCount);l.setHTML(k.lcid,e.lineCount)});i(c,j,f)}c.block=0},1)},_toggleMetrics:function(){var b=this,a=b.editor;b.state=!b.state;
+a.controlManager.setActive("toggle_metrics",b.state);tinymce.DOM.setStyle(b.tid,"display",b.state?"block":"none");if(b.state){b._count(a)}},getInfo:function(){return{longname:"Text Metrics Plugin",author:"Scriptito, LLC",authorurl:"http://www.scriptito.com",infourl:"http://www.scriptito.com",version:"1.2.2"}}});tinymce.PluginManager.add("s_textmetrics",scriptito.plugins.TextMetrics)})();
\ No newline at end of file
diff --git a/plugins/s_textmetrics/editor_plugin_src.js b/plugins/s_textmetrics/editor_plugin_src.js
index 70deaef..dc8f7cb 100644
--- a/plugins/s_textmetrics/editor_plugin_src.js
+++ b/plugins/s_textmetrics/editor_plugin_src.js
@@ -1,127 +1,140 @@
/**
- */
-
-(function() {
-
- tinymce.create('scriptito.plugins.TextMetrics', {
-
- block : 0,
- tid: null,
- ccid : null,
- wcid : null,
- scid : null,
- pcid : null,
-
- init : function(ed, url) {
-
- var t = this;
-
- t.editor = ed;
-
- t.tid = ed.id + "-metrics";
- t.ccid = ed.id + '-character-count';
- t.wcid = ed.id + '-word-count';
- t.scid = ed.id + '-sentence-count';
- t.pcid = ed.id + '-paragraph-count';
-
- t.state = ed.getParam('s_textmetrics_on');
-
- ed.addCommand("s_toggleMetrics", t._toggleMetrics, t);
-
- ed.addButton('toggle_metrics', { title:'s_textmetrics.button_title', cmd:'s_toggleMetrics' });
-
- ed.onPostRender.add(function(ed, cm) {
- var row, id;
- id = ed.getParam('textmetrics_target_id');
- if (!id) {
- row = tinymce.DOM.get(ed.id + '_path_row');
- if (row) {
- tinymce.DOM.add(
- row.parentNode,
- 'div',
- { 'id':t.tid, 'class':'metrics', 'style':'display:' + (t.state ? "block;" : "none;") },
- '' + ed.getLang('s_textmetrics.characters', 'Characters: ') + '0' +
- '' + ed.getLang('s_textmetrics.words', 'Words: ') + '0' +
- '' + ed.getLang('s_textmetrics.sentences', 'Sentences: ') + '0' +
- '' + ed.getLang('s_textmetrics.paragraphs', 'Paragraphs: ') + '0');
- }
- ed.controlManager.setActive('toggle_metrics', t.state);
- }
- else {
- tinymce.DOM.add(id, 'span', {}, '0');
- }
- });
-
- ed.onSetContent.add(function(ed) {
- t._count(ed);
- });
-
- ed.onLoadContent.add(function(ed) {
- t._count(ed);
- });
-
- ed.onUndo.add(function(ed) {
- t._count(ed);
- });
-
- ed.onPaste.add(function(ed) {
- t._count(ed);
- });
-
- ed.onKeyUp.add(function(ed, e) {
- if (sTextUtils.isWhitespaceKeyCode(e.keyCode) || sTextUtils.isPunctuationKeyCode(e.keyCode)
+*/
+
+(function () {
+
+ tinymce.create('scriptito.plugins.TextMetrics', {
+
+ block: 0,
+ tid: null,
+ ccid: null,
+ wcid: null,
+ scid: null,
+ pcid: null,
+ lcid: null,
+
+ init: function (ed, url) {
+
+ var t = this;
+
+ t.editor = ed;
+
+ t.tid = ed.id + "-metrics";
+ t.ccid = ed.id + '-character-count';
+ t.wcid = ed.id + '-word-count';
+ t.scid = ed.id + '-sentence-count';
+ t.pcid = ed.id + '-paragraph-count';
+ t.lcid = ed.id + '-line-count';
+
+ t.state = ed.getParam('s_textmetrics_on');
+
+ ed.addCommand("s_toggleMetrics", t._toggleMetrics, t);
+
+ ed.addButton('toggle_metrics', { title: 's_textmetrics.button_title', cmd: 's_toggleMetrics' });
+
+ ed.onPostRender.add(function (ed, cm) {
+ var row, id;
+ id = ed.getParam('textmetrics_target_id');
+ if (!id) {
+ row = tinymce.DOM.get(ed.id + '_path_row');
+ if (row) {
+ tinymce.DOM.add(
+ row.parentNode,
+ 'div',
+ { 'id': t.tid, 'class': 'metrics', 'style': 'display:' + (t.state ? "block;" : "none;") },
+ ed.getParam('s_textmetrics_template', function (ed, t) {
+ return '' + ed.getLang('s_textmetrics.characters', 'Characters: ') + '0' +
+ '' + ed.getLang('s_textmetrics.words', 'Words: ') + '0' +
+ '' + ed.getLang('s_textmetrics.sentences', 'Sentences: ') + '0' +
+ '' + ed.getLang('s_textmetrics.paragraphs', 'Paragraphs: ') + '0' +
+ '' + ed.getLang('s_textmetrics.lines', 'Lines: ') + '0';
+ })(ed, t)
+ );
+ }
+ ed.controlManager.setActive('toggle_metrics', t.state);
+ }
+ else {
+ tinymce.DOM.add(id, 'span', {}, '0');
+ }
+ });
+
+ ed.onSetContent.add(function (ed) {
+ t._count(ed);
+ });
+
+ ed.onLoadContent.add(function (ed) {
+ t._count(ed);
+ });
+
+ ed.onUndo.add(function (ed) {
+ t._count(ed);
+ });
+
+ ed.onPaste.add(function (ed) {
+ t._count(ed);
+ });
+
+ ed.onKeyUp.add(function (ed, e) {
+ if (sTextUtils.isWhitespaceKeyCode(e.keyCode) || sTextUtils.isPunctuationKeyCode(e.keyCode)
|| 8 == e.keyCode // Backspace
|| 46 == e.keyCode) { // Delete
- t._count(ed);
- }
- });
-
- },
-
- _count : function(ed) {
- var t = this, tc = 0;
-
- if (!t.state || t.block)
- return;
-
- t.block = 1;
-
- setTimeout(function() {
- var tx = ed.getContent({format : 'raw'});
- if (tx) {
- var d = tinymce.DOM;
- var m = sTextUtils.getMetricsForHtml(tx);
- d.setHTML(t.ccid, m.characterCount);
- d.setHTML(t.wcid, m.wordCount);
- d.setHTML(t.scid, m.sentenceCount);
- d.setHTML(t.pcid, m.paragraphCount);
+ t._count(ed);
+ }
+ });
+
+ },
+
+ _count: function (ed) {
+ var t = this, tc = 0;
+
+ if (!t.state || t.block)
+ return;
+
+ t.block = 1;
+
+ setTimeout(function () {
+ var tx = null;
+ try {
+ tx = ed.getContent({ format: 'raw' });
+ } catch (e) { }
+ if (tx) {
+ var d = tinymce.DOM;
+ var m = sTextUtils.getMetricsForHtml(tx, ed.getParam('s_textmetrics_charsperline', 80));
+ var updater = ed.getParam('s_textmetrics_updater', function (t, d, m) {
+ d.setHTML(t.ccid, m.characterCount);
+ d.setHTML(t.wcid, m.wordCount);
+ d.setHTML(t.scid, m.sentenceCount);
+ d.setHTML(t.pcid, m.paragraphCount);
+ d.setHTML(t.lcid, m.lineCount);
+ });
+ updater(t, d, m);
+ }
+ t.block = 0;
+ }, 1);
+ },
+
+ _toggleMetrics: function () {
+ var t = this, ed = t.editor;
+ t.state = !t.state;
+ ed.controlManager.setActive('toggle_metrics', t.state);
+ tinymce.DOM.setStyle(t.tid, "display", t.state ? "block" : "none");
+ if (t.state) {
+ t._count(ed);
+ }
+ },
+
+ getInfo: function () {
+ return {
+ longname: 'Text Metrics Plugin',
+ author: 'Scriptito, LLC',
+ authorurl: 'http://www.scriptito.com',
+ infourl: 'http://www.scriptito.com',
+ version: "1.2.2"
+ };
}
- t.block = 0;
- }, 1);
- },
-
- _toggleMetrics:function() {
- var t = this, ed = t.editor;
- t.state = !t.state;
- ed.controlManager.setActive('toggle_metrics', t.state);
- tinymce.DOM.setStyle(t.tid, "display", t.state ? "block" : "none");
- if (t.state) {
- t._count(ed);
- }
- },
-
- getInfo: function() {
- return {
- longname : 'Text Metrics Plugin',
- author : 'Scriptito, LLC',
- authorurl : 'http://www.scriptito.com',
- infourl : 'http://www.scriptito.com',
- version : "1.2"
- };
- }
-
- });
-
- tinymce.PluginManager.add('s_textmetrics', scriptito.plugins.TextMetrics);
+
+ });
+
+ tinymce.PluginManager.add('s_textmetrics', scriptito.plugins.TextMetrics);
})();
diff --git a/plugins/s_textmetrics/text_utils.js b/plugins/s_textmetrics/text_utils.js
index f7b3b1a..7ba89fc 100644
--- a/plugins/s_textmetrics/text_utils.js
+++ b/plugins/s_textmetrics/text_utils.js
@@ -1,35 +1,5 @@
-/**
- * Copyright 2010, Scriptito LLC.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-sTextUtils={STATE_WHITESPACE:0,STATE_TAG:1,STATE_WORD:2,STATE_CHAR_REF:3,CHAR_CODE_AMP:"&".charCodeAt(0),CHAR_CODE_CARRIAGE:"\r".charCodeAt(0),CHAR_CODE_EXCLAIM:"!".charCodeAt(0),CHAR_CODE_GT:">".charCodeAt(0),CHAR_CODE_LT:"<".charCodeAt(0),CHAR_CODE_NEWLINE:"\n".charCodeAt(0),CHAR_CODE_PERIOD:".".charCodeAt(0),CHAR_CODE_QUESTION:"?".charCodeAt(0),CHAR_CODE_SEMI:";".charCodeAt(0),CHAR_CODE_SPACE:" ".charCodeAt(0),getMetricsForHtml:function(pText){var lState=this.STATE_WHITESPACE;var lPrevState=this.STATE_WHITESPACE;var lCharCount=0;var lWhitespaceCount=0;var lWordCount=0;var lSentenceCount=0;var lParagraphCount=0;var lSentenceChars=0;var lBufferStart=0;var lBufferLen=0;var lBuffer="";for(var i=0;i".charCodeAt(0),CHAR_CODE_LT:"<".charCodeAt(0),CHAR_CODE_NEWLINE:"\n".charCodeAt(0),CHAR_CODE_PERIOD:".".charCodeAt(0),CHAR_CODE_QUESTION:"?".charCodeAt(0),CHAR_CODE_SEMI:";".charCodeAt(0),CHAR_CODE_SPACE:" ".charCodeAt(0),getMetricsForHtml:function(g,p){var r=this.STATE_WHITESPACE;var d=this.STATE_WHITESPACE;
+var j=0;var h=0;var q=0;var f=0;var k=0;var o=0;var n=0;var b=0;var m=0;var l=0;var a="";p=p||80;for(var e=0;e=p){f++;k=0}if(c==this.CHAR_CODE_AMP){m=e;d=r;r=this.STATE_CHAR_REF}else{if(this.isPunctuation(c)){}else{if(!this.isWhitespace(c)){q++;b++;if(b==1){o++}r=this.STATE_WORD}else{h++}}}}break;case this.STATE_TAG:if(c==this.CHAR_CODE_GT){var a=g.substring(m+1,e).toLowerCase();
+if(a=="p"||a=="li"){n++;f++;k=0;b=0;r=this.STATE_WHITESPACE}else{r=d}}break;case this.STATE_CHAR_REF:if(c==this.CHAR_CODE_SEMI){var a=g.substring(m+1,e).toLowerCase();if(a=="nbsp"){h++;r=this.STATE_WHITESPACE}else{if(d==this.STATE_WHITESPACE){q++}r=this.STATE_WORD}}break;case this.STATE_WORD:if(c==this.CHAR_CODE_LT){m=e;d=r;r=this.STATE_TAG}else{j++;k++;if(k>=p){f++;k=0}b++;if(c==this.CHAR_CODE_AMP){m=e;d=r;r=this.STATE_CHAR_REF}else{if(this.isPunctuation(c)){b=0;r=this.STATE_WHITESPACE}else{if(this.isWhitespace(c)){h++;
+r=this.STATE_WHITESPACE}}}}break;default:}}return{characterCount:j,paragraphCount:n,sentenceCount:o,whitespaceCount:h,wordCount:q,lineCount:f}},isPunctuation:function(a){return a==this.CHAR_CODE_PERIOD||a==this.CHAR_CODE_EXCLAIM||a==this.CHAR_CODE_QUESTION},isPunctuationKeyCode:function(a){return(a==190||a==46)||a==49||(a==191||a==47)},isWhitespace:function(a){return a==this.CHAR_CODE_SPACE||a==this.CHAR_CODE_NEWLINE||a==this.CHAR_CODE_CARRIAGE},isWhitespaceKeyCode:function(a){return a==13||a==32
+}};
\ No newline at end of file
diff --git a/plugins/s_textmetrics/text_utils_src.js b/plugins/s_textmetrics/text_utils_src.js
index cdf3572..32d6c43 100644
--- a/plugins/s_textmetrics/text_utils_src.js
+++ b/plugins/s_textmetrics/text_utils_src.js
@@ -32,13 +32,14 @@ sTextUtils = {
CHAR_CODE_SEMI:";".charCodeAt(0),
CHAR_CODE_SPACE:" ".charCodeAt(0),
- getMetricsForHtml:function(pText) {
-
+ getMetricsForHtml:function(pText, pCharsPerLine) {
var lState = this.STATE_WHITESPACE;
var lPrevState = this.STATE_WHITESPACE;
var lCharCount = 0;
var lWhitespaceCount = 0;
var lWordCount = 0;
+ var lLineCount = 0;
+ var lLineChars = 0;
var lSentenceCount = 0;
var lParagraphCount = 0;
var lSentenceChars = 0;
@@ -46,6 +47,8 @@ sTextUtils = {
var lBufferLen = 0;
var lBuffer = "";
+ pCharsPerLine = pCharsPerLine || 80;
+
for (var i = 0; i < pText.length; i++)
{
var lCharCode = pText.charCodeAt(i);
@@ -60,6 +63,11 @@ sTextUtils = {
else
{
lCharCount++;
+ lLineChars++;
+ if (lLineChars >= pCharsPerLine) {
+ lLineCount++;
+ lLineChars = 0;
+ }
if (lCharCode == this.CHAR_CODE_AMP) {
lBufferStart = i;
lPrevState = lState;
@@ -86,6 +94,9 @@ sTextUtils = {
var lBuffer = pText.substring(lBufferStart + 1, i).toLowerCase();
if (lBuffer == "p" || lBuffer == "li") {
lParagraphCount++;
+ lLineCount++;
+ lLineChars = 0;
+
lSentenceChars = 0;
lState = this.STATE_WHITESPACE;
}
@@ -117,6 +128,11 @@ sTextUtils = {
}
else {
lCharCount++;
+ lLineChars++;
+ if (lLineChars >= pCharsPerLine) {
+ lLineCount++;
+ lLineChars = 0;
+ }
lSentenceChars++;
if (lCharCode == this.CHAR_CODE_AMP) {
lBufferStart = i;
@@ -143,7 +159,8 @@ sTextUtils = {
"paragraphCount":lParagraphCount,
"sentenceCount":lSentenceCount,
"whitespaceCount":lWhitespaceCount,
- "wordCount":lWordCount
+ "wordCount":lWordCount,
+ "lineCount":lLineCount
};
},