mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-09 18:08:09 +01:00
When setting the featured image from the dedicated meta box, only show the featured image section in the media chooser. props koopersmith. fixes #22731
* Less distracting * Some of these sections won't apply for CPTs without an editor git-svn-id: http://core.svn.wordpress.org/trunk@23069 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e84a4a0c89
commit
d8d39ff764
@ -320,6 +320,74 @@
|
|||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
wp.media.featuredImage = {
|
||||||
|
get: function() {
|
||||||
|
return wp.media.view.settings.post.featuredImageId;
|
||||||
|
},
|
||||||
|
|
||||||
|
set: function( id ) {
|
||||||
|
var settings = wp.media.view.settings;
|
||||||
|
|
||||||
|
settings.post.featuredImageId = id;
|
||||||
|
|
||||||
|
wp.media.post( 'set-post-thumbnail', {
|
||||||
|
json: true,
|
||||||
|
post_id: settings.post.id,
|
||||||
|
thumbnail_id: settings.post.featuredImageId,
|
||||||
|
_wpnonce: settings.post.nonce
|
||||||
|
}).done( function( html ) {
|
||||||
|
$( '.inside', '#postimagediv' ).html( html );
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
frame: function() {
|
||||||
|
if ( this._frame )
|
||||||
|
return this._frame;
|
||||||
|
|
||||||
|
this._frame = wp.media({
|
||||||
|
state: 'featured-image',
|
||||||
|
states: [ new wp.media.controller.FeaturedImage() ]
|
||||||
|
});
|
||||||
|
|
||||||
|
this._frame.on( 'toolbar:create:featured-image', function( toolbar ) {
|
||||||
|
this.createSelectToolbar( toolbar, {
|
||||||
|
text: wp.media.view.l10n.setFeaturedImage
|
||||||
|
});
|
||||||
|
}, this._frame );
|
||||||
|
|
||||||
|
this._frame.state('featured-image').on( 'select', this.select );
|
||||||
|
return this._frame;
|
||||||
|
},
|
||||||
|
|
||||||
|
select: function() {
|
||||||
|
var settings = wp.media.view.settings,
|
||||||
|
selection = this.get('selection').single();
|
||||||
|
|
||||||
|
if ( ! settings.post.featuredImageId )
|
||||||
|
return;
|
||||||
|
|
||||||
|
wp.media.featuredImage.set( selection ? selection.id : -1 );
|
||||||
|
},
|
||||||
|
|
||||||
|
init: function() {
|
||||||
|
// Open the content media manager to the 'featured image' tab when
|
||||||
|
// the post thumbnail is clicked.
|
||||||
|
$('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {
|
||||||
|
event.preventDefault();
|
||||||
|
// Stop propagation to prevent thickbox from activating.
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
wp.media.featuredImage.frame().open();
|
||||||
|
|
||||||
|
// Update the featured image id when the 'remove' link is clicked.
|
||||||
|
}).on( 'click', '#remove-post-thumbnail', function() {
|
||||||
|
wp.media.view.settings.post.featuredImageId = -1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$( wp.media.featuredImage.init );
|
||||||
|
|
||||||
wp.media.editor = {
|
wp.media.editor = {
|
||||||
insert: function( h ) {
|
insert: function( h ) {
|
||||||
var mce = typeof(tinymce) != 'undefined',
|
var mce = typeof(tinymce) != 'undefined',
|
||||||
@ -443,24 +511,7 @@
|
|||||||
}
|
}
|
||||||
}, this );
|
}, this );
|
||||||
|
|
||||||
workflow.state('featured-image').on( 'select', function() {
|
workflow.state('featured-image').on( 'select', wp.media.featuredImage.select );
|
||||||
var settings = wp.media.view.settings,
|
|
||||||
selection = this.get('selection').single();
|
|
||||||
|
|
||||||
if ( ! settings.post.featuredImageId )
|
|
||||||
return;
|
|
||||||
|
|
||||||
settings.post.featuredImageId = selection ? selection.id : -1;
|
|
||||||
wp.media.post( 'set-post-thumbnail', {
|
|
||||||
json: true,
|
|
||||||
post_id: settings.post.id,
|
|
||||||
thumbnail_id: settings.post.featuredImageId,
|
|
||||||
_wpnonce: settings.post.nonce
|
|
||||||
}).done( function( html ) {
|
|
||||||
$( '.inside', '#postimagediv' ).html( html );
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
workflow.setState( workflow.options.state );
|
workflow.setState( workflow.options.state );
|
||||||
return workflow;
|
return workflow;
|
||||||
},
|
},
|
||||||
@ -586,37 +637,6 @@
|
|||||||
|
|
||||||
wp.media.editor.open( editor );
|
wp.media.editor.open( editor );
|
||||||
});
|
});
|
||||||
|
|
||||||
// Open the content media manager to the 'featured image' tab when
|
|
||||||
// the post thumbnail is clicked.
|
|
||||||
$('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {
|
|
||||||
event.preventDefault();
|
|
||||||
// Stop propagation to prevent thickbox from activating.
|
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
// Always get the 'content' frame, since this is tailored to post.php.
|
|
||||||
var frame = wp.media.editor.add('content'),
|
|
||||||
initialState = frame.state().id,
|
|
||||||
escape;
|
|
||||||
|
|
||||||
escape = function() {
|
|
||||||
// Only run this event once.
|
|
||||||
this.off( 'escape', escape );
|
|
||||||
|
|
||||||
// If we're still on the 'featured-image' state, restore
|
|
||||||
// the initial state.
|
|
||||||
if ( 'featured-image' === this.state().id )
|
|
||||||
this.setState( initialState );
|
|
||||||
};
|
|
||||||
|
|
||||||
frame.on( 'escape', escape, frame );
|
|
||||||
|
|
||||||
frame.setState('featured-image').open();
|
|
||||||
|
|
||||||
// Update the featured image id when the 'remove' link is clicked.
|
|
||||||
}).on( 'click', '#remove-post-thumbnail', function() {
|
|
||||||
wp.media.view.settings.post.featuredImageId = -1;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@
|
|||||||
this.frame.router.render( mode );
|
this.frame.router.render( mode );
|
||||||
|
|
||||||
view = router.get();
|
view = router.get();
|
||||||
if ( view.select )
|
if ( view && view.select )
|
||||||
view.select( this.frame.content.mode() );
|
view.select( this.frame.content.mode() );
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -304,7 +304,7 @@
|
|||||||
menu.mode( mode );
|
menu.mode( mode );
|
||||||
|
|
||||||
view = menu.get();
|
view = menu.get();
|
||||||
if ( view.select )
|
if ( view && view.select )
|
||||||
view.select( this.id );
|
view.select( this.id );
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -357,6 +357,7 @@
|
|||||||
sidebar: 'settings',
|
sidebar: 'settings',
|
||||||
content: 'upload',
|
content: 'upload',
|
||||||
router: 'browse',
|
router: 'browse',
|
||||||
|
menu: 'default',
|
||||||
searchable: true,
|
searchable: true,
|
||||||
filterable: false,
|
filterable: false,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
@ -638,7 +639,6 @@
|
|||||||
id: 'featured-image',
|
id: 'featured-image',
|
||||||
filterable: 'uploaded',
|
filterable: 'uploaded',
|
||||||
multiple: false,
|
multiple: false,
|
||||||
menu: 'main',
|
|
||||||
toolbar: 'featured-image',
|
toolbar: 'featured-image',
|
||||||
title: l10n.featuredImageTitle,
|
title: l10n.featuredImageTitle,
|
||||||
priority: 60
|
priority: 60
|
||||||
@ -676,6 +676,17 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
activate: function() {
|
activate: function() {
|
||||||
|
this.updateSelection();
|
||||||
|
this.frame.on( 'open', this.updateSelection, this );
|
||||||
|
media.controller.Library.prototype.activate.apply( this, arguments );
|
||||||
|
},
|
||||||
|
|
||||||
|
deactivate: function() {
|
||||||
|
this.frame.off( 'open', this.updateSelection, this );
|
||||||
|
media.controller.Library.prototype.deactivate.apply( this, arguments );
|
||||||
|
},
|
||||||
|
|
||||||
|
updateSelection: function() {
|
||||||
var selection = this.get('selection'),
|
var selection = this.get('selection'),
|
||||||
id = media.view.settings.post.featuredImageId,
|
id = media.view.settings.post.featuredImageId,
|
||||||
attachment;
|
attachment;
|
||||||
@ -686,7 +697,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
selection.reset( attachment ? [ attachment ] : [] );
|
selection.reset( attachment ? [ attachment ] : [] );
|
||||||
media.controller.Library.prototype.activate.apply( this, arguments );
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -697,7 +707,7 @@
|
|||||||
defaults: {
|
defaults: {
|
||||||
id: 'embed',
|
id: 'embed',
|
||||||
url: '',
|
url: '',
|
||||||
menu: 'main',
|
menu: 'default',
|
||||||
content: 'embed',
|
content: 'embed',
|
||||||
toolbar: 'main-embed',
|
toolbar: 'main-embed',
|
||||||
type: 'link',
|
type: 'link',
|
||||||
@ -1200,6 +1210,9 @@
|
|||||||
model.frame = this;
|
model.frame = this;
|
||||||
model.trigger('ready');
|
model.trigger('ready');
|
||||||
}, this );
|
}, this );
|
||||||
|
|
||||||
|
if ( this.options.states )
|
||||||
|
this.states.add( this.options.states );
|
||||||
},
|
},
|
||||||
|
|
||||||
reset: function() {
|
reset: function() {
|
||||||
@ -1263,6 +1276,9 @@
|
|||||||
// Bind default title creation.
|
// Bind default title creation.
|
||||||
this.on( 'title:create:default', this.createTitle, this );
|
this.on( 'title:create:default', this.createTitle, this );
|
||||||
this.title.mode('default');
|
this.title.mode('default');
|
||||||
|
|
||||||
|
// Bind default menu.
|
||||||
|
this.on( 'menu:create:default', this.createMenu, this );
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
@ -1319,12 +1335,12 @@
|
|||||||
src: tabUrl + '&tab=' + id,
|
src: tabUrl + '&tab=' + id,
|
||||||
title: title,
|
title: title,
|
||||||
content: 'iframe',
|
content: 'iframe',
|
||||||
menu: 'main'
|
menu: 'default'
|
||||||
}, options ) );
|
}, options ) );
|
||||||
}, this );
|
}, this );
|
||||||
|
|
||||||
this.on( 'content:create:iframe', this.iframeContent, this );
|
this.on( 'content:create:iframe', this.iframeContent, this );
|
||||||
this.on( 'menu:render:main', this.iframeMenu, this );
|
this.on( 'menu:render:default', this.iframeMenu, this );
|
||||||
this.on( 'open', this.hijackThickbox, this );
|
this.on( 'open', this.hijackThickbox, this );
|
||||||
this.on( 'close', this.restoreThickbox, this );
|
this.on( 'close', this.restoreThickbox, this );
|
||||||
},
|
},
|
||||||
@ -1418,6 +1434,9 @@
|
|||||||
createStates: function() {
|
createStates: function() {
|
||||||
var options = this.options;
|
var options = this.options;
|
||||||
|
|
||||||
|
if ( this.options.states )
|
||||||
|
return;
|
||||||
|
|
||||||
// Add the default states.
|
// Add the default states.
|
||||||
this.states.add([
|
this.states.add([
|
||||||
// Main states.
|
// Main states.
|
||||||
@ -1425,7 +1444,6 @@
|
|||||||
selection: options.selection,
|
selection: options.selection,
|
||||||
library: media.query( options.library ),
|
library: media.query( options.library ),
|
||||||
multiple: options.multiple,
|
multiple: options.multiple,
|
||||||
menu: 'main',
|
|
||||||
title: options.title,
|
title: options.title,
|
||||||
priority: 20
|
priority: 20
|
||||||
})
|
})
|
||||||
@ -1433,7 +1451,6 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
bindHandlers: function() {
|
bindHandlers: function() {
|
||||||
this.on( 'menu:create:main', this.createMenu, this );
|
|
||||||
this.on( 'router:create:browse', this.createRouter, this );
|
this.on( 'router:create:browse', this.createRouter, this );
|
||||||
this.on( 'router:render:browse', this.browseRouter, this );
|
this.on( 'router:render:browse', this.browseRouter, this );
|
||||||
this.on( 'content:create:browse', this.browseContent, this );
|
this.on( 'content:create:browse', this.browseContent, this );
|
||||||
@ -1519,7 +1536,6 @@
|
|||||||
id: 'insert',
|
id: 'insert',
|
||||||
title: l10n.insertMediaTitle,
|
title: l10n.insertMediaTitle,
|
||||||
priority: 20,
|
priority: 20,
|
||||||
menu: 'main',
|
|
||||||
toolbar: 'main-insert',
|
toolbar: 'main-insert',
|
||||||
filterable: 'all',
|
filterable: 'all',
|
||||||
library: media.query( options.library ),
|
library: media.query( options.library ),
|
||||||
@ -1538,7 +1554,6 @@
|
|||||||
id: 'gallery',
|
id: 'gallery',
|
||||||
title: l10n.createGalleryTitle,
|
title: l10n.createGalleryTitle,
|
||||||
priority: 40,
|
priority: 40,
|
||||||
menu: 'main',
|
|
||||||
toolbar: 'main-gallery',
|
toolbar: 'main-gallery',
|
||||||
filterable: 'uploaded',
|
filterable: 'uploaded',
|
||||||
multiple: 'add',
|
multiple: 'add',
|
||||||
@ -1568,10 +1583,7 @@
|
|||||||
|
|
||||||
|
|
||||||
if ( media.view.settings.post.featuredImageId ) {
|
if ( media.view.settings.post.featuredImageId ) {
|
||||||
this.states.add( new media.controller.FeaturedImage({
|
this.states.add( new media.controller.FeaturedImage() );
|
||||||
controller: this,
|
|
||||||
menu: 'main'
|
|
||||||
}) );
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1585,7 +1597,7 @@
|
|||||||
|
|
||||||
var handlers = {
|
var handlers = {
|
||||||
menu: {
|
menu: {
|
||||||
'main': 'mainMenu',
|
'default': 'mainMenu',
|
||||||
'gallery': 'galleryMenu'
|
'gallery': 'galleryMenu'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user