PluginProbe
Friends / 2.7.5
Friends v2.7.5
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 2.7.5, at friends-admin.js

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