2014-03-04 22:54:15 -05:00
|
|
|
/* global ajaxurl, attachMediaBoxL10n */
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
var findPosts;
|
2014-03-04 22:54:15 -05:00
|
|
|
( function( $ ){
|
2012-08-22 20:04:18 -04:00
|
|
|
findPosts = {
|
2014-03-04 22:54:15 -05:00
|
|
|
open: function( af_name, af_val ) {
|
|
|
|
var overlay = $( '.ui-find-overlay' );
|
2012-11-20 13:50:15 -05:00
|
|
|
|
2013-11-15 00:16:09 -05:00
|
|
|
if ( overlay.length === 0 ) {
|
2012-11-20 13:50:15 -05:00
|
|
|
$( 'body' ).append( '<div class="ui-find-overlay"></div>' );
|
|
|
|
findPosts.overlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
overlay.show();
|
2012-08-22 20:04:18 -04:00
|
|
|
|
|
|
|
if ( af_name && af_val ) {
|
2014-03-04 22:54:15 -05:00
|
|
|
$( '#affected' ).attr( 'name', af_name ).val( af_val );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2014-03-04 18:11:13 -05:00
|
|
|
|
2014-03-04 22:54:15 -05:00
|
|
|
$( '#find-posts' ).show();
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2014-03-04 22:54:15 -05:00
|
|
|
$('#find-posts-input').focus().keyup( function( event ){
|
|
|
|
if ( event.which == 27 ) {
|
|
|
|
findPosts.close();
|
|
|
|
} // close on Escape
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2012-11-20 13:50:15 -05:00
|
|
|
// Pull some results up by default
|
|
|
|
findPosts.send();
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2014-03-04 22:54:15 -05:00
|
|
|
close: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
$('#find-posts-response').html('');
|
2014-03-04 22:54:15 -05:00
|
|
|
$('#find-posts').hide();
|
2012-11-20 13:50:15 -05:00
|
|
|
$( '.ui-find-overlay' ).hide();
|
|
|
|
},
|
|
|
|
|
2014-03-04 22:54:15 -05:00
|
|
|
overlay: function() {
|
2014-03-04 18:11:13 -05:00
|
|
|
$( '.ui-find-overlay' ).on( 'click', function () {
|
2012-11-20 13:50:15 -05:00
|
|
|
findPosts.close();
|
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
},
|
|
|
|
|
2014-03-04 22:54:15 -05:00
|
|
|
send: function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
var post = {
|
2014-03-04 22:54:15 -05:00
|
|
|
ps: $( '#find-posts-input' ).val(),
|
2012-11-20 13:50:15 -05:00
|
|
|
action: 'find_posts',
|
|
|
|
_ajax_nonce: $('#_ajax_nonce').val()
|
|
|
|
},
|
|
|
|
spinner = $( '.find-box-search .spinner' );
|
|
|
|
|
|
|
|
spinner.show();
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2014-03-04 22:54:15 -05:00
|
|
|
$.ajax( ajaxurl, {
|
|
|
|
type: 'POST',
|
|
|
|
data: post,
|
|
|
|
dataType: 'json'
|
|
|
|
}).always( function() {
|
|
|
|
spinner.hide();
|
|
|
|
}).done( function( x ) {
|
|
|
|
if ( ! x.success ) {
|
|
|
|
$( '#find-posts-response' ).text( attachMediaBoxL10n.error );
|
|
|
|
}
|
2012-11-20 13:50:15 -05:00
|
|
|
|
2014-03-04 22:54:15 -05:00
|
|
|
$( '#find-posts-response' ).html( x.data );
|
|
|
|
}).fail( function() {
|
|
|
|
$( '#find-posts-response' ).text( attachMediaBoxL10n.error );
|
2012-11-20 13:50:15 -05:00
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-04 22:54:15 -05:00
|
|
|
$( document ).ready( function() {
|
|
|
|
$( '#find-posts-submit' ).click( function( event ) {
|
|
|
|
if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length )
|
|
|
|
event.preventDefault();
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
$( '#find-posts .find-box-search :input' ).keypress( function( event ) {
|
|
|
|
if ( 13 == event.which ) {
|
|
|
|
findPosts.send();
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-04 22:54:15 -05:00
|
|
|
});
|
2012-08-22 20:04:18 -04:00
|
|
|
$( '#find-posts-search' ).click( findPosts.send );
|
|
|
|
$( '#find-posts-close' ).click( findPosts.close );
|
2014-03-04 22:54:15 -05:00
|
|
|
$( '#doaction, #doaction2' ).click( function( event ) {
|
|
|
|
$( 'select[name^="action"]' ).each( function() {
|
|
|
|
if ( $(this).val() === 'attach' ) {
|
|
|
|
event.preventDefault();
|
2012-08-22 20:04:18 -04:00
|
|
|
findPosts.open();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2014-03-04 22:54:15 -05:00
|
|
|
|
|
|
|
// Enable whole row to be clicked
|
|
|
|
$( '.find-box-inside' ).on( 'click', 'tr', function() {
|
|
|
|
$( this ).find( '.found-radio input' ).prop( 'checked', true );
|
2014-03-04 18:11:13 -05:00
|
|
|
});
|
2012-11-20 13:50:15 -05:00
|
|
|
});
|
2014-03-04 22:54:15 -05:00
|
|
|
})( jQuery );
|