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