diff --git a/wp-admin/custom-background.php b/wp-admin/custom-background.php index e8e9f94109..631af6af85 100644 --- a/wp-admin/custom-background.php +++ b/wp-admin/custom-background.php @@ -106,7 +106,7 @@ class Custom_Background { ); add_thickbox(); - wp_enqueue_script('media-upload'); + wp_enqueue_media(); wp_enqueue_script('custom-background'); wp_enqueue_style('wp-color-picker'); } @@ -269,7 +269,9 @@ if ( get_background_image() ) { ?>


- +

diff --git a/wp-admin/js/custom-background.js b/wp-admin/js/custom-background.js index bfc0e6a719..08d09b1a17 100644 --- a/wp-admin/js/custom-background.js +++ b/wp-admin/js/custom-background.js @@ -1,7 +1,7 @@ (function($) { - $(document).ready(function() { - var bgImage = $("#custom-background-image"); + var bgImage = $("#custom-background-image"), + frame; $('#background-color').wpColorPicker({ change: function( event, ui ) { @@ -19,6 +19,45 @@ $('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().add({ + 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.state('library'); + }); + }); })(jQuery); \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index a2370d3246..cf9ec77064 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -501,7 +501,7 @@ function wp_default_scripts( &$scripts ) { ) ); $scripts->add( 'custom-header', "/wp-admin/js/custom-header.js", array( 'jquery-masonry' ), false, 1 ); - $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker' ), false, 1 ); + $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 ); $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array('jquery'), false, 1 ); } }