2012-02-21 10:35:05 -05:00
|
|
|
(function($,undefined) {
|
2009-01-02 10:08:58 -05:00
|
|
|
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.
|
2012-02-21 10:35:05 -05:00
|
|
|
w : /\S\s+/g, // word-counting regexp
|
|
|
|
c : /\S/g // char-counting regexp for asian languages
|
2009-01-02 10:08:58 -05:00
|
|
|
},
|
|
|
|
|
2011-05-16 02:17:44 -04:00
|
|
|
block : 0,
|
|
|
|
|
2012-02-21 10:35:05 -05:00
|
|
|
wc : function(tx, type) {
|
2011-04-24 21:01:34 -04:00
|
|
|
var t = this, w = $('.word-count'), tc = 0;
|
2009-01-02 10:08:58 -05:00
|
|
|
|
2012-02-21 10:35:05 -05:00
|
|
|
if ( type === undefined )
|
|
|
|
type = wordCountL10n.type;
|
|
|
|
if ( type !== 'w' && type !== 'c' )
|
|
|
|
type = 'w';
|
|
|
|
|
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, '' );
|
2012-02-21 10:35:05 -05:00
|
|
|
tx.replace( t.settings[type], 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));
|