2011-05-16 08:17:44 +02:00
|
|
|
|
2009-01-02 16:08:58 +01:00
|
|
|
(function($) {
|
|
|
|
wpWordCount = {
|
|
|
|
|
2011-05-16 08:17:44 +02: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 16:08:58 +01:00
|
|
|
},
|
|
|
|
|
2011-05-16 08:17:44 +02:00
|
|
|
block : 0,
|
|
|
|
|
2009-01-02 16:08:58 +01:00
|
|
|
wc : function(tx) {
|
2011-04-25 03:01:34 +02:00
|
|
|
var t = this, w = $('.word-count'), tc = 0;
|
2009-01-02 16:08:58 +01:00
|
|
|
|
2011-05-16 08:17:44 +02:00
|
|
|
if ( t.block )
|
|
|
|
return;
|
|
|
|
|
2009-01-02 16:08:58 +01:00
|
|
|
t.block = 1;
|
|
|
|
|
|
|
|
setTimeout( function() {
|
|
|
|
if ( tx ) {
|
2011-05-16 08:17:44 +02: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 16:08:58 +01:00
|
|
|
}
|
|
|
|
w.html(tc.toString());
|
|
|
|
|
|
|
|
setTimeout( function() { t.block = 0; }, 2000 );
|
|
|
|
}, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-16 08:17:44 +02:00
|
|
|
$(document).bind( 'wpcountwords', function(e, txt) {
|
|
|
|
wpWordCount.wc(txt);
|
|
|
|
});
|
2009-01-02 16:08:58 +01:00
|
|
|
}(jQuery));
|