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
This commit is contained in:
Andrew Nacin 2012-11-27 19:09:00 +00:00
parent fe3ace4f05
commit 45ce9d2a96
5 changed files with 36 additions and 37 deletions

View File

@ -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 ) {

View File

@ -1148,7 +1148,7 @@ html[dir="rtl"] .wp-switch-editor {
padding: 2px;
position: absolute;
display: none;
z-index: 999998;
z-index: 100000;
}
#wp_editimgbtn,

View File

@ -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 {

View File

@ -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));
}(jQuery));

View File

@ -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