Ticket #8759: 8759.2.diff

File 8759.2.diff, 1.3 KB (added by tenpura, 14 months ago)

counting spaces, too?

Line 
1Index: wp-admin/js/word-count.dev.js
2===================================================================
3--- wp-admin/js/word-count.dev.js       (revision 20205)
4+++ wp-admin/js/word-count.dev.js       (working copy)
5@@ -4,8 +4,7 @@
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
11+                       count : /\S\s+/g, // word-counting regexp
12                },
13 
14                block : 0,
15@@ -25,9 +24,16 @@
16 
17                        setTimeout( function() {
18                                if ( tx ) {
19-                                       tx = tx.replace( t.settings.strip, ' ' ).replace( /&nbsp;|&#160;/gi, ' ' );
20-                                       tx = tx.replace( t.settings.clean, '' );
21-                                       tx.replace( t.settings[type], function(){tc++;} );
22+                                       if ( type == 'w' ) { // word-counting
23+                                               tx = tx.replace( t.settings.strip, ' ' ).replace( /&nbsp;|&#160;/gi, ' ' );
24+                                               tx = tx.replace( t.settings.clean, '' );
25+                                               tx.replace( t.settings.count, function(){tc++;} );
26+                                       }
27+                                       else if ( type == 'c' ) { // char-counting for asian languages
28+                                               tx = tx.replace( t.settings.strip, '' ).replace( /^ +| +$/gm, '' );
29+                                               tx = tx.replace( / +|&nbsp;|&#160;/gi, ' ' );
30+                                               tx.replace( /[\S \u00A0\u3000]/g, function(){tc++;} );
31+                                       }
32                                }
33                                w.html(tc.toString());
34