2011-05-16 02:17:44 -04:00
|
|
|
|
2009-01-02 10:08:58 -05:00
|
|
|
(function($) {
|
|
|
|
wpWordCount = {
|
|
|
|
|
2011-05-16 02:17:44 -04:00
|
|
|
settings : {
|
|
|
|
strip : /<[a-zA-Z\/][^<>]*>/g, // strip HTML tags
|
|
|
|
clean : /[0-9.(),;:!?%#$¿'"_+=\\/-]+/g, // regexp to remove punctuation, etc.
|
|
|
|
count : /\S\s+/g // counting regexp
|
2009-01-02 10:08:58 -05:00
|
|
|
},
|
|
|
|
|
2011-05-16 02:17:44 -04:00
|
|
|
block : 0,
|
|
|
|
|
2009-01-02 10:08:58 -05:00
|
|
|
wc : function(tx) {
|
2011-04-24 21:01:34 -04:00
|
|
|
var t = this, w = $('.word-count'), tc = 0;
|
2009-01-02 10:08:58 -05:00
|
|
|
|
2011-05-16 02:17:44 -04:00
|
|
|
if ( t.block )
|
|
|
|
return;
|
|
|
|
|
2009-01-02 10:08:58 -05:00
|
|
|
t.block = 1;
|
|
|
|
|
|
|
|
setTimeout( function() {
|
|
|
|
if ( tx ) {
|
2011-05-16 02:17:44 -04:00
|
|
|
tx = tx.replace( t.settings.strip, ' ' ).replace( / | /gi, ' ' );
|
|
|
|
tx = tx.replace( t.settings.clean, '' );
|
|
|
|
tx.replace( t.settings.count, function(){tc++;} );
|
2009-01-02 10:08:58 -05:00
|
|
|
}
|
|
|
|
w.html(tc.toString());
|
|
|
|
|
|
|
|
setTimeout( function() { t.block = 0; }, 2000 );
|
|
|
|
}, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 02:17:44 -04:00
|
|
|
$(document).bind( 'wpcountwords', function(e, txt) {
|
|
|
|
wpWordCount.wc(txt);
|
|
|
|
});
|
2009-01-02 10:08:58 -05:00
|
|
|
}(jQuery));
|