Make WordPress Core

Ticket #20738: 20738.2.patch

File 20738.2.patch, 1.3 KB (added by chriscct7, 10 years ago)

Missed some formatting

  • wp-admin/js/word-count.js

     
    2929                                if ( tx ) {
    3030                                        tx = tx.replace( t.settings.strip, ' ' ).replace( / | /gi, ' ' );
    3131                                        tx = tx.replace( t.settings.clean, '' );
    32                                         tx.replace( t.settings[type], function(){tc++;} );
     32                                        tc = doubleCount(tx) + wordCount(tx);
    3333                                }
    3434                                w.html(tc.toString());
    3535
     
    4242                wpWordCount.wc(txt);
    4343        });
    4444}(jQuery));
     45
     46/* Count double-byte length characters */
     47/* #32401 */
     48/* Props: Ydoow for https://wordpress.org/plugins/word-count-with-double-byte-character/ whose code this is based on */
     49function doubleCount( txt ){
     50  var counter = 0; 
     51  for( var i = 0; i < txt.length; i++ ){
     52    if( txt.charCodeAt( i ) > 255 ){
     53      counter++;
     54    }
     55  }
     56  return counter;
     57}
     58
     59/* Count words */
     60function wordCount( txt ){
     61  var counter = 0; 
     62  for( var i = 0; i< txt.length; i++ ){
     63    while( txt.charAt( i ) == ' ' || txt.charCodeAt( i ) > 255 || txt.charAt( i )=='\n' ){
     64                i++;
     65        }
     66        if( txt.charAt( i + 1 ) == ' '|| txt.charAt( i + 1 ) == '\n' || txt.charCodeAt( i + 1 ) > 255 || i == txt.length - 1 ){
     67                counter++;
     68        }
     69  }
     70  return counter;
     71}