Ticket #26018: 26018.diff
| File 26018.diff, 2.0 KB (added by , 13 years ago) |
|---|
-
src/wp-admin/js/word-count.js
1 (function($,undefined) { 2 wpWordCount = { 1 /* global wordCountL10n:false */ 3 2 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 3 (function( $ ) { 4 var wpWordCount = { 5 6 settings: { 7 strip: /<[a-zA-Z\/][^<>]*>/g, // strip HTML tags 8 clean: /[0-9.(),;:!?%#$¿'"_+=\/-]+/g, // regexp to remove punctuation, etc. 9 w: /\S\s+/g, // word-counting regexp 10 c: /\S/g // char-counting regexp for asian languages 9 11 }, 10 12 11 block : 0,13 block: 0, 12 14 13 wc : function(tx, type) {14 var t = this, w = $( '.word-count'), tc = 0;15 wc: function( tx, type ) { 16 var t = this, w = $( '.word-count' ), tc = 0; 15 17 16 if ( type === undefined ) 18 if ( type === undefined ) { 17 19 type = wordCountL10n.type; 18 if ( type !== 'w' && type !== 'c' ) 20 } 21 22 if ( type !== 'w' && type !== 'c' ) { 19 23 type = 'w'; 24 } 20 25 21 if ( t.block ) 26 if ( t.block ) { 22 27 return; 28 } 23 29 24 30 t.block = 1; 25 31 26 setTimeout( function() {32 setTimeout(function() { 27 33 if ( tx ) { 28 34 tx = tx.replace( t.settings.strip, ' ' ).replace( / | /gi, ' ' ); 29 35 tx = tx.replace( t.settings.clean, '' ); 30 tx.replace( t.settings[type], function(){tc++;} ); 36 tx.replace( t.settings[ type ], function(){ 37 tc++; 38 }); 31 39 } 32 w.html( tc.toString());40 w.html( tc.toString() ); 33 41 34 setTimeout( function() { t.block = 0; }, 2000 ); 42 setTimeout(function() { 43 t.block = 0; 44 }, 2000 ); 35 45 }, 1 ); 36 46 } 37 } 47 }; 38 48 39 $( document).bind( 'wpcountwords', function(e, txt) {40 wpWordCount.wc( txt);49 $( document ).bind( 'wpcountwords', function( e, txt ) { 50 wpWordCount.wc( txt ); 41 51 }); 42 } (jQuery));52 })( jQuery );