24 * @memberOf findPosts |
24 * @memberOf findPosts |
25 * |
25 * |
26 * @param {string} af_name The name of the affected element. |
26 * @param {string} af_name The name of the affected element. |
27 * @param {string} af_val The value of the affected post element. |
27 * @param {string} af_val The value of the affected post element. |
28 * |
28 * |
29 * @returns {boolean} Always returns false. |
29 * @return {boolean} Always returns false. |
30 */ |
30 */ |
31 open: function( af_name, af_val ) { |
31 open: function( af_name, af_val ) { |
32 var overlay = $( '.ui-find-overlay' ); |
32 var overlay = $( '.ui-find-overlay' ); |
33 |
33 |
34 if ( overlay.length === 0 ) { |
34 if ( overlay.length === 0 ) { |
122 dataType: 'json' |
122 dataType: 'json' |
123 }).always( function() { |
123 }).always( function() { |
124 spinner.removeClass( 'is-active' ); |
124 spinner.removeClass( 'is-active' ); |
125 }).done( function( x ) { |
125 }).done( function( x ) { |
126 if ( ! x.success ) { |
126 if ( ! x.success ) { |
127 $( '#find-posts-response' ).text( attachMediaBoxL10n.error ); |
127 $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) ); |
128 } |
128 } |
129 |
129 |
130 $( '#find-posts-response' ).html( x.data ); |
130 $( '#find-posts-response' ).html( x.data ); |
131 }).fail( function() { |
131 }).fail( function() { |
132 $( '#find-posts-response' ).text( attachMediaBoxL10n.error ); |
132 $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) ); |
133 }); |
133 }); |
134 } |
134 } |
135 }; |
135 }; |
136 |
136 |
137 /** |
137 /** |
138 * Initializes the file once the DOM is fully loaded and attaches events to the |
138 * Initializes the file once the DOM is fully loaded and attaches events to the |
139 * various form elements. |
139 * various form elements. |
140 * |
140 * |
141 * @returns {void} |
141 * @return {void} |
142 */ |
142 */ |
143 $( document ).ready( function() { |
143 $( document ).ready( function() { |
144 var settings, $mediaGridWrap = $( '#wp-media-grid' ); |
144 var settings, $mediaGridWrap = $( '#wp-media-grid' ); |
145 |
145 |
146 // Opens a manage media frame into the grid. |
146 // Opens a manage media frame into the grid. |
147 if ( $mediaGridWrap.length && window.wp && window.wp.media ) { |
147 if ( $mediaGridWrap.length && window.wp && window.wp.media ) { |
148 settings = _wpMediaGridSettings; |
148 settings = _wpMediaGridSettings; |
149 |
149 |
150 window.wp.media({ |
150 var frame = window.wp.media({ |
151 frame: 'manage', |
151 frame: 'manage', |
152 container: $mediaGridWrap, |
152 container: $mediaGridWrap, |
153 library: settings.queryVars |
153 library: settings.queryVars |
154 }).open(); |
154 }).open(); |
|
155 |
|
156 // Fire a global ready event. |
|
157 $mediaGridWrap.trigger( 'wp-media-grid-ready', frame ); |
155 } |
158 } |
156 |
159 |
157 // Prevents form submission if no post has been selected. |
160 // Prevents form submission if no post has been selected. |
158 $( '#find-posts-submit' ).click( function( event ) { |
161 $( '#find-posts-submit' ).click( function( event ) { |
159 if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length ) |
162 if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length ) |