From e4f3de8bb267eff0603ce4feaabfd4ed9cccbd26 Mon Sep 17 00:00:00 2001 From: Scott Stafford Date: Wed, 28 Mar 2012 13:40:12 -0400 Subject: [PATCH 1/4] added support for counting estimated number of lines of the text, given 80 chars per line. --- plugins/s_textmetrics/editor_plugin.js | 6 +----- plugins/s_textmetrics/editor_plugin_src.js | 8 ++++++-- plugins/s_textmetrics/text_utils.js | 20 +------------------- plugins/s_textmetrics/text_utils_src.js | 20 +++++++++++++++++++- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/plugins/s_textmetrics/editor_plugin.js b/plugins/s_textmetrics/editor_plugin.js index 9bf4df5..5165869 100644 --- a/plugins/s_textmetrics/editor_plugin.js +++ b/plugins/s_textmetrics/editor_plugin.js @@ -1,5 +1 @@ -(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.getLang("s_textmetrics.characters","Characters: ")+'0'+e.getLang("s_textmetrics.words","Words: ")+'0'+e.getLang("s_textmetrics.sentences","Sentences: ")+'0'+e.getLang("s_textmetrics.paragraphs","Paragraphs: ")+'0'+e.getLang("s_textmetrics.lines","Lines: ")+'0')}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 f=b.getContent({format:"raw"});if(f){var g=tinymce.DOM;var e=sTextUtils.getMetricsForHtml(f);g.setHTML(c.ccid,e.characterCount);g.setHTML(c.wcid,e.wordCount);g.setHTML(c.scid,e.sentenceCount);g.setHTML(c.pcid,e.paragraphCount);g.setHTML(c.lcid,e.lineCount)}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.1"}}});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..79cd881 100644 --- a/plugins/s_textmetrics/editor_plugin_src.js +++ b/plugins/s_textmetrics/editor_plugin_src.js @@ -11,6 +11,7 @@ wcid : null, scid : null, pcid : null, + lcid : null, init : function(ed, url) { @@ -23,6 +24,7 @@ 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'); @@ -43,7 +45,8 @@ '' + 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.paragraphs', 'Paragraphs: ') + '0' + + '' + ed.getLang('s_textmetrics.lines', 'Lines: ') + '0'); } ed.controlManager.setActive('toggle_metrics', t.state); } @@ -95,6 +98,7 @@ d.setHTML(t.wcid, m.wordCount); d.setHTML(t.scid, m.sentenceCount); d.setHTML(t.pcid, m.paragraphCount); + d.setHTML(t.lcid, m.lineCount); } t.block = 0; }, 1); @@ -116,7 +120,7 @@ author : 'Scriptito, LLC', authorurl : 'http://www.scriptito.com', infourl : 'http://www.scriptito.com', - version : "1.2" + version : "1.2.1" }; } diff --git a/plugins/s_textmetrics/text_utils.js b/plugins/s_textmetrics/text_utils.js index f7b3b1a..aecc14b 100644 --- a/plugins/s_textmetrics/text_utils.js +++ b/plugins/s_textmetrics/text_utils.js @@ -14,22 +14,4 @@ * 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),CHARS_PER_LINE:80,getMetricsForHtml:function(g){var q=this.STATE_WHITESPACE;var d=this.STATE_WHITESPACE;var j=0;var h=0;var p=0;var f=0;var k=0;var o=0;var n=0;var b=0;var m=0;var l=0;var a="";for(var e=0;e=this.CHARS_PER_LINE){f++;k=0}if(c==this.CHAR_CODE_AMP){m=e;d=q;q=this.STATE_CHAR_REF}else{if(this.isPunctuation(c)){}else{if(!this.isWhitespace(c)){p++;b++;if(b==1){o++}q=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;q=this.STATE_WHITESPACE}else{q=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++;q=this.STATE_WHITESPACE}else{if(d==this.STATE_WHITESPACE){p++}q=this.STATE_WORD}}break;case this.STATE_WORD:if(c==this.CHAR_CODE_LT){m=e;d=q;q=this.STATE_TAG}else{j++;k++;if(k>=this.CHARS_PER_LINE){f++;k=0}b++;if(c==this.CHAR_CODE_AMP){m=e;d=q;q=this.STATE_CHAR_REF}else{if(this.isPunctuation(c)){b=0;q=this.STATE_WHITESPACE}else{if(this.isWhitespace(c)){h++;q=this.STATE_WHITESPACE}}}}break;default:}}return{characterCount:j,paragraphCount:n,sentenceCount:o,whitespaceCount:h,wordCount:p,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..0e089f5 100644 --- a/plugins/s_textmetrics/text_utils_src.js +++ b/plugins/s_textmetrics/text_utils_src.js @@ -32,6 +32,8 @@ sTextUtils = { CHAR_CODE_SEMI:";".charCodeAt(0), CHAR_CODE_SPACE:" ".charCodeAt(0), + CHARS_PER_LINE: 80, + getMetricsForHtml:function(pText) { var lState = this.STATE_WHITESPACE; @@ -39,6 +41,8 @@ sTextUtils = { var lCharCount = 0; var lWhitespaceCount = 0; var lWordCount = 0; + var lLineCount = 0; + var lLineChars = 0; var lSentenceCount = 0; var lParagraphCount = 0; var lSentenceChars = 0; @@ -60,6 +64,11 @@ sTextUtils = { else { lCharCount++; + lLineChars++; + if (lLineChars >= this.CHARS_PER_LINE) { + lLineCount++; + lLineChars = 0; + } if (lCharCode == this.CHAR_CODE_AMP) { lBufferStart = i; lPrevState = lState; @@ -86,6 +95,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 +129,11 @@ sTextUtils = { } else { lCharCount++; + lLineChars++; + if (lLineChars >= this.CHARS_PER_LINE) { + lLineCount++; + lLineChars = 0; + } lSentenceChars++; if (lCharCode == this.CHAR_CODE_AMP) { lBufferStart = i; @@ -143,7 +160,8 @@ sTextUtils = { "paragraphCount":lParagraphCount, "sentenceCount":lSentenceCount, "whitespaceCount":lWhitespaceCount, - "wordCount":lWordCount + "wordCount":lWordCount, + "lineCount":lLineCount }; }, From 68123a34f9d8e75303646c5da7e60b17b3cfff67 Mon Sep 17 00:00:00 2001 From: Scott Stafford Date: Wed, 28 Mar 2012 16:36:02 -0400 Subject: [PATCH 2/4] Added output templating via new configuration options, s_textmetrics_template and s_textmetrics_updater. --- plugins/s_textmetrics/editor_plugin.js | 6 ++++- plugins/s_textmetrics/editor_plugin_src.js | 28 +++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/plugins/s_textmetrics/editor_plugin.js b/plugins/s_textmetrics/editor_plugin.js index 5165869..3f511a3 100644 --- a/plugins/s_textmetrics/editor_plugin.js +++ b/plugins/s_textmetrics/editor_plugin.js @@ -1 +1,5 @@ -(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.getLang("s_textmetrics.characters","Characters: ")+'0'+e.getLang("s_textmetrics.words","Words: ")+'0'+e.getLang("s_textmetrics.sentences","Sentences: ")+'0'+e.getLang("s_textmetrics.paragraphs","Paragraphs: ")+'0'+e.getLang("s_textmetrics.lines","Lines: ")+'0')}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 f=b.getContent({format:"raw"});if(f){var g=tinymce.DOM;var e=sTextUtils.getMetricsForHtml(f);g.setHTML(c.ccid,e.characterCount);g.setHTML(c.wcid,e.wordCount);g.setHTML(c.scid,e.sentenceCount);g.setHTML(c.pcid,e.paragraphCount);g.setHTML(c.lcid,e.lineCount)}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.1"}}});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 f=b.getContent({format:"raw"});if(f){var h=tinymce.DOM;var e=sTextUtils.getMetricsForHtml(f);var g=b.getParam("s_textmetrics_updater",function(j,k,i){k.setHTML(j.ccid,i.characterCount);k.setHTML(j.wcid,i.wordCount);k.setHTML(j.scid,i.sentenceCount);k.setHTML(j.pcid,i.paragraphCount);k.setHTML(j.lcid,i.lineCount)});g(c,h,e)}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 79cd881..c9d77c0 100644 --- a/plugins/s_textmetrics/editor_plugin_src.js +++ b/plugins/s_textmetrics/editor_plugin_src.js @@ -42,11 +42,14 @@ 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.getLang('s_textmetrics.lines', 'Lines: ') + '0'); + 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); } @@ -94,11 +97,14 @@ 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); - d.setHTML(t.lcid, m.lineCount); + 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); @@ -120,7 +126,7 @@ author : 'Scriptito, LLC', authorurl : 'http://www.scriptito.com', infourl : 'http://www.scriptito.com', - version : "1.2.1" + version : "1.2.2" }; } From f4b9aeb93a1367b79d547eaefce1a79e6b62a4bd Mon Sep 17 00:00:00 2001 From: Scott Stafford Date: Fri, 30 Mar 2012 10:30:24 -0400 Subject: [PATCH 3/4] Added one more parameter, 's_textmetrics_charsperline' (default 80) which sets the 'estimated' characters per line parameter. --- plugins/s_textmetrics/editor_plugin.js | 4 ++-- plugins/s_textmetrics/editor_plugin_src.js | 2 +- plugins/s_textmetrics/text_utils.js | 6 +++++- plugins/s_textmetrics/text_utils_src.js | 11 +++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/s_textmetrics/editor_plugin.js b/plugins/s_textmetrics/editor_plugin.js index 3f511a3..15e4440 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,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 f=b.getContent({format:"raw"});if(f){var h=tinymce.DOM;var e=sTextUtils.getMetricsForHtml(f);var g=b.getParam("s_textmetrics_updater",function(j,k,i){k.setHTML(j.ccid,i.characterCount);k.setHTML(j.wcid,i.wordCount);k.setHTML(j.scid,i.sentenceCount);k.setHTML(j.pcid,i.paragraphCount);k.setHTML(j.lcid,i.lineCount)});g(c,h,e)}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 +}c.block=1;setTimeout(function(){var f=b.getContent({format:"raw"});if(f){var h=tinymce.DOM;var e=sTextUtils.getMetricsForHtml(f,b.getParam("s_textmetrics_charsperline",80));var g=b.getParam("s_textmetrics_updater",function(j,k,i){k.setHTML(j.ccid,i.characterCount);k.setHTML(j.wcid,i.wordCount);k.setHTML(j.scid,i.sentenceCount);k.setHTML(j.pcid,i.paragraphCount);k.setHTML(j.lcid,i.lineCount)});g(c,h,e)}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 c9d77c0..4a958c5 100644 --- a/plugins/s_textmetrics/editor_plugin_src.js +++ b/plugins/s_textmetrics/editor_plugin_src.js @@ -96,7 +96,7 @@ var tx = ed.getContent({format : 'raw'}); if (tx) { var d = tinymce.DOM; - var m = sTextUtils.getMetricsForHtml(tx); + 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); diff --git a/plugins/s_textmetrics/text_utils.js b/plugins/s_textmetrics/text_utils.js index aecc14b..c00e465 100644 --- a/plugins/s_textmetrics/text_utils.js +++ b/plugins/s_textmetrics/text_utils.js @@ -14,4 +14,8 @@ * 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),CHARS_PER_LINE:80,getMetricsForHtml:function(g){var q=this.STATE_WHITESPACE;var d=this.STATE_WHITESPACE;var j=0;var h=0;var p=0;var f=0;var k=0;var o=0;var n=0;var b=0;var m=0;var l=0;var a="";for(var e=0;e=this.CHARS_PER_LINE){f++;k=0}if(c==this.CHAR_CODE_AMP){m=e;d=q;q=this.STATE_CHAR_REF}else{if(this.isPunctuation(c)){}else{if(!this.isWhitespace(c)){p++;b++;if(b==1){o++}q=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;q=this.STATE_WHITESPACE}else{q=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++;q=this.STATE_WHITESPACE}else{if(d==this.STATE_WHITESPACE){p++}q=this.STATE_WORD}}break;case this.STATE_WORD:if(c==this.CHAR_CODE_LT){m=e;d=q;q=this.STATE_TAG}else{j++;k++;if(k>=this.CHARS_PER_LINE){f++;k=0}b++;if(c==this.CHAR_CODE_AMP){m=e;d=q;q=this.STATE_CHAR_REF}else{if(this.isPunctuation(c)){b=0;q=this.STATE_WHITESPACE}else{if(this.isWhitespace(c)){h++;q=this.STATE_WHITESPACE}}}}break;default:}}return{characterCount:j,paragraphCount:n,sentenceCount:o,whitespaceCount:h,wordCount:p,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 +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(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 0e089f5..32d6c43 100644 --- a/plugins/s_textmetrics/text_utils_src.js +++ b/plugins/s_textmetrics/text_utils_src.js @@ -32,10 +32,7 @@ sTextUtils = { CHAR_CODE_SEMI:";".charCodeAt(0), CHAR_CODE_SPACE:" ".charCodeAt(0), - CHARS_PER_LINE: 80, - - getMetricsForHtml:function(pText) { - + getMetricsForHtml:function(pText, pCharsPerLine) { var lState = this.STATE_WHITESPACE; var lPrevState = this.STATE_WHITESPACE; var lCharCount = 0; @@ -50,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); @@ -65,7 +64,7 @@ sTextUtils = { { lCharCount++; lLineChars++; - if (lLineChars >= this.CHARS_PER_LINE) { + if (lLineChars >= pCharsPerLine) { lLineCount++; lLineChars = 0; } @@ -130,7 +129,7 @@ sTextUtils = { else { lCharCount++; lLineChars++; - if (lLineChars >= this.CHARS_PER_LINE) { + if (lLineChars >= pCharsPerLine) { lLineCount++; lLineChars = 0; } From 793a0d93e6584119ee319d97408feea52fe5126c Mon Sep 17 00:00:00 2001 From: Scott Stafford Date: Tue, 3 Jul 2012 15:49:38 -0400 Subject: [PATCH 4/4] Fix innocuous javascript error if frame is closed. --- plugins/s_textmetrics/editor_plugin.js | 4 +- plugins/s_textmetrics/editor_plugin_src.js | 253 +++++++++++---------- plugins/s_textmetrics/text_utils.js | 16 -- 3 files changed, 130 insertions(+), 143 deletions(-) diff --git a/plugins/s_textmetrics/editor_plugin.js b/plugins/s_textmetrics/editor_plugin.js index 15e4440..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,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 f=b.getContent({format:"raw"});if(f){var h=tinymce.DOM;var e=sTextUtils.getMetricsForHtml(f,b.getParam("s_textmetrics_charsperline",80));var g=b.getParam("s_textmetrics_updater",function(j,k,i){k.setHTML(j.ccid,i.characterCount);k.setHTML(j.wcid,i.wordCount);k.setHTML(j.scid,i.sentenceCount);k.setHTML(j.pcid,i.paragraphCount);k.setHTML(j.lcid,i.lineCount)});g(c,h,e)}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 +}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 4a958c5..dc8f7cb 100644 --- a/plugins/s_textmetrics/editor_plugin_src.js +++ b/plugins/s_textmetrics/editor_plugin_src.js @@ -1,137 +1,140 @@ /** - */ - -(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' + +*/ + +(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) + } + 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, 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._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.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 c00e465..7ba89fc 100644 --- a/plugins/s_textmetrics/text_utils.js +++ b/plugins/s_textmetrics/text_utils.js @@ -1,19 +1,3 @@ -/** - * 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(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++;