PageSourceSearch

https://ostpreussen.net/wp-content/plugins/wpforo/assets/js/ajax.js?ver=3.2.2

js ostpreussen.net collected 2026-10-02 12:20:27 UTC 61,814 bytes, 1,908 lines download raw bytes

1/* global wpforo */
2
3$wpf.ajaxSetup({
4	url: wpforo.ajax_url,
5	data: {
6		referer: window.location.origin + window.location.pathname,
7	},
8});
9
10function wpforo_post_url_fixer (hash) {
11	var postid = 0;
12	var match = hash.match(/^#post-(\d+)$/);
13	if (match && (postid = match[1])) {
14		if (!$wpf(hash).length && $wpf.active === 0) {
15			$wpf.ajax({
16				type: 'POST',
17				data: {
18					postid: postid,
19					action: 'wpforo_post_url_fixer',
20					_wpfnonce: wpforo['nonces']['wpforo_post_url_fixer'],
21				},
22			}).done(function (response) {
23				if (/^https?:\/\/[^\r\n\t\s\0'"]+$/.test(response)) {
24					window.location.assign(response);
25				}
26				
27				wpforo_trigger_custom_event(document, 'wpforo_post_url_fixer', { response });
28			});
29		}
30	}
31}
32
33$wpf(document).ready(function ($) {
34	var wpforo_wrap = $('#wpforo-wrap');
35	
36	//location hash ajax redirect fix
37	setTimeout(function () {
38		wpforo_post_url_fixer(window.location.hash);
39	}, 500);
40	window.onhashchange = function () {
41		wpforo_post_url_fixer(window.location.hash);
42	};
43
44//  Reactions
45	wpforo_wrap.on('click', '.wpforo-reaction .wpf-react:not(.wpf-processing)', function () {
46		var $this = $(this);
47		var wrap = $this.closest('.wpf-reaction-wrap');
48		var type = $this.data('type');
49		if (!type.trim()) type = 'up';
50		var postid = $this.closest('[data-postid]').data('postid');
51		
52		$this.addClass('wpf-processing');
53		$.ajax({
54			type: 'POST',
55			data: {
56				postid,
57				type,
58				action: 'wpforo_react',
59				_wpfnonce: wpforo['nonces']['wpforo_react'],
60			},
61		}).done(function (response) {
62			if (response.success) {
63				$('.reacted-users', wrap.closest('.wpforo-post')).html(response.data['likers']);
64				wrap.replaceWith(response.data['like_button']);
65			}
66			wpforo_trigger_custom_event(document, 'wpforo_react', { response });
67		}).always(function () {
68			$this.removeClass('wpf-processing');
69		});
70	});
71	
72	wpforo_wrap.on('click', '.wpforo-reaction .wpf-unreact:not(.wpf-processing)', function () {
73		var $this = $(this);
74		var wrap = $this.closest('.wpf-reaction-wrap');
75		var postid = $this.closest('[data-postid]').data('postid');
76		
77		$this.addClass('wpf-processing');
78		$.ajax({
79			type: 'POST',
80			data: {
81				postid,
82				action: 'wpforo_unreact',
83				_wpfnonce: wpforo['nonces']['wpforo_unreact'],
84			},
85		}).done(function (response) {
86			if (response.success) {
87				$('.reacted-users', wrap.closest('.wpforo-post')).html(response.data['likers']);
88				wrap.replaceWith(response.data['like_button']);
89			}
90			wpforo_trigger_custom_event(document, 'wpforo_unreact', { response });
91		}).always(function () {
92			$this.removeClass('wpf-processing');
93		});
94	});
95
96//	Vote
97	wpforo_wrap.on('click', '.wpforo-voteup:not(.wpf-processing)', function () {
98		wpforo_load_show();
99		var type   = $(this).data('type'),
100			postid = $(this).data('postid'),
101			$this  = $(this);
102		var buttons = $('.wpforo-voteup, .wpforo-votedown', $this.closest('.wpforo-post-voting'));
103		buttons.addClass('wpf-processing');
104		var votestatus = ($this.hasClass('wpf-vote-active') ? 'clear' : 'up');
105		$.ajax({
106			type: 'POST',
107			url: wpforo.ajax_url,
108			data: {
109				itemtype: type,
110				postid,
111				votestatus,
112				action: 'wpforo_vote_ajax',
113				_wpfnonce: wpforo['nonces']['wpforo_vote_ajax'],
114			},
115		}).done(function (response) {
116			if (response.success) {
117				$this.parents('.post-wrap').find('.wpfvote-num').text(response.data.votes).fadeIn();
118				var buttons_wrap = $this.closest('.wpforo-post-voting');
119				if (buttons_wrap.length) {
120					var vote_active_buttons = $('.wpf-vote-active', buttons_wrap);
121					if (vote_active_buttons.length) vote_active_buttons.removeClass('wpf-vote-active');
122				}
123				if (votestatus !== 'clear') $this.addClass('wpf-vote-active');
124			}
125			wpforo_load_hide();
126			wpforo_notice_show(response.data.notice, (response.success ? 'success' : 'error'));
127			buttons.removeClass('wpf-processing');
128			
129			wpforo_trigger_custom_event(document, 'wpforo_voteup_ajax', { response });
130		});
131	});
132	
133	wpforo_wrap.on('click', '.wpforo-votedown:not(.wpf-processing)', function () {
134		wpforo_load_show();
135		var type   = $(this).data('type'),
136			postid = $(this).data('postid'),
137			$this  = $(this);
138		var buttons = $('.wpforo-voteup, .wpforo-votedown', $this.closest('.wpforo-post-voting'));
139		buttons.addClass('wpf-processing');
140		var votestatus = ($this.hasClass('wpf-vote-active') ? 'clear' : 'down');
141		$.ajax({
142			type: 'POST',
143			url: wpforo.ajax_url,
144			data: {
145				itemtype: type,
146				postid,
147				votestatus,
148				action: 'wpforo_vote_ajax',
149				_wpfnonce: wpforo['nonces']['wpforo_vote_ajax'],
150			},
151		}).done(function (response) {
152			if (response.success) {
153				$this.parents('.post-wrap').find('.wpfvote-num').text(response.data.votes).fadeIn();
154				var buttons_wrap = $this.closest('.wpforo-post-voting');
155				if (buttons_wrap.length) {
156					var vote_active_buttons = $('.wpf-vote-active', buttons_wrap);
157					if (vote_active_buttons.length) vote_active_buttons.removeClass('wpf-vote-active');
158				}
159				if (votestatus !== 'clear') $this.addClass('wpf-vote-active');
160			}
161			wpforo_load_hide();
162			wpforo_notice_show(response.data.notice, (response.success ? 'success' : 'error'));
163			buttons.removeClass('wpf-processing');
164			
165			wpforo_trigger_custom_event(document, 'wpforo_vote_down_ajax', { response });
166		});
167	});
168
169//	Answer
170	wpforo_wrap.on('click', '.wpf-toggle-answer:not(.wpf-processing)', function () {
171		wpforo_load_show();
172		var postid = $(this).data('postid'),
173			$this  = $(this);
174		$this.addClass('wpf-processing');
175		$.ajax({
176			type: 'POST',
177			url: wpforo.ajax_url,
178			data: {
179				postid: postid,
180				answerstatus: 0,
181				action: 'wpforo_answer_ajax',
182				_wpfnonce: wpforo['nonces']['wpforo_answer_ajax'],
183			},
184		}).done(function (response) {
185			if (response.success) {
186				$this.removeClass('wpf-toggle-answer').addClass('wpf-toggle-not-answer');
187				setTimeout(function () {
188					window.location.reload();
189				}, 300);
190			}
191			wpforo_load_hide();
192			wpforo_notice_show(response.data.notice, (response.success ? 'success' : 'error'));
193			$this.removeClass('wpf-processing');
194			
195			wpforo_trigger_custom_event(document, 'wpforo_answer_ajax', { response });
196		});
197	});
198	
199	wpforo_wrap.on('click', '.wpf-toggle-not-answer:not(.wpf-processing)', function () {
200		wpforo_load_show();
201		var postid = $(this).data('postid'),
202			$this  = $(this);
203		$this.addClass('wpf-processing');
204		$.ajax({
205			type: 'POST',
206			url: wpforo.ajax_url,
207			data: {
208				postid: postid,
209				answerstatus: 1,
210				action: 'wpforo_answer_ajax',
211				_wpfnonce: wpforo['nonces']['wpforo_answer_ajax'],
212			},
213		}).done(function (response) {
214			if (response.success) {
215				$this.removeClass('wpf-toggle-not-answer').addClass('wpf-toggle-answer');
216				setTimeout(function () {
217					window.location.reload();
218				}, 300);
219			}
220			wpforo_load_hide();
221			wpforo_notice_show(response.data.notice, (response.success ? 'success' : 'error'));
222			$this.removeClass('wpf-processing');
223			
224			wpforo_trigger_custom_event(document, 'wpforo_not_answer_ajax', { response });
225		});
226	});
227
228//	Quote
229	wpforo_wrap.on('click', '.wpforo-quote:not(.wpf-processing)', function () {
230		wpforo_load_show();
231		
232		var $this = $(this);
233		$this.addClass('wpf-processing');
234		
235		var main_form = $('form.wpforo-main-form[data-textareaid]');
236		var wrap = main_form.closest('.wpf-form-wrapper');
237		wrap.show();
238		
239		var post_wrap = $(this).closest('[id^=post-][data-postid]');
240		var postid = post_wrap.data('postid');
241		if (!postid) postid = 0;
242		$('.wpf-form-post-parentid').val(postid);
243		$.ajax({
244			type: 'POST',
245			url: wpforo.ajax_url,
246			data: {
247				postid: postid,
248				action: 'wpforo_quote_ajax',
249				_wpfnonce: wpforo['nonces']['wpforo_quote_ajax'],
250			},
251		}).done(function (response) {
252			var phrase = wpforo_phrase('Reply with quote');
253			phrase = phrase.charAt(0).toUpperCase() + phrase.slice(1);
254			$('.wpf-reply-form-title').html(phrase);
255			$('.wpf-form-postid', main_form).val(0);
256			
257			wpforo_editor.set_content(response.data);
258			wpforo_load_hide();
259			$this.removeClass('wpf-processing');
260			
261			wpforo_trigger_custom_event(document, 'wpforo_quote_ajax', { response });
262		});
263	});
264
265//	Report
266	wpforo_wrap.on('click', '.wpforo-report', function () {
267		wpforo_load_show();
268		var form = $('form#wpforo-report');
269		$('#wpforo-report-postid', form).val($(this).data('postid'));
270		wpforo_dialog_show('', form, '45%', '295px');
271		$('#wpforo-report-content', form).trigger('focus');
272		wpforo_load_hide();
273	});
274	
275	$(document).on('click', '#wpforo-report-send:not(.wpf-processing)', wpforo_report_send);
276	$(document).on('keydown', 'form#wpforo-report', function (e) {
277		if ((e.ctrlKey || e.metaKey) && (e.code === 'Enter' || e.code === 'NumpadEnter')) {
278			$('#wpforo-report-send').trigger('click');
279		}
280	});
281	
282	function wpforo_report_send () {
283		wpforo_load_show();
284		var $this = $(this);
285		$this.addClass('wpf-processing');
286		
287		var postid = $('#wpforo-report-postid').val();
288		var messagecontent = $('#wpforo-report-content').val();
289		
290		$.ajax({
291			type: 'POST',
292			url: wpforo.ajax_url,
293			data: {
294				postid: postid,
295				reportmsg: messagecontent,
296				action: 'wpforo_report_ajax',
297				_wpfnonce: wpforo['nonces']['wpforo_report_ajax'],
298			},
299		}).done(function (response) {
300			wpforo_dialog_hide();
301			$('#wpforo-report-content').val('');
302			wpforo_load_hide();
303			wpforo_notice_show(response.data, (response.success ? 'success' : 'error'));
304			$this.removeClass('wpf-processing');
305			
306			wpforo_trigger_custom_event(document, 'wpforo_report_ajax', { response });
307		});
308	}
309
310//	Sticky
311	wpforo_wrap.on('click', '.wpforo-sticky:not(.wpf-processing)', function () {
312		wpforo_load_show();
313		var topicid = $(this).data('topicid'),
314			$this   = $(this);
315		
316		$this.addClass('wpf-processing');
317		
318		$.ajax({
319			type: 'POST',
320			url: wpforo.ajax_url,
321			data: {
322				topicid: topicid,
323				status: 'sticky',
324				action: 'wpforo_sticky_ajax',
325				_wpfnonce: wpforo['nonces']['wpforo_sticky_ajax'],
326			},
327		}).done(function (response) {
328			if (response.success) {
329				$this.find('.wpforo-sticky-txt').text(' ' + wpforo_phrase('Unsticky'));
330				$this.removeClass('wpforo-sticky').addClass('wpforo-unsticky');
331				if ($this.is('[wpf-tooltip]')) {
332					$this.attr('wpf-tooltip', wpforo_phrase('Unsticky'));
333				}
334			}
335			wpforo_load_hide();
336			wpforo_notice_show(response.data.notice, (response.success ? 'success' : 'error'));
337			$this.removeClass('wpf-processing');
338			
339			wpforo_trigger_custom_event(document, 'wpforo_sticky_ajax', { response });
340		});
341	});
342	
343	wpforo_wrap.on('click', '.wpforo-unsticky:not(.wpf-processing)', function () {
344		wpforo_load_show();
345		var topicid = $(this).data('topicid'),
346			$this   = $(this);
347		
348		$this.addClass('wpf-processing');
349		
350		$.ajax({
351			type: 'POST',
352			url: wpforo.ajax_url,
353			data: {
354				topicid: topicid,
355				status: 'unsticky',
356				action: 'wpforo_sticky_ajax',
357				_wpfnonce: wpforo['nonces']['wpforo_sticky_ajax'],
358			},
359		}).done(function (response) {
360			if (response.success) {
361				$this.find('.wpforo-sticky-txt').text(' ' + wpforo_phrase('Sticky'));
362				$this.removeClass('wpforo-unsticky').addClass('wpforo-sticky');
363				if ($this.is('[wpf-tooltip]')) {
364					$this.attr('wpf-tooltip', wpforo_phrase('Sticky'));
365				}
366			}
367			wpforo_load_hide();
368			wpforo_notice_show(response.data.notice, (response.success ? 'success' : 'error'));
369			$this.removeClass('wpf-processing');
370			
371			wpforo_trigger_custom_event(document, 'wpforo_unsticky_ajax', { response });
372		});
373	});
374
375//	Approve
376	wpforo_wrap.on('click', '.wpforo-approve:not(.wpf-processing)', function () {
377		wpforo_load_show();
378		var postid_value = $(this).attr('id'),
379			$this        = $(this);
380		var postid = postid_value.replace('wpfapprove', '');
381		
382		$this.addClass('wpf-processing');
383		
384		$.ajax({
385			type: 'POST',
386			url: wpforo.ajax_url,
387			data: {
388				postid: postid,
389				status: 'approve',
390				action: 'wpforo_approve_ajax',
391				_wpfnonce: wpforo['nonces']['wpforo_approve_ajax'],
392			},
393		}).done(function (response) {
394			if (response.success) {
395				$('#' + postid_value).removeClass('wpforo-approve').addClass('wpforo-unapprove');
396				$('#approveicon' + postid).removeClass('fa-check').addClass('fa-exclamation-circle');
397				$('#wpforo-wrap #post-' + postid + ' .wpf-mod-message').hide();
398				$('#wpforo-wrap .wpf-status-title').hide();
399				$('#approvetext' + postid).text(' ' + wpforo_phrase('Unapprove'));
400				if ($this.is('[wpf-tooltip]')) {
401					$this.attr('wpf-tooltip', wpforo_phrase('Unapprove'));
402				}
403			}
404			wpforo_load_hide();
405			window.location.reload();
406			$this.removeClass('wpf-processing');
407			
408			wpforo_trigger_custom_event(document, 'wpforo_approve_ajax', { response });
409		});
410	});
411
412//	Unapprove
413	wpforo_wrap.on('click', '.wpforo-unapprove:not(.wpf-processing)', function () {
414		wpforo_load_show();
415		var postid_value = $(this).attr('id'),
416			$this        = $(this);
417		var postid = postid_value.replace('wpfapprove', '');
418		
419		$this.addClass('wpf-processing');
420		
421		$.ajax({
422			type: 'POST',
423			url: wpforo.ajax_url,
424			data: {
425				postid: postid,
426				status: 'unapprove',
427				action: 'wpforo_approve_ajax',
428				_wpfnonce: wpforo['nonces']['wpforo_approve_ajax'],
429			},
430		}).done(function (response) {
431			if (response.success) {
432				$('#' + postid_value).removeClass('wpforo-unapprove').addClass('wpforo-approve');
433				$('#approveicon' + postid).removeClass('fa-exclamation-circle').addClass('fa-check');
434				$('#wpforo-wrap #post-' + postid + ' .wpf-mod-message').visible();
435				$('#wpforo-wrap .wpf-status-title').visible();
436				$('#approvetext' + postid).text(' ' + wpforo_phrase('Approve'));
437				if ($this.is('[wpf-tooltip]')) {
438					$this.attr('wpf-tooltip', wpforo_phrase('Approve'));
439				}
440			}
441			wpforo_load_hide();
442			window.location.reload();
443			$this.removeClass('wpf-processing');
444			
445			wpforo_trigger_custom_event(document, 'wpforo_unapprove_ajax', { response });
446		});
447	});
448
449//	Private
450	wpforo_wrap.on('click', '.wpforo-private:not(.wpf-processing)', function () {
451		wpforo_load_show();
452		var postid_value = $(this).attr('id'),
453			$this        = $(this);
454		var topicid = postid_value.replace('wpfprivate', '');
455		
456		$this.addClass('wpf-processing');
457		
458		$.ajax({
459			type: 'POST',
460			url: wpforo.ajax_url,
461			data: {
462				topicid: topicid,
463				status: 'private',
464				action: 'wpforo_private_ajax',
465				_wpfnonce: wpforo['nonces']['wpforo_private_ajax'],
466			},
467		}).done(function (response) {
468			if (response.success) {
469				$('#' + postid_value).removeClass('wpforo-private').addClass('wpforo-public');
470				$('#privateicon' + topicid).removeClass('fa-eye-slash').addClass('fa-eye');
471				$('#privatetext' + topicid).text(' ' + wpforo_phrase('Public'));
472				if ($this.is('[wpf-tooltip]')) {
473					$this.attr('wpf-tooltip', wpforo_phrase('Public'));
474				}
475			}
476			wpforo_load_hide();
477			$this.removeClass('wpf-processing');
478			
479			wpforo_trigger_custom_event(document, 'wpforo_private_ajax', { response });
480		});
481	});
482	
483	wpforo_wrap.on('click', '.wpforo-public:not(.wpf-processing)', function () {
484		wpforo_load_show();
485		var postid_value = $(this).attr('id'),
486			$this        = $(this);
487		var topicid = postid_value.replace('wpfprivate', '');
488		
489		$this.addClass('wpf-processing');
490		
491		$.ajax({
492			type: 'POST',
493			url: wpforo.ajax_url,
494			data: {
495				topicid: topicid,
496				status: 'public',
497				action: 'wpforo_private_ajax',
498				_wpfnonce: wpforo['nonces']['wpforo_private_ajax'],
499			},
500		}).done(function (response) {
501			if (response.success) {
502				$('#' + postid_value).removeClass('wpforo-public').addClass('wpforo-private');
503				$('#privateicon' + topicid).removeClass('fa-eye').addClass('fa-eye-slash');
504				$('#privatetext' + topicid).text(' ' + wpforo_phrase('Private'));
505				if ($this.is('[wpf-tooltip]')) {
506					$this.attr('wpf-tooltip', wpforo_phrase('Private'));
507				}
508			}
509			wpforo_load_hide();
510			$this.removeClass('wpf-processing');
511			
512			wpforo_trigger_custom_event(document, 'wpforo_unprivate_ajax', { response });
513		});
514	});
515
516//	Solved
517	wpforo_wrap.on('click', '.wpforo-solved:not(.wpf-processing)', function () {
518		wpforo_load_show();
519		var postid_value = $(this).attr('id'),
520			$this        = $(this);
521		var postid = postid_value.replace('wpfsolved', '');
522		
523		$this.addClass('wpf-processing');
524		
525		$.ajax({
526			type: 'POST',
527			url: wpforo.ajax_url,
528			data: {
529				postid: postid,
530				status: 'solved',
531				action: 'wpforo_solved_ajax',
532				_wpfnonce: wpforo['nonces']['wpforo_solved_ajax'],
533			},
534		}).done(function (response) {
535			if (response.success) {
536				$('#' + postid_value).removeClass('wpforo-solved').addClass('wpforo-unsolved');
537				$('#solvedtext' + postid).text(' ' + wpforo_phrase('Unsolved'));
538				if ($this.is('[wpf-tooltip]')) {
539					$this.attr('wpf-tooltip', wpforo_phrase('Unsolved'));
540				}
541			}
542			wpforo_load_hide();
543			$this.removeClass('wpf-processing');
544			
545			wpforo_trigger_custom_event(document, 'wpforo_solved_ajax', { response });
546		});
547	});
548	
549	wpforo_wrap.on('click', '.wpforo-unsolved:not(.wpf-processing)', function () {
550		wpforo_load_show();
551		var postid_value = $(this).attr('id'),
552			$this        = $(this);
553		var postid = postid_value.replace('wpfsolved', '');
554		
555		$this.addClass('wpf-processing');
556		
557		$.ajax({
558			type: 'POST',
559			url: wpforo.ajax_url,
560			data: {
561				postid: postid,
562				status: 'unsolved',
563				action: 'wpforo_solved_ajax',
564				_wpfnonce: wpforo['nonces']['wpforo_solved_ajax'],
565			},
566		}).done(function (response) {
567			if (response.success) {
568				$('#' + postid_value).removeClass('wpforo-unsolved').addClass('wpforo-solved');
569				$('#solvedtext' + postid).text(' ' + wpforo_phrase('Solved'));
570				if ($this.is('[wpf-tooltip]')) {
571					$this.attr('wpf-tooltip', wpforo_phrase('Solved'));
572				}
573			}
574			wpforo_load_hide();
575			$this.removeClass('wpf-processing');
576			
577			wpforo_trigger_custom_event(document, 'wpforo_unsolved_ajax', { response });
578		});
579	});
580
581//	Close
582	wpforo_wrap.on('click', '.wpforo-close:not(.wpf-processing)', function () {
583		wpforo_load_show();
584		var postid_value = $(this).attr('id'),
585			$this        = $(this);
586		var topicid = postid_value.replace('wpfclose', '');
587		
588		$this.addClass('wpf-processing');
589		
590		$.ajax({
591			type: 'POST',
592			url: wpforo.ajax_url,
593			data: {
594				topicid: topicid,
595				status: 'close',
596				action: 'wpforo_close_ajax',
597				_wpfnonce: wpforo['nonces']['wpforo_close_ajax'],
598			},
599		}).done(function (response) {
600			if (response.success) {
601				$('#' + postid_value).removeClass('wpforo-close').addClass('wpforo-open');
602				$('#closeicon' + topicid).removeClass('fa-lock').addClass('fa-unlock');
603				$('#closetext' + topicid).text(' ' + wpforo_phrase('Open'));
604				if ($this.is('[wpf-tooltip]')) {
605					$this.attr('wpf-tooltip', wpforo_phrase('Open'));
606				}
607				$('.wpf-form-wrapper').remove();
608				$('.wpforo-reply').remove();
609				$('.wpforo-quote').remove();
610				$('.wpforo-edit').remove();
611				$('.wpf-answer-button').remove();
612				$('.wpf-add-comment-button').remove();
613			}
614			wpforo_load_hide();
615			$this.removeClass('wpf-processing');
616			
617			wpforo_trigger_custom_event(document, 'wpforo_close_ajax', { response });
618		});
619	});
620	
621	wpforo_wrap.on('click', '.wpforo-open:not(.wpf-processing)', function () {
622		wpforo_load_show();
623		var postid_value = $(this).attr('id'),
624			$this        = $(this);
625		var topicid = postid_value.replace('wpfclose', '');
626		
627		$this.addClass('wpf-processing');
628		
629		$.ajax({
630			type: 'POST',
631			url: wpforo.ajax_url,
632			data: {
633				topicid: topicid,
634				status: 'closed',
635				action: 'wpforo_close_ajax',
636				_wpfnonce: wpforo['nonces']['wpforo_close_ajax'],
637			},
638		}).done(function (response) {
639			if (response.success) {
640				if ($this.is('[wpf-tooltip]')) {
641					$this.attr('wpf-tooltip', wpforo_phrase('Close'));
642				}
643				window.location.reload();
644			}
645			wpforo_load_hide();
646			$this.removeClass('wpf-processing');
647			
648			wpforo_trigger_custom_event(document, 'wpforo_open_ajax', { response });
649		});
650	});
651	
652	// Edit post
653	wpforo_wrap.on('click', '.wpforo-edit:not(.wpf-processing)', function () {
654		var $this = $(this);
655		var wrap = $(this).closest('[id^=post-][data-postid]');
656		if (wrap.length) {
657			$this.addClass('wpf-processing');
658			var children = wrap.contents().not(':hidden');
659			var loading = $('<div class="wpforo-loading-portable"><i class="fas fa-3x fa-circle-notch fa-spin"></i></div>');
660			wrap.append(loading);
661			
662			var show_form = function (form, init) {
663				loading.remove();
664				children.fadeOut('fast');
665				var f = $(form);
666				f.on('click', '.wpf-edit-post-cancel', function (e) {
667					e.stopPropagation();
668					e.preventDefault();
669					f.fadeOut('fast');
670					children.fadeIn('slow');
671					wpforo_editor.set_active(wpforo_editor.get_main());
672					$('html').scrollTop((wrap.offset().top - 80));
673				});
674				if (init) {
675					f.appendTo(wrap);
676					wpforo_trigger_custom_event(document, 'wpforo_topic_portable_form', f);
677				}
678				f.fadeIn('slow');
679				$('html').scrollTop((wrap.offset().top - 80));
680				$this.removeClass('wpf-processing');
681			};
682			
683			var f = $('.wpf-form-wrapper', wrap);
684			if (f.length) {
685				show_form(f);
686			} else {
687				$.ajax({
688					type: 'POST',
689					url: wpforo.ajax_url,
690					data: {
691						postid: parseInt(wrap.data('postid')),
692						action: 'wpforo_post_edit',
693						_wpfnonce: wpforo['nonces']['wpforo_post_edit'],
694					},
695				}).done(function (response) {
696					if (response.success) show_form(response.data.html, true);
697					wpforo_trigger_custom_event(document, 'wpforo_post_edit', { response });
698				});
699			}
700		}
701	});
702
703//	Delete
704	wpforo_wrap.on('click', '.wpforo-delete:not(.wpf-processing)', function () {
705		if (confirm(wpforo_ucwords(wpforo_phrase('are you sure you want to delete?')))) {
706			wpforo_load_show();
707			var $this = $(this);
708			$this.addClass('wpf-processing');
709			
710			var postid_value = $(this).attr('id');
711			var is_topic = postid_value.indexOf('topic');
712			
713			var postid, status_value;
714			if (is_topic === -1) {
715				postid = postid_value.replace('wpfreplydelete', '');
716				status_value = 'reply';
717			} else {
718				postid = postid_value.replace('wpftopicdelete', '');
719				status_value = 'topic';
720			}
721			
722			var forumid = 0;
723			var wpf_forumid = $('input[type=\'hidden\'].wpf-form-forumid');
724			if (wpf_forumid.length) forumid = wpf_forumid.val();
725			
726			$.ajax({
727				type: 'POST',
728				url: wpforo.ajax_url,
729				data: {
730					forumid: forumid,
731					postid: postid,
732					status: status_value,
733					action: 'wpforo_delete_ajax',
734					_wpfnonce: wpforo['nonces']['wpforo_delete_ajax'],
735				},
736			}).done(function (response) {
737				if (response.success) {
738					if (is_topic === -1) {
739						var to_be_removed = $('#post-' + response.data.postid);
740						if (to_be_removed.hasClass('wpf-answer-wrap')) {
741							var qa_item_wrap = to_be_removed.parents('.wpforo-qa-item-wrap');
742							if (qa_item_wrap.length) to_be_removed = qa_item_wrap;
743						}
744						to_be_removed.remove().delay(200);
745						$('#wpf-post-replies-' + response.data.postid).remove().delay(100);
746						$('#wpf-ttgg-' + response.data.root + ' .wpf-post-replies-count').text(response.data.root_count);
747					} else {
748						window.location.assign(response.data.location);
749					}
750				}
751				wpforo_load_hide();
752				wpforo_notice_show(response.data.notice, (response.success ? 'success' : 'error'));
753				$this.removeClass('wpf-processing');
754				
755				wpforo_trigger_custom_event(document, 'wpforo_delete_ajax', { response });
756			});
757		}
758	});
759
760//	Subscribe
761	wpforo_wrap.on('click', '.wpf-subscribe-forum:not(.wpf-processing), .wpf-subscribe-topic:not(.wpf-processing), .wpf-subscribe-user:not(.wpf-processing)', function () {
762		wpforo_load_show();
763		
764		var $this = $(this);
765		$this.addClass('wpf-processing');
766		
767		var type = $this.data('type');
768		var itemid = $this.data('itemid');
769		
770		$.ajax({
771			type: 'POST',
772			url: wpforo.ajax_url,
773			data: {
774				itemid,
775				type,
776				status: 'subscribe',
777				action: 'wpforo_subscribe_ajax',
778				_wpfnonce: wpforo['nonces']['wpforo_subscribe_ajax'],
779			},
780		}).done(function (response) {
781			if (response.success) {
782				$this.removeClass('wpfcl-5').removeClass('wpf-subscribe-' + type).addClass('wpf-unsubscribe-' + type).text(' ' + wpforo_phrase('Unsubscribe'));
783			}
784			wpforo_notice_show(response.data.notice, (response.success ? 'success' : 'error'));
785			
786			wpforo_trigger_custom_event(document, 'wpforo_subscribe_ajax', { response });
787		}).always(function () {
788			wpforo_load_hide();
789			$this.removeClass('wpf-processing');
790		});
791	});
792	
793	wpforo_wrap.on('click', '.wpf-unsubscribe-forum:not(.wpf-processing), .wpf-unsubscribe-topic:not(.wpf-processing), .wpf-unsubscribe-user:not(.wpf-processing)', function () {
794		wpforo_load_show();
795		
796		var $this = $(this);
797		$this.addClass('wpf-processing');
798		
799		var type = $this.data('type');
800		var itemid = $this.data('itemid');
801		var button_phrase = '';
802		if (type === 'forum') {
803			button_phrase = wpforo_ucwords(wpforo_phrase('Subscribe for new topics'));
804		} else if (type === 'topic') {
805			button_phrase = wpforo_ucwords(wpforo_phrase('Subscribe for new replies'));
806		} else if (type === 'user') {
807			button_phrase = wpforo_ucwords(wpforo_phrase('Subscribe for new posts'));
808		}
809		$.ajax({
810			type: 'POST',
811			url: wpforo.ajax_url,
812			data: {
813				itemid,
814				type,
815				status: 'unsubscribe',
816				action: 'wpforo_subscribe_ajax',
817				_wpfnonce: wpforo['nonces']['wpforo_subscribe_ajax'],
818			},
819		}).done(function (response) {
820			if (response.success) {
821				$this.removeClass('wpf-unsubscribe-' + type).addClass('wpf-subscribe-' + type).addClass('wpfcl-5').text(' ' + button_phrase);
822			}
823			wpforo_notice_show(response.data.notice, (response.success ? 'success' : 'error'));
824			
825			wpforo_trigger_custom_event(document, 'wpforo_unsubscribe_ajax', { response });
826		}).always(function () {
827			wpforo_load_hide();
828			$this.removeClass('wpf-processing');
829		});
830	});
831	
832	wpforo_wrap.on('change', '.wpf-topic-form-forumid', function () {
833		var $this = $(this);
834		var form_wrap = $this.closest('.wpf-topic-form-extra-wrap');
835		var form_ajax_wrap = $('.wpf-topic-form-ajax-wrap', form_wrap);
836		var l = $('<i class="fas fa-spinner fa-spin wpf-icon-spinner"></i>');
837		form_ajax_wrap.empty();
838		l.appendTo(form_ajax_wrap);
839		$this.attr('disabled', true);
840		$('.wpf-topic-form-no-selected-forum', form_wrap).hide();
841		
842		var forumid = parseInt($this.val());
843		if (forumid) {
844			$.ajax({
845				type: 'POST',
846				data: {
847					forumid: forumid,
848					action: 'wpforo_topic_portable_form',
849					_wpfnonce: wpforo['nonces']['wpforo_topic_portable_form'],
850				},
851			}).done(function (response) {
852				l.remove();
853				if (response.success) {
854					var f = $(response.data);
855					form_ajax_wrap.empty();
856					f.appendTo(form_ajax_wrap);
857					f.fadeIn('slow');
858					wpforo_trigger_custom_event(document, 'wpforo_topic_portable_form', f);
859				}
860				$this.attr('disabled', false);
861			});
862		}
863	});
864	
865	wpforo_wrap.on('click', '.wpforo-tools', function () {
866		var tools = $('#wpf_moderation_tools');
867		if (tools.is(':visible')) {
868			tools.slideUp(250, 'linear');
869		} else {
870			wpforo_load_show();
871			tools.find('.wpf-tool-tabs .wpf-tool-tab').removeClass('wpf-tt-active');
872			tools.find('.wpf-tool-tabs .wpf-tool-tab:first-child').addClass('wpf-tt-active');
873			wpforo_topic_tools_tab_load();
874		}
875	});
876	
877	wpforo_wrap.on('click', '#wpf_moderation_tools .wpf-tool-tabs .wpf-tool-tab:not(.wpf-tt-active)', function () {
878		wpforo_notice_hide();
879		$(this).siblings('.wpf-tool-tab').removeClass('wpf-tt-active');
880		if (!$(this).hasClass('wpf-tt-active')) $(this).addClass('wpf-tt-active');
881		wpforo_topic_tools_tab_load();
882	});
883	
884	wpforo_topic_tools_tab_load();
885	
886	wpforo_wrap.on('click', 'div.wpfl-4:not(.wpf-processing) .wpf-load-threads a.wpf-threads-filter', function () {
887		var wrap = $(this).parents('div.wpfl-4');
888		var topics_list = $('.wpf-thread-list', wrap);
889		topics_list.data('paged', 0);
890		topics_list.data('filter', $(this).data('filter'));
891		$('.wpf-more-topics > a', wrap).trigger('click');
892		$(this).siblings('a.wpf-threads-filter').removeClass('wpf-active');
893		$(this).addClass('wpf-active');
894	});
895	
896	wpforo_wrap.on('click', 'div.wpfl-4:not(.wpf-processing) .wpf-more-topics > a', function () {
897		var $this = $(this);
898		var wrap = $this.parents('div.wpfl-4');
899		wrap.addClass('wpf-processing');
900		var topics_list = $('.wpf-thread-list', wrap);
901		var filter = topics_list.data('filter');
902		var forumid = topics_list.data('forumid');
903		var paged = topics_list.data('paged');
904		var append = paged !== 0;
905		topics_list.data('paged', ++paged);
906		
907		var load_msg = wpforo_phrase('Loading Topics');
908		
909		wpforo_load_show(load_msg);
910		
911		var i = $('.wpf-load-threads a.wpf-threads-filter[data-filter="' + filter + '"] i', wrap);
912		var i_class = i.attr('class');
913		var i_spin_class = 'fas fa-circle-notch fa-spin';
914		var i_toggle_class = i_class + ' ' + i_spin_class;
915		
916		var i2 = $('i', $this);
917		var i2_class = i2.attr('class');
918		var i2_toggle_class = i2_class + ' ' + i_spin_class;
919		
920		wpforo_notice_hide();
921		
922		i.toggleClass(i_toggle_class);
923		if (append) i2.toggleClass(i2_toggle_class);
924		
925		$.ajax({
926			type: 'POST',
927			data: {
928				forumid: forumid,
929				filter: filter,
930				paged: paged,
931				action: 'wpforo_layout4_loadmore',
932				_wpfnonce: wpforo['nonces']['wpforo_layout4_loadmore'],
933			},
934		}).done(function (response) {
935			if (response.success) {
936				if (append) {
937					topics_list.append(response.data.output_html);
938				} else {
939					topics_list.html(response.data.output_html);
940					$this.show();
941				}
942			} else {
943				if (!append) {
944					topics_list.html('<span class="wpf-no-thread">' + wpforo_phrase('No threads found') + '</span>');
945				}
946			}
947			
948			if (response.data.no_more) {
949				$this.hide();
950			}
951			
952			i.toggleClass(i_toggle_class);
953			if (append) i2.toggleClass(i2_toggle_class);
954			wpforo_load_hide();
955			wrap.removeClass('wpf-processing');
956			
957			wpforo_trigger_custom_event(document, 'wpforo_layout4_loadmore', { response });
958		});
959	});
960	
961	wpforo_wrap.on('click', '.wpforo-qa-show-rest-comments:not(.wpf-processing)', function () {
962		wpforo_load_show();
963		var $this = $(this);
964		$this.addClass('wpf-processing');
965		var wrap = $this.parents('.wpforo-qa-item-wrap');
966		var root_wrap = wrap.children('.post-wrap');
967		var comments_list = $('.wpforo-qa-comments', wrap);
968		var parentid = root_wrap.data('postid');
969		$.ajax({
970			type: 'POST',
971			data: {
972				parentid: parentid,
973				action: 'wpforo_qa_comment_loadrest',
974				_wpfnonce: wpforo['nonces']['wpforo_qa_comment_loadrest'],
975			},
976		}).done(function (response) {
977			if (response.success) {
978				comments_list.append(response.data['output_html']);
979				$this.remove();
980				wpforo_load_hide();
981			}
982			$this.removeClass('wpf-processing');
983			
984			wpforo_trigger_custom_event(document, 'wpforo_qa_comment_loadrest', { response });
985		});
986	});
987	
988	wpforo_wrap.on('click', 'form[data-textareaid] .wpforo_post_preview:not(.wpf-disabled):not(.wpf-processing)', function () {
989		var $this = $(this);
990		var ico = $('.wpf-rev-preview-ico', $this);
991		var form = $this.closest('form[data-textareaid]');
992		
993		//$('.wpforo_save_revision', form).trigger("click");
994		
995		var textareaid = form.data('textareaid');
996		var postid = $('input.wpf-form-postid', form).val();
997		var body = wpforo_editor.get_content('raw');
998		var body_info = wpforo_editor.get_stats();
999		
1000		if (textareaid && body_info.has_content) {
1001			$this.addClass('wpf-processing');
1002			wpforo_load_show();
1003			ico.toggleClass('fa-eye fa-circle-notch fa-spin');
1004			$.ajax({
1005				type: 'POST',
1006				data: {
1007					textareaid: textareaid,
1008					postid: postid,
1009					body: body,
1010					action: 'wpforo_post_preview',
1011					_wpfnonce: wpforo['nonces']['wpforo_post_preview'],
1012				},
1013			}).done(function (response) {
1014				if (response.success) {
1015					$('.wpforo-revisions-action-buttons .wpforo-revision-action-button', form).removeClass('wpf-rev-button-active');
1016					$this.addClass('wpf-rev-button-active');
1017					$('.wpforo-revisions-preview-wrap', form).html(response.data);
1018				}
1019				
1020				wpforo_trigger_custom_event(document, 'wpforo_post_preview', { response });
1021			}).always(function () {
1022				wpforo_load_hide();
1023				ico.toggleClass('fa-eye fa-circle-notch fa-spin');
1024				$this.removeClass('wpf-processing');
1025			});
1026		}
1027		
1028	});
1029	
1030	wpforo_wrap.on('click', 'form[data-textareaid] .wpforo_save_revision:not(.wpf-processing)', function () {
1031		var $this = $(this);
1032		if ($this.is(':visible')) {
1033			var ico = $('.wpf-rev-save-ico', $this);
1034			var form = $this.closest('form[data-textareaid]');
1035			var textareaid = form.data('textareaid');
1036			var postid = $('input.wpf-form-postid', form).val();
1037			var body = wpforo_editor.get_content('raw');
1038			var body_info = wpforo_editor.get_stats();
1039			if (textareaid && body_info.has_content) {
1040				$this.addClass('wpf-processing');
1041				wpforo_load_show('Saving Draft');
1042				ico.toggleClass('fa-save fa-circle-notch fa-spin');
1043				$.ajax({
1044					type: 'POST',
1045					data: {
1046						textareaid: textareaid,
1047						postid: postid,
1048						body: body,
1049						action: 'wpforo_save_revision',
1050						_wpfnonce: wpforo['nonces']['wpforo_save_revision'],
1051					},
1052				}).done(function (response) {
1053					if (response.success) {
1054						wpforo_deactivate_revision_action_buttons(form);
1055						$('.wpf-rev-history-count', form).text(response.data.revisions_count);
1056						if (response.data.revisionhtml && $('.wpforo_revisions_history', form).hasClass('wpf-rev-button-active')) {
1057							var revisions_preview_wrap = $('.wpforo-revisions-preview-wrap', form);
1058							revisions_preview_wrap.prepend(response.data.revisionhtml);
1059							var wpforo_revision = $('.wpforo-revision', revisions_preview_wrap);
1060							if (wpforo_revision.length >= wpforo.revision_options.max_drafts_per_page) {
1061								wpforo_revision.each(function (i) {
1062									if (i >= wpforo.revision_options.max_drafts_per_page) $(this).remove();
1063								});
1064							}
1065						}
1066					}
1067					wpforo_trigger_custom_event(document, 'wpforo_save_revision', { response });
1068				}).always(function () {
1069					wpforo_load_hide();
1070					ico.toggleClass('fa-save fa-circle-notch fa-spin');
1071					$this.removeClass('wpf-processing');
1072				});
1073			}
1074		}
1075	});
1076	
1077	wpforo_wrap.on('click', 'form[data-textareaid] .wpforo_revisions_history:not(.wpf-processing)', function () {
1078		var $this = $(this);
1079		var ico = $('.wpf-rev-ico', $this);
1080		var form = $this.closest('form[data-textareaid]');
1081		var textareaid = form.data('textareaid');
1082		var postid = $('input.wpf-form-postid', form).val();
1083		
1084		if (textareaid) {
1085			$this.addClass('wpf-processing');
1086			wpforo_load_show();
1087			ico.toggleClass('fa-history fa-circle-notch fa-spin');
1088			$.ajax({
1089				type: 'POST',
1090				data: {
1091					textareaid: textareaid,
1092					postid: postid,
1093					action: 'wpforo_get_revisions_history',
1094					_wpfnonce: wpforo['nonces']['wpforo_get_revisions_history'],
1095				},
1096			}).done(function (response) {
1097				if (response.success) {
1098					$('.wpf-rev-history-count', form).text(response.data.revisions_count);
1099					$('.wpforo-revisions-action-buttons .wpforo-revision-action-button', form).removeClass('wpf-rev-button-active');
1100					$this.addClass('wpf-rev-button-active');
1101					$('.wpforo-revisions-preview-wrap', form).html(response.data.revisionhtml);
1102				}
1103				wpforo_trigger_custom_event(document, 'wpforo_get_revisions_history', { response });
1104			}).always(function () {
1105				wpforo_load_hide();
1106				ico.toggleClass('fa-history fa-circle-notch fa-spin');
1107				$this.removeClass('wpf-processing');
1108			});
1109		}
1110	});
1111	
1112	wpforo_wrap.on('click', 'form[data-textareaid] .wpforo-revision-action-restore:not(.wpf-processing)', function () {
1113		var $this = $(this);
1114		var ico = $('.wpf-rev-ico', $this);
1115		var form = $this.closest('form[data-textareaid]');
1116		var rev_wrap = $this.closest('.wpforo-revision[data-revisionid]');
1117		if (rev_wrap.length) {
1118			$this.addClass('wpf-processing');
1119			wpforo_load_show('Restore Revision');
1120			ico.toggleClass('fa-history fa-circle-notch fa-spin');
1121			var revisionid = rev_wrap.data('revisionid');
1122			$.ajax({
1123				type: 'POST',
1124				data: {
1125					revisionid: revisionid,
1126					action: 'wpforo_get_revision',
1127					_wpfnonce: wpforo['nonces']['wpforo_get_revision'],
1128				},
1129			}).done(function (response) {
1130				if (response.success) {
1131					wpforo_editor.set_content(response.data.body);
1132				}
1133				wpforo_trigger_custom_event(document, 'wpforo_get_revision', { response });
1134			}).always(function () {
1135				wpforo_load_hide();
1136				ico.toggleClass('fa-history fa-circle-notch fa-spin');
1137				$this.removeClass('wpf-processing');
1138			});
1139		}
1140	});
1141	
1142	wpforo_wrap.on('click', 'form[data-textareaid] .wpforo-revision-action-delete:not(.wpf-processing)', function () {
1143		var $this = $(this);
1144		var ico = $('.wpf-rev-ico', $this);
1145		var form = $this.closest('form[data-textareaid]');
1146		var rev_wrap = $this.closest('.wpforo-revision[data-revisionid]');
1147		if (rev_wrap.length) {
1148			$this.addClass('wpf-processing');
1149			wpforo_load_show('Deleting Revision');
1150			ico.toggleClass('fa-trash fa-circle-notch fa-spin');
1151			var revisionid = rev_wrap.data('revisionid');
1152			$.ajax({
1153				type: 'POST',
1154				data: {
1155					revisionid: revisionid,
1156					action: 'wpforo_delete_revision',
1157					_wpfnonce: wpforo['nonces']['wpforo_delete_revision'],
1158				},
1159			}).done(function (response) {
1160				if (response.success) {
1161					rev_wrap.fadeOut(500, function () {
1162						rev_wrap.remove();
1163						$('.wpf-rev-history-count', form).text(response.data.revisions_count);
1164					});
1165				}
1166				
1167				wpforo_trigger_custom_event(document, 'wpforo_delete_revision', { response });
1168			}).always(function () {
1169				wpforo_load_hide();
1170				ico.toggleClass('fa-trash fa-circle-notch fa-spin');
1171				$this.removeClass('wpf-processing');
1172			});
1173		}
1174	});
1175	
1176	wpforo_wrap.on('click', '.wpforo-user-actions .wpf-ab-mute_mention:not(.wpf-processing)', function () {
1177		var $this = $(this);
1178		var currentstate = parseInt($this.data('currentstate'));
1179		if (isNaN(currentstate)) currentstate = 0;
1180		$this.addClass('wpf-processing');
1181		wpforo_load_show();
1182		$.ajax({
1183			type: 'POST',
1184			data: {
1185				currentstate,
1186				action: 'wpforo_mute_mentions',
1187				_wpfnonce: wpforo['nonces']['wpforo_mute_mentions'],
1188			},
1189		}).done(function (response) {
1190			if (response.success) {
1191				$('> i', $this).replaceWith(response.data['ico']);
1192				wpforo_setAttr($this, 'data-currentstate', response.data['currentstate']);
1193				var label = $this.data((response.data['currentstate'] ? 'active_label' : 'inactive_label'));
1194				wpforo_setAttr($this, 'wpf-tooltip', label);
1195			}
1196			
1197			wpforo_trigger_custom_event(document, 'wpforo_mute_mentions', { response });
1198		}).always(function () {
1199			wpforo_load_hide();
1200			$this.removeClass('wpf-processing');
1201		});
1202	});
1203	
1204	wpforo_wrap.on('click', '.wpforo-user-actions .wpf-ab-ban:not(.wpf-processing)', function () {
1205		var $this = $(this);
1206		var currentstate = parseInt($this.data('currentstate'));
1207		if (isNaN(currentstate)) currentstate = 1;
1208		$this.addClass('wpf-processing');
1209		wpforo_load_show();
1210		$.ajax({
1211			type: 'POST',
1212			data: {
1213				currentstate,
1214				action: 'wpforo_user_ban',
1215				_wpfnonce: wpforo['nonces']['wpforo_user_ban'],
1216			},
1217		}).done(function (response) {
1218			if (response.success) {
1219				wpforo_setAttr($this, 'data-currentstate', response.data['currentstate']);
1220				var label = $this.data((response.data['currentstate'] ? 'active_label' : 'inactive_label'));
1221				wpforo_setAttr($this, 'wpf-tooltip', label);
1222			}
1223			wpforo_notice_show(response.data['notice']);
1224			
1225			wpforo_trigger_custom_event(document, 'wpforo_user_ban', { response });
1226		}).always(function () {
1227			wpforo_load_hide();
1228			$this.removeClass('wpf-processing');
1229		});
1230	});
1231	
1232	function wpforo_activate_revision_action_buttons (form) {
1233		var rev_saved = $('.wpforo_revision_saved', form);
1234		if (rev_saved.is(':visible')) {
1235			rev_saved.fadeOut(1000, function () {
1236				var save_revision = $('.wpforo_save_revision', form);
1237				save_revision.show();
1238				
1239				if (wpforo.revision_options.is_draft_on && parseInt(wpforo.revision_options.auto_draft_interval) && !save_revision.data('auto_draft')) {
1240					setInterval(function () {
1241						save_revision.trigger('click');
1242					}, wpforo.revision_options.auto_draft_interval);
1243					save_revision.data('auto_draft', true);
1244				}
1245			});
1246		}
1247	}
1248	
1249	function wpforo_deactivate_revision_action_buttons (form) {
1250		$('.wpforo_revision_saved', form).show();
1251		$('.wpforo_save_revision', form).hide();
1252	}
1253	
1254	function wpforo_content_changed () {
1255		var form = $('form[data-textareaid="' + wpforo_editor.get_active_textareaid() + '"]');
1256		if (wpforo_editor.get_stats().has_content) {
1257			wpforo_activate_revision_action_buttons(form);
1258			$('.wpforo_post_preview', form).removeClass('wpf-disabled');
1259		} else {
1260			wpforo_deactivate_revision_action_buttons(form);
1261			$('.wpforo_post_preview', form).addClass('wpf-disabled');
1262		}
1263	}
1264	
1265	function wpforo_content_ctrl_s () {
1266		$('form[data-textareaid="' + wpforo_editor.get_active_textareaid() + '"] .wpforo_save_revision').trigger('click');
1267	}
1268	
1269	wpforo_wrap.on('input propertychange', 'form[data-textareaid] textarea', function (e) {
1270		wpforo_trigger_custom_event(document, 'wpforo_textarea_content_changed', e);
1271	});
1272	
1273	document.addEventListener('wpforo_tinymce_content_changed', wpforo_content_changed);
1274	document.addEventListener('wpforo_textarea_content_changed', wpforo_content_changed);
1275	document.addEventListener('wpforo_tinymce_ctrl_s', wpforo_content_ctrl_s);
1276	document.addEventListener('wpforo_textarea_ctrl_s', wpforo_content_ctrl_s);
1277	
1278	wpforo_tags_suggest();
1279	document.addEventListener('wpforo_topic_portable_form', function (e) {
1280		wpforo_tags_suggest();
1281		window.wpforo_fix_form_data_attributes();
1282		var f = e.detail;
1283		if (f && f.length) {
1284			var t = $('[type="text"][required]', f);
1285			if (t.length && t.val().length) {
1286				wpforo_tinymce_initializeIt('[data-wpforoeditor="tinymce"]');
1287			} else {
1288				wpforo_tinymce_initializeIt('[data-wpforoeditor="tinymce"]', true);
1289				t.trigger('focus');
1290			}
1291		}
1292	});
1293	
1294	wpforo_wrap.on('click', '.wpforo-rcn-wrap .wpforo-rcn-dismiss-button:not(.wpf-processing)', function () {
1295		var $this = $(this);
1296		$this.addClass('wpf-processing');
1297		wpforo_load_show();
1298		var wrap = $(this).closest('.wpforo-rcn-wrap');
1299		$.ajax({
1300			type: 'POST',
1301			data: {
1302				backend: 0,
1303				action: 'wpforo_dissmiss_recaptcha_note',
1304			},
1305		}).done(function (response) {
1306			if (response.success) {
1307				wrap.remove();
1308				wpforo_notice_show('done', 'success');
1309			}
1310			
1311			wpforo_trigger_custom_event(document, 'wpforo_dissmiss_recaptcha_note', { response });
1312		}).always(function () {
1313			wpforo_load_hide();
1314			$this.removeClass('wpf-processing');
1315		});
1316	});
1317	
1318	wpforo_wrap.on('click', '.wpf-admincp .wpf-acp-toggle:not(.wpf-processing)', function () {
1319		var $this = $(this);
1320		$this.addClass('wpf-processing');
1321		var wrap = $this.closest('.wpf-admincp');
1322		$('.wpf-acp-body', wrap).slideToggle(function () {
1323			$('.fas', $this).toggleClass('fa-minus-square fa-plus-square');
1324			var toggle_status = $(this).is(':visible') ? 'open' : 'close';
1325			$.ajax({
1326				type: 'POST',
1327				data: {
1328					toggle_status: toggle_status,
1329					action: 'wpforo_acp_toggle',
1330					_wpfnonce: wpforo['nonces']['wpforo_acp_toggle'],
1331				},
1332			}).always(function () {
1333				$this.removeClass('wpf-processing');
1334			});
1335		});
1336	});
1337	
1338	/* -- #################################################### -- */
1339	
1340	/* image adjust and upload  from frontend */
1341	
1342	function processfile (file, max_width, max_height, quality, callback) {
1343		if (!(/image/i).test(file.type)) {
1344			alert('File ' + file.name + ' is not an image.');
1345			return false;
1346		}
1347		
1348		// read the files
1349		var reader = new FileReader();
1350		reader.readAsArrayBuffer(file);
1351		
1352		reader.onload = function (event) {
1353			// blob stuff
1354			var blob = new Blob([event.target.result]); // create blob...
1355			window.URL = window.URL || window.webkitURL;
1356			var blobURL = window.URL.createObjectURL(blob); // and get its URL
1357			
1358			// helper Image object
1359			var image = new Image();
1360			image.src = blobURL;
1361			//preview.appendChild(image); // preview commented out, I am using the canvas instead
1362			image.onload = function () {
1363				// have to wait till it's loaded
1364				var resized = resizeMe(image, max_width, max_height, quality); // send it to canvas
1365				callback(resized);
1366			};
1367		};
1368	}
1369	
1370	// === RESIZE ====
1371	function resizeMe (img, max_width, max_height, quality) {
1372		var canvas = document.createElement('canvas');
1373		var width = img.width;
1374		var height = img.height;
1375		
1376		// calculate the width and height, constraining the proportions
1377		if (width > height) {
1378			if (width > max_width) {
1379				//height *= max_width / width;
1380				height = Math.round(height *= max_width / width);
1381				width = max_width;
1382			}
1383		} else {
1384			if (height > max_height) {
1385				//width *= max_height / height;
1386				width = Math.round(width *= max_height / height);
1387				height = max_height;
1388			}
1389		}
1390		
1391		// resize the canvas and draw the image data into it
1392		canvas.width = width;
1393		canvas.height = height;
1394		var ctx = canvas.getContext('2d');
1395		ctx.drawImage(img, 0, 0, width, height);
1396		
1397		return canvas.toDataURL('image/jpeg', quality); // get the data from canvas as 70% JPG (can be also PNG, etc.)
1398	}
1399	
1400	function OpenFileDialog (accept, callback) {
1401		// this function must be called from  a user
1402		// activation event (ie an onclick event)
1403		
1404		// Create an input element
1405		var inputElement = document.createElement('input');
1406		
1407		// Set its type to file
1408		inputElement.type = 'file';
1409		
1410		// Set accept to the file types you want the user to select.
1411		// Include both the file extension and the mime type
1412		inputElement.accept = accept;
1413		
1414		// set onchange event to call callback when user has selected file
1415		inputElement.addEventListener('change', callback);
1416		
1417		// dispatch a click event to open the file dialog
1418		inputElement.dispatchEvent(new MouseEvent('click'));
1419	}
1420	
1421	wpforo_wrap.on('click', '.wpforo-profile .wpforo-profile-head .wpf-edit-cover:not(.wpf-processing)', function (e) {
1422		if (e.target.dataset['action'] === 'editcover') {
1423			var options = $('.wpf-edit-cover-options', $(this));
1424			options.css('display', (options.is(':visible') ? 'none' : 'flex'));
1425		}
1426	});
1427	
1428	wpforo_wrap.on('click', '.wpforo-profile .wpforo-profile-head .wpf-edit-cover .wpf-upload-cover:not(.wpf-processing)', function () {
1429		if (!(window.File && window.FileReader && window.FileList && window.Blob)) {
1430			alert('The File APIs are not fully supported in this browser.');
1431			return false;
1432		}
1433		var that = $(this);
1434		that.closest('.wpf-edit-cover-options').hide();
1435		OpenFileDialog('image/png,image/jpg,image/jpeg,image/gif', function () {
1436			if (this.files.length) {
1437				that.addClass('wpf-processing');
1438				wpforo_load_show('Uploading...');
1439				processfile(this.files[0], 1120, 460, 0.7, function (imageblob) {
1440					$wpf.ajax({
1441						type: 'POST',
1442						data: {
1443							image_blob: imageblob,
1444							action: 'wpforo_profile_cover_upload',
1445							_wpfnonce: wpforo['nonces']['wpforo_profile_cover_upload'],
1446						},
1447					}).done(function () {
1448						that.closest('.wpforo-profile-head').css('background-image', 'url(\'' + imageblob + '\')');
1449						wpforo_trigger_custom_event(document, 'wpforo_profile_cover_upload', { imageblob });
1450					}).always(function () {
1451						that.removeClass('wpf-processing');
1452						wpforo_load_hide();
1453					});
1454				});
1455			}
1456		});
1457	});
1458	
1459	wpforo_wrap.on('click', '.wpforo-profile .wpforo-profile-head .wpf-edit-cover .wpf-delete-cover:not(.wpf-processing)', function () {
1460		var that = $(this);
1461		that.closest('.wpf-edit-cover-options').hide();
1462		that.addClass('wpf-processing');
1463		wpforo_load_show('Uploading...');
1464		$wpf.ajax({
1465			type: 'POST',
1466			data: {
1467				action: 'wpforo_profile_cover_delete',
1468				_wpfnonce: wpforo['nonces']['wpforo_profile_cover_delete'],
1469			},
1470		}).done(function (r) {
1471			if (r.success) that.closest('.wpforo-profile-head').css('background-image', 'url(\'' + r.data['background_url'] + '\')');
1472			wpforo_trigger_custom_event(document, 'wpforo_profile_cover_delete', { r });
1473		}).always(function () {
1474			that.removeClass('wpf-processing');
1475			wpforo_load_hide();
1476		});
1477	});
1478	
1479	wpforo_wrap.on('click', '.wpforo-profile .wpforo-follow-user:not(.wpf-processing)', function () {
1480		if (document.body.classList.contains('logged-in')) {
1481			var that = $(this);
1482			var userid = parseInt(that.data('userid'));
1483			var stat = !parseInt(that.data('stat'));
1484			that.addClass('wpf-processing');
1485			wpforo_load_show();
1486			$wpf.ajax({
1487				type: 'POST',
1488				data: {
1489					userid,
1490					stat: (stat ? 1 : 0),
1491					action: 'wpforo_follow_unfollow_user',
1492					_wpfnonce: wpforo['nonces']['wpforo_follow_unfollow_user'],
1493				},
1494			}).done(function (r) {
1495				if (r.success) {
1496					that.data('stat', r.data['stat']);
1497					that.prop('stat', r.data['stat']);
1498					that.attr('stat', r.data['stat']);
1499					$('.wpforo-follow-user-label', that).text(r.data['phrase']);
1500					$('.wpforo-follow-user-followers-count', that.closest('.wpforo-follow-wrap')).text(r.data['followers_count']);
1501				}
1502				wpforo_notice_show(r.data['notice'], (r.success ? 'success' : 'error'));
1503				
1504				wpforo_trigger_custom_event(document, 'wpforo_follow_unfollow_user', { stat, r });
1505			}).always(function () {
1506				that.removeClass('wpf-processing');
1507				wpforo_load_hide();
1508			});
1509		} else {
1510			wpforo_notice_show(wpforo['notice']['login_or_register']);
1511		}
1512	});
1513	
1514	wpforo_wrap.on('click', '.wpforo-post-head .wpf-pb-more', function () {
1515		var that = $(this);
1516		var wrap = that.closest('.wpforo-post-head');
1517		var topicid = parseInt(that.closest('.wpforo-topic-head-wrap[data-topicid]').data('topicid'));
1518		
1519		if (!isNaN(topicid) && topicid) {
1520			
1521			that.find('span > svg').toggle();
1522			
1523			var more = $('.wpf-topic-more-info', wrap);
1524			var already_loaded = !!more.html().trim();
1525			if (!(!already_loaded && more.is(':visible'))) more.toggle();
1526			
1527			if (!already_loaded) {
1528				more.addClass('wpforo-section-loading');
1529				
1530				$wpf.ajax({
1531					type: 'POST',
1532					data: {
1533						topicid,
1534						action: 'wpforo_get_topic_head_more_info',
1535						_wpfnonce: wpforo['nonces']['wpforo_get_topic_head_more_info'],
1536					},
1537				}).done(function (r) {
1538					if (r.success) {
1539						more.html(r.data['html']);
1540					}
1541					wpforo_trigger_custom_event(document, 'wpforo_get_topic_head_more_info', { r });
1542				}).always(function () {
1543					more.removeClass('wpforo-section-loading');
1544				});
1545			}
1546			
1547			var ico = $('i.fa-chevron-up, i.fa-chevron-down', that);
1548			var label = $('span', that);
1549			if (more.is(':visible')) {
1550				ico.removeClass('fa-chevron-down').addClass('fa-chevron-up');
1551			} else {
1552				ico.removeClass('fa-chevron-up').addClass('fa-chevron-down');
1553			}
1554		}
1555	});
1556	
1557	var topic_head_more_info = $('.wpforo-topic-head-wrap .wpf-topic-more-info', wpforo_wrap);
1558	if (topic_head_more_info.is(':visible') && !topic_head_more_info.html().trim()) {
1559		$('.wpforo-post-head .wpf-pb-more', wpforo_wrap).trigger('click');
1560	}
1561	
1562	wpforo_wrap.on('click', '.wpf-tmi-overview .wpf-action.wpf-topic-overview-load-more:not(.wpf-processing)', function () {
1563		var that = $(this);
1564		var wrap = that.closest('.wpf-tmi-overview');
1565		var tree = $('.wpf-topic-overview-tree', wrap);
1566		var nomore = parseInt(tree.data('nomore'));
1567		if (!nomore) {
1568			var topicid = parseInt(that.closest('.wpforo-topic-head-wrap[data-topicid]').data('topicid'));
1569			if (!isNaN(topicid)) {
1570				that.addClass('wpf-processing');
1571				wpforo_load_show();
1572				
1573				var chunksize = parseInt(tree.data('chunksize'));
1574				var offset = parseInt(tree.data('offset'));
1575				if (isNaN(chunksize)) chunksize = 5;
1576				if (isNaN(offset)) offset = 0;
1577				offset = offset + chunksize;
1578				
1579				$wpf.ajax({
1580					type: 'POST',
1581					data: {
1582						topicid,
1583						chunksize,
1584						offset,
1585						action: 'wpforo_get_topic_overview_chunk',
1586						_wpfnonce: wpforo['nonces']['wpforo_get_topic_overview_chunk'],
1587					},
1588				}).done(function (r) {
1589					if (r.success) {
1590						var nomore = r.data['nomore'] ? 1 : 0;
1591						tree.append(r.data['html']);
1592						
1593						wpforo_setAttr(tree, 'data-offset', offset);
1594						wpforo_setAttr(tree, 'data-chunksize', chunksize);
1595						wpforo_setAttr(tree, 'data-nomore', nomore);
1596					}
1597					wpforo_trigger_custom_event(document, 'wpforo_get_topic_overview_chunk', { r });
1598				}).always(function () {
1599					that.removeClass('wpf-processing');
1600					wpforo_load_hide();
1601				});
1602			}
1603		}
1604	});
1605	
1606	wpforo_wrap.on('click', '.wpf-tmi-overview .wpf-topic-overview-tree .wpf-tmi-item .wpf-link.wpf-tmi-item-body-excerpt:not(.wpf-processing)', function () {
1607		var $this = $(this);
1608		var postid = parseInt($this.data('postid'));
1609		if (!isNaN(postid)) {
1610			if (!wpforo['overview']) wpforo['overview'] = [];
1611			var overview = wpforo['overview'][postid];
1612			if (!overview) {
1613				$this.addClass('wpf-processing');
1614				wpforo_load_show();
1615				$.ajax({
1616					type: 'POST',
1617					data: {
1618						postid,
1619						action: 'wpforo_get_overview',
1620						_wpfnonce: wpforo['nonces']['wpforo_get_overview'],
1621					},
1622				}).done(function (r) {
1623					if (r.success) {
1624						wpforo['overview'][postid] = r.data;
1625						wpforo_dialog_show(r.data['title'], r.data['content'], '50%', '350px');
1626					}
1627					wpforo_trigger_custom_event(document, 'wpforo_get_overview', { r });
1628				}).always(function () {
1629					$this.removeClass('wpf-processing');
1630					wpforo_load_hide();
1631				});
1632			} else {
1633				wpforo_dialog_show(overview['title'], overview['content'], '50%', '350px');
1634			}
1635		}
1636	});
1637	
1638	wpforo_wrap.on('click', '.wpf-action.wpforo-bookmark:not(.wpf-processing), .wpf-action.wpforo-unbookmark:not(.wpf-processing)', {}, function () {
1639		var $this = $(this);
1640		var wrap = $this.closest('.post-wrap[data-postid], .reply-wrap[data-postid], .comment-wrap[data-postid]');
1641		if (wrap.length) {
1642			var postid = parseInt(wrap.data('postid'));
1643			if (!isNaN(postid)) {
1644				$this.addClass('wpf-processing');
1645				var _action = ($this.hasClass('wpforo-bookmark') ? 'wpforo_bookmark' : 'wpforo_unbookmark');
1646				$.ajax({
1647					type: 'POST',
1648					data: {
1649						postid,
1650						action: _action,
1651						_wpfnonce: wpforo['nonces'][_action],
1652					},
1653				}).done(function (r) {
1654					if (r.success) $this.replaceWith(r.data['button']);
1655					wpforo_trigger_custom_event(document, _action, { r });
1656				}).always(function () {
1657					$this.removeClass('wpf-processing');
1658				});
1659			}
1660		}
1661	});
1662	
1663	wpforo_wrap.on('click', '.sbn-action .wpf-sbn-unsbscrb:not(.wpf-processing)', {}, function () {
1664		var $this = $(this);
1665		var wrap = $this.closest('.wpforo-sb');
1666		var key = $this.data('key');
1667		var boardid = $this.data('boardid');
1668		if (key) {
1669			$this.addClass('wpf-processing');
1670			$.ajax({
1671				type: 'POST',
1672				data: {
1673					key,
1674					boardid,
1675					action: 'wpforo_unsubscribe',
1676					_wpfnonce: wpforo['nonces']['wpforo_unsubscribe'],
1677				},
1678			}).done(function (r) {
1679				if (r.success) wrap.remove();
1680				wpforo_notice_show(r.data['notice'], (r.success ? 'success' : 'error'));
1681				wpforo_trigger_custom_event(document, 'wpforo_unsubscribe', { r });
1682			}).always(function () {
1683				$this.removeClass('wpf-processing');
1684			});
1685		}
1686	});
1687	
1688	function action_get_member_template ($this, wrap, href) {
1689		if ($this && $this.length && wrap && wrap.length && href) {
1690			$this.addClass('wpf-processing');
1691			wpforo_load_show();
1692			$.ajax({
1693				type: 'POST',
1694				data: {
1695					href,
1696					'action': 'wpforo_get_member_template',
1697					_wpfnonce: wpforo['nonces']['wpforo_get_member_template'],
1698				},
1699			}).done(function (r) {
1700				if (r.success) {
1701					$this.siblings().removeClass('wpf-active');
1702					$this.addClass('wpf-active');
1703					wrap.html(r.data['html']);
1704				}
1705				wpforo_trigger_custom_event(document, 'wpforo_get_member_template', { r });
1706			}).always(function () {
1707				$this.removeClass('wpf-processing');
1708				wpforo_load_hide();
1709			});
1710		}
1711	}
1712	
1713	wpforo_wrap.on('click', '.wpf-member-template-link.wpf-ajax-link:not(.wpf-processing)', {}, function (e) {
1714		e.preventDefault();
1715		var $this = $(this);
1716		var wrap = $this.closest('.wpf-profile-body');
1717		var href = e.target.href;
1718		action_get_member_template($this, wrap, href);
1719	});
1720	
1721	wpforo_wrap.on('click', '.wpf-member-template-link.wpf-ajax-link .wpf-navi .wpf-navi-dropdown', {}, function () {
1722		this.onchange = false;
1723	});
1724	
1725	wpforo_wrap.on('change', '.wpf-member-template-link.wpf-ajax-link .wpf-navi .wpf-navi-dropdown', {}, function (e) {
1726		var $this = $(this).closest('.wpf-member-template-link.wpf-ajax-link');
1727		var wrap = $this.closest('.wpf-profile-body');
1728		action_get_member_template($this, wrap, e.target.value);
1729	});
1730	
1731	let ts_input_old_value = '';
1732	let ts_request;
1733	wpforo_wrap.on('input propertychange', '.wpf-topic-create[data-suggestion="true"] form .wpf-field-name-title input[type="text"]', {}, function () {
1734		if ($('input[name=wpfaction][value=topic_add]', $(this).closest('form')).length) {
1735			if (ts_request && ts_request.readyState !== 4) ts_request.abort();
1736			setTimeout(() => {
1737				const $this = $(this);
1738				let input_value = $this.val().trim();
1739				if (input_value.length && ts_input_old_value !== input_value) {
1740					wpforo_load_show();
1741					ts_request = $.ajax({
1742						type: 'POST',
1743						data: {
1744							title: input_value,
1745							action: 'wpforo_search_existed_topics',
1746							_wpfnonce: wpforo['nonces']['wpforo_search_existed_topics'],
1747						},
1748					}).done(function (r) {
1749						const tlist = document.createElement('div');
1750						tlist.classList.add('wpf-suggested-topics-list');
1751						$this.siblings('.wpf-suggested-topics-list').remove();
1752						$this.after(tlist);
1753						if (r.success) {
1754							tlist.innerHTML = '<div class="wpf-suggested-topics-title">' + wpforo_phrase('Discussions that may already have the information you are looking for') + ' &nbsp;<i class="fa-solid fa-angles-down"></i></div>';
1755							r.data.forEach(function (topic) {
1756								const node = document.createElement('div');
1757								node.classList.add('wpf-suggested-topic-node');
1758								node.innerHTML = `<i class="fa-solid fa-caret-right"></i>&nbsp; <a href="${topic['url']}" target="_blank">${topic['title']}</a>`;
1759								tlist.append(node);
1760							});
1761						}
1762						wpforo_trigger_custom_event(document, 'wpforo_search_existed_topics', { r });
1763					}).always(function () {
1764						wpforo_load_hide();
1765					});
1766					
1767					ts_input_old_value = input_value;
1768				}
1769			}, 700);
1770			wpforo_load_hide();
1771		}
1772	});
1773	
1774	wpforo_wrap.on('focusout', '.wpf-topic-create form .wpf-field-name-title', {}, function () {
1775		setTimeout(function () {
1776			$('.wpf-topic-create form .wpf-field-name-title .wpf-suggested-topics-list').remove();
1777		}, 100);
1778	});
1779	
1780	wpforo_wrap.on('click', '.wpforo-user-actions .wpforo-user-tools .wpf-ab-delete', {}, function (e) {
1781		const a = $(this).closest('a');
1782		if (a.length) {
1783			const action_url = a[0].href;
1784			if (action_url) {
1785				e.preventDefault();
1786				const pwd = prompt('Please confirm the account deletion by entering your account password.');
1787				if (pwd) {
1788					wpforo_load_show();
1789					$.ajax({
1790						type: 'POST',
1791						data: {
1792							pwd: pwd,
1793							action: 'wpforo_confirm_current_user_password',
1794							_wpfnonce: wpforo['nonces']['wpforo_confirm_current_user_password'],
1795						},
1796					}).done((r) => {
1797						if (r.success) {
1798							window.location.assign(action_url + '&pwd=' + pwd);
1799						} else {
1800							wpforo_notice_show('The password you entered is incorrect.', 'error');
1801						}
1802					}).always(function () {
1803						wpforo_load_hide();
1804					});
1805				} else {
1806					wpforo_notice_show('To permanently delete your account from this website, please enter your password for confirmation.', 'error');
1807				}
1808			}
1809		}
1810	});
1811	
1812});
1813
1814function wpforo_init_phrases () {
1815	if ($wpf.active === 0) {
1816		$wpf.ajax({
1817			url: wpforo.ajax_url,
1818			type: 'POST',
1819			dataType: 'json',
1820			async: false,
1821			data: {
1822				action: 'wpforo_get_phrases',
1823				_wpfnonce: wpforo['nonces']['wpforo_get_phrases'],
1824			},
1825		}).done(function (r) {
1826			window.wpforo_phrases = r;
1827			wpforo_trigger_custom_event(document, 'wpforo_get_phrases', { r });
1828		});
1829	}
1830}
1831
1832function wpforo_ucwords (str) {
1833	return (str + '').replace(/^([a-z])|\s+([a-z])/, function ($1) {
1834		return $1.toUpperCase();
1835	});
1836}
1837
1838function wpforo_topic_tools_tab_load () {
1839	var active_tab = $wpf('#wpf_moderation_tools').find('.wpf-tool-tab.wpf-tt-active');
1840	if (active_tab.length) {
1841		var active_tab_id = active_tab.attr('id');
1842		if (active_tab_id && $wpf.active === 0) {
1843			wpforo_notice_hide();
1844			$wpf('#wpf_tool_tab_content_wrap').html('<i class="fas fa-spinner fa-spin wpf-icon-spinner"></i>');
1845			$wpf.ajax({
1846				type: 'POST',
1847				data: {
1848					active_tab_id: active_tab_id,
1849					action: 'wpforo_active_tab_content_ajax',
1850					_wpfnonce: wpforo['nonces']['wpforo_active_tab_content_ajax'],
1851				},
1852			}).done(function (response) {
1853				if (response) {
1854					$wpf('#wpf_tool_tab_content_wrap').html(response);
1855					$wpf('#wpf_moderation_tools').slideDown(400, 'linear');
1856				}
1857				wpforo_load_hide();
1858				wpforo_trigger_custom_event(document, 'wpforo_active_tab_content_ajax', { response });
1859			});
1860		}
1861	}
1862}
1863
1864function wpforo_tags_suggest () {
1865	var wpf_tags = $wpf('.wpf-tags');
1866	wpf_tags.suggest(
1867		wpforo.ajax_url + (/\?/.test(wpforo.ajax_url) ? '&' : '?') + 'action=wpforo_tag_search',
1868		{
1869			multiple: true,
1870			multipleSep: ',',
1871			delay: 1000,
1872			minchars: 3,
1873			resultsClass: 'wpf_ac_results',
1874			selectClass: 'wpf_ac_over',
1875			matchClass: 'wpf_ac_match',
1876			onSelect: function () {},
1877		},
1878	);
1879	$wpf('.wpf_ac_results').on('blur', function () {
1880		wpf_tags.removeClass('wpf-ac-loading');
1881	});
1882	wpf_tags.on('blur', function () {
1883		wpf_tags.removeClass('wpf-ac-loading');
1884	});
1885	wpf_tags.on('keydown',
1886		function (e) {
1887			var tags = wpf_tags.val();
1888			if (tags.length >= 1) {
1889				switch (e.code) {
1890					case 'ArrowUp':  // up
1891					case 'ArrowDown':  // down
1892					case 'Backspace':   // backspace
1893					case 'Tab':   // tab
1894					case 'Enter':  // return
1895					case 'NumpadEnter':  // return
1896					case 'Escape':  // escape
1897					case 'Space':  // space
1898					case 'Comma': // comma
1899						wpf_tags.removeClass('wpf-ac-loading');
1900						break;
1901					default:
1902						wpf_tags.addClass('wpf-ac-loading');
1903				}
1904			}
1905			setTimeout(function () { wpf_tags.removeClass('wpf-ac-loading'); }, 1000);
1906		},
1907	);
1908}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.