includes/clientside/tinymce/plugins/wordcount/editor_plugin_src.js
author Dan Fuhry <dan@enanocms.org>
Fri, 19 Nov 2010 03:30:35 -0500
changeset 1329 61d87ee12e80
parent 1193 e3b94bd055dc
permissions -rw-r--r--
Added conflict resolution for wikitext heading names
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1193
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
     1
/**
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
     2
 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
     3
 *
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
     4
 * @author Moxiecode
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
     5
 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
     6
 */
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
     7
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
     8
(function() {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
     9
    tinymce.create('tinymce.plugins.WordCount', {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    10
		block : 0,
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    11
		id : null,
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    12
		countre : null,
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    13
		cleanre : null,
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    14
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    15
		init : function(ed, url) {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    16
			var t = this, last = 0;
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    17
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    18
			t.countre = ed.getParam('wordcount_countregex', /\S\s+/g);
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    19
			t.cleanre = ed.getParam('wordcount_cleanregex', /[0-9.(),;:!?%#$¿'"_+=\\/-]*/g);
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    20
			t.id = ed.id + '-word-count';
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    21
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    22
			ed.onPostRender.add(function(ed, cm) {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    23
				var row, id;
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    24
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    25
				// Add it to the specified id or the theme advanced path
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    26
				id = ed.getParam('wordcount_target_id');
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    27
				if (!id) {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    28
					row = tinymce.DOM.get(ed.id + '_path_row');
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    29
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    30
					if (row)
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    31
						tinymce.DOM.add(row.parentNode, 'div', {'style': 'float: right'}, ed.getLang('wordcount.words', 'Words: ') + '<span id="' + t.id + '">0</span>');
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    32
				} else
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    33
					tinymce.DOM.add(id, 'span', {}, '<span id="' + t.id + '">0</span>');
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    34
			});
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    35
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    36
            ed.onInit.add(function(ed) {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    37
				ed.selection.onSetContent.add(function() {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    38
					t._count(ed);
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    39
				});
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    40
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    41
				t._count(ed);
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    42
			});
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    43
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    44
			ed.onSetContent.add(function(ed) {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    45
				t._count(ed);
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    46
			});
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    47
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    48
			ed.onKeyUp.add(function(ed, e) {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    49
				if (e.keyCode == last)
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    50
					return;
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    51
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    52
				if (13 == e.keyCode || 8 == last || 46 == last)
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    53
					t._count(ed);
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    54
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    55
				last = e.keyCode;
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    56
			});
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    57
		},
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    58
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    59
		_count : function(ed) {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    60
			var t = this, tc = 0;
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    61
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    62
			// Keep multiple calls from happening at the same time
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    63
			if (t.block)
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    64
				return;
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    65
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    66
			t.block = 1;
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    67
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    68
			setTimeout(function() {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    69
				var tx = ed.getContent({format : 'raw'});
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    70
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    71
				if (tx) {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    72
					tx = tx.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' '); // remove html tags and space chars
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    73
					tx = tx.replace(t.cleanre, ''); // remove numbers and punctuation
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    74
					tx.replace(t.countre, function() {tc++;}); // count the words
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    75
				}
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    76
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    77
				tinymce.DOM.setHTML(t.id, tc.toString());
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    78
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    79
				setTimeout(function() {t.block = 0;}, 2000);
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    80
			}, 1);
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    81
		},
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    82
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    83
        getInfo: function() {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    84
			return {
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    85
				longname : 'Word Count plugin',
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    86
				author : 'Moxiecode Systems AB',
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    87
				authorurl : 'http://tinymce.moxiecode.com',
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    88
				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/wordcount',
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    89
				version : tinymce.majorVersion + "." + tinymce.minorVersion
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    90
			};
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    91
        }
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    92
    });
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    93
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    94
    tinymce.PluginManager.add('wordcount', tinymce.plugins.WordCount);
e3b94bd055dc TinyMCE: Bumped to v3.2.7
Dan
parents:
diff changeset
    95
})();