From 45ce9d2a96095e9e1f20da78ee8eb63615a94d0f Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 27 Nov 2012 19:09:00 +0000 Subject: [PATCH] Media: Introduce wp.media.editor.open(editor_id) and leverage it in distraction-free writing (fullscreen). props azaozz, koopersmith. fixes #22541. git-svn-id: http://core.svn.wordpress.org/trunk@22875 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/wp-fullscreen.js | 10 +--- wp-includes/css/editor.css | 2 +- wp-includes/css/media-views.css | 4 +- wp-includes/js/media-editor.js | 46 ++++++++++++------- .../plugins/wordpress/editor_plugin_src.js | 11 +---- 5 files changed, 36 insertions(+), 37 deletions(-) diff --git a/wp-admin/js/wp-fullscreen.js b/wp-admin/js/wp-fullscreen.js index df6791d606..4746b286a2 100644 --- a/wp-admin/js/wp-fullscreen.js +++ b/wp-admin/js/wp-fullscreen.js @@ -482,14 +482,8 @@ PubSub.prototype.publish = function( topic, args ) { } api.medialib = function() { - if ( s.has_tinymce && 'tinymce' === s.mode ) { - tinyMCE.execCommand('WP_Medialib'); - } else { - var href = $('#wp-' + s.editor_id + '-media-buttons a.thickbox').attr('href') || ''; - - if ( href ) - tb_show('', href); - } + if ( typeof wp !== 'undefined' && wp.media && wp.media.editor ) + wp.media.editor.open(s.editor_id); } api.refresh_buttons = function( fade ) { diff --git a/wp-includes/css/editor.css b/wp-includes/css/editor.css index 0d0d8c66a2..4763436689 100644 --- a/wp-includes/css/editor.css +++ b/wp-includes/css/editor.css @@ -1148,7 +1148,7 @@ html[dir="rtl"] .wp-switch-editor { padding: 2px; position: absolute; display: none; - z-index: 999998; + z-index: 100000; } #wp_editimgbtn, diff --git a/wp-includes/css/media-views.css b/wp-includes/css/media-views.css index 5b9a023a2e..47eb8329a9 100644 --- a/wp-includes/css/media-views.css +++ b/wp-includes/css/media-views.css @@ -68,7 +68,7 @@ input[type="search"] { left: 40px; right: 40px; bottom: 40px; - z-index: 125000; + z-index: 160000; } .media-modal-backdrop { @@ -79,7 +79,7 @@ input[type="search"] { bottom: 0; background: #000; opacity: 0.8; - z-index: 120000; + z-index: 159900; } .media-modal-backdrop div { diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index 3134a8e91f..19be0db3d5 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -471,10 +471,9 @@ }, init: function() { - $(document.body).on('click', '.insert-media', function( event ) { + $(document.body).on( 'click', '.insert-media', function( event ) { var $this = $(this), - editor = $this.data('editor'), - workflow; + editor = $this.data('editor'); event.preventDefault(); @@ -485,22 +484,35 @@ // See: http://core.trac.wordpress.org/ticket/22445 $this.blur(); - if ( ! _.isString( editor ) ) - return; - - workflow = wp.media.editor.get( editor ); - - // If the workflow exists, just open it. - if ( workflow ) { - workflow.open(); - return; - } - - // Initialize the editor's workflow if we haven't yet. - wp.media.editor.add( editor ); + wp.media.editor.open( editor ); }); + }, + + open: function( id ) { + var workflow; + + // If an empty `id` is provided, default to `wpActiveEditor`. + id = id || wpActiveEditor; + + // If that doesn't work, fall back to `tinymce.activeEditor`. + if ( ! id && typeof tinymce !== 'undefined' && tinymce.activeEditor ) + id = id || tinymce.activeEditor.id; + + // Last but not least, fall back to the empty string. + id = id || ''; + + workflow = wp.media.editor.get( id ); + + // If the workflow exists, open it. + // Initialize the editor's workflow if we haven't yet. + if ( workflow ) + workflow.open(); + else + workflow = wp.media.editor.add( id ); + + return workflow; } }; $( wp.media.editor.init ); -}(jQuery)); \ No newline at end of file +}(jQuery)); diff --git a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js index 6a6d151ea7..2c1e902cf8 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js +++ b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js @@ -63,15 +63,8 @@ }); ed.addCommand('WP_Medialib', function() { - var id = ed.getParam('wp_fullscreen_editor_id') || ed.getParam('fullscreen_editor_id') || ed.id, - link = tinymce.DOM.select('#wp-' + id + '-media-buttons a.thickbox'); - - if ( link && link[0] ) - link = link[0]; - else - return; - - tb_show('', link.href); + if ( typeof wp !== 'undefined' && wp.media && wp.media.editor ) + wp.media.editor.open( ed.id ); }); // Register buttons