5
|
1 |
/* global ajaxurl, attachMediaBoxL10n, _wpMediaGridSettings */ |
0
|
2 |
|
|
3 |
var findPosts; |
5
|
4 |
( function( $ ){ |
0
|
5 |
findPosts = { |
5
|
6 |
open: function( af_name, af_val ) { |
|
7 |
var overlay = $( '.ui-find-overlay' ); |
0
|
8 |
|
5
|
9 |
if ( overlay.length === 0 ) { |
0
|
10 |
$( 'body' ).append( '<div class="ui-find-overlay"></div>' ); |
|
11 |
findPosts.overlay(); |
|
12 |
} |
|
13 |
|
|
14 |
overlay.show(); |
|
15 |
|
|
16 |
if ( af_name && af_val ) { |
5
|
17 |
$( '#affected' ).attr( 'name', af_name ).val( af_val ); |
0
|
18 |
} |
5
|
19 |
|
|
20 |
$( '#find-posts' ).show(); |
0
|
21 |
|
5
|
22 |
$('#find-posts-input').focus().keyup( function( event ){ |
|
23 |
if ( event.which == 27 ) { |
|
24 |
findPosts.close(); |
|
25 |
} // close on Escape |
0
|
26 |
}); |
|
27 |
|
|
28 |
// Pull some results up by default |
|
29 |
findPosts.send(); |
|
30 |
|
|
31 |
return false; |
|
32 |
}, |
|
33 |
|
5
|
34 |
close: function() { |
|
35 |
$('#find-posts-response').empty(); |
|
36 |
$('#find-posts').hide(); |
0
|
37 |
$( '.ui-find-overlay' ).hide(); |
|
38 |
}, |
|
39 |
|
5
|
40 |
overlay: function() { |
|
41 |
$( '.ui-find-overlay' ).on( 'click', function () { |
0
|
42 |
findPosts.close(); |
|
43 |
}); |
|
44 |
}, |
|
45 |
|
5
|
46 |
send: function() { |
0
|
47 |
var post = { |
5
|
48 |
ps: $( '#find-posts-input' ).val(), |
0
|
49 |
action: 'find_posts', |
|
50 |
_ajax_nonce: $('#_ajax_nonce').val() |
|
51 |
}, |
|
52 |
spinner = $( '.find-box-search .spinner' ); |
|
53 |
|
5
|
54 |
spinner.addClass( 'is-active' ); |
0
|
55 |
|
5
|
56 |
$.ajax( ajaxurl, { |
|
57 |
type: 'POST', |
|
58 |
data: post, |
|
59 |
dataType: 'json' |
|
60 |
}).always( function() { |
|
61 |
spinner.removeClass( 'is-active' ); |
|
62 |
}).done( function( x ) { |
|
63 |
if ( ! x.success ) { |
|
64 |
$( '#find-posts-response' ).text( attachMediaBoxL10n.error ); |
|
65 |
} |
0
|
66 |
|
5
|
67 |
$( '#find-posts-response' ).html( x.data ); |
|
68 |
}).fail( function() { |
|
69 |
$( '#find-posts-response' ).text( attachMediaBoxL10n.error ); |
0
|
70 |
}); |
|
71 |
} |
|
72 |
}; |
|
73 |
|
5
|
74 |
$( document ).ready( function() { |
|
75 |
var settings, $mediaGridWrap = $( '#wp-media-grid' ); |
|
76 |
|
|
77 |
// Open up a manage media frame into the grid. |
|
78 |
if ( $mediaGridWrap.length && window.wp && window.wp.media ) { |
|
79 |
settings = _wpMediaGridSettings; |
|
80 |
|
|
81 |
window.wp.media({ |
|
82 |
frame: 'manage', |
|
83 |
container: $mediaGridWrap, |
|
84 |
library: settings.queryVars |
|
85 |
}).open(); |
|
86 |
} |
|
87 |
|
|
88 |
$( '#find-posts-submit' ).click( function( event ) { |
|
89 |
if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length ) |
|
90 |
event.preventDefault(); |
0
|
91 |
}); |
|
92 |
$( '#find-posts .find-box-search :input' ).keypress( function( event ) { |
|
93 |
if ( 13 == event.which ) { |
|
94 |
findPosts.send(); |
|
95 |
return false; |
|
96 |
} |
5
|
97 |
}); |
0
|
98 |
$( '#find-posts-search' ).click( findPosts.send ); |
|
99 |
$( '#find-posts-close' ).click( findPosts.close ); |
5
|
100 |
$( '#doaction, #doaction2' ).click( function( event ) { |
|
101 |
$( 'select[name^="action"]' ).each( function() { |
|
102 |
if ( $(this).val() === 'attach' ) { |
|
103 |
event.preventDefault(); |
0
|
104 |
findPosts.open(); |
|
105 |
} |
|
106 |
}); |
|
107 |
}); |
5
|
108 |
|
|
109 |
// Enable whole row to be clicked |
|
110 |
$( '.find-box-inside' ).on( 'click', 'tr', function() { |
|
111 |
$( this ).find( '.found-radio input' ).prop( 'checked', true ); |
|
112 |
}); |
0
|
113 |
}); |
5
|
114 |
})( jQuery ); |