Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: media.js
/**
[0] Fix | Delete
* Creates a dialog containing posts that can have a particular media attached
[1] Fix | Delete
* to it.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 2.7.0
[4] Fix | Delete
* @output wp-admin/js/media.js
[5] Fix | Delete
*
[6] Fix | Delete
* @namespace findPosts
[7] Fix | Delete
*
[8] Fix | Delete
* @requires jQuery
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
/* global ajaxurl, _wpMediaGridSettings, showNotice, findPosts */
[12] Fix | Delete
[13] Fix | Delete
( function( $ ){
[14] Fix | Delete
window.findPosts = {
[15] Fix | Delete
/**
[16] Fix | Delete
* Opens a dialog to attach media to a post.
[17] Fix | Delete
*
[18] Fix | Delete
* Adds an overlay prior to retrieving a list of posts to attach the media to.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 2.7.0
[21] Fix | Delete
*
[22] Fix | Delete
* @memberOf findPosts
[23] Fix | Delete
*
[24] Fix | Delete
* @param {string} af_name The name of the affected element.
[25] Fix | Delete
* @param {string} af_val The value of the affected post element.
[26] Fix | Delete
*
[27] Fix | Delete
* @return {boolean} Always returns false.
[28] Fix | Delete
*/
[29] Fix | Delete
open: function( af_name, af_val ) {
[30] Fix | Delete
var overlay = $( '.ui-find-overlay' );
[31] Fix | Delete
[32] Fix | Delete
if ( overlay.length === 0 ) {
[33] Fix | Delete
$( 'body' ).append( '<div class="ui-find-overlay"></div>' );
[34] Fix | Delete
findPosts.overlay();
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
overlay.show();
[38] Fix | Delete
[39] Fix | Delete
if ( af_name && af_val ) {
[40] Fix | Delete
// #affected is a hidden input field in the dialog that keeps track of which media should be attached.
[41] Fix | Delete
$( '#affected' ).attr( 'name', af_name ).val( af_val );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
$( '#find-posts' ).show();
[45] Fix | Delete
[46] Fix | Delete
// Close the dialog when the escape key is pressed.
[47] Fix | Delete
$('#find-posts-input').trigger( 'focus' ).on( 'keyup', function( event ){
[48] Fix | Delete
if ( event.which == 27 ) {
[49] Fix | Delete
findPosts.close();
[50] Fix | Delete
}
[51] Fix | Delete
});
[52] Fix | Delete
[53] Fix | Delete
// Retrieves a list of applicable posts for media attachment and shows them.
[54] Fix | Delete
findPosts.send();
[55] Fix | Delete
[56] Fix | Delete
return false;
[57] Fix | Delete
},
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Clears the found posts lists before hiding the attach media dialog.
[61] Fix | Delete
*
[62] Fix | Delete
* @since 2.7.0
[63] Fix | Delete
*
[64] Fix | Delete
* @memberOf findPosts
[65] Fix | Delete
*
[66] Fix | Delete
* @return {void}
[67] Fix | Delete
*/
[68] Fix | Delete
close: function() {
[69] Fix | Delete
$('#find-posts-response').empty();
[70] Fix | Delete
$('#find-posts').hide();
[71] Fix | Delete
$( '.ui-find-overlay' ).hide();
[72] Fix | Delete
},
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Binds a click event listener to the overlay which closes the attach media
[76] Fix | Delete
* dialog.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 3.5.0
[79] Fix | Delete
*
[80] Fix | Delete
* @memberOf findPosts
[81] Fix | Delete
*
[82] Fix | Delete
* @return {void}
[83] Fix | Delete
*/
[84] Fix | Delete
overlay: function() {
[85] Fix | Delete
$( '.ui-find-overlay' ).on( 'click', function () {
[86] Fix | Delete
findPosts.close();
[87] Fix | Delete
});
[88] Fix | Delete
},
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Retrieves and displays posts based on the search term.
[92] Fix | Delete
*
[93] Fix | Delete
* Sends a post request to the admin_ajax.php, requesting posts based on the
[94] Fix | Delete
* search term provided by the user. Defaults to all posts if no search term is
[95] Fix | Delete
* provided.
[96] Fix | Delete
*
[97] Fix | Delete
* @since 2.7.0
[98] Fix | Delete
*
[99] Fix | Delete
* @memberOf findPosts
[100] Fix | Delete
*
[101] Fix | Delete
* @return {void}
[102] Fix | Delete
*/
[103] Fix | Delete
send: function() {
[104] Fix | Delete
var post = {
[105] Fix | Delete
ps: $( '#find-posts-input' ).val(),
[106] Fix | Delete
action: 'find_posts',
[107] Fix | Delete
_ajax_nonce: $('#_ajax_nonce').val()
[108] Fix | Delete
},
[109] Fix | Delete
spinner = $( '.find-box-search .spinner' );
[110] Fix | Delete
[111] Fix | Delete
spinner.addClass( 'is-active' );
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Send a POST request to admin_ajax.php, hide the spinner and replace the list
[115] Fix | Delete
* of posts with the response data. If an error occurs, display it.
[116] Fix | Delete
*/
[117] Fix | Delete
$.ajax( ajaxurl, {
[118] Fix | Delete
type: 'POST',
[119] Fix | Delete
data: post,
[120] Fix | Delete
dataType: 'json'
[121] Fix | Delete
}).always( function() {
[122] Fix | Delete
spinner.removeClass( 'is-active' );
[123] Fix | Delete
}).done( function( x ) {
[124] Fix | Delete
if ( ! x.success ) {
[125] Fix | Delete
$( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
$( '#find-posts-response' ).html( x.data );
[129] Fix | Delete
}).fail( function() {
[130] Fix | Delete
$( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) );
[131] Fix | Delete
});
[132] Fix | Delete
}
[133] Fix | Delete
};
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Initializes the file once the DOM is fully loaded and attaches events to the
[137] Fix | Delete
* various form elements.
[138] Fix | Delete
*
[139] Fix | Delete
* @return {void}
[140] Fix | Delete
*/
[141] Fix | Delete
$( document ).ready( function() {
[142] Fix | Delete
var settings, $mediaGridWrap = $( '#wp-media-grid' );
[143] Fix | Delete
[144] Fix | Delete
// Opens a manage media frame into the grid.
[145] Fix | Delete
if ( $mediaGridWrap.length && window.wp && window.wp.media ) {
[146] Fix | Delete
settings = _wpMediaGridSettings;
[147] Fix | Delete
[148] Fix | Delete
var frame = window.wp.media({
[149] Fix | Delete
frame: 'manage',
[150] Fix | Delete
container: $mediaGridWrap,
[151] Fix | Delete
library: settings.queryVars
[152] Fix | Delete
}).open();
[153] Fix | Delete
[154] Fix | Delete
// Fire a global ready event.
[155] Fix | Delete
$mediaGridWrap.trigger( 'wp-media-grid-ready', frame );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
// Prevents form submission if no post has been selected.
[159] Fix | Delete
$( '#find-posts-submit' ).on( 'click', function( event ) {
[160] Fix | Delete
if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length )
[161] Fix | Delete
event.preventDefault();
[162] Fix | Delete
});
[163] Fix | Delete
[164] Fix | Delete
// Submits the search query when hitting the enter key in the search input.
[165] Fix | Delete
$( '#find-posts .find-box-search :input' ).on( 'keypress', function( event ) {
[166] Fix | Delete
if ( 13 == event.which ) {
[167] Fix | Delete
findPosts.send();
[168] Fix | Delete
return false;
[169] Fix | Delete
}
[170] Fix | Delete
});
[171] Fix | Delete
[172] Fix | Delete
// Binds the click event to the search button.
[173] Fix | Delete
$( '#find-posts-search' ).on( 'click', findPosts.send );
[174] Fix | Delete
[175] Fix | Delete
// Binds the close dialog click event.
[176] Fix | Delete
$( '#find-posts-close' ).on( 'click', findPosts.close );
[177] Fix | Delete
[178] Fix | Delete
// Binds the bulk action events to the submit buttons.
[179] Fix | Delete
$( '#doaction' ).on( 'click', function( event ) {
[180] Fix | Delete
[181] Fix | Delete
/*
[182] Fix | Delete
* Handle the bulk action based on its value.
[183] Fix | Delete
*/
[184] Fix | Delete
$( 'select[name="action"]' ).each( function() {
[185] Fix | Delete
var optionValue = $( this ).val();
[186] Fix | Delete
[187] Fix | Delete
if ( 'attach' === optionValue ) {
[188] Fix | Delete
event.preventDefault();
[189] Fix | Delete
findPosts.open();
[190] Fix | Delete
} else if ( 'delete' === optionValue ) {
[191] Fix | Delete
if ( ! showNotice.warn() ) {
[192] Fix | Delete
event.preventDefault();
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
});
[196] Fix | Delete
});
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Enables clicking on the entire table row.
[200] Fix | Delete
*
[201] Fix | Delete
* @return {void}
[202] Fix | Delete
*/
[203] Fix | Delete
$( '.find-box-inside' ).on( 'click', 'tr', function() {
[204] Fix | Delete
$( this ).find( '.found-radio input' ).prop( 'checked', true );
[205] Fix | Delete
});
[206] Fix | Delete
});
[207] Fix | Delete
})( jQuery );
[208] Fix | Delete
[209] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function