Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: word-count.js
/**
[0] Fix | Delete
* Word or character counting functionality. Count words or characters in a
[1] Fix | Delete
* provided text string.
[2] Fix | Delete
*
[3] Fix | Delete
* @namespace wp.utils
[4] Fix | Delete
*
[5] Fix | Delete
* @since 2.6.0
[6] Fix | Delete
* @output wp-admin/js/word-count.js
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
( function() {
[10] Fix | Delete
/**
[11] Fix | Delete
* Word counting utility
[12] Fix | Delete
*
[13] Fix | Delete
* @namespace wp.utils.wordcounter
[14] Fix | Delete
* @memberof wp.utils
[15] Fix | Delete
*
[16] Fix | Delete
* @class
[17] Fix | Delete
*
[18] Fix | Delete
* @param {Object} settings Optional. Key-value object containing overrides for
[19] Fix | Delete
* settings.
[20] Fix | Delete
* @param {RegExp} settings.HTMLRegExp Optional. Regular expression to find HTML elements.
[21] Fix | Delete
* @param {RegExp} settings.HTMLcommentRegExp Optional. Regular expression to find HTML comments.
[22] Fix | Delete
* @param {RegExp} settings.spaceRegExp Optional. Regular expression to find irregular space
[23] Fix | Delete
* characters.
[24] Fix | Delete
* @param {RegExp} settings.HTMLEntityRegExp Optional. Regular expression to find HTML entities.
[25] Fix | Delete
* @param {RegExp} settings.connectorRegExp Optional. Regular expression to find connectors that
[26] Fix | Delete
* split words.
[27] Fix | Delete
* @param {RegExp} settings.removeRegExp Optional. Regular expression to find remove unwanted
[28] Fix | Delete
* characters to reduce false-positives.
[29] Fix | Delete
* @param {RegExp} settings.astralRegExp Optional. Regular expression to find unwanted
[30] Fix | Delete
* characters when searching for non-words.
[31] Fix | Delete
* @param {RegExp} settings.wordsRegExp Optional. Regular expression to find words by spaces.
[32] Fix | Delete
* @param {RegExp} settings.characters_excluding_spacesRegExp Optional. Regular expression to find characters which
[33] Fix | Delete
* are non-spaces.
[34] Fix | Delete
* @param {RegExp} settings.characters_including_spacesRegExp Optional. Regular expression to find characters
[35] Fix | Delete
* including spaces.
[36] Fix | Delete
* @param {RegExp} settings.shortcodesRegExp Optional. Regular expression to find shortcodes.
[37] Fix | Delete
* @param {Object} settings.l10n Optional. Localization object containing specific
[38] Fix | Delete
* configuration for the current localization.
[39] Fix | Delete
* @param {string} settings.l10n.type Optional. Method of finding words to count.
[40] Fix | Delete
* @param {Array} settings.l10n.shortcodes Optional. Array of shortcodes that should be removed
[41] Fix | Delete
* from the text.
[42] Fix | Delete
*
[43] Fix | Delete
* @return {void}
[44] Fix | Delete
*/
[45] Fix | Delete
function WordCounter( settings ) {
[46] Fix | Delete
var key,
[47] Fix | Delete
shortcodes;
[48] Fix | Delete
[49] Fix | Delete
// Apply provided settings to object settings.
[50] Fix | Delete
if ( settings ) {
[51] Fix | Delete
for ( key in settings ) {
[52] Fix | Delete
[53] Fix | Delete
// Only apply valid settings.
[54] Fix | Delete
if ( settings.hasOwnProperty( key ) ) {
[55] Fix | Delete
this.settings[ key ] = settings[ key ];
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
shortcodes = this.settings.l10n.shortcodes;
[61] Fix | Delete
[62] Fix | Delete
// If there are any localization shortcodes, add this as type in the settings.
[63] Fix | Delete
if ( shortcodes && shortcodes.length ) {
[64] Fix | Delete
this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'g' );
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// Default settings.
[69] Fix | Delete
WordCounter.prototype.settings = {
[70] Fix | Delete
HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
[71] Fix | Delete
HTMLcommentRegExp: /<!--[\s\S]*?-->/g,
[72] Fix | Delete
spaceRegExp: /&nbsp;|&#160;/gi,
[73] Fix | Delete
HTMLEntityRegExp: /&\S+?;/g,
[74] Fix | Delete
[75] Fix | Delete
// \u2014 = em-dash.
[76] Fix | Delete
connectorRegExp: /--|\u2014/g,
[77] Fix | Delete
[78] Fix | Delete
// Characters to be removed from input text.
[79] Fix | Delete
removeRegExp: new RegExp( [
[80] Fix | Delete
'[',
[81] Fix | Delete
[82] Fix | Delete
// Basic Latin (extract).
[83] Fix | Delete
'\u0021-\u0040\u005B-\u0060\u007B-\u007E',
[84] Fix | Delete
[85] Fix | Delete
// Latin-1 Supplement (extract).
[86] Fix | Delete
'\u0080-\u00BF\u00D7\u00F7',
[87] Fix | Delete
[88] Fix | Delete
/*
[89] Fix | Delete
* The following range consists of:
[90] Fix | Delete
* General Punctuation
[91] Fix | Delete
* Superscripts and Subscripts
[92] Fix | Delete
* Currency Symbols
[93] Fix | Delete
* Combining Diacritical Marks for Symbols
[94] Fix | Delete
* Letterlike Symbols
[95] Fix | Delete
* Number Forms
[96] Fix | Delete
* Arrows
[97] Fix | Delete
* Mathematical Operators
[98] Fix | Delete
* Miscellaneous Technical
[99] Fix | Delete
* Control Pictures
[100] Fix | Delete
* Optical Character Recognition
[101] Fix | Delete
* Enclosed Alphanumerics
[102] Fix | Delete
* Box Drawing
[103] Fix | Delete
* Block Elements
[104] Fix | Delete
* Geometric Shapes
[105] Fix | Delete
* Miscellaneous Symbols
[106] Fix | Delete
* Dingbats
[107] Fix | Delete
* Miscellaneous Mathematical Symbols-A
[108] Fix | Delete
* Supplemental Arrows-A
[109] Fix | Delete
* Braille Patterns
[110] Fix | Delete
* Supplemental Arrows-B
[111] Fix | Delete
* Miscellaneous Mathematical Symbols-B
[112] Fix | Delete
* Supplemental Mathematical Operators
[113] Fix | Delete
* Miscellaneous Symbols and Arrows
[114] Fix | Delete
*/
[115] Fix | Delete
'\u2000-\u2BFF',
[116] Fix | Delete
[117] Fix | Delete
// Supplemental Punctuation.
[118] Fix | Delete
'\u2E00-\u2E7F',
[119] Fix | Delete
']'
[120] Fix | Delete
].join( '' ), 'g' ),
[121] Fix | Delete
[122] Fix | Delete
// Remove UTF-16 surrogate points, see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF
[123] Fix | Delete
astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
[124] Fix | Delete
wordsRegExp: /\S\s+/g,
[125] Fix | Delete
characters_excluding_spacesRegExp: /\S/g,
[126] Fix | Delete
[127] Fix | Delete
/*
[128] Fix | Delete
* Match anything that is not a formatting character, excluding:
[129] Fix | Delete
* \f = form feed
[130] Fix | Delete
* \n = new line
[131] Fix | Delete
* \r = carriage return
[132] Fix | Delete
* \t = tab
[133] Fix | Delete
* \v = vertical tab
[134] Fix | Delete
* \u00AD = soft hyphen
[135] Fix | Delete
* \u2028 = line separator
[136] Fix | Delete
* \u2029 = paragraph separator
[137] Fix | Delete
*/
[138] Fix | Delete
characters_including_spacesRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
[139] Fix | Delete
l10n: window.wordCountL10n || {}
[140] Fix | Delete
};
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* Counts the number of words (or other specified type) in the specified text.
[144] Fix | Delete
*
[145] Fix | Delete
* @since 2.6.0
[146] Fix | Delete
*
[147] Fix | Delete
* @memberof wp.utils.wordcounter
[148] Fix | Delete
*
[149] Fix | Delete
* @param {string} text Text to count elements in.
[150] Fix | Delete
* @param {string} type Optional. Specify type to use.
[151] Fix | Delete
*
[152] Fix | Delete
* @return {number} The number of items counted.
[153] Fix | Delete
*/
[154] Fix | Delete
WordCounter.prototype.count = function( text, type ) {
[155] Fix | Delete
var count = 0;
[156] Fix | Delete
[157] Fix | Delete
// Use default type if none was provided.
[158] Fix | Delete
type = type || this.settings.l10n.type;
[159] Fix | Delete
[160] Fix | Delete
// Sanitize type to one of three possibilities: 'words', 'characters_excluding_spaces' or 'characters_including_spaces'.
[161] Fix | Delete
if ( type !== 'characters_excluding_spaces' && type !== 'characters_including_spaces' ) {
[162] Fix | Delete
type = 'words';
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
// If we have any text at all.
[166] Fix | Delete
if ( text ) {
[167] Fix | Delete
text = text + '\n';
[168] Fix | Delete
[169] Fix | Delete
// Replace all HTML with a new-line.
[170] Fix | Delete
text = text.replace( this.settings.HTMLRegExp, '\n' );
[171] Fix | Delete
[172] Fix | Delete
// Remove all HTML comments.
[173] Fix | Delete
text = text.replace( this.settings.HTMLcommentRegExp, '' );
[174] Fix | Delete
[175] Fix | Delete
// If a shortcode regular expression has been provided use it to remove shortcodes.
[176] Fix | Delete
if ( this.settings.shortcodesRegExp ) {
[177] Fix | Delete
text = text.replace( this.settings.shortcodesRegExp, '\n' );
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
// Normalize non-breaking space to a normal space.
[181] Fix | Delete
text = text.replace( this.settings.spaceRegExp, ' ' );
[182] Fix | Delete
[183] Fix | Delete
if ( type === 'words' ) {
[184] Fix | Delete
[185] Fix | Delete
// Remove HTML Entities.
[186] Fix | Delete
text = text.replace( this.settings.HTMLEntityRegExp, '' );
[187] Fix | Delete
[188] Fix | Delete
// Convert connectors to spaces to count attached text as words.
[189] Fix | Delete
text = text.replace( this.settings.connectorRegExp, ' ' );
[190] Fix | Delete
[191] Fix | Delete
// Remove unwanted characters.
[192] Fix | Delete
text = text.replace( this.settings.removeRegExp, '' );
[193] Fix | Delete
} else {
[194] Fix | Delete
[195] Fix | Delete
// Convert HTML Entities to "a".
[196] Fix | Delete
text = text.replace( this.settings.HTMLEntityRegExp, 'a' );
[197] Fix | Delete
[198] Fix | Delete
// Remove surrogate points.
[199] Fix | Delete
text = text.replace( this.settings.astralRegExp, 'a' );
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
// Match with the selected type regular expression to count the items.
[203] Fix | Delete
text = text.match( this.settings[ type + 'RegExp' ] );
[204] Fix | Delete
[205] Fix | Delete
// If we have any matches, set the count to the number of items found.
[206] Fix | Delete
if ( text ) {
[207] Fix | Delete
count = text.length;
[208] Fix | Delete
}
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
return count;
[212] Fix | Delete
};
[213] Fix | Delete
[214] Fix | Delete
// Add the WordCounter to the WP Utils.
[215] Fix | Delete
window.wp = window.wp || {};
[216] Fix | Delete
window.wp.utils = window.wp.utils || {};
[217] Fix | Delete
window.wp.utils.WordCounter = WordCounter;
[218] Fix | Delete
} )();
[219] Fix | Delete
[220] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function