Make WordPress Core

Changeset 22502


Ignore:
Timestamp:
11/09/2012 11:37:24 AM (14 years ago)
Author:
koopersmith
Message:

Integrate media with the custom background page. fixes #21818, see #21390.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-background.php

    r22470 r22502  
    107107
    108108                add_thickbox();
    109                 wp_enqueue_script('media-upload');
     109                wp_enqueue_media();
    110110                wp_enqueue_script('custom-background');
    111111                wp_enqueue_style('wp-color-picker');
    … …  
    270270        <p>
    271271                <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
    272                 <a id="choose-from-library-link" class="button thickbox" href="<?php echo esc_url( $image_library_url ); ?>"><?php _e( 'Choose Image' ); ?></a>
     272                <a id="choose-from-library-link" class="button"
     273                        data-choose="<?php esc_attr_e( 'Choose a Background Image' ); ?>"
     274                        data-update="<?php esc_attr_e( 'Set as background' ); ?>"><?php _e( 'Choose Image' ); ?></a>
    273275        </p>
    274276        </form>
  • trunk/wp-admin/js/custom-background.js

    r22030 r22502  
    11(function($) {
    2 
    32        $(document).ready(function() {
    4                 var bgImage = $("#custom-background-image");
     3                var bgImage = $("#custom-background-image"),
     4                        frame;
    55
    66                $('#background-color').wpColorPicker({
    … …  
    2020                        bgImage.css('background-repeat', $(this).val());
    2121                });
     22
     23                $('#choose-from-library-link').click( function( event ) {
     24                        var $el = $(this);
     25
     26                        event.preventDefault();
     27
     28                        if ( frame ) {
     29                                frame.open();
     30                                return;
     31                        }
     32
     33                        frame = wp.media({
     34                                title:     $el.data('choose'),
     35                                library:   {
     36                                        type: 'image'
     37                                }
     38                        });
     39
     40                        frame.toolbar.on( 'activate:select', function() {
     41                                frame.toolbar.view().add({
     42                                        select: {
     43                                                style: 'primary',
     44                                                text:  $el.data('update'),
     45
     46                                                click: function() {
     47                                                        var attachment = frame.state().get('selection').first();
     48                                                        $.post( ajaxurl, {
     49                                                                action: 'set-background-image',
     50                                                                attachment_id: attachment.id,
     51                                                                size: 'full'
     52                                                        }, function() {
     53                                                                window.location.reload();
     54                                                        });
     55                                                }
     56                                        }
     57                                });
     58                        });
     59
     60                        frame.state('library');
     61                });
    2262        });
    23 
    2463})(jQuery);
  • trunk/wp-includes/script-loader.php

    r22494 r22502  
    502502
    503503                $scripts->add( 'custom-header', "/wp-admin/js/custom-header.js", array( 'jquery-masonry' ), false, 1 );
    504                 $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker' ), false, 1 );
     504                $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 );
    505505                $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array('jquery'), false, 1 );
    506506        }
Note: See TracChangeset for help on using the changeset viewer.