2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
( function( $ ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Creates the tinyMCE editors.
|
|
|
|
*
|
|
|
|
* Creates the tinyMCE editor and binds all events used for switching
|
|
|
|
* from visual to text mode.
|
|
|
|
*
|
|
|
|
* @since 4.3.0
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
function SwitchEditors() {
|
|
|
|
var tinymce, $$,
|
|
|
|
exports = {};
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Initializes the event binding for switching editors.
|
|
|
|
*
|
|
|
|
* @since 4.3.0
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
function init() {
|
|
|
|
if ( ! tinymce && window.tinymce ) {
|
|
|
|
tinymce = window.tinymce;
|
|
|
|
$$ = tinymce.$;
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Handles onclick events for the editor buttons.
|
|
|
|
*
|
|
|
|
* @since 4.3.0
|
|
|
|
*
|
|
|
|
* Handles an onclick event on the document.
|
|
|
|
* Switches the editor between visual and text,
|
|
|
|
* if the clicked element has the 'wp-switch-editor' class.
|
|
|
|
* If the class name is switch-html switches to the HTML editor,
|
|
|
|
* if the class name is switch-tmce
|
|
|
|
* switches to the TMCE editor.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
$$( document ).on( 'click', function( event ) {
|
|
|
|
var id, mode,
|
|
|
|
target = $$( event.target );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( target.hasClass( 'wp-switch-editor' ) ) {
|
|
|
|
id = target.attr( 'data-wp-editor-id' );
|
|
|
|
mode = target.hasClass( 'switch-tmce' ) ? 'tmce' : 'html';
|
|
|
|
switchEditor( id, mode );
|
|
|
|
}
|
|
|
|
});
|
2013-11-15 16:03:10 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Retrieves the height of the toolbar based on the container the
|
|
|
|
* editor is placed in.
|
|
|
|
*
|
|
|
|
* @since 3.9.0
|
|
|
|
*
|
|
|
|
* @param {Object} editor The tinyMCE editor.
|
|
|
|
* @returns {number} If the height is between 10 and 200 return the height,
|
|
|
|
* else return 30.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
function getToolbarHeight( editor ) {
|
|
|
|
var node = $$( '.mce-toolbar-grp', editor.getContainer() )[0],
|
2014-04-03 21:31:15 -04:00
|
|
|
height = node && node.clientHeight;
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
|
2014-04-03 21:31:15 -04:00
|
|
|
if ( height && height > 10 && height < 200 ) {
|
|
|
|
return parseInt( height, 10 );
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
}
|
|
|
|
|
2014-04-03 21:31:15 -04:00
|
|
|
return 30;
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Switches the editor between visual and text.
|
|
|
|
*
|
|
|
|
* @since 4.3.0
|
|
|
|
*
|
|
|
|
* @memberof switchEditors
|
|
|
|
*
|
|
|
|
* @param {string} id The id of the editor you want to change the editor mode for.
|
|
|
|
* If no id is given, it defaults to content.
|
|
|
|
* @param {string} mode The mode you want to switch to.
|
|
|
|
* If an undefined mode is given, it defaults to toggle.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
function switchEditor( id, mode ) {
|
|
|
|
id = id || 'content';
|
|
|
|
mode = mode || 'toggle';
|
|
|
|
|
|
|
|
var editorHeight, toolbarHeight, iframe,
|
|
|
|
editor = tinymce.get( id ),
|
|
|
|
wrap = $$( '#wp-' + id + '-wrap' ),
|
|
|
|
$textarea = $$( '#' + id ),
|
|
|
|
textarea = $textarea[0];
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Toggle the mode between visual and textual representation.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( 'toggle' === mode ) {
|
|
|
|
if ( editor && ! editor.isHidden() ) {
|
|
|
|
mode = 'html';
|
|
|
|
} else {
|
|
|
|
mode = 'tmce';
|
|
|
|
}
|
2013-11-15 16:03:10 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// If the mode is tmce or tinymce, show the editor.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( 'tmce' === mode || 'tinymce' === mode ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the editor isn't hidden we are already in tmce mode
|
|
|
|
* and we don't need to switch.
|
|
|
|
* Return false to stop event bubbling.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( editor && ! editor.isHidden() ) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Close the QuickTags toolbars if they are visible.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( typeof( window.QTags ) !== 'undefined' ) {
|
|
|
|
window.QTags.closeAllTags( id );
|
|
|
|
}
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
editorHeight = parseInt( textarea.style.height, 10 ) || 0;
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( editor ) {
|
|
|
|
editor.show();
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Don't resize the iframe in iOS.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( ! tinymce.Env.iOS && editorHeight ) {
|
|
|
|
toolbarHeight = getToolbarHeight( editor );
|
|
|
|
editorHeight = editorHeight - toolbarHeight + 14;
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Height must be between 50 and 5000.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( editorHeight > 50 && editorHeight < 5000 ) {
|
|
|
|
editor.theme.resizeTo( null, editorHeight );
|
|
|
|
}
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
}
|
2015-06-21 18:01:28 -04:00
|
|
|
} else {
|
|
|
|
tinymce.init( window.tinyMCEPreInit.mceInit[id] );
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
wrap.removeClass( 'html-active' ).addClass( 'tmce-active' );
|
|
|
|
$textarea.attr( 'aria-hidden', true );
|
|
|
|
window.setUserSetting( 'editor', 'tinymce' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Hide the editor if mode is html.
|
2015-06-21 18:01:28 -04:00
|
|
|
} else if ( 'html' === mode ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the editor is hidden we are already in html mode and
|
|
|
|
* we don't need to switch.
|
|
|
|
* Return false to stop event bubbling.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( editor && editor.isHidden() ) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( editor ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Don't resize the iframe in iOS.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( ! tinymce.Env.iOS ) {
|
|
|
|
iframe = editor.iframeElement;
|
|
|
|
editorHeight = iframe ? parseInt( iframe.style.height, 10 ) : 0;
|
2014-05-29 22:38:16 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( editorHeight ) {
|
|
|
|
toolbarHeight = getToolbarHeight( editor );
|
|
|
|
editorHeight = editorHeight + toolbarHeight - 14;
|
2014-05-29 22:38:16 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Height must be between 50 and 5000.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( editorHeight > 50 && editorHeight < 5000 ) {
|
|
|
|
textarea.style.height = editorHeight + 'px';
|
|
|
|
}
|
2014-05-29 22:38:16 -04:00
|
|
|
}
|
TinyMCE 4.0.12, first run.
- Removes wp-tinymce-schema.js and mark-loaded.js, no longer needed.
- Removes the inlinepopups and most of the wpdialogs plugins; wpdialog.js is moved to wp-includes/js.
- Adds charmap, compat3x, image, link and textcolor plugins, previously contained in /themes/advanced.
- Updates the wordpress, wpeditimage, wpfullscreen, wpgallery and wplink plugins.
- Updates DFW, wp-admin/js/wp-fullscreen.js.
See #24067.
Built from https://develop.svn.wordpress.org/trunk@26876
git-svn-id: http://core.svn.wordpress.org/trunk@26759 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-12-28 18:53:15 -05:00
|
|
|
}
|
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
editor.hide();
|
|
|
|
} else {
|
2017-01-06 17:11:57 -05:00
|
|
|
// The TinyMCE instance doesn't exist, show the textarea.
|
2015-06-21 18:01:28 -04:00
|
|
|
$textarea.css({ 'display': '', 'visibility': '' });
|
2013-11-15 16:03:10 -05:00
|
|
|
}
|
2013-03-22 16:43:37 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
wrap.removeClass( 'tmce-active' ).addClass( 'html-active' );
|
|
|
|
$textarea.attr( 'aria-hidden', false );
|
|
|
|
window.setUserSetting( 'editor', 'html' );
|
2013-03-22 16:43:37 -04:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Replaces all paragraphs with double line breaks.
|
|
|
|
*
|
|
|
|
* Replaces all paragraphs with double line breaks. Taking into account
|
|
|
|
* the elements where the <p> should be preserved.
|
|
|
|
* Unifies all whitespaces.
|
|
|
|
* Adds indenting with tabs to li, dt and dd elements.
|
|
|
|
* Trims whitespaces from beginning and end of the html input.
|
|
|
|
*
|
|
|
|
* @since 4.3.0
|
|
|
|
*
|
|
|
|
* @memberof switchEditors
|
|
|
|
*
|
|
|
|
* @param {string} html The content from the editor.
|
|
|
|
* @return {string} The formatted html string.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
function removep( html ) {
|
2015-12-17 18:06:25 -05:00
|
|
|
var blocklist = 'blockquote|ul|ol|li|dl|dt|dd|table|thead|tbody|tfoot|tr|th|td|h[1-6]|fieldset',
|
2015-06-21 18:01:28 -04:00
|
|
|
blocklist1 = blocklist + '|div|p',
|
|
|
|
blocklist2 = blocklist + '|pre',
|
|
|
|
preserve_linebreaks = false,
|
2016-07-12 18:09:31 -04:00
|
|
|
preserve_br = false,
|
|
|
|
preserve = [];
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( ! html ) {
|
|
|
|
return '';
|
|
|
|
}
|
2014-07-28 15:44:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/*
|
|
|
|
* Protect script and style tags by replacing them with <wp-preserve>.
|
|
|
|
* Push matches into the preserve array.
|
|
|
|
*/
|
2016-07-12 18:09:31 -04:00
|
|
|
if ( html.indexOf( '<script' ) !== -1 || html.indexOf( '<style' ) !== -1 ) {
|
|
|
|
html = html.replace( /<(script|style)[^>]*>[\s\S]*?<\/\1>/g, function( match ) {
|
|
|
|
preserve.push( match );
|
|
|
|
return '<wp-preserve>';
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/*
|
|
|
|
* Protect pre tags by replacing all newlines and
|
|
|
|
* <br> tags with <wp-line-break>.
|
|
|
|
*/
|
2016-07-12 18:09:31 -04:00
|
|
|
if ( html.indexOf( '<pre' ) !== -1 ) {
|
2015-06-21 18:01:28 -04:00
|
|
|
preserve_linebreaks = true;
|
2016-07-12 18:09:31 -04:00
|
|
|
html = html.replace( /<pre[^>]*>[\s\S]+?<\/pre>/g, function( a ) {
|
2015-06-21 18:01:28 -04:00
|
|
|
a = a.replace( /<br ?\/?>(\r\n|\n)?/g, '<wp-line-break>' );
|
|
|
|
a = a.replace( /<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-line-break>' );
|
|
|
|
return a.replace( /\r?\n/g, '<wp-line-break>' );
|
|
|
|
});
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/*
|
|
|
|
* Keep <br> tags inside captions and remove line breaks by replacing
|
|
|
|
* them with <wp-temp-br>.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( html.indexOf( '[caption' ) !== -1 ) {
|
|
|
|
preserve_br = true;
|
|
|
|
html = html.replace( /\[caption[\s\S]+?\[\/caption\]/g, function( a ) {
|
|
|
|
return a.replace( /<br([^>]*)>/g, '<wp-temp-br$1>' ).replace( /[\r\n\t]+/, '' );
|
|
|
|
});
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Format the text to be readable in the source editor.
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( new RegExp( '\\s*</(' + blocklist1 + ')>\\s*', 'g' ), '</$1>\n' );
|
|
|
|
html = html.replace( new RegExp( '\\s*<((?:' + blocklist1 + ')(?: [^>]*)?)>', 'g' ), '\n<$1>' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
// Mark </p> if it has any attributes.
|
|
|
|
html = html.replace( /(<p [^>]+>.*?)<\/p>/g, '$1</p#>' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// If the content of a container starts with a paragraph, replace the <p> tag with 2 newlines.
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /<div( [^>]*)?>\s*<p>/gi, '<div$1>\n\n' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Remove <p> and </p> tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /\s*<p>/gi, '' );
|
|
|
|
html = html.replace( /\s*<\/p>\s*/gi, '\n\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove white spaces between newlines. u00a0 is a no breaking space.
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /\n[\s\u00a0]+\n/g, '\n\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove <br> tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /\s*<br ?\/?>\s*/gi, '\n' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/*
|
|
|
|
* Fix some block element newline issues.
|
|
|
|
* Replace white spaces with newlines in combination with <div> tags.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /\s*<div/g, '\n<div' );
|
|
|
|
html = html.replace( /<\/div>\s*/g, '</div>\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Replace white spaces with newlines in combination with [caption] shortcodes.
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /\s*\[caption([^\[]+)\[\/caption\]\s*/gi, '\n\n[caption$1[/caption]\n\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Limit the newlines in combination with [caption]'s to a maximum of
|
|
|
|
* two consecutive occurrences.
|
|
|
|
* .
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /caption\]\n\n+\[caption/g, 'caption]\n\n[caption' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/*
|
|
|
|
* Replace white spaces with newlines in combination with
|
|
|
|
* all elements listed in blocklist2.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( new RegExp('\\s*<((?:' + blocklist2 + ')(?: [^>]*)?)\\s*>', 'g' ), '\n<$1>' );
|
|
|
|
html = html.replace( new RegExp('\\s*</(' + blocklist2 + ')>\\s*', 'g' ), '</$1>\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Add indentation by adding a tab in front of <li>, <dt> and <dd> tags.
|
2015-12-17 18:06:25 -05:00
|
|
|
html = html.replace( /<((li|dt|dd)[^>]*)>/g, ' \t<$1>' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Replace white spaces with newlines in combination with <select> and <option> tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( html.indexOf( '<option' ) !== -1 ) {
|
|
|
|
html = html.replace( /\s*<option/g, '\n<option' );
|
|
|
|
html = html.replace( /\s*<\/select>/g, '\n</select>' );
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Replace white spaces with 2 newlines in combination with <hr> tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( html.indexOf( '<hr' ) !== -1 ) {
|
|
|
|
html = html.replace( /\s*<hr( [^>]*)?>\s*/g, '\n\n<hr$1>\n\n' );
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Remove newlines in <object> tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( html.indexOf( '<object' ) !== -1 ) {
|
|
|
|
html = html.replace( /<object[\s\S]+?<\/object>/g, function( a ) {
|
|
|
|
return a.replace( /[\r\n]+/g, '' );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Unmark special paragraph closing tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /<\/p#>/g, '</p>\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
// Add a new line before <p> tags when there is content inside the paragraph
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /\s*(<p [^>]+>[\s\S]*?<\/p>)/g, '\n$1' );
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/*
|
|
|
|
* Remove whitespaces at the start and end of a string.
|
|
|
|
* u00a0 is a no breaking space.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
html = html.replace( /^\s+/, '' );
|
|
|
|
html = html.replace( /[\s\u00a0]+$/, '' );
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Replace <wp-line-break> tags with a newline.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( preserve_linebreaks ) {
|
|
|
|
html = html.replace( /<wp-line-break>/g, '\n' );
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Restore the <wp-temp-br> with <br> tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( preserve_br ) {
|
|
|
|
html = html.replace( /<wp-temp-br([^>]*)>/g, '<br$1>' );
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Restore preserved tags.
|
2016-07-12 18:09:31 -04:00
|
|
|
if ( preserve.length ) {
|
|
|
|
html = html.replace( /<wp-preserve>/g, function() {
|
|
|
|
return preserve.shift();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
return html;
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Adds paragraph tags to the text.
|
|
|
|
*
|
|
|
|
* Adds paragraph tags to the text taking into account block level elements.
|
|
|
|
* Normalizes the whitespaces and newlines.
|
|
|
|
*
|
|
|
|
* Similar to `wpautop()` in formatting.php.
|
|
|
|
*
|
|
|
|
* @since 4.3.0
|
|
|
|
*
|
|
|
|
* @memberof switchEditors
|
|
|
|
*
|
|
|
|
* @param {string} text The text input.
|
|
|
|
* @returns {string} The formatted text.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
function autop( text ) {
|
|
|
|
var preserve_linebreaks = false,
|
|
|
|
preserve_br = false,
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// A list containing all block level elements.
|
2015-06-21 18:01:28 -04:00
|
|
|
blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre' +
|
|
|
|
'|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section' +
|
|
|
|
'|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary';
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Normalize line breaks.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /\r\n|\r/g, '\n' );
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// If there are no newlines, return the text.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( text.indexOf( '\n' ) === -1 ) {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( text.indexOf( '<object' ) !== -1 ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// If there are multiple newlines in an <object>, remove them.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /<object[\s\S]+?<\/object>/g, function( a ) {
|
|
|
|
return a.replace( /\n+/g, '' );
|
|
|
|
});
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Replace all new lines and tabs with spaces inside tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /<[^<>]+>/g, function( a ) {
|
|
|
|
return a.replace( /[\n\t ]+/g, ' ' );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Protect <pre> and <script> tags by replacing them with <wp-line-break>.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( text.indexOf( '<pre' ) !== -1 || text.indexOf( '<script' ) !== -1 ) {
|
|
|
|
preserve_linebreaks = true;
|
2015-11-22 14:13:28 -05:00
|
|
|
text = text.replace( /<(pre|script)[^>]*>[\s\S]*?<\/\1>/g, function( a ) {
|
2015-06-21 18:01:28 -04:00
|
|
|
return a.replace( /\n/g, '<wp-line-break>' );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
2015-06-21 18:01:28 -04:00
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Keep <br> tags inside captions.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( text.indexOf( '[caption' ) !== -1 ) {
|
|
|
|
preserve_br = true;
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Replace all white spaces and <br> tags with <wp-temp-br>.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /\[caption[\s\S]+?\[\/caption\]/g, function( a ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Protect <br> tags by converting them to <wp-temp-br> tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
a = a.replace( /<br([^>]*)>/g, '<wp-temp-br$1>' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Replace all new lines and tabs with spaces inside HTML tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
a = a.replace( /<[^<>]+>/g, function( b ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Replace newlines and tabs with a space.
|
2015-06-21 18:01:28 -04:00
|
|
|
return b.replace( /[\n\t ]+/, ' ' );
|
|
|
|
});
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Convert remaining line breaks to <wp-temp-br />.
|
2015-06-21 18:01:28 -04:00
|
|
|
return a.replace( /\s*\n\s*/g, '<wp-temp-br />' );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Append 2 newlines at the end of the text.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text + '\n\n';
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Replace a <br> tag followed by 1 or more spaces
|
|
|
|
* and another <br> tag with 2 newlines.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /<br \/>\s*<br \/>/gi, '\n\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Replace a block level element open tag with 2 newlines
|
|
|
|
* followed by the captured block level element.
|
|
|
|
*/
|
2016-09-13 02:03:31 -04:00
|
|
|
text = text.replace( new RegExp( '(<(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '\n\n$1' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Replace a block level element closing tag with the captured
|
|
|
|
* block level element followed by 2 newlines.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( new RegExp( '(</(?:' + blocklist + ')>)', 'gi' ), '$1\n\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Add 2 newlines to a <hr> tag. <hr> is a self closing block element.
|
|
|
|
text = text.replace( /<hr( [^>]*)?>/gi, '<hr$1>\n\n' );
|
|
|
|
|
|
|
|
// Remove the spaces before an <option> tag.
|
|
|
|
text = text.replace( /\s*<option/gi, '<option' );
|
|
|
|
|
|
|
|
// Remove the spaces after an <option> closing tag.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /<\/option>\s*/gi, '</option>' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove the spaces between two newlines.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /\n\s*\n+/g, '\n\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Convert 2 newlines to a paragraph and a single newline.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /([\s\S]+?)\n\n/g, '<p>$1</p>\n' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove empty paragraphs.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /<p>\s*?<\/p>/gi, '');
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove spaces and <p> tags around block level elements.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), '$1' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove <p> tags around li elements.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /<p>(<li.+?)<\/p>/gi, '$1');
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove spaces and <p> tags from blockquotes.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /<p>\s*<blockquote([^>]*)>/gi, '<blockquote$1><p>');
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Place the <blockquote> outside of the paragraph.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /<\/blockquote>\s*<\/p>/gi, '</p></blockquote>');
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove spaces at the start and <p> tags from block level elements.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '$1' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove spaces at the end and <p> tags from block level elements.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( new RegExp( '(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), '$1' );
|
2015-08-17 13:36:24 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Remove spaces and newlines after a <br> tag.
|
2015-08-17 13:36:24 -04:00
|
|
|
text = text.replace( /(<br[^>]*>)\s*\n/gi, '$1' );
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Replace spaces followed by a newline with a <br> tag followed by a new line.
|
2015-08-17 13:36:24 -04:00
|
|
|
text = text.replace( /\s*\n/g, '<br />\n');
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Remove <br> tag that follows a block element directly, ignoring spaces.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( new RegExp( '(</?(?:' + blocklist + ')[^>]*>)\\s*<br />', 'gi' ), '$1' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a br tag preceding white spaces followed by a
|
|
|
|
* <p>, <li>, <div>, <dl>, <dd>, <dt>, <th>, <pre>, <td>, <ul>, or <ol> tag.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1' );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Remove white spaces, <p> and <br> tags in captions.
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]' );
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Makes sure there is a paragraph open tag for a close tag.
|
|
|
|
*
|
|
|
|
* @since 2.9.0
|
|
|
|
*
|
|
|
|
* Makes sure there is a paragraph open tag when there is a paragraph close tag
|
|
|
|
* in a div, th, td, form, fieldset or dd element.
|
|
|
|
* @param {string} a The complete match.
|
|
|
|
* @param {string} b The first capture group.
|
|
|
|
* @param {string} c The second capture group.
|
|
|
|
* @returns {string} The string in paragraph tags.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
text = text.replace( /(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g, function( a, b, c ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the matched group has a p open tag in it. If so, we don't need to
|
|
|
|
* enclose it with a paragraph.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( c.match( /<p( [^>]*)?>/ ) ) {
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/*
|
|
|
|
* If there is no p open tag in the matched string,
|
|
|
|
* add it and return the string including p tags.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
return b + '<p>' + c + '</p>';
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Restore the line breaks in <pre> and <script> tags.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( preserve_linebreaks ) {
|
|
|
|
text = text.replace( /<wp-line-break>/g, '\n' );
|
2013-11-15 16:03:10 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Restore the <br> tags in captions.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( preserve_br ) {
|
|
|
|
text = text.replace( /<wp-temp-br([^>]*)>/g, '<br$1>' );
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
return text;
|
2013-11-15 16:03:10 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Modifies the data when a switch is made from HTML to text.
|
|
|
|
*
|
|
|
|
* Modifies the data when a switch is made.
|
|
|
|
* Remove the <p> tags from text.
|
|
|
|
* Returns the modified text.
|
|
|
|
* Adds a trigger on beforePreWpautop and afterPreWpautop.
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @memberof switchEditors
|
|
|
|
*
|
|
|
|
* @param {String} html The content from the visual editor.
|
|
|
|
* @returns {String} the modified text.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
function pre_wpautop( html ) {
|
|
|
|
var obj = { o: exports, data: html, unfiltered: html };
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( $ ) {
|
|
|
|
$( 'body' ).trigger( 'beforePreWpautop', [ obj ] );
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
obj.data = removep( obj.data );
|
2013-11-15 16:03:10 -05:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( $ ) {
|
|
|
|
$( 'body' ).trigger( 'afterPreWpautop', [ obj ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj.data;
|
2013-11-15 16:03:10 -05:00
|
|
|
}
|
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @summary Modifies the data when a switch is made from text to HTML.
|
|
|
|
*
|
|
|
|
* Modifies the data when a switch is made. Runs autop to add p tags from text.
|
|
|
|
* Returns the modified text. Adds a trigger on beforeWpautop and afterWpautop.
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @memberof switchEditors
|
|
|
|
*
|
|
|
|
* @param {String} text The content from the text editor.
|
|
|
|
* @returns {String} the modified text.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
function wpautop( text ) {
|
|
|
|
var obj = { o: exports, data: text, unfiltered: text };
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( $ ) {
|
|
|
|
$( 'body' ).trigger( 'beforeWpautop', [ obj ] );
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
obj.data = autop( obj.data );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( $ ) {
|
|
|
|
$( 'body' ).trigger( 'afterWpautop', [ obj ] );
|
|
|
|
}
|
2013-11-15 16:03:10 -05:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
return obj.data;
|
2013-11-15 16:03:10 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
// Bind the init function to be run when the document is loaded.
|
2015-06-21 18:01:28 -04:00
|
|
|
if ( $ ) {
|
|
|
|
$( document ).ready( init );
|
|
|
|
} else if ( document.addEventListener ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Use the addEventListener to bind the init event on document load.
|
2015-06-21 18:01:28 -04:00
|
|
|
document.addEventListener( 'DOMContentLoaded', init, false );
|
|
|
|
window.addEventListener( 'load', init, false );
|
2017-01-06 17:11:57 -05:00
|
|
|
|
2015-06-21 18:01:28 -04:00
|
|
|
} else if ( window.attachEvent ) {
|
2017-01-06 17:11:57 -05:00
|
|
|
|
|
|
|
// Use the addEvent to bind the init event on document load.
|
2015-06-21 18:01:28 -04:00
|
|
|
window.attachEvent( 'onload', init );
|
|
|
|
document.attachEvent( 'onreadystatechange', function() {
|
|
|
|
if ( 'complete' === document.readyState ) {
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
} );
|
2013-11-15 16:03:10 -05:00
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/*
|
|
|
|
* Make sure the window.wp object exists so autop and removep
|
|
|
|
* can be bound to it.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
window.wp = window.wp || {};
|
|
|
|
window.wp.editor = window.wp.editor || {};
|
|
|
|
window.wp.editor.autop = wpautop;
|
|
|
|
window.wp.editor.removep = pre_wpautop;
|
|
|
|
|
|
|
|
exports = {
|
|
|
|
go: switchEditor,
|
|
|
|
wpautop: wpautop,
|
|
|
|
pre_wpautop: pre_wpautop,
|
|
|
|
_wp_Autop: autop,
|
|
|
|
_wp_Nop: removep
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2015-06-21 18:01:28 -04:00
|
|
|
|
2017-01-06 17:11:57 -05:00
|
|
|
/**
|
|
|
|
* @namespace {SwitchEditors} switchEditors
|
|
|
|
* Expose the switch editors to be used globally.
|
|
|
|
*/
|
2015-06-21 18:01:28 -04:00
|
|
|
window.switchEditors = new SwitchEditors();
|
|
|
|
}( window.jQuery ));
|