Editor: restructure word count
* The WordCounter should only do one thing: count words. This makes it also easier to test. * Add some really basic unit tests. * Instead of only refreshing the count on enter and delete, refresh the count when the user stops typing. Also look at paste and content changes in TinyMCE. * Use `match` instead of `replace` when it is appropriate. * More readable code. See #30966. Fixes #26620. Built from https://develop.svn.wordpress.org/trunk@32856 git-svn-id: http://core.svn.wordpress.org/trunk@32827 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -7,8 +7,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
|
||||
var DOM = tinymce.DOM,
|
||||
each = tinymce.each,
|
||||
__ = editor.editorManager.i18n.translate,
|
||||
wpAdvButton, style,
|
||||
last = 0;
|
||||
wpAdvButton, style;
|
||||
|
||||
if ( typeof window.jQuery !== 'undefined' ) {
|
||||
window.jQuery( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] );
|
||||
@@ -363,23 +362,6 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
|
||||
}
|
||||
});
|
||||
|
||||
// Word count
|
||||
if ( typeof window.jQuery !== 'undefined' ) {
|
||||
editor.on( 'keyup', function( e ) {
|
||||
var key = e.keyCode || e.charCode;
|
||||
|
||||
if ( key === last ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 13 === key || 8 === last || 46 === last ) {
|
||||
window.jQuery( document ).triggerHandler( 'wpcountwords', [ editor.getContent({ format : 'raw' }) ] );
|
||||
}
|
||||
|
||||
last = key;
|
||||
});
|
||||
}
|
||||
|
||||
editor.on( 'SaveContent', function( e ) {
|
||||
// If editor is hidden, we just want the textarea's value to be saved
|
||||
if ( ! editor.inline && editor.isHidden() ) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user