web/wp-admin/js/word-count.js
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
     1 (function(a,b){wpWordCount={settings:{strip:/<[a-zA-Z\/][^<>]*>/g,clean:/[0-9.(),;:!?%#$¿'"_+=\\/-]+/g,w:/\S\s+/g,c:/\S/g},block:0,wc:function(e,g){var f=this,d=a(".word-count"),c=0;if(g===b){g=wordCountL10n.type}if(g!=="w"&&g!=="c"){g="w"}if(f.block){return}f.block=1;setTimeout(function(){if(e){e=e.replace(f.settings.strip," ").replace(/&nbsp;|&#160;/gi," ");e=e.replace(f.settings.clean,"");e.replace(f.settings[g],function(){c++})}d.html(c.toString());setTimeout(function(){f.block=0},2000)},1)}};a(document).bind("wpcountwords",function(d,c){wpWordCount.wc(c)})}(jQuery));
     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( /&nbsp;|&#160;/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));