wp/wp-admin/js/custom-background.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    19 		/**
    19 		/**
    20 		 * Instantiates the WordPress color picker and binds the change and clear events.
    20 		 * Instantiates the WordPress color picker and binds the change and clear events.
    21 		 *
    21 		 *
    22 		 * @since 3.5.0
    22 		 * @since 3.5.0
    23 		 *
    23 		 *
    24 		 * @returns {void}
    24 		 * @return {void}
    25 		 */
    25 		 */
    26 		$('#background-color').wpColorPicker({
    26 		$('#background-color').wpColorPicker({
    27 			change: function( event, ui ) {
    27 			change: function( event, ui ) {
    28 				bgImage.css('background-color', ui.color.toString());
    28 				bgImage.css('background-color', ui.color.toString());
    29 			},
    29 			},
    35 		/**
    35 		/**
    36 		 * Alters the background size CSS property whenever the background size input has changed.
    36 		 * Alters the background size CSS property whenever the background size input has changed.
    37 		 *
    37 		 *
    38 		 * @since 4.7.0
    38 		 * @since 4.7.0
    39 		 *
    39 		 *
    40 		 * @returns {void}
    40 		 * @return {void}
    41 		 */
    41 		 */
    42 		$( 'select[name="background-size"]' ).change( function() {
    42 		$( 'select[name="background-size"]' ).change( function() {
    43 			bgImage.css( 'background-size', $( this ).val() );
    43 			bgImage.css( 'background-size', $( this ).val() );
    44 		});
    44 		});
    45 
    45 
    46 		/**
    46 		/**
    47 		 * Alters the background position CSS property whenever the background position input has changed.
    47 		 * Alters the background position CSS property whenever the background position input has changed.
    48 		 *
    48 		 *
    49 		 * @since 4.7.0
    49 		 * @since 4.7.0
    50 		 *
    50 		 *
    51 		 * @returns {void}
    51 		 * @return {void}
    52 		 */
    52 		 */
    53 		$( 'input[name="background-position"]' ).change( function() {
    53 		$( 'input[name="background-position"]' ).change( function() {
    54 			bgImage.css( 'background-position', $( this ).val() );
    54 			bgImage.css( 'background-position', $( this ).val() );
    55 		});
    55 		});
    56 
    56 
    57 		/**
    57 		/**
    58 		 * Alters the background repeat CSS property whenever the background repeat input has changed.
    58 		 * Alters the background repeat CSS property whenever the background repeat input has changed.
    59 		 *
    59 		 *
    60 		 * @since 3.0.0
    60 		 * @since 3.0.0
    61 		 *
    61 		 *
    62 		 * @returns {void}
    62 		 * @return {void}
    63 		 */
    63 		 */
    64 		$( 'input[name="background-repeat"]' ).change( function() {
    64 		$( 'input[name="background-repeat"]' ).change( function() {
    65 			bgImage.css( 'background-repeat', $( this ).is( ':checked' ) ? 'repeat' : 'no-repeat' );
    65 			bgImage.css( 'background-repeat', $( this ).is( ':checked' ) ? 'repeat' : 'no-repeat' );
    66 		});
    66 		});
    67 
    67 
    68 		/**
    68 		/**
    69 		 * Alters the background attachment CSS property whenever the background attachment input has changed.
    69 		 * Alters the background attachment CSS property whenever the background attachment input has changed.
    70 		 *
    70 		 *
    71 		 * @since 4.7.0
    71 		 * @since 4.7.0
    72 		 *
    72 		 *
    73 		 * @returns {void}
    73 		 * @return {void}
    74 		 */
    74 		 */
    75 		$( 'input[name="background-attachment"]' ).change( function() {
    75 		$( 'input[name="background-attachment"]' ).change( function() {
    76 			bgImage.css( 'background-attachment', $( this ).is( ':checked' ) ? 'scroll' : 'fixed' );
    76 			bgImage.css( 'background-attachment', $( this ).is( ':checked' ) ? 'scroll' : 'fixed' );
    77 		});
    77 		});
    78 
    78 
    79 		/**
    79 		/**
    80 		 * Binds the event for opening the WP Media dialog.
    80 		 * Binds the event for opening the WP Media dialog.
    81 		 *
    81 		 *
    82 		 * @since 3.5.0
    82 		 * @since 3.5.0
    83 		 *
    83 		 *
    84 		 * @returns {void}
    84 		 * @return {void}
    85 		 */
    85 		 */
    86 		$('#choose-from-library-link').click( function( event ) {
    86 		$('#choose-from-library-link').click( function( event ) {
    87 			var $el = $(this);
    87 			var $el = $(this);
    88 
    88 
    89 			event.preventDefault();
    89 			event.preventDefault();
   119 			/**
   119 			/**
   120 			 * When an image is selected, run a callback.
   120 			 * When an image is selected, run a callback.
   121 			 *
   121 			 *
   122 			 * @since 3.5.0
   122 			 * @since 3.5.0
   123 			 *
   123 			 *
   124 			 * @returns {void}
   124 			 * @return {void}
   125  			 */
   125  			 */
   126 			frame.on( 'select', function() {
   126 			frame.on( 'select', function() {
   127 				// Grab the selected attachment.
   127 				// Grab the selected attachment.
   128 				var attachment = frame.state().get('selection').first();
   128 				var attachment = frame.state().get('selection').first();
   129 
   129 
   130 				// Run an AJAX request to set the background image.
   130 				// Run an Ajax request to set the background image.
   131 				$.post( ajaxurl, {
   131 				$.post( ajaxurl, {
   132 					action: 'set-background-image',
   132 					action: 'set-background-image',
   133 					attachment_id: attachment.id,
   133 					attachment_id: attachment.id,
   134 					size: 'full'
   134 					size: 'full'
   135 				}).done( function() {
   135 				}).done( function() {