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', /\S\s+/g);
\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
39 ed.onInit.add(function(ed) {
\r
40 ed.selection.onSetContent.add(function() {
\r
47 ed.onSetContent.add(function(ed) {
\r
51 ed.onKeyUp.add(function(ed, e) {
\r
52 if (e.keyCode == last)
\r
55 if (13 == e.keyCode || 8 == last || 46 == last)
\r
62 _count : function(ed) {
\r
63 var t = this, tc = 0;
\r
65 // Keep multiple calls from happening at the same time
\r
71 setTimeout(function() {
\r
72 var tx = ed.getContent({format : 'raw'});
\r
75 tx = tx.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' '); // remove html tags and space chars
\r
76 tx = tx.replace(t.cleanre, ''); // remove numbers and punctuation
\r
77 tx.replace(t.countre, function() {tc++;}); // count the words
\r
80 tinymce.DOM.setHTML(t.id, tc.toString());
\r
82 setTimeout(function() {t.block = 0;}, 2000);
\r
86 getInfo: function() {
\r
88 longname : 'Word Count plugin',
\r
89 author : 'Moxiecode Systems AB',
\r
90 authorurl : 'http://tinymce.moxiecode.com',
\r
91 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/wordcount',
\r
92 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
97 tinymce.PluginManager.add('wordcount', tinymce.plugins.WordCount);
\r