Make WordPress Core

Changeset 33290


Ignore:
Timestamp:
07/15/2015 11:47:02 PM (11 years ago)
Author:
iseulde
Message:

Editor: word count: add all type

This type will count all characters including spaces.

See #30966.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/word-count.js

    r32856 r33290  
    1818                wordsRegExp: /\S\s+/g,
    1919                charactersRegExp: /\S/g,
     20                allRegExp: /[^\f\n\r\t\v\u00ad\u2028\u2029]/g,
    2021                l10n: window.wordCountL10n || {}
    2122        };
    … …  
    2728
    2829                if ( text ) {
    29                         text = ' ' + text + ' ';
     30                        text = text + '\n';
    3031
    31                         text = text.replace( this.settings.HTMLRegExp, ' ' );
     32                        text = text.replace( this.settings.HTMLRegExp, '\n' );
    3233                        text = text.replace( this.settings.spaceRegExp, ' ' );
    3334                        text = text.replace( this.settings.removeRegExp, '' );
  • trunk/tests/qunit/wp-admin/js/word-count.js

    r32856 r33290  
    1 ( function( QUnit ) {
    2         var wordCounter = new window.wp.utils.WordCounter();
    3 
     1( function( QUnit, wordCounter ) {
    42        QUnit.module( 'word-count' );
    53
    64        QUnit.test( 'All.', function( assert ) {
    7                 var tests = [
     5                _.each( [
    86                        {
    97                                message: 'Basic test.',
    108                                string: 'one two three',
    11                                 wordCount: 3,
    12                                 charCount: 11
     9                                words: 3,
     10                                characters: 11,
     11                                all: 13
    1312                        },
    1413                        {
    1514                                message: 'HTML tags.',
    1615                                string: 'one <em class="test">two</em><br />three',
    17                                 wordCount: 3,
    18                                 charCount: 11
     16                                words: 3,
     17                                characters: 11,
     18                                all: 12
    1919                        },
    2020                        {
    2121                                message: 'Line breaks.',
    2222                                string: 'one\ntwo\nthree',
    23                                 wordCount: 3,
    24                                 charCount: 11
     23                                words: 3,
     24                                characters: 11,
     25                                all: 11
    2526                        },
    2627                        {
    2728                                message: 'Encoded spaces.',
    2829                                string: 'one&nbsp;two&#160;three',
    29                                 wordCount: 3,
    30                                 charCount: 11
     30                                words: 3,
     31                                characters: 11,
     32                                all: 13
    3133                        },
    3234                        {
    3335                                message: 'Punctuation.',
    3436                                string: 'It\'s two three... 4?',
    35                                 wordCount: 3,
    36                                 charCount: 11
     37                                words: 3,
     38                                characters: 11,
     39                                all: 14
    3740                        }
    38                 ];
    39 
    40                 var i = tests.length;
    41 
    42                 while ( i-- ) {
    43                         assert.equal( wordCounter.count( tests[ i ].string ), tests[ i ].wordCount, tests[ i ].message + ' (words)' );
    44                         assert.equal( wordCounter.count( tests[ i ].string, 'characters' ), tests[ i ].charCount, tests[ i ].message + ' (characters)' );
    45                 }
     41                ], function( test ) {
     42                        _.each( [ 'words', 'characters', 'all' ], function( type ) {
     43                                assert.equal( wordCounter.count( test.string, type ), test[ type ], test.message + ' (' + type + ')' );
     44                        } );
     45                } );
    4646        } );
    47 } )( window.QUnit );
     47} )( window.QUnit, new window.wp.utils.WordCounter() );
Note: See TracChangeset for help on using the changeset viewer.