source: trunk/www.guidonia.net/wp/wp-admin/js/word-count.dev.js@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 964 bytes
Line 
1// Word count
2(function($) {
3 wpWordCount = {
4
5 init : function() {
6 var t = this, last = 0, co = $('#content');
7
8 $('#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 = $('#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;|&#160;/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
38 $(document).ready( function(){ wpWordCount.init(); } );
39}(jQuery));
Note: See TracBrowser for help on using the repository browser.