2 * editor_plugin_src.js
\r
4 * Copyright 2009, Moxiecode Systems AB
\r
5 * Released under LGPL License.
\r
7 * License: http://tinymce.moxiecode.com/license
\r
8 * Contributing: http://tinymce.moxiecode.com/contributing
\r
12 tinymce.create('tinymce.plugins.WordCount', {
\r
18 init : function(ed, url) {
\r
19 var t = this, last = 0;
\r
21 t.countre = ed.getParam('wordcount_countregex', /[\w\u2019\'-]+/g); // u2019 == ’
\r
22 t.cleanre = ed.getParam('wordcount_cleanregex', /[0-9.(),;:!?%#$?\'\"_+=\\\/-]*/g);
\r
23 t.id = ed.id + '-word-count';
\r
25 ed.onPostRender.add(function(ed, cm) {
\r
28 // Add it to the specified id or the theme advanced path
\r
29 id = ed.getParam('wordcount_target_id');
\r
31 row = tinymce.DOM.get(ed.id + '_path_row');
\r
34 tinymce.DOM.add(row.parentNode, 'div', {'style': 'float: right'}, ed.getLang('wordcount.words', 'Words: ') + '<span id="' + t.id + '">0</span>');
\r
36 tinymce.DOM.add(id, 'span', {}, '<span id="' + t.id + '">0</span>');
\r
40 ed.onInit.add(function(ed) {
\r
41 ed.selection.onSetContent.add(function() {
\r
48 ed.onSetContent.add(function(ed) {
\r
52 ed.onKeyUp.add(function(ed, e) {
\r
53 if (e.keyCode == last)
\r
56 if (13 == e.keyCode || 8 == last || 46 == last)
\r
63 _getCount : function(ed) {
\r
65 var tx = ed.getContent({ format: 'raw' });
\r
68 tx = tx.replace(/\.\.\./g, ' '); // convert ellipses to spaces
\r
69 tx = tx.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' '); // remove html tags and space chars
\r
71 // deal with html entities
\r
72 tx = tx.replace(/(\w+)(&.+?;)+(\w+)/, "$1$3").replace(/&.+?;/g, ' ');
\r
73 tx = tx.replace(this.cleanre, ''); // remove numbers and punctuation
\r
75 var wordArray = tx.match(this.countre);
\r
77 tc = wordArray.length;
\r
84 _count : function(ed) {
\r
87 // Keep multiple calls from happening at the same time
\r
93 setTimeout(function() {
\r
94 var tc = t._getCount(ed);
\r
96 tinymce.DOM.setHTML(t.id, tc.toString());
\r
98 setTimeout(function() {t.block = 0;}, 2000);
\r
102 getInfo: function() {
\r
104 longname : 'Word Count plugin',
\r
105 author : 'Moxiecode Systems AB',
\r
106 authorurl : 'http://tinymce.moxiecode.com',
\r
107 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/wordcount',
\r
108 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
113 tinymce.PluginManager.add('wordcount', tinymce.plugins.WordCount);
\r