diff --git a/wp-includes/class-wp-editor.php b/wp-includes/class-wp-editor.php index 48bcc85f5a..58ffd9a1a4 100644 --- a/wp-includes/class-wp-editor.php +++ b/wp-includes/class-wp-editor.php @@ -234,6 +234,7 @@ final class _WP_Editors { 'wpeditimage', 'wpgallery', 'wplink', + 'wpdialogs', ) ) ); if ( ! empty( $mce_external_plugins ) ) { diff --git a/wp-includes/js/tinymce/plugins/wpdialogs/plugin.js b/wp-includes/js/tinymce/plugins/wpdialogs/plugin.js index c6d164a494..7e18713c23 100644 --- a/wp-includes/js/tinymce/plugins/wpdialogs/plugin.js +++ b/wp-includes/js/tinymce/plugins/wpdialogs/plugin.js @@ -1,36 +1,48 @@ /* global tinymce */ - -tinymce.WPWindowManager = function( editor ) { - var element; +/** + * Included for back-compat. + * The default WindowManager in TinyMCE 4.0 supports three types of dialogs: + * - With HTML created from JS. + * - With inline HTML (like WPWindowManager). + * - Old type iframe based dialogs. + * For examples see the default plugins: https://github.com/tinymce/tinymce/tree/master/js/tinymce/plugins + */ +tinymce.WPWindowManager = tinymce.InlineWindowManager = function( editor ) { this.parent = editor.windowManager; this.editor = editor; - tinymce.extend( this, this.parent ) + tinymce.extend( this, this.parent ); this.open = function( args, params ) { - var self = this, element; + var self = this, $element; - if ( ! args.wpDialog ) + if ( ! args.wpDialog ) { return this.parent.open( args, params ); - else if ( ! args.id ) + } else if ( ! args.id ) { return; + } - self.element = element = jQuery('#' + args.id); - if ( ! element.length ) + self.element = $element = jQuery( '#' + args.id ); + + if ( ! $element.length ) { return; + } + + if ( window && window.console ) { + window.console.log('tinymce.WPWindowManager is deprecated. Use the default editor.windowManager to open dialogs with inline HTML.'); + } self.features = args; self.params = params; - self.onOpen.dispatch( self, args, params ); - self.windows.push( element ); + self.windows.push( $element ); - // Store selection - // self.bookmark = self.editor.selection.getBookmark(1); + // Store selection. Takes a snapshot in the FocusManager of the selection before focus is moved to the dialog. + editor.nodeChanged(); // Create the dialog if necessary - if ( ! element.data('wpdialog') ) { - element.wpdialog({ + if ( ! $element.data('wpdialog') ) { + $element.wpdialog({ title: args.title, width: args.width, height: args.height, @@ -40,12 +52,23 @@ tinymce.WPWindowManager = function( editor ) { }); } - element.wpdialog('open'); + $element.wpdialog('open'); + + $element.on( 'wpdialogclose', function() { + var i = self.windows.length; + + while ( i-- && i > -1 ) { + if ( self.windows[i] === self.element ) { + self.windows.splice( i, 1 ); + } + } + }); }; this.close = function() { - if ( ! this.features.wpDialog ) + if ( ! this.features.wpDialog ) { return this.parent.close.apply( this, arguments ); + } this.element.wpdialog('close'); }; diff --git a/wp-includes/js/tinymce/plugins/wpdialogs/plugin.min.js b/wp-includes/js/tinymce/plugins/wpdialogs/plugin.min.js index 81ec3ec144..cc6592ef0f 100644 --- a/wp-includes/js/tinymce/plugins/wpdialogs/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wpdialogs/plugin.min.js @@ -1 +1 @@ -tinymce.WPWindowManager=function(a){this.parent=a.windowManager,this.editor=a,tinymce.extend(this,this.parent),this.open=function(a,b){var c,d=this;return a.wpDialog?(a.id&&(d.element=c=jQuery("#"+a.id),c.length&&(d.features=a,d.params=b,d.onOpen.dispatch(d,a,b),d.windows.push(c),c.data("wpdialog")||c.wpdialog({title:a.title,width:a.width,height:a.height,modal:!0,dialogClass:"wp-dialog",zIndex:3e5}),c.wpdialog("open"))),void 0):this.parent.open(a,b)},this.close=function(){return this.features.wpDialog?(this.element.wpdialog("close"),void 0):this.parent.close.apply(this,arguments)}},tinymce.PluginManager.add("wpdialogs",function(a){a.on("init",function(){a.windowManager=new tinymce.WPWindowManager(a)})}); \ No newline at end of file +tinymce.WPWindowManager=tinymce.InlineWindowManager=function(a){this.parent=a.windowManager,this.editor=a,tinymce.extend(this,this.parent),this.open=function(b,c){var d,e=this;return b.wpDialog?(b.id&&(e.element=d=jQuery("#"+b.id),d.length&&(window&&window.console&&window.console.log("tinymce.WPWindowManager is deprecated. Use the default editor.windowManager to open dialogs with inline HTML."),e.features=b,e.params=c,e.windows.push(d),a.nodeChanged(),d.data("wpdialog")||d.wpdialog({title:b.title,width:b.width,height:b.height,modal:!0,dialogClass:"wp-dialog",zIndex:3e5}),d.wpdialog("open"),d.on("wpdialogclose",function(){for(var a=e.windows.length;a--&&a>-1;)e.windows[a]===e.element&&e.windows.splice(a,1)}))),void 0):this.parent.open(b,c)},this.close=function(){return this.features.wpDialog?(this.element.wpdialog("close"),void 0):this.parent.close.apply(this,arguments)}},tinymce.PluginManager.add("wpdialogs",function(a){a.on("init",function(){a.windowManager=new tinymce.WPWindowManager(a)})}); \ No newline at end of file diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index 1f2b2c1d0a..535501311a 100644 Binary files a/wp-includes/js/tinymce/wp-tinymce.js.gz and b/wp-includes/js/tinymce/wp-tinymce.js.gz differ