Ticket #8759: 8759.4.diff

File 8759.4.diff, 1.7 KB (added by jiehanzheng, 13 months ago)

Patch that supports only Chinese. The file itself to follow.

Line 
1Index: wp-admin/js/word-count.dev.js
2===================================================================
3--- wp-admin/js/word-count.dev.js       (revision 20709)
4+++ wp-admin/js/word-count.dev.js       (working copy)
5@@ -1,23 +1,21 @@
6-(function($,undefined) {
7+(function($) {
8        wpWordCount = {
9 
10                settings : {
11                        strip : /<[a-zA-Z\/][^<>]*>/g, // strip HTML tags
12                        clean : /[0-9.(),;:!?%#$¿'"_+=\\/-]+/g, // regexp to remove punctuation, etc.
13-                       w : /\S\s+/g, // word-counting regexp
14-                       c : /\S/g // char-counting regexp for asian languages
15+                       count : /\S\s+/g // counting regexp
16                },
17 
18+               settingsEastAsia : {
19+                       count : /[\u3100-\u312F\u31A0-\u31BF\u4E00-\u9FCF\u3400-\u4DBF\uF900-\uFAFF\u2F00-\u2FDF\u2E80-\u2EFF\u31C0-\u31EF\u2FF0-\u2FFF\u1100-\u11FF\uA960-\uA97F\uD780-\uD7FF\u3130-\u318F\uFFA0-\uFFDC\uAC00-\uD7AF\u3040-\u309F\u30A0-\u30FF\u31F0-\u31FF\uFF65-\uFF9F\u3190-\u319F\uA4D0-\uA4FF\uA000-\uA48F\uA490-\uA4CF]/g
20+               },
21+
22                block : 0,
23 
24-               wc : function(tx, type) {
25+               wc : function(tx) {
26                        var t = this, w = $('.word-count'), tc = 0;
27 
28-                       if ( type === undefined )
29-                               type = wordCountL10n.type;
30-                       if ( type !== 'w' && type !== 'c' )
31-                               type = 'w';
32-
33                        if ( t.block )
34                                return;
35 
36@@ -25,9 +23,15 @@
37 
38                        setTimeout( function() {
39                                if ( tx ) {
40+                                       // remove generally useless stuff first
41                                        tx = tx.replace( t.settings.strip, ' ' ).replace( /&nbsp;|&#160;/gi, ' ' );
42+
43+                                       // count east asia chars
44+                                       tx = tx.replace( t.settingsEastAsia.count, function(){ tc++; return ''; } );
45+
46+                                       // count remaining western characters
47                                        tx = tx.replace( t.settings.clean, '' );
48-                                       tx.replace( t.settings[type], function(){tc++;} );
49+                                       tx.replace( t.settings.count, function(){ tc++; return ''; } );
50                                }
51                                w.html(tc.toString());
52