Wordpress/wp-admin/js/custom-background.js
Andrew Nacin f88b538001 Bring Featured Images back into the main media dialog.
Most users don't realize that the Featured Image meta box exists; if they do, few use it.

Restores the old meta box UI, including the admin_post_thumbnail_html filter. If a plugin is using _wp_post_thumbnail_html() in conjunction with Thickbox elsewhere, it will also magically still work.

Specific underlying changes:
 * Converts the modal view to use the view manager, which means that a call to open() will automatically call render and attach if necessary.
 * Doesn't automatically set a state in wp.media, to allow code to customize the states to be added before activation.

props koopersmith.
fixes #21776.



git-svn-id: https://develop.svn.wordpress.org/trunk@22979 602fd350-edb4-49c9-b593-d223f7449a82
2012-12-03 02:38:10 +00:00

63 lines
1.3 KiB
JavaScript

(function($) {
$(document).ready(function() {
var bgImage = $("#custom-background-image"),
frame;
$('#background-color').wpColorPicker({
change: function( event, ui ) {
bgImage.css('background-color', ui.color.toString());
},
clear: function() {
bgImage.css('background-color', '');
}
});
$('input[name="background-position-x"]').change(function() {
bgImage.css('background-position', $(this).val() + ' top');
});
$('input[name="background-repeat"]').change(function() {
bgImage.css('background-repeat', $(this).val());
});
$('#choose-from-library-link').click( function( event ) {
var $el = $(this);
event.preventDefault();
if ( frame ) {
frame.open();
return;
}
frame = wp.media({
title: $el.data('choose'),
library: {
type: 'image'
}
});
frame.toolbar.on( 'activate:select', function() {
frame.toolbar.view().set({
select: {
style: 'primary',
text: $el.data('update'),
click: function() {
var attachment = frame.state().get('selection').first();
$.post( ajaxurl, {
action: 'set-background-image',
attachment_id: attachment.id,
size: 'full'
}, function() {
window.location.reload();
});
}
}
});
});
frame.setState('library').open();
});
});
})(jQuery);