]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/word-count.dev.js
Wordpress 3.3
[autoinstalls/wordpress.git] / wp-admin / js / word-count.dev.js
1
2 (function($) {
3         wpWordCount = {
4
5                 settings : {
6                         strip : /<[a-zA-Z\/][^<>]*>/g, // strip HTML tags
7                         clean : /[0-9.(),;:!?%#$¿'"_+=\\/-]+/g, // regexp to remove punctuation, etc.
8                         count : /\S\s+/g // counting regexp
9                 },
10
11                 block : 0,
12
13                 wc : function(tx) {
14                         var t = this, w = $('.word-count'), tc = 0;
15
16                         if ( t.block )
17                                 return;
18
19                         t.block = 1;
20
21                         setTimeout( function() {
22                                 if ( tx ) {
23                                         tx = tx.replace( t.settings.strip, ' ' ).replace( /&nbsp;|&#160;/gi, ' ' );
24                                         tx = tx.replace( t.settings.clean, '' );
25                                         tx.replace( t.settings.count, function(){tc++;} );
26                                 }
27                                 w.html(tc.toString());
28
29                                 setTimeout( function() { t.block = 0; }, 2000 );
30                         }, 1 );
31                 }
32         }
33
34         $(document).bind( 'wpcountwords', function(e, txt) {
35                 wpWordCount.wc(txt);
36         });
37 }(jQuery));