2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/custom-background.js
|
|
|
|
*/
|
|
|
|
|
2013-11-14 00:40:11 -05:00
|
|
|
/* global ajaxurl */
|
2017-06-15 09:24:41 -04:00
|
|
|
|
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Registers all events for customizing the background.
|
2017-06-15 09:24:41 -04:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @requires jQuery
|
|
|
|
*/
|
2012-08-22 20:04:18 -04:00
|
|
|
(function($) {
|
|
|
|
$(document).ready(function() {
|
2013-11-14 00:40:11 -05:00
|
|
|
var frame,
|
|
|
|
bgImage = $( '#custom-background-image' );
|
2012-09-26 21:57:38 -04:00
|
|
|
|
2017-06-15 09:24:41 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Instantiates the WordPress color picker and binds the change and clear events.
|
2017-06-15 09:24:41 -04:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {void}
|
2017-06-15 09:24:41 -04:00
|
|
|
*/
|
2012-09-26 21:57:38 -04:00
|
|
|
$('#background-color').wpColorPicker({
|
|
|
|
change: function( event, ui ) {
|
|
|
|
bgImage.css('background-color', ui.color.toString());
|
|
|
|
},
|
|
|
|
clear: function() {
|
|
|
|
bgImage.css('background-color', '');
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2017-06-15 09:24:41 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Alters the background size CSS property whenever the background size input has changed.
|
2017-06-15 09:24:41 -04:00
|
|
|
*
|
|
|
|
* @since 4.7.0
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {void}
|
2017-06-15 09:24:41 -04:00
|
|
|
*/
|
Customize: Improve custom background properties UI.
Introduces new control for managing the background position. Adds control for setting the `background-size`.
Props cdog, celloexpressions, grapplerulrich, MikeHansenMe, FolioVision, afercia, helen, melchoyce, karmatosed, westonruter, Kelderic, sebastian.pisula.
Fixes #22058.
Built from https://develop.svn.wordpress.org/trunk@38948
git-svn-id: http://core.svn.wordpress.org/trunk@38891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 02:52:29 -04:00
|
|
|
$( 'select[name="background-size"]' ).change( function() {
|
|
|
|
bgImage.css( 'background-size', $( this ).val() );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2017-06-15 09:24:41 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Alters the background position CSS property whenever the background position input has changed.
|
2017-06-15 09:24:41 -04:00
|
|
|
*
|
|
|
|
* @since 4.7.0
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {void}
|
2017-06-15 09:24:41 -04:00
|
|
|
*/
|
Customize: Improve custom background properties UI.
Introduces new control for managing the background position. Adds control for setting the `background-size`.
Props cdog, celloexpressions, grapplerulrich, MikeHansenMe, FolioVision, afercia, helen, melchoyce, karmatosed, westonruter, Kelderic, sebastian.pisula.
Fixes #22058.
Built from https://develop.svn.wordpress.org/trunk@38948
git-svn-id: http://core.svn.wordpress.org/trunk@38891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 02:52:29 -04:00
|
|
|
$( 'input[name="background-position"]' ).change( function() {
|
|
|
|
bgImage.css( 'background-position', $( this ).val() );
|
|
|
|
});
|
|
|
|
|
2017-06-15 09:24:41 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Alters the background repeat CSS property whenever the background repeat input has changed.
|
2017-06-15 09:24:41 -04:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {void}
|
2017-06-15 09:24:41 -04:00
|
|
|
*/
|
Customize: Improve custom background properties UI.
Introduces new control for managing the background position. Adds control for setting the `background-size`.
Props cdog, celloexpressions, grapplerulrich, MikeHansenMe, FolioVision, afercia, helen, melchoyce, karmatosed, westonruter, Kelderic, sebastian.pisula.
Fixes #22058.
Built from https://develop.svn.wordpress.org/trunk@38948
git-svn-id: http://core.svn.wordpress.org/trunk@38891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 02:52:29 -04:00
|
|
|
$( 'input[name="background-repeat"]' ).change( function() {
|
|
|
|
bgImage.css( 'background-repeat', $( this ).is( ':checked' ) ? 'repeat' : 'no-repeat' );
|
|
|
|
});
|
|
|
|
|
2017-06-15 09:24:41 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Alters the background attachment CSS property whenever the background attachment input has changed.
|
2017-06-15 09:24:41 -04:00
|
|
|
*
|
|
|
|
* @since 4.7.0
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {void}
|
2017-06-15 09:24:41 -04:00
|
|
|
*/
|
Customize: Improve custom background properties UI.
Introduces new control for managing the background position. Adds control for setting the `background-size`.
Props cdog, celloexpressions, grapplerulrich, MikeHansenMe, FolioVision, afercia, helen, melchoyce, karmatosed, westonruter, Kelderic, sebastian.pisula.
Fixes #22058.
Built from https://develop.svn.wordpress.org/trunk@38948
git-svn-id: http://core.svn.wordpress.org/trunk@38891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 02:52:29 -04:00
|
|
|
$( 'input[name="background-attachment"]' ).change( function() {
|
|
|
|
bgImage.css( 'background-attachment', $( this ).is( ':checked' ) ? 'scroll' : 'fixed' );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2017-06-15 09:24:41 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Binds the event for opening the WP Media dialog.
|
2017-06-15 09:24:41 -04:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {void}
|
2017-06-15 09:24:41 -04:00
|
|
|
*/
|
2012-11-09 06:37:24 -05:00
|
|
|
$('#choose-from-library-link').click( function( event ) {
|
|
|
|
var $el = $(this);
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
2012-12-04 11:21:57 -05:00
|
|
|
// If the media frame already exists, reopen it.
|
2012-11-09 06:37:24 -05:00
|
|
|
if ( frame ) {
|
|
|
|
frame.open();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-04 11:21:57 -05:00
|
|
|
// Create the media frame.
|
2012-12-06 00:06:49 -05:00
|
|
|
frame = wp.media.frames.customBackground = wp.media({
|
2012-12-04 11:21:57 -05:00
|
|
|
// Set the title of the modal.
|
|
|
|
title: $el.data('choose'),
|
|
|
|
|
|
|
|
// Tell the modal to show only images.
|
|
|
|
library: {
|
2012-11-09 06:37:24 -05:00
|
|
|
type: 'image'
|
2012-12-04 11:21:57 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Customize the submit button.
|
|
|
|
button: {
|
|
|
|
// Set the text of the button.
|
|
|
|
text: $el.data('update'),
|
2017-06-15 09:24:41 -04:00
|
|
|
/*
|
|
|
|
* Tell the button not to close the modal, since we're
|
|
|
|
* going to refresh the page when the image is selected.
|
|
|
|
*/
|
2012-12-04 11:21:57 -05:00
|
|
|
close: false
|
2012-11-09 06:37:24 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-15 09:24:41 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* When an image is selected, run a callback.
|
2017-06-15 09:24:41 -04:00
|
|
|
*
|
|
|
|
* @since 3.5.0
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {void}
|
2017-06-15 09:24:41 -04:00
|
|
|
*/
|
2012-12-04 11:21:57 -05:00
|
|
|
frame.on( 'select', function() {
|
|
|
|
// Grab the selected attachment.
|
|
|
|
var attachment = frame.state().get('selection').first();
|
2020-10-29 14:09:13 -04:00
|
|
|
var nonceValue = $( '#_wpnonce' ).val() || '';
|
2012-12-04 11:21:57 -05:00
|
|
|
|
2020-06-25 08:43:07 -04:00
|
|
|
// Run an Ajax request to set the background image.
|
2012-12-04 11:21:57 -05:00
|
|
|
$.post( ajaxurl, {
|
|
|
|
action: 'set-background-image',
|
|
|
|
attachment_id: attachment.id,
|
2020-10-29 14:09:13 -04:00
|
|
|
_ajax_nonce: nonceValue,
|
2012-12-04 11:21:57 -05:00
|
|
|
size: 'full'
|
|
|
|
}).done( function() {
|
|
|
|
// When the request completes, reload the window.
|
|
|
|
window.location.reload();
|
2012-11-09 06:37:24 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-12-04 11:21:57 -05:00
|
|
|
// Finally, open the modal.
|
|
|
|
frame.open();
|
2012-11-09 06:37:24 -05:00
|
|
|
});
|
|
|
|
});
|
2013-11-14 00:40:11 -05:00
|
|
|
})(jQuery);
|