wp/wp-includes/js/tinymce/plugins/wordpress/plugin.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     1 /* global getUserSetting, setUserSetting */
     1 /* global getUserSetting, setUserSetting */
     2 ( function( tinymce ) {
     2 ( function( tinymce ) {
     3 // Set the minimum value for the modals z-index higher than #wpadminbar (100000)
     3 // Set the minimum value for the modals z-index higher than #wpadminbar (100000).
     4 if ( ! tinymce.ui.FloatPanel.zIndex || tinymce.ui.FloatPanel.zIndex < 100100 ) {
     4 if ( ! tinymce.ui.FloatPanel.zIndex || tinymce.ui.FloatPanel.zIndex < 100100 ) {
     5 	tinymce.ui.FloatPanel.zIndex = 100100;
     5 	tinymce.ui.FloatPanel.zIndex = 100100;
     6 }
     6 }
     7 
     7 
     8 tinymce.PluginManager.add( 'wordpress', function( editor ) {
     8 tinymce.PluginManager.add( 'wordpress', function( editor ) {
    86 			wpAdvButton = this;
    86 			wpAdvButton = this;
    87 			wpAdvButton.active( getUserSetting( 'hidetb' ) === '1' );
    87 			wpAdvButton.active( getUserSetting( 'hidetb' ) === '1' );
    88 		}
    88 		}
    89 	});
    89 	});
    90 
    90 
    91 	// Hide the toolbars after loading
    91 	// Hide the toolbars after loading.
    92 	editor.on( 'PostRender', function() {
    92 	editor.on( 'PostRender', function() {
    93 		if ( editor.getParam( 'wordpress_adv_hidden', true ) && getUserSetting( 'hidetb', '0' ) === '0' ) {
    93 		if ( editor.getParam( 'wordpress_adv_hidden', true ) && getUserSetting( 'hidetb', '0' ) === '0' ) {
    94 			toggleToolbars( 'hide' );
    94 			toggleToolbars( 'hide' );
    95 		} else {
    95 		} else {
    96 			tinymce.$( '.block-library-classic__toolbar' ).addClass( 'has-advanced-toolbar' );
    96 			tinymce.$( '.block-library-classic__toolbar' ).addClass( 'has-advanced-toolbar' );
   189 				return string || image;
   189 				return string || image;
   190 			});
   190 			});
   191 		}
   191 		}
   192 	});
   192 	});
   193 
   193 
   194 	// Display the tag name instead of img in element path
   194 	// Display the tag name instead of img in element path.
   195 	editor.on( 'ResolveName', function( event ) {
   195 	editor.on( 'ResolveName', function( event ) {
   196 		var attr;
   196 		var attr;
   197 
   197 
   198 		if ( event.target.nodeName === 'IMG' && ( attr = editor.dom.getAttrib( event.target, 'data-wp-more' ) ) ) {
   198 		if ( event.target.nodeName === 'IMG' && ( attr = editor.dom.getAttrib( event.target, 'data-wp-more' ) ) ) {
   199 			event.name = attr;
   199 			event.name = attr;
   200 		}
   200 		}
   201 	});
   201 	});
   202 
   202 
   203 	// Register commands
   203 	// Register commands.
   204 	editor.addCommand( 'WP_More', function( tag ) {
   204 	editor.addCommand( 'WP_More', function( tag ) {
   205 		var parent, html, title,
   205 		var parent, html, title,
   206 			classname = 'wp-more-tag',
   206 			classname = 'wp-more-tag',
   207 			dom = editor.dom,
   207 			dom = editor.dom,
   208 			node = editor.selection.getNode(),
   208 			node = editor.selection.getNode(),
   213 		title = tag === 'more' ? 'Read more...' : 'Next page';
   213 		title = tag === 'more' ? 'Read more...' : 'Next page';
   214 		title = __( title );
   214 		title = __( title );
   215 		html = '<img src="' + tinymce.Env.transparentSrc + '" alt="" title="' + title + '" class="' + classname + '" ' +
   215 		html = '<img src="' + tinymce.Env.transparentSrc + '" alt="" title="' + title + '" class="' + classname + '" ' +
   216 			'data-wp-more="' + tag + '" data-mce-resize="false" data-mce-placeholder="1" />';
   216 			'data-wp-more="' + tag + '" data-mce-resize="false" data-mce-placeholder="1" />';
   217 
   217 
   218 		// Most common case
   218 		// Most common case.
   219 		if ( node === rootNode || ( node.nodeName === 'P' && node.parentNode === rootNode ) ) {
   219 		if ( node === rootNode || ( node.nodeName === 'P' && node.parentNode === rootNode ) ) {
   220 			editor.insertContent( html );
   220 			editor.insertContent( html );
   221 			return;
   221 			return;
   222 		}
   222 		}
   223 
   223 
   224 		// Get the top level parent node
   224 		// Get the top level parent node.
   225 		parent = dom.getParent( node, function( found ) {
   225 		parent = dom.getParent( node, function( found ) {
   226 			if ( found.parentNode && found.parentNode === rootNode ) {
   226 			if ( found.parentNode && found.parentNode === rootNode ) {
   227 				return true;
   227 				return true;
   228 			}
   228 			}
   229 
   229 
   326 		header = [ __( 'Letter' ), __( 'Action' ), __( 'Letter' ), __( 'Action' ) ];
   326 		header = [ __( 'Letter' ), __( 'Action' ), __( 'Letter' ), __( 'Action' ) ];
   327 		header = '<tr><th>' + header.join( '</th><th>' ) + '</th></tr>';
   327 		header = '<tr><th>' + header.join( '</th><th>' ) + '</th></tr>';
   328 
   328 
   329 		html = '<div class="wp-editor-help">';
   329 		html = '<div class="wp-editor-help">';
   330 
   330 
   331 		// Main section, default and additional shortcuts
   331 		// Main section, default and additional shortcuts.
   332 		html = html +
   332 		html = html +
   333 			'<h2>' + __( 'Default shortcuts,' ) + ' ' + meta + '</h2>' +
   333 			'<h2>' + __( 'Default shortcuts,' ) + ' ' + meta + '</h2>' +
   334 			'<table class="wp-help-th-center fixed">' +
   334 			'<table class="wp-help-th-center fixed">' +
   335 				header +
   335 				header +
   336 				table1.join('') +
   336 				table1.join('') +
   340 				header +
   340 				header +
   341 				table2.join('') +
   341 				table2.join('') +
   342 			'</table>';
   342 			'</table>';
   343 
   343 
   344 		if ( editor.plugins.wptextpattern && ( ! tinymce.Env.ie || tinymce.Env.ie > 8 ) ) {
   344 		if ( editor.plugins.wptextpattern && ( ! tinymce.Env.ie || tinymce.Env.ie > 8 ) ) {
   345 			// Text pattern section
   345 			// Text pattern section.
   346 			html = html +
   346 			html = html +
   347 				'<h2>' + __( 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' ) + '</h2>' +
   347 				'<h2>' + __( 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' ) + '</h2>' +
   348 				'<table class="wp-help-th-center fixed">' +
   348 				'<table class="wp-help-th-center fixed">' +
   349 					tr({ '*':  'Bullet list', '1.':  'Numbered list' }) +
   349 					tr({ '*':  'Bullet list', '1.':  'Numbered list' }) +
   350 					tr({ '-':  'Bullet list', '1)':  'Numbered list' }) +
   350 					tr({ '-':  'Bullet list', '1)':  'Numbered list' }) +
   361 					tr({ '######': 'Heading 6' }) +
   361 					tr({ '######': 'Heading 6' }) +
   362 					tr({ '---': 'Horizontal line' }) +
   362 					tr({ '---': 'Horizontal line' }) +
   363 				'</table>';
   363 				'</table>';
   364 		}
   364 		}
   365 
   365 
   366 		// Focus management section
   366 		// Focus management section.
   367 		html = html +
   367 		html = html +
   368 			'<h2>' + __( 'Focus shortcuts:' ) + '</h2>' +
   368 			'<h2>' + __( 'Focus shortcuts:' ) + '</h2>' +
   369 			'<table class="wp-help-single">' +
   369 			'<table class="wp-help-single">' +
   370 				tr({ 'Alt + F8':  'Inline toolbar (when an image, link or preview is selected)' }) +
   370 				tr({ 'Alt + F8':  'Inline toolbar (when an image, link or preview is selected)' }) +
   371 				tr({ 'Alt + F9':  'Editor menu (when enabled)' }) +
   371 				tr({ 'Alt + F9':  'Editor menu (when enabled)' }) +
   411 		if ( wp && wp.media && wp.media.editor ) {
   411 		if ( wp && wp.media && wp.media.editor ) {
   412 			wp.media.editor.open( editor.id );
   412 			wp.media.editor.open( editor.id );
   413 		}
   413 		}
   414 	});
   414 	});
   415 
   415 
   416 	// Register buttons
   416 	// Register buttons.
   417 	editor.addButton( 'wp_more', {
   417 	editor.addButton( 'wp_more', {
   418 		tooltip: 'Insert Read More tag',
   418 		tooltip: 'Insert Read More tag',
   419 		onclick: function() {
   419 		onclick: function() {
   420 			editor.execCommand( 'WP_More', 'more' );
   420 			editor.execCommand( 'WP_More', 'more' );
   421 		}
   421 		}
   437 		tooltip: 'Code',
   437 		tooltip: 'Code',
   438 		cmd: 'WP_Code',
   438 		cmd: 'WP_Code',
   439 		stateSelector: 'code'
   439 		stateSelector: 'code'
   440 	});
   440 	});
   441 
   441 
   442 	// Insert->Add Media
   442 	// Insert->Add Media.
   443 	if ( wp && wp.media && wp.media.editor ) {
   443 	if ( wp && wp.media && wp.media.editor ) {
   444 		editor.addButton( 'wp_add_media', {
   444 		editor.addButton( 'wp_add_media', {
   445 			tooltip: 'Add Media',
   445 			tooltip: 'Add Media',
   446 			icon: 'dashicon dashicons-admin-media',
   446 			icon: 'dashicon dashicons-admin-media',
   447 			cmd: 'WP_Medialib'
   447 			cmd: 'WP_Medialib'
   453 			context: 'insert',
   453 			context: 'insert',
   454 			cmd: 'WP_Medialib'
   454 			cmd: 'WP_Medialib'
   455 		});
   455 		});
   456 	}
   456 	}
   457 
   457 
   458 	// Insert "Read More..."
   458 	// Insert "Read More...".
   459 	editor.addMenuItem( 'wp_more', {
   459 	editor.addMenuItem( 'wp_more', {
   460 		text: 'Insert Read More tag',
   460 		text: 'Insert Read More tag',
   461 		icon: 'wp_more',
   461 		icon: 'wp_more',
   462 		context: 'insert',
   462 		context: 'insert',
   463 		onclick: function() {
   463 		onclick: function() {
   464 			editor.execCommand( 'WP_More', 'more' );
   464 			editor.execCommand( 'WP_More', 'more' );
   465 		}
   465 		}
   466 	});
   466 	});
   467 
   467 
   468 	// Insert "Next Page"
   468 	// Insert "Next Page".
   469 	editor.addMenuItem( 'wp_page', {
   469 	editor.addMenuItem( 'wp_page', {
   470 		text: 'Page break',
   470 		text: 'Page break',
   471 		icon: 'wp_page',
   471 		icon: 'wp_page',
   472 		context: 'insert',
   472 		context: 'insert',
   473 		onclick: function() {
   473 		onclick: function() {
   494 		}
   494 		}
   495 	});
   495 	});
   496 
   496 
   497 	editor.on( 'init', function() {
   497 	editor.on( 'init', function() {
   498 		var env = tinymce.Env,
   498 		var env = tinymce.Env,
   499 			bodyClass = ['mceContentBody'], // back-compat for themes that use this in editor-style.css...
   499 			bodyClass = ['mceContentBody'], // Back-compat for themes that use this in editor-style.css...
   500 			doc = editor.getDoc(),
   500 			doc = editor.getDoc(),
   501 			dom = editor.dom;
   501 			dom = editor.dom;
   502 
   502 
   503 		if ( env.iOS ) {
   503 		if ( env.iOS ) {
   504 			dom.addClass( doc.documentElement, 'ios' );
   504 			dom.addClass( doc.documentElement, 'ios' );
   529 			if ( cls ) {
   529 			if ( cls ) {
   530 				dom.addClass( doc.body, cls );
   530 				dom.addClass( doc.body, cls );
   531 			}
   531 			}
   532 		});
   532 		});
   533 
   533 
   534 		// Remove invalid parent paragraphs when inserting HTML
   534 		// Remove invalid parent paragraphs when inserting HTML.
   535 		editor.on( 'BeforeSetContent', function( event ) {
   535 		editor.on( 'BeforeSetContent', function( event ) {
   536 			if ( event.content ) {
   536 			if ( event.content ) {
   537 				event.content = event.content.replace( /<p>\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi, '<$1$2>' )
   537 				event.content = event.content.replace( /<p>\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi, '<$1$2>' )
   538 					.replace( /<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi, '</$1>' );
   538 					.replace( /<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi, '</$1>' );
   539 			}
   539 			}
   552 			});
   552 			});
   553 		}
   553 		}
   554 
   554 
   555 		if ( editor.getParam( 'wp_paste_filters', true ) ) {
   555 		if ( editor.getParam( 'wp_paste_filters', true ) ) {
   556 			editor.on( 'PastePreProcess', function( event ) {
   556 			editor.on( 'PastePreProcess', function( event ) {
   557 				// Remove trailing <br> added by WebKit browsers to the clipboard
   557 				// Remove trailing <br> added by WebKit browsers to the clipboard.
   558 				event.content = event.content.replace( /<br class="?Apple-interchange-newline"?>/gi, '' );
   558 				event.content = event.content.replace( /<br class="?Apple-interchange-newline"?>/gi, '' );
   559 
   559 
   560 				// In WebKit this is handled by removeWebKitStyles()
   560 				// In WebKit this is handled by removeWebKitStyles().
   561 				if ( ! tinymce.Env.webkit ) {
   561 				if ( ! tinymce.Env.webkit ) {
   562 					// Remove all inline styles
   562 					// Remove all inline styles.
   563 					event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' );
   563 					event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' );
   564 
   564 
   565 					// Put back the internal styles
   565 					// Put back the internal styles.
   566 					event.content = event.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi, '$1 style=$2' );
   566 					event.content = event.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi, '$1 style=$2' );
   567 				}
   567 				}
   568 			});
   568 			});
   569 
   569 
   570 			editor.on( 'PastePostProcess', function( event ) {
   570 			editor.on( 'PastePostProcess', function( event ) {
   571 				// Remove empty paragraphs
   571 				// Remove empty paragraphs.
   572 				editor.$( 'p', event.node ).each( function( i, node ) {
   572 				editor.$( 'p', event.node ).each( function( i, node ) {
   573 					if ( dom.isEmpty( node ) ) {
   573 					if ( dom.isEmpty( node ) ) {
   574 						dom.remove( node );
   574 						dom.remove( node );
   575 					}
   575 					}
   576 				});
   576 				});
   583 			});
   583 			});
   584 		}
   584 		}
   585 	});
   585 	});
   586 
   586 
   587 	editor.on( 'SaveContent', function( event ) {
   587 	editor.on( 'SaveContent', function( event ) {
   588 		// If editor is hidden, we just want the textarea's value to be saved
   588 		// If editor is hidden, we just want the textarea's value to be saved.
   589 		if ( ! editor.inline && editor.isHidden() ) {
   589 		if ( ! editor.inline && editor.isHidden() ) {
   590 			event.content = event.element.value;
   590 			event.content = event.element.value;
   591 			return;
   591 			return;
   592 		}
   592 		}
   593 
   593 
   636 			if ( wp && wp.autosave ) {
   636 			if ( wp && wp.autosave ) {
   637 				wp.autosave.server.triggerSave();
   637 				wp.autosave.server.triggerSave();
   638 			}
   638 			}
   639 		} );
   639 		} );
   640 
   640 
   641 		// Alt+Shift+Z removes a block in the Block Editor, don't add it to the Classic Block.
   641 		// Alt+Shift+Z removes a block in the block editor, don't add it to the Classic block.
   642 		if ( ! editor.settings.classic_block_editor ) {
   642 		if ( ! editor.settings.classic_block_editor ) {
   643 			editor.addShortcut( 'access+z', '', 'WP_Adv' );
   643 			editor.addShortcut( 'access+z', '', 'WP_Adv' );
   644 		}
   644 		}
   645 
   645 
   646 		// Workaround for not triggering the global help modal in the Block Editor by the Classic Block shortcut.
   646 		// Workaround for not triggering the global help modal in the block editor by the Classic block shortcut.
   647 		editor.on( 'keydown', function( event ) {
   647 		editor.on( 'keydown', function( event ) {
   648 			var match;
   648 			var match;
   649 
   649 
   650 			if ( tinymce.Env.mac ) {
   650 			if ( tinymce.Env.mac ) {
   651 				match = event.ctrlKey && event.altKey && event.code === 'KeyH';
   651 				match = event.ctrlKey && event.altKey && event.code === 'KeyH';
   698 		var access = 'Shift+Alt+';
   698 		var access = 'Shift+Alt+';
   699 		var meta = 'Ctrl+';
   699 		var meta = 'Ctrl+';
   700 
   700 
   701 		wpTooltips = {};
   701 		wpTooltips = {};
   702 
   702 
   703 		// For MacOS: ctrl = \u2303, cmd = \u2318, alt = \u2325
   703 		// For MacOS: ctrl = \u2303, cmd = \u2318, alt = \u2325.
   704 		if ( tinymce.Env.mac ) {
   704 		if ( tinymce.Env.mac ) {
   705 			access = '\u2303\u2325';
   705 			access = '\u2303\u2325';
   706 			meta = '\u2318';
   706 			meta = '\u2318';
   707 		}
   707 		}
   708 
   708 
   759 			}
   759 			}
   760 		} );
   760 		} );
   761 	}
   761 	}
   762 
   762 
   763 	function addShortcutsToListbox() {
   763 	function addShortcutsToListbox() {
   764 		// listbox for the "blocks" drop-down
   764 		// listbox for the "blocks" drop-down.
   765 		each( editor.theme.panel.find( 'listbox' ), function( listbox ) {
   765 		each( editor.theme.panel.find( 'listbox' ), function( listbox ) {
   766 			if ( listbox && listbox.settings.text === 'Paragraph' ) {
   766 			if ( listbox && listbox.settings.text === 'Paragraph' ) {
   767 				each( listbox.settings.values, function( item ) {
   767 				each( listbox.settings.values, function( item ) {
   768 					if ( item.text && wpTooltips.hasOwnProperty( item.text ) ) {
   768 					if ( item.text && wpTooltips.hasOwnProperty( item.text ) ) {
   769 						item.shortcut = '(' + wpTooltips[ item.text ] + ')';
   769 						item.shortcut = '(' + wpTooltips[ item.text ] + ')';
   787 			wpAdminbar = document.getElementById( 'wpadminbar' ),
   787 			wpAdminbar = document.getElementById( 'wpadminbar' ),
   788 			mceIframe = document.getElementById( editor.id + '_ifr' ),
   788 			mceIframe = document.getElementById( editor.id + '_ifr' ),
   789 			mceToolbar,
   789 			mceToolbar,
   790 			mceStatusbar,
   790 			mceStatusbar,
   791 			wpStatusbar,
   791 			wpStatusbar,
   792 			isChromeRtl = ( editor.rtl && /Chrome/.test( navigator.userAgent ) );
   792 			cachedWinSize;
   793 
   793 
   794 			if ( container ) {
   794 			if ( container ) {
   795 				mceToolbar = tinymce.$( '.mce-toolbar-grp', container )[0];
   795 				mceToolbar = tinymce.$( '.mce-toolbar-grp', container )[0];
   796 				mceStatusbar = tinymce.$( '.mce-statusbar', container )[0];
   796 				mceStatusbar = tinymce.$( '.mce-statusbar', container )[0];
   797 			}
   797 			}
  1038 				return this;
  1038 				return this;
  1039 			}
  1039 			}
  1040 
  1040 
  1041 			toolbar.on( 'show', function() {
  1041 			toolbar.on( 'show', function() {
  1042 				this.reposition();
  1042 				this.reposition();
  1043 
       
  1044 				if ( isChromeRtl ) {
       
  1045 					tinymce.$( '.mce-widget.mce-tooltip' ).addClass( 'wp-hide-mce-tooltip' );
       
  1046 				}
       
  1047 			} );
       
  1048 
       
  1049 			toolbar.on( 'hide', function() {
       
  1050 				if ( isChromeRtl ) {
       
  1051 					tinymce.$( '.mce-widget.mce-tooltip' ).removeClass( 'wp-hide-mce-tooltip' );
       
  1052 				}
       
  1053 			} );
  1043 			} );
  1054 
  1044 
  1055 			toolbar.on( 'keydown', function( event ) {
  1045 			toolbar.on( 'keydown', function( event ) {
  1056 				if ( event.keyCode === 27 ) {
  1046 				if ( event.keyCode === 27 ) {
  1057 					this.hide();
  1047 					this.hide();
  1113 				activeToolbar.show();
  1103 				activeToolbar.show();
  1114 			}
  1104 			}
  1115 		} );
  1105 		} );
  1116 
  1106 
  1117 		function hide( event ) {
  1107 		function hide( event ) {
       
  1108 			var win;
       
  1109 			var size;
       
  1110 
  1118 			if ( activeToolbar ) {
  1111 			if ( activeToolbar ) {
  1119 				if ( activeToolbar.tempHide || event.type === 'hide' || event.type === 'blur' ) {
  1112 				if ( activeToolbar.tempHide || event.type === 'hide' || event.type === 'blur' ) {
  1120 					activeToolbar.hide();
  1113 					activeToolbar.hide();
  1121 					activeToolbar = false;
  1114 					activeToolbar = false;
  1122 				} else if ( (
  1115 				} else if ( (
  1123 					event.type === 'resizewindow' ||
  1116 					event.type === 'resizewindow' ||
  1124 					event.type === 'scrollwindow' ||
  1117 					event.type === 'scrollwindow' ||
  1125 					event.type === 'resize' ||
  1118 					event.type === 'resize' ||
  1126 					event.type === 'scroll'
  1119 					event.type === 'scroll'
  1127 				) && ! activeToolbar.blockHide ) {
  1120 				) && ! activeToolbar.blockHide ) {
       
  1121 					/*
       
  1122 					 * Showing a tooltip may trigger a `resize` event in Chromium browsers.
       
  1123 					 * That results in a flicketing inline menu; tooltips are shown on hovering over a button,
       
  1124 					 * which then hides the toolbar on `resize`, then it repeats as soon as the toolbar is shown again.
       
  1125 					 */
       
  1126 					if ( event.type === 'resize' || event.type === 'resizewindow' ) {
       
  1127 						win = editor.getWin();
       
  1128 						size = win.innerHeight + win.innerWidth;
       
  1129 
       
  1130 						// Reset old cached size.
       
  1131 						if ( cachedWinSize && ( new Date() ).getTime() - cachedWinSize.timestamp > 2000 ) {
       
  1132 							cachedWinSize = null;
       
  1133 						}
       
  1134 
       
  1135 						if ( cachedWinSize ) {
       
  1136 							if ( size && Math.abs( size - cachedWinSize.size ) < 2 ) {
       
  1137 								// `resize` fired but the window hasn't been resized. Bail.
       
  1138 								return;
       
  1139 							}
       
  1140 						} else {
       
  1141 							// First of a new series of `resize` events. Store the cached size and bail.
       
  1142 							cachedWinSize = {
       
  1143 								timestamp: ( new Date() ).getTime(),
       
  1144 								size: size,
       
  1145 							};
       
  1146 
       
  1147 							return;
       
  1148 						}
       
  1149 					}
       
  1150 
  1128 					clearTimeout( timeout );
  1151 					clearTimeout( timeout );
  1129 
  1152 
  1130 					timeout = setTimeout( function() {
  1153 					timeout = setTimeout( function() {
  1131 						if ( activeToolbar && typeof activeToolbar.show === 'function' ) {
  1154 						if ( activeToolbar && typeof activeToolbar.show === 'function' ) {
  1132 							activeToolbar.scrolling = false;
  1155 							activeToolbar.scrolling = false;
  1138 					activeToolbar.hide();
  1161 					activeToolbar.hide();
  1139 				}
  1162 				}
  1140 			}
  1163 			}
  1141 		}
  1164 		}
  1142 
  1165 
  1143 		editor.dom.bind( editor.getWin(), 'resize', hide );
       
  1144 
       
  1145 		if ( editor.inline ) {
  1166 		if ( editor.inline ) {
       
  1167 			editor.on( 'resizewindow', hide );
       
  1168 
  1146 			// Enable `capture` for the event.
  1169 			// Enable `capture` for the event.
  1147 			// This will hide/reposition the toolbar on any scrolling in the document.
  1170 			// This will hide/reposition the toolbar on any scrolling in the document.
  1148 			document.addEventListener( 'scroll', hide, true );
  1171 			document.addEventListener( 'scroll', hide, true );
  1149 		} else {
  1172 		} else {
  1150 			editor.dom.bind( editor.getWin(), 'scroll', hide );
  1173 			// Bind to the editor iframe and to the parent window.
  1151 			// For full height iframe editor.
  1174 			editor.dom.bind( editor.getWin(), 'resize scroll', hide );
  1152 			editor.on( 'resizewindow scrollwindow', hide );
  1175 			editor.on( 'resizewindow scrollwindow', hide );
  1153 		}
  1176 		}
  1154 
  1177 
  1155 		editor.on( 'remove', function() {
  1178 		editor.on( 'remove', function() {
  1156 			document.removeEventListener( 'scroll', hide, true );
  1179 			document.removeEventListener( 'scroll', hide, true );
  1164 		editor.wp._createToolbar = create;
  1187 		editor.wp._createToolbar = create;
  1165 	}, true );
  1188 	}, true );
  1166 
  1189 
  1167 	function noop() {}
  1190 	function noop() {}
  1168 
  1191 
  1169 	// Expose some functions (back-compat)
  1192 	// Expose some functions (back-compat).
  1170 	return {
  1193 	return {
  1171 		_showButtons: noop,
  1194 		_showButtons: noop,
  1172 		_hideButtons: noop,
  1195 		_hideButtons: noop,
  1173 		_setEmbed: noop,
  1196 		_setEmbed: noop,
  1174 		_getEmbed: noop
  1197 		_getEmbed: noop