From f6d42a08e9f5af6dec49a9d2060a76642e2ad4f9 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 3 Jan 2014 02:33:00 +0000 Subject: [PATCH] TinyMCE: back-compat, refresh and re-enable the 'wpdialogs' plugin, and mark it as deprecated. See #24067. git-svn-id: https://develop.svn.wordpress.org/trunk@26899 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-editor.php | 1 + .../js/tinymce/plugins/wpdialogs/plugin.js | 57 +++++++++++++------ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index 48bcc85f5a..58ffd9a1a4 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/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/src/wp-includes/js/tinymce/plugins/wpdialogs/plugin.js b/src/wp-includes/js/tinymce/plugins/wpdialogs/plugin.js index c6d164a494..7e18713c23 100644 --- a/src/wp-includes/js/tinymce/plugins/wpdialogs/plugin.js +++ b/src/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'); };