Make WordPress Core

Ticket #26620: 26620.2.diff

File 26620.2.diff, 2.6 KB (added by jorbin, 12 years ago)
  • src/wp-admin/js/word-count.js

     
    3030                                        tx = tx.replace( t.settings.strip, ' ' ).replace( / | /gi, ' ' );
    3131                                        tx = tx.replace( t.settings.clean, '' );
    3232                                        tx.replace( t.settings[type], function(){tc++;} );
     33
     34                                        // in the text editor, using word counting regex, when the last charector is a word charector, add one
     35                                        if ( ('.tmce-active').length !== 0  && type == 'w' && tx.charAt(tx.length-1).match(/\w/) )
     36                                                tc++
     37
    3338                                }
    3439                                w.html(tc.toString());
    3540
  • tests/qunit/index.html

     
    1414
    1515  <!-- Tested files -->
    1616  <script src="../../src/wp-admin/js/password-strength-meter.js"></script>
     17  <script src="../../src/wp-admin/js/word-count.js"></script>
    1718  <script src="../../src/wp-includes/js/shortcode.js"></script>
    1819
    1920  <!-- Unit tests -->
    2021  <script src="wp-admin/js/password-strength-meter.js"></script>
     22  <script src="wp-admin/js/word-count.js"></script>
    2123  <script src="wp-includes/js/shortcode.js"></script>
    2224
    2325</head>
     
    2729    <h2 id="qunit-banner"></h2>
    2830    <h2 id="qunit-userAgent"></h2>
    2931    <ol id="qunit-tests"></ol>
    30     <div id="qunit-fixture"></div>
     32    <div id="qunit-fixture">
     33                <span class='word-count'></span>       
     34        </div>
    3135  </div>
    3236</body>
    3337</html>
  • tests/qunit/wp-admin/js/word-count.js

     
     1var wordCountL10n;
     2jQuery( function() {
     3        module( 'word-count' );
     4
     5        // This is an async test since it involves testing dom  manipulation
     6        asyncTest('wpWordCount should set .word-count with the correct number of words for english language words', function(){
     7                wordCountL10n = 'w'
     8                wpWordCount.wc('This is some content. It should be ten words long.');
     9                setTimeout(function(){
     10                        // http://core.trac.wordpress.org/ticket/6991
     11                        equal(10, parseInt( jQuery('.word-count').html(), 10 ),
     12                                'the string "This is some content. It should be ten words long." shows 10');
     13                        start();
     14                }, 100)
     15
     16        });
     17
     18});