+++ /dev/null
-/**\r
- * editor_plugin_src.js\r
- *\r
- * Copyright 2009, Moxiecode Systems AB\r
- * Released under LGPL License.\r
- *\r
- * License: http://tinymce.moxiecode.com/license\r
- * Contributing: http://tinymce.moxiecode.com/contributing\r
- */\r
-\r
-(function() {\r
- tinymce.create('tinymce.plugins.WordCount', {\r
- block : 0,\r
- id : null,\r
- countre : null,\r
- cleanre : null,\r
-\r
- init : function(ed, url) {\r
- var t = this, last = 0;\r
-\r
- t.countre = ed.getParam('wordcount_countregex', /[\w\u2019\'-]+/g); // u2019 == ’\r
- t.cleanre = ed.getParam('wordcount_cleanregex', /[0-9.(),;:!?%#$?\'\"_+=\\\/-]*/g);\r
- t.id = ed.id + '-word-count';\r
-\r
- ed.onPostRender.add(function(ed, cm) {\r
- var row, id;\r
-\r
- // Add it to the specified id or the theme advanced path\r
- id = ed.getParam('wordcount_target_id');\r
- if (!id) {\r
- row = tinymce.DOM.get(ed.id + '_path_row');\r
-\r
- if (row)\r
- tinymce.DOM.add(row.parentNode, 'div', {'style': 'float: right'}, ed.getLang('wordcount.words', 'Words: ') + '<span id="' + t.id + '">0</span>');\r
- } else {\r
- tinymce.DOM.add(id, 'span', {}, '<span id="' + t.id + '">0</span>');\r
- }\r
- });\r
-\r
- ed.onInit.add(function(ed) {\r
- ed.selection.onSetContent.add(function() {\r
- t._count(ed);\r
- });\r
-\r
- t._count(ed);\r
- });\r
-\r
- ed.onSetContent.add(function(ed) {\r
- t._count(ed);\r
- });\r
-\r
- ed.onKeyUp.add(function(ed, e) {\r
- if (e.keyCode == last)\r
- return;\r
-\r
- if (13 == e.keyCode || 8 == last || 46 == last)\r
- t._count(ed);\r
-\r
- last = e.keyCode;\r
- });\r
- },\r
-\r
- _getCount : function(ed) {\r
- var tc = 0;\r
- var tx = ed.getContent({ format: 'raw' });\r
-\r
- if (tx) {\r
- tx = tx.replace(/\.\.\./g, ' '); // convert ellipses to spaces\r
- tx = tx.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' '); // remove html tags and space chars\r
-\r
- // deal with html entities\r
- tx = tx.replace(/(\w+)(&.+?;)+(\w+)/, "$1$3").replace(/&.+?;/g, ' ');\r
- tx = tx.replace(this.cleanre, ''); // remove numbers and punctuation\r
-\r
- var wordArray = tx.match(this.countre);\r
- if (wordArray) {\r
- tc = wordArray.length;\r
- }\r
- }\r
-\r
- return tc;\r
- },\r
-\r
- _count : function(ed) {\r
- var t = this;\r
-\r
- // Keep multiple calls from happening at the same time\r
- if (t.block)\r
- return;\r
-\r
- t.block = 1;\r
-\r
- setTimeout(function() {\r
- var tc = t._getCount(ed);\r
-\r
- tinymce.DOM.setHTML(t.id, tc.toString());\r
-\r
- setTimeout(function() {t.block = 0;}, 2000);\r
- }, 1);\r
- },\r
-\r
- getInfo: function() {\r
- return {\r
- longname : 'Word Count plugin',\r
- author : 'Moxiecode Systems AB',\r
- authorurl : 'http://tinymce.moxiecode.com',\r
- infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/wordcount',\r
- version : tinymce.majorVersion + "." + tinymce.minorVersion\r
- };\r
- }\r
- });\r
-\r
- tinymce.PluginManager.add('wordcount', tinymce.plugins.WordCount);\r
-})();\r