X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/849f15aeed7a5e39314057bdc0064d8edd60dd7d..bd54ad7dcd1cbf3b37f7822f71ca57b742f00a77:/wp-includes/js/tinymce/plugins/wordpress/plugin.js diff --git a/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/wp-includes/js/tinymce/plugins/wordpress/plugin.js index f3af6490..968ebd9a 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -1,14 +1,19 @@ -/* global tinymce, getUserSetting, setUserSetting */ - +/* global getUserSetting, setUserSetting */ +( function( tinymce ) { // Set the minimum value for the modals z-index higher than #wpadminbar (100000) tinymce.ui.FloatPanel.zIndex = 100100; tinymce.PluginManager.add( 'wordpress', function( editor ) { - var DOM = tinymce.DOM, wpAdvButton, modKey, style, - last = 0; - - if ( typeof window.jQuery !== 'undefined' ) { - window.jQuery( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] ); + var wpAdvButton, style, + DOM = tinymce.DOM, + each = tinymce.each, + __ = editor.editorManager.i18n.translate, + $ = window.jQuery, + wp = window.wp, + hasWpautop = ( wp && wp.editor && wp.editor.autop && editor.getParam( 'wpautop', true ) ); + + if ( $ ) { + $( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] ); } function toggleToolbars( state ) { @@ -29,7 +34,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { state = 'hide'; } - tinymce.each( toolbars, function( toolbar, i ) { + each( toolbars, function( toolbar, i ) { if ( i > 0 ) { if ( state === 'hide' ) { toolbar.hide(); @@ -86,26 +91,41 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }); // Replace Read More/Next Page tags with images - editor.on( 'BeforeSetContent', function( e ) { + editor.on( 'BeforeSetContent', function( event ) { var title; - if ( e.content ) { - if ( e.content.indexOf( '/g, function( match, moretext ) { + event.content = event.content.replace( //g, function( match, moretext ) { return ''; + 'class="wp-more-tag mce-wp-more" alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />'; }); } - if ( e.content.indexOf( '' ) !== -1 ) { - title = editor.editorManager.i18n.translate( 'Page break' ); + if ( event.content.indexOf( '' ) !== -1 ) { + title = __( 'Page break' ); - e.content = e.content.replace( //g, + event.content = event.content.replace( //g, '' ); + 'alt="" title="' + title + '" data-mce-resize="false" data-mce-placeholder="1" />' ); } + + if ( event.load && event.format !== 'raw' && hasWpautop ) { + event.content = wp.editor.autop( event.content ); + } + + // Remove spaces from empty paragraphs. + // Avoid backtracking, can freeze the editor. See #35890. + // (This is also quite faster than using only one regex.) + event.content = event.content.replace( /
([^<>]+)<\/p>/gi, function( tag, text ) { + if ( /^( |\s|\u00a0|\ufeff)+$/i.test( text ) ) { + return '
' + __( 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' ) + '
'; + + html += '\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre|address)( [^>]*)?>/gi, '<$1$2>'); - e.content = e.content.replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre|address)>\s*<\/p>/gi, '$1>'); + editor.on( 'BeforeSetContent', function( event ) { + if ( event.content ) { + event.content = event.content.replace( /
\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi, '<$1$2>' )
+ .replace( /<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi, '$1>' );
}
});
- if ( typeof window.jQuery !== 'undefined' ) {
- window.jQuery( document ).triggerHandler( 'tinymce-editor-init', [editor] );
+ if ( $ ) {
+ $( document ).triggerHandler( 'tinymce-editor-init', [editor] );
}
if ( window.tinyMCEPreInit && window.tinyMCEPreInit.dragDropUpload ) {
dom.bind( doc, 'dragstart dragend dragover drop', function( event ) {
- if ( typeof window.jQuery !== 'undefined' ) {
+ if ( $ ) {
// Trigger the jQuery handlers.
- window.jQuery( document ).trigger( new window.jQuery.Event( event ) );
+ $( document ).trigger( new $.Event( event ) );
}
});
}
if ( editor.getParam( 'wp_paste_filters', true ) ) {
- if ( ! tinymce.Env.webkit ) {
- // In WebKit handled by removeWebKitStyles()
- editor.on( 'PastePreProcess', function( event ) {
+ editor.on( 'PastePreProcess', function( event ) {
+ // Remove trailing
added by WebKit browsers to the clipboard
+ event.content = event.content.replace( /
/gi, '' );
+
+ // In WebKit this is handled by removeWebKitStyles()
+ if ( ! tinymce.Env.webkit ) {
// Remove all inline styles
event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' );
// Put back the internal styles
event.content = event.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi, '$1 style=$2' );
- });
- }
+ }
+ });
editor.on( 'PastePostProcess', function( event ) {
// Remove empty paragraphs
- tinymce.each( dom.select( 'p', event.node ), function( node ) {
+ each( dom.select( 'p', event.node ), function( node ) {
if ( dom.isEmpty( node ) ) {
dom.remove( node );
}
@@ -360,158 +504,443 @@ 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 ) {
+ editor.on( 'SaveContent', function( event ) {
// If editor is hidden, we just want the textarea's value to be saved
if ( ! editor.inline && editor.isHidden() ) {
- e.content = e.element.value;
+ event.content = event.element.value;
return;
}
// Keep empty paragraphs :(
- e.content = e.content.replace( /
(?:
|\u00a0|\uFEFF| )*<\/p>/g, '
' ); - - if ( editor.getParam( 'wpautop', true ) && typeof window.switchEditors !== 'undefined' ) { - e.content = window.switchEditors.pre_wpautop( e.content ); - } - }); + event.content = event.content.replace( /
(?:
|\u00a0|\uFEFF| )*<\/p>/g, '
' ); - // Remove spaces from empty paragraphs. - editor.on( 'BeforeSetContent', function( event ) { - if ( event.content ) { - event.content = event.content.replace( /
(?: |\u00a0|\uFEFF| )+<\/p>/gi, '
' ); + if ( hasWpautop ) { + event.content = wp.editor.removep( event.content ); } }); editor.on( 'preInit', function() { - // Don't replace with and with and don't remove them when empty - editor.schema.addValidElements( '@[id|accesskey|class|dir|lang|style|tabindex|title|contenteditable|draggable|dropzone|hidden|spellcheck|translate],i,b' ); + var validElementsSetting = '@[id|accesskey|class|dir|lang|style|tabindex|' + + 'title|contenteditable|draggable|dropzone|hidden|spellcheck|translate],' + // Global attributes. + 'i,' + // Don't replace with and with and don't remove them when empty. + 'b,' + + 'script[src|async|defer|type|charset|crossorigin|integrity]'; // Add support for