PluginProbe
Friends / 4.3.2
Friends v4.3.2
4.3.2 4.3.1 4.3.0 4.2.2 4.2.1 4.2.0 4.1.0 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.1 All 88 releases
friends / friends-admin.js

friends-admin.js in Friends 4.3.2, at friends-admin.js

385 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global jQuery, friends */
2 jQuery( function ( $ ) {
3 $( document ).on( 'click', 'input#require_codeword', function () {
4 if ( this.checked ) {
5 $( '#codeword_options' ).removeClass( 'hidden' );
6 $( '#codeword' ).focus();
7 } else {
8 $( '#codeword_options' ).addClass( 'hidden' );
9 }
10 } );
11
12 $( document ).on( 'click', 'a#send-friends-advanced', function () {
13 $( 'tr.friends-advanced' )
14 .removeClass( 'hidden' )
15 .first()
16 .find( 'input:visible:first' )
17 .focus();
18 $( this ).remove();
19 return false;
20 } );
21
22 $( document ).on( 'click', 'a#add-another-feed', function () {
23 $( 'tr.another-feed' )
24 .removeClass( 'hidden' )
25 .find( 'input:visible:first' )
26 .focus();
27 $( this ).remove();
28 return false;
29 } );
30
31 $( document ).on( 'keyup', 'input#display_name', function ( e ) {
32 const login = $( '#user_login' );
33 if ( this.value && login.data( 'original' ) === login.val() ) {
34 const generated_login = this.value.toLowerCase().replace( /[^a-z0-9.]+/g, '-' ).replace( /-$/, '' ).replace( /^-/, '' );
35 login.val( generated_login );
36 login.data( 'original', generated_login );
37 }
38 } );
39
40
41 $( document ).on( 'click', 'a#show-details', function () {
42 $( '.details' ).toggleClass( 'hidden' ).focus();
43 return false;
44 } );
45
46 $( document ).on( 'click', 'a#show-alternate-feeds', function () {
47 $( 'li.rel-alternate' ).toggleClass( 'hidden' );
48 return false;
49 } );
50
51 $( document ).on( 'click', 'a#show-unsupported-feeds', function () {
52 $( '#unsupported-feeds' ).toggleClass( 'hidden' );
53 return false;
54 } );
55
56 $( document ).on( 'click', '#friends_retention_days', function ( e ) {
57 e.stopPropagation();
58 } );
59
60 $( document ).on(
61 'click',
62 '#friends_enable_retention_days, #friends_enable_retention_days_line',
63 function () {
64 const el = document.getElementById(
65 'friends_enable_retention_days'
66 );
67 if ( this.id !== el.id ) {
68 $( '#friends_enable_retention_days' ).attr(
69 'checked',
70 ! el.checked
71 );
72 }
73 $( '#friends_retention_days' ).attr( 'disabled', ! el.checked );
74 $( '#friends_enable_retention_days_line' ).attr(
75 'class',
76 el.checked ? '' : 'disabled'
77 );
78 }
79 );
80
81 $( document ).on( 'click', '#friends_retention_number', function ( e ) {
82 e.stopPropagation();
83 } );
84
85 $( document ).on(
86 'click',
87 '#friends_enable_retention_number, #friends_enable_retention_number_line',
88 function () {
89 const el = document.getElementById(
90 'friends_enable_retention_number'
91 );
92 if ( this.id !== el.id ) {
93 $( '#friends_enable_retention_number' ).attr(
94 'checked',
95 ! el.checked
96 );
97 }
98 $( '#friends_retention_number' ).attr( 'disabled', ! el.checked );
99 $( '#friends_enable_retention_number_line' ).attr(
100 'class',
101 el.checked ? '' : 'disabled'
102 );
103 }
104 );
105
106 $( document ).on( 'click', 'a#toggle-raw-rules-data', function () {
107 $( '#raw-rules-data' ).toggle();
108 return false;
109 } );
110
111 const previewRules = function () {
112 const $this = $( 'button#refresh-preview-rules' );
113 let url = friends.ajax_url + '?user=' + $this.data( 'friend' );
114 if ( $this.data( 'post' ) ) {
115 url += '&post=' + $this.data( 'post' );
116 }
117 $.post(
118 url,
119 $( 'form#edit-rules [name^=rules]' )
120 .add( 'form#edit-rules [name=catch_all]' )
121 .serialize() +
122 '&_wpnonce=' +
123 $this.data( 'nonce' ) +
124 '&action=friends_preview_rules',
125 function ( response ) {
126 $( '#preview-rules' ).html( response );
127 }
128 );
129 };
130
131 $( document ).on( 'change', 'select.rule-action', function () {
132 const tdReplace = $( this ).closest( 'tr' ).find( 'td.replace-with' );
133 if ( 'replace' === $( this ).val() ) {
134 tdReplace.show();
135 } else {
136 tdReplace.hide();
137 }
138 previewRules();
139 } );
140
141 $( document ).on(
142 'keyup click',
143 '#edit-rules input, #edit-rules select',
144 previewRules
145 );
146
147 $( document ).on( 'click', 'button#refresh-preview-rules', function () {
148 previewRules();
149 return false;
150 } );
151
152 $( document ).on( 'click', 'a.preview-parser', function () {
153 const url = $( this ).closest( 'tbody' ).find( 'input.url' ).val();
154 if ( ! url ) {
155 return false;
156 }
157 this.href = this.href.replace(
158 /&parser(=[^&$]+)?([&$])/,
159 '&parser=' +
160 encodeURIComponent(
161 $( this ).closest( 'tr' ).find( 'select' ).val()
162 ) +
163 '&'
164 );
165 this.href = this.href.replace(
166 /&preview(=[^&$]+)?([&$])/,
167 '&preview=' + encodeURIComponent( url ) + '&'
168 );
169 } );
170
171 $( document ).on( 'click', 'a.show-inactive-feeds', function () {
172 $( 'ul.feeds' ).show().find( 'li.inactive' ).toggleClass( 'hidden' );
173 return false;
174 } );
175
176 $( document ).on( 'click', 'a.show-log-lines', function () {
177 $( 'ul.feeds li.active p.lastlog' ).toggleClass( 'hidden' );
178 return false;
179 } );
180
181 $( document ).on( 'click', 'a.add-feed', function () {
182 $( 'ul.feeds' )
183 .removeClass( 'hidden' )
184 .find( 'li.template' )
185 .removeClass( 'hidden' )
186 .find( 'input:first' )
187 .focus();
188 $( this ).remove();
189 return false;
190 } );
191
192 $(
193 '<a href="' +
194 friends.add_friend_url +
195 '" class="page-title-action">' +
196 friends.add_friend_text +
197 '</a>'
198 ).insertAfter( 'a.page-title-action[href$="user-new.php"]' );
199
200 $( document ).on( 'click', '#admin-add-emoji', function () {
201 $( '#friends-reaction-picker' ).toggle();
202 return false;
203 } );
204
205 $( document ).on( 'click', '.delete-emoji', function () {
206 $( this ).closest( 'li' ).remove();
207 return false;
208 } );
209
210 $( document ).on( 'click', '.delete-feed', function () {
211 // eslint-disable-next-line no-alert
212 if ( window.confirm( friends.delete_feed_question ) ) {
213 $( this ).closest( 'li' ).remove();
214 }
215 return false;
216 } );
217
218 $( '#friends-reaction-picker' ).on( 'click', 'button', function () {
219 const id = $( this ).data( 'emoji' );
220 if ( $( '#emoji-' + id ).length ) {
221 return;
222 }
223 $( '#available-emojis' ).append(
224 $( '#available-emojis-template' )
225 .html()
226 .replace( /%1\$s/g, id )
227 .replace( /%2\$s/g, $( this ).html() )
228 );
229 return false;
230 } );
231
232 $( document ).on( 'click', '#admin-add-keyword', function () {
233 $( '#keyword-notifications' ).append(
234 '<li>' +
235 $( '#keyword-template' )
236 .html()
237 .replace(
238 /\[0\]/g,
239 '[' + $( '#keyword-notifications li' ).length + ']'
240 )
241 );
242 $( '#keyword-notifications input:last ' ).focus();
243 return false;
244 } );
245
246 $( document ).on( 'click', '#friends-bulk-publish', function () {
247 $( this )
248 .closest( 'div' )
249 .find( 'select option[value=publish]' )
250 .prop( 'selected', true );
251 } );
252
253 $( document ).on( 'click', 'a.set-avatar', function () {
254 setAvatarUrl(
255 $( this ).find( 'img' ).prop( 'src' ),
256 $( this ).data( 'user' ),
257 $( this ).data( 'nonce' )
258 );
259 return false;
260 } );
261
262 const setAvatarUrl = function ( url, user, nonce ) {
263 if ( ! url || ! url.match( /^https?:\/\// ) ) {
264 return;
265 }
266 $.post(
267 friends.ajax_url,
268 {
269 user,
270 avatar: url,
271 _ajax_nonce: nonce,
272 action: 'friends_set_avatar',
273 },
274 function ( response ) {
275 if ( response.success ) {
276 window.location.reload();
277 } else {
278 $( '#friend-avatar-setting p.description' ).text(
279 '⚠️ ' + response.data
280 );
281 }
282 }
283 );
284 };
285
286 $( document ).on( 'click', 'button#set-avatar-url', function () {
287 const url = $( '#new-avatar-url' );
288 setAvatarUrl( url.val(), url.data( 'user' ), url.data( 'nonce' ) );
289 return false;
290 } );
291
292 $( document ).on( 'keyup', 'input#new-avatar-url', function ( e ) {
293 const url = $( '#new-avatar-url' );
294 if ( e.keyCode === 13 ) {
295 setAvatarUrl( url.val(), url.data( 'user' ), url.data( 'nonce' ) );
296 return false;
297 }
298 } );
299
300 var updateDashboardWidgets = function() {
301 $( '.friends-dashboard-widget' ).each( function() {
302 const $this = $( this );
303 if ( $this.find( 'li.friends-post' ).length ) {
304 $( '#friends-dashboard-widget' ).append( ' <i class="friends-loading"></i>' );
305 }
306 const data = {
307 _ajax_nonce: $this.data( 'nonce' ),
308 action: 'friends_dashboard',
309 };
310 if ( $this.data( 'friend' ) ) {
311 data.friend = $this.data( 'friend' );
312 }
313 if ( $this.data( 'format' ) ) {
314 data.format = $this.data( 'format' );
315 }
316
317 $.post(
318 friends.ajax_url,
319 data,
320 function ( response ) {
321 if ( response.success ) {
322 if ( ! $this.find( 'li.friends-post' ).length ) {
323 $this.html( response.data );
324 } else {
325 $( $( response.data ).find( 'li.friends-post' ).get().reverse() ).each( function () {
326 if ( ! document.getElementById( $( this ).attr('id') ) ) {
327 $this.find( 'ul' ).prepend( this );
328 }
329 } );
330 $( '.friends-dashboard-widget li.friends-post:gt(49)' ).remove();
331 }
332 } else {
333 $this.find( 'i' )
334 .removeClass( 'friends-loading' )
335 .addClass( 'dashicons dashicons-warning' )
336 .prop( 'title', response.data );
337 }
338 }
339 );
340 } );
341 };
342 if ( $( '.friends-dashboard-widget' ).length ) {
343 updateDashboardWidgets();
344 setInterval( updateDashboardWidgets, 60000 );
345 }
346
347 $( document ).on( 'click', '#copy-api-key', function ( e ) {
348 e.preventDefault();
349 const $this = $( this );
350 const $input = $( '#api-key' );
351 navigator.clipboard.writeText( $input.val() );
352 $this.text( friends.copied_text );
353 setTimeout( function () {
354 $this.text( friends.copy_text );
355 }, 2000 );
356 return false;
357 } );
358
359 setTimeout( function () {
360 if ( $( '#fetch-feeds' ).length ) {
361 $( '#fetch-feeds' ).append( ' <i class="friends-loading"></i>' );
362 $.post(
363 friends.ajax_url,
364 {
365 friend: $( '#fetch-feeds' ).data( 'friend' ),
366 _ajax_nonce: $( '#fetch-feeds' ).data( 'nonce' ),
367 action: 'friends_fetch_feeds',
368 },
369 function ( response ) {
370 if ( response.success ) {
371 $( '#fetch-feeds i' )
372 .removeClass( 'friends-loading' )
373 .addClass( 'dashicons dashicons-saved' );
374 } else {
375 $( '#fetch-feeds i' )
376 .removeClass( 'friends-loading' )
377 .addClass( 'dashicons dashicons-warning' )
378 .prop( 'title', response.data );
379 }
380 }
381 );
382 }
383 }, 500 );
384 } );
385