]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/word-count.js
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-admin / js / word-count.js
1 // Word count
2 (function(JQ) {
3         wpWordCount = {
4
5                 init : function() {
6                         var t = this, last = 0, co = JQ('#content');
7
8                         JQ('#wp-word-count').html( wordCountL10n.count.replace( /%d/, '<span id="word-count">0</span>' ) );
9                         t.block = 0;
10                         t.wc(co.val());
11                         co.keyup( function(e) { 
12                                 if ( e.keyCode == last ) return true;
13                                 if ( 13 == e.keyCode || 8 == last || 46 == last ) t.wc(co.val());
14                                 last = e.keyCode;
15                                 return true;
16                         });
17                 },
18
19                 wc : function(tx) {
20                         var t = this, w = JQ('#word-count'), tc = 0;
21
22                         if ( t.block ) return;
23                         t.block = 1;
24
25                         setTimeout( function() {
26                                 if ( tx ) {
27                                         tx = tx.replace( /<.[^<>]*?>/g, ' ' ).replace( /&nbsp;/gi, ' ' );
28                                         tx = tx.replace( /[0-9.(),;:!?%#$¿'"_+=\\/-]*/g, '' );
29                                         tx.replace( /\S\s+/g, function(){tc++;} );
30                                 }
31                                 w.html(tc.toString());
32
33                                 setTimeout( function() { t.block = 0; }, 2000 );
34                         }, 1 );
35                 }
36         } 
37 }(jQuery));
38
39 jQuery(document).ready( function(){ wpWordCount.init(); } );