diff --git src/wp-admin/js/media.js src/wp-admin/js/media.js
index e23adebb17..4c1dc58fc3 100644
|
|
|
1 | 1 | /* global ajaxurl, attachMediaBoxL10n, _wpMediaGridSettings, showNotice */ |
2 | 2 | |
| 3 | /** |
| 4 | * @summary Creates a dialog containing posts that can have a particular media attached to it. |
| 5 | * |
| 6 | * @since 2.7.0 |
| 7 | * |
| 8 | * @global |
| 9 | * @namespace |
| 10 | * |
| 11 | * @requires jQuery |
| 12 | */ |
3 | 13 | var findPosts; |
| 14 | |
4 | 15 | ( function( $ ){ |
5 | 16 | findPosts = { |
| 17 | /** |
| 18 | * @summary Opens a dialog to attach media to a post. |
| 19 | * |
| 20 | * Adds an overlay prior to retrieving a list of posts to attach the media to. |
| 21 | * |
| 22 | * @since 2.7.0 |
| 23 | * |
| 24 | * @memberOf findPosts |
| 25 | * |
| 26 | * @param {string} af_name The name of the affected element. |
| 27 | * @param {string} af_val The value of the affected post element. |
| 28 | * |
| 29 | * @returns {boolean} Always returns false. |
| 30 | */ |
6 | 31 | open: function( af_name, af_val ) { |
7 | 32 | var overlay = $( '.ui-find-overlay' ); |
8 | 33 | |
… |
… |
var findPosts; |
14 | 39 | overlay.show(); |
15 | 40 | |
16 | 41 | if ( af_name && af_val ) { |
| 42 | // #affected is a hidden input field in the dialog that keeps track of which media should be attached. |
17 | 43 | $( '#affected' ).attr( 'name', af_name ).val( af_val ); |
18 | 44 | } |
19 | 45 | |
20 | 46 | $( '#find-posts' ).show(); |
21 | 47 | |
| 48 | // Close the dialog when the escape key is pressed. |
22 | 49 | $('#find-posts-input').focus().keyup( function( event ){ |
23 | 50 | if ( event.which == 27 ) { |
24 | 51 | findPosts.close(); |
25 | | } // close on Escape |
| 52 | } |
26 | 53 | }); |
27 | 54 | |
28 | | // Pull some results up by default |
| 55 | // Retrieves a list of applicable posts for media attachment and shows them. |
29 | 56 | findPosts.send(); |
30 | 57 | |
31 | 58 | return false; |
32 | 59 | }, |
33 | 60 | |
| 61 | /** |
| 62 | * @summary Clears the found posts lists before hiding the attach media dialog. |
| 63 | * |
| 64 | * @since 2.7.0 |
| 65 | * |
| 66 | * @memberOf findPosts |
| 67 | * |
| 68 | * @returns {void} |
| 69 | */ |
34 | 70 | close: function() { |
35 | 71 | $('#find-posts-response').empty(); |
36 | 72 | $('#find-posts').hide(); |
37 | 73 | $( '.ui-find-overlay' ).hide(); |
38 | 74 | }, |
39 | 75 | |
| 76 | /** |
| 77 | * @summary Binds a click event listener to the overlay which closes the attach media dialog. |
| 78 | * |
| 79 | * @since 3.5.0 |
| 80 | * |
| 81 | * @memberOf findPosts |
| 82 | * |
| 83 | * @returns {void} |
| 84 | */ |
40 | 85 | overlay: function() { |
41 | 86 | $( '.ui-find-overlay' ).on( 'click', function () { |
42 | 87 | findPosts.close(); |
43 | 88 | }); |
44 | 89 | }, |
45 | 90 | |
| 91 | /** |
| 92 | * @summary Retrieves and displays posts based on the search term. |
| 93 | * |
| 94 | * Sends a post request to the admin_ajax.php, requesting posts based on the search term provided by the user. |
| 95 | * Defaults to all posts if no search term is provided. |
| 96 | * |
| 97 | * @since 2.7.0 |
| 98 | * |
| 99 | * @memberOf findPosts |
| 100 | * |
| 101 | * @returns {void} |
| 102 | */ |
46 | 103 | send: function() { |
47 | 104 | var post = { |
48 | 105 | ps: $( '#find-posts-input' ).val(), |
… |
… |
var findPosts; |
53 | 110 | |
54 | 111 | spinner.addClass( 'is-active' ); |
55 | 112 | |
| 113 | /** |
| 114 | * Send a POST request to admin_ajax.php, hide the spinner and replace the list of posts with the response data. |
| 115 | * If an error occurs, display it. |
| 116 | */ |
56 | 117 | $.ajax( ajaxurl, { |
57 | 118 | type: 'POST', |
58 | 119 | data: post, |
… |
… |
var findPosts; |
71 | 132 | } |
72 | 133 | }; |
73 | 134 | |
| 135 | /** |
| 136 | * @summary Initializes the file once the DOM is fully loaded and attaches events to the various form elements. |
| 137 | * |
| 138 | * @returns {void} |
| 139 | */ |
74 | 140 | $( document ).ready( function() { |
75 | 141 | var settings, $mediaGridWrap = $( '#wp-media-grid' ); |
76 | 142 | |
77 | | // Open up a manage media frame into the grid. |
| 143 | // Opens a manage media frame into the grid. |
78 | 144 | if ( $mediaGridWrap.length && window.wp && window.wp.media ) { |
79 | 145 | settings = _wpMediaGridSettings; |
80 | 146 | |
… |
… |
var findPosts; |
85 | 151 | }).open(); |
86 | 152 | } |
87 | 153 | |
| 154 | // Prevents form submission if no post has been selected. |
88 | 155 | $( '#find-posts-submit' ).click( function( event ) { |
89 | 156 | if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length ) |
90 | 157 | event.preventDefault(); |
91 | 158 | }); |
| 159 | |
| 160 | // Submits the search query when hitting the enter key in the search input. |
92 | 161 | $( '#find-posts .find-box-search :input' ).keypress( function( event ) { |
93 | 162 | if ( 13 == event.which ) { |
94 | 163 | findPosts.send(); |
95 | 164 | return false; |
96 | 165 | } |
97 | 166 | }); |
| 167 | |
| 168 | // Binds the click event to the search button. |
98 | 169 | $( '#find-posts-search' ).click( findPosts.send ); |
| 170 | |
| 171 | // Binds the close dialog click event. |
99 | 172 | $( '#find-posts-close' ).click( findPosts.close ); |
| 173 | |
| 174 | // Binds the bulk action events to the submit buttons. |
100 | 175 | $( '#doaction, #doaction2' ).click( function( event ) { |
| 176 | |
| 177 | /* |
| 178 | * Retrieves all select elements for bulk actions that have a name starting with `action` |
| 179 | * and handle its action based on its value. |
| 180 | */ |
101 | 181 | $( 'select[name^="action"]' ).each( function() { |
102 | 182 | var optionValue = $( this ).val(); |
103 | 183 | |
… |
… |
var findPosts; |
112 | 192 | }); |
113 | 193 | }); |
114 | 194 | |
115 | | // Enable whole row to be clicked |
| 195 | /** |
| 196 | * @summary Enables clicking on the entire table row. |
| 197 | * |
| 198 | * @returns {void} |
| 199 | */ |
116 | 200 | $( '.find-box-inside' ).on( 'click', 'tr', function() { |
117 | 201 | $( this ).find( '.found-radio input' ).prop( 'checked', true ); |
118 | 202 | }); |