equal
deleted
inserted
replaced
1 (function($,undefined) { |
|
2 wpWordCount = { |
|
3 |
|
4 settings : { |
|
5 strip : /<[a-zA-Z\/][^<>]*>/g, // strip HTML tags |
|
6 clean : /[0-9.(),;:!?%#$¿'"_+=\\/-]+/g, // regexp to remove punctuation, etc. |
|
7 w : /\S\s+/g, // word-counting regexp |
|
8 c : /\S/g // char-counting regexp for asian languages |
|
9 }, |
|
10 |
|
11 block : 0, |
|
12 |
|
13 wc : function(tx, type) { |
|
14 var t = this, w = $('.word-count'), tc = 0; |
|
15 |
|
16 if ( type === undefined ) |
|
17 type = wordCountL10n.type; |
|
18 if ( type !== 'w' && type !== 'c' ) |
|
19 type = 'w'; |
|
20 |
|
21 if ( t.block ) |
|
22 return; |
|
23 |
|
24 t.block = 1; |
|
25 |
|
26 setTimeout( function() { |
|
27 if ( tx ) { |
|
28 tx = tx.replace( t.settings.strip, ' ' ).replace( / | /gi, ' ' ); |
|
29 tx = tx.replace( t.settings.clean, '' ); |
|
30 tx.replace( t.settings[type], function(){tc++;} ); |
|
31 } |
|
32 w.html(tc.toString()); |
|
33 |
|
34 setTimeout( function() { t.block = 0; }, 2000 ); |
|
35 }, 1 ); |
|
36 } |
|
37 } |
|
38 |
|
39 $(document).bind( 'wpcountwords', function(e, txt) { |
|
40 wpWordCount.wc(txt); |
|
41 }); |
|
42 }(jQuery)); |
|