Ticket #8759: 8759.3.diff
File 8759.3.diff, 5.1 KB (added by , 12 years ago) |
---|
-
wp-admin/js/word-count.dev.js
1 (function($,undefined ) {1 (function($,undefined,undefined,undefined) { 2 2 wpWordCount = { 3 3 4 4 settings : { 5 5 strip : /<[a-zA-Z\/][^<>]*>/g, // strip HTML tags 6 }, 7 8 settingsLatin : { 6 9 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 10 count_w : /\S\s+/g, // word-counting regexp 11 count_c_with_spaces : /[\S \u00A0\u3000]/g, 12 count_c_without_spaces : /\S/g, 9 13 }, 14 15 settingsEastAsia : { 16 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, // currently misses 20000-2A6DF, 2A700-2B73F, 2B740-2B81F, 2F800-2FA1F, 1B000-1B0FF, 16F00-16F9F due to JavaScript RegExp restrictions 17 count_punc : /[\u3000-\u303F\uFE30-\uFE4F\uFF01-\uFF60\uFE10-\uFE1F]/g, // regexp to remove CJK punctuation. 18 }, 10 19 11 20 block : 0, 12 21 13 wc : function(tx, type) {22 wc : function(tx, countLatinBy, countLatinSpaces, countEastAsiaPunc) { 14 23 var t = this, w = $('.word-count'), tc = 0; 15 24 16 if ( type === undefined ) 17 type = wordCountL10n.type; 18 if ( type !== 'w' && type !== 'c' ) 19 type = 'w'; 20 25 if ( countLatinBy === undefined ) 26 countLatinBy = wordCountL10n.countLatinBy; 27 if ( countLatinBy !== 'w' && countLatinBy !== 'c' ) 28 countLatinBy = 'w'; 29 30 if ( countLatinSpaces === undefined ) 31 countLatinSpaces = wordCountL10n.countLatinSpaces; 32 if ( countLatinSpaces !== 'y' && countLatinSpaces !== 'n' ) 33 countLatinSpaces = 'n'; 34 35 if ( countEastAsiaPunc === undefined ) 36 countEastasiaPunc = wordCountL10n.countEastAsiaPunc; 37 if ( countEastAsiaPunc !== 'y' && countEastAsiaPunc !== 'n' ) 38 countEastAsiaPunc = 'y'; 39 21 40 if ( t.block ) 22 41 return; 23 42 … … 25 44 26 45 setTimeout( function() { 27 46 if ( tx ) { 47 // general 28 48 tx = tx.replace( t.settings.strip, ' ' ).replace( / | /gi, ' ' ); 29 tx = tx.replace( t.settings.clean, '' ); 30 tx.replace( t.settings[type], function(){tc++;} ); 49 50 // East Asia 51 tx = tx.replace( t.settingsEastAsia.count, function(){tc++; return '';} ); 52 if ( countEastAsiaPunc === 'y' ) 53 tx = tx.replace( t.settingsEastAsia.clean, function(){tc++; return '';} ); 54 55 // Latin 56 tx = tx.replace( t.settingsLatin.clean, '' ); 57 if ( countLatinBy === 'w' ) 58 tx.replace( t.settingsLatin.count_w, function(){tc++; return '';} ); 59 else { 60 if ( countLatinSpaces === 'y' ) { 61 tx = tx.replace( t.settingsLatin.count_c_with_spaces, function(){tc++; return '';} ); 62 } else { 63 tx = tx.replace( t.settingsLatin.count_c_without_spaces, function(){tc++; return '';} ); 64 } 65 } 31 66 } 32 67 w.html(tc.toString()); 33 68 -
wp-includes/script-loader.php
287 287 288 288 $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), false, 1 ); 289 289 $scripts->localize( 'word-count', 'wordCountL10n', array( 290 /* translators: If your word count is based on single characters (East Asian characters), 291 enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */ 292 'type' => 'characters' == _x( 'words', 'word count: words or characters?' ) ? 'c' : 'w', 290 /* translators: How would you like to count Latin (English, French, etc.)? 291 translate this to 'characters' if you think 'two words' shoule be counted as 7, 292 translate this to 'words' if you think 'two words' should be counted as 2. 293 Default: 'words'. 294 */ 295 'countLatinBy' => 'characters' == _x( 'Count Latin by', 'Latin word count: as words or characters?' ) ? 'c' : 'w', 296 297 /* translators: If you set countLatinBy to 'characters', would you count spaces? 298 translate this to 'yes' if you want spaces to be counted, 299 translate this to 'no' if you do not want spaces to be counted. 300 Default: 'no'. 301 */ 302 'countLatinSpaces' => 'yes' == _x( 'Count Latin spaces', 'Latin spaces count: yes or no?' ) ? 'y' : 'n', 303 304 /* translators: Would you like to count punctuation marks for East Asia text? 305 translate this to 'yes' if you want punctuation marks to be counted, 306 translate this to 'no' if you do not want punctuation marks to be counted. 307 Default: 'yes'. 308 */ 309 'countEastAsiaPunc' => 'no' == _x( 'Count East Asia punctuation marks', 'East Asia punctuation marks count: yes or no?' ) ? 'n' : 'y', 293 310 ) ); 294 311 295 312 $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), false, 1 );