mp-wp_genesis 1 // Word count
mp-wp_genesis 2 (function(JQ) {
mp-wp_genesis 3 wpWordCount = {
mp-wp_genesis 4
mp-wp_genesis 5 init : function() {
mp-wp_genesis 6 var t = this, last = 0, co = JQ('#content');
mp-wp_genesis 7
mp-wp_genesis 8 JQ('#wp-word-count').html( wordCountL10n.count.replace( /%d/, '<span id="word-count">0</span>' ) );
mp-wp_genesis 9 t.block = 0;
mp-wp_genesis 10 t.wc(co.val());
mp-wp_genesis 11 co.keyup( function(e) {
mp-wp_genesis 12 if ( e.keyCode == last ) return true;
mp-wp_genesis 13 if ( 13 == e.keyCode || 8 == last || 46 == last ) t.wc(co.val());
mp-wp_genesis 14 last = e.keyCode;
mp-wp_genesis 15 return true;
mp-wp_genesis 16 });
mp-wp_genesis 17 },
mp-wp_genesis 18
mp-wp_genesis 19 wc : function(tx) {
mp-wp_genesis 20 var t = this, w = JQ('#word-count'), tc = 0;
mp-wp_genesis 21
mp-wp_genesis 22 if ( t.block ) return;
mp-wp_genesis 23 t.block = 1;
mp-wp_genesis 24
mp-wp_genesis 25 setTimeout( function() {
mp-wp_genesis 26 if ( tx ) {
mp-wp_genesis 27 tx = tx.replace( /<.[^<>]*?>/g, ' ' ).replace( / /gi, ' ' );
mp-wp_genesis 28 tx = tx.replace( /[0-9.(),;:!?%#$'"_+=\\/-]*/g, '' );
mp-wp_genesis 29 tx.replace( /\S\s+/g, function(){tc++;} );
mp-wp_genesis 30 }
mp-wp_genesis 31 w.html(tc.toString());
mp-wp_genesis 32
mp-wp_genesis 33 setTimeout( function() { t.block = 0; }, 2000 );
mp-wp_genesis 34 }, 1 );
mp-wp_genesis 35 }
mp-wp_genesis 36 }
mp-wp_genesis 37 }(jQuery));
mp-wp_genesis 38
mp-wp_genesis 39 jQuery(document).ready( function(){ wpWordCount.init(); } );