3
$(document).ready(function() {
5
bgImage = $( '#custom-background-image' );
7
$('#background-color').wpColorPicker({
8
change: function( event, ui ) {
9
bgImage.css('background-color', ui.color.toString());
12
bgImage.css('background-color', '');
16
$('input[name="background-position-x"]').change(function() {
17
bgImage.css('background-position', $(this).val() + ' top');
20
$('input[name="background-repeat"]').change(function() {
21
bgImage.css('background-repeat', $(this).val());
24
$('#choose-from-library-link').click( function( event ) {
27
event.preventDefault();
29
// If the media frame already exists, reopen it.
35
// Create the media frame.
36
frame = wp.media.frames.customBackground = wp.media({
37
// Set the title of the modal.
38
title: $el.data('choose'),
40
// Tell the modal to show only images.
45
// Customize the submit button.
47
// Set the text of the button.
48
text: $el.data('update'),
49
// Tell the button not to close the modal, since we're
50
// going to refresh the page when the image is selected.
55
// When an image is selected, run a callback.
56
frame.on( 'select', function() {
57
// Grab the selected attachment.
58
var attachment = frame.state().get('selection').first();
60
// Run an AJAX request to set the background image.
62
action: 'set-background-image',
63
attachment_id: attachment.id,
66
// When the request completes, reload the window.
67
window.location.reload();
71
// Finally, open the modal.