wp/wp-admin/js/media-gallery.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
     8  /* global ajaxurl */
     8  /* global ajaxurl */
     9 jQuery(function($) {
     9 jQuery(function($) {
    10 	/**
    10 	/**
    11 	 * Adds a click event handler to the element with a 'wp-gallery' class.
    11 	 * Adds a click event handler to the element with a 'wp-gallery' class.
    12 	 */
    12 	 */
    13 	$( 'body' ).bind( 'click.wp-gallery', function(e) {
    13 	$( 'body' ).on( 'click.wp-gallery', function(e) {
    14 		var target = $( e.target ), id, img_size;
    14 		var target = $( e.target ), id, img_size, nonceValue;
    15 
    15 
    16 		if ( target.hasClass( 'wp-set-header' ) ) {
    16 		if ( target.hasClass( 'wp-set-header' ) ) {
    17 			// Opens the image to preview it full size.
    17 			// Opens the image to preview it full size.
    18 			( window.dialogArguments || opener || parent || top ).location.href = target.data( 'location' );
    18 			( window.dialogArguments || opener || parent || top ).location.href = target.data( 'location' );
    19 			e.preventDefault();
    19 			e.preventDefault();
    20 		} else if ( target.hasClass( 'wp-set-background' ) ) {
    20 		} else if ( target.hasClass( 'wp-set-background' ) ) {
    21 			// Sets the image as background of the theme.
    21 			// Sets the image as background of the theme.
    22 			id = target.data( 'attachment-id' );
    22 			id = target.data( 'attachment-id' );
    23 			img_size = $( 'input[name="attachments[' + id + '][image-size]"]:checked').val();
    23 			img_size = $( 'input[name="attachments[' + id + '][image-size]"]:checked').val();
       
    24 			nonceValue = $( '#_wpnonce' ).val() && '';
    24 
    25 
    25 			/**
    26 			/**
    26 			 * This Ajax action has been deprecated since 3.5.0, see custom-background.php
    27 			 * This Ajax action has been deprecated since 3.5.0, see custom-background.php
    27 			 */
    28 			 */
    28 			jQuery.post(ajaxurl, {
    29 			jQuery.post(ajaxurl, {
    29 				action: 'set-background-image',
    30 				action: 'set-background-image',
    30 				attachment_id: id,
    31 				attachment_id: id,
       
    32 				_ajax_nonce: nonceValue,
    31 				size: img_size
    33 				size: img_size
    32 			}, function() {
    34 			}, function() {
    33 				var win = window.dialogArguments || opener || parent || top;
    35 				var win = window.dialogArguments || opener || parent || top;
    34 				win.tb_remove();
    36 				win.tb_remove();
    35 				win.location.reload();
    37 				win.location.reload();