PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 1.3.2
Forumax – AI Powered Advanced Community Forum Plugin v1.3.2
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / assets / admin / js / admin-main.js

admin-main.js in Forumax – AI Powered Advanced Community Forum Plugin 1.3.2, at assets/admin/js/admin-main.js

484 lines 14.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 'use strict';
3
4 /*------------ Cookie functions and color js ------------*/
5 function createCookie(name, value, days) {
6 var expires = '';
7 if (days) {
8 var date = new Date();
9 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
10 expires = '; expires=' + date.toUTCString();
11 }
12 document.cookie = name + '=' + value + expires + '; path=/';
13 }
14
15 function readCookie(name) {
16 var nameEQ = name + '=';
17 var ca = document.cookie.split(';');
18 for (var i = 0; i < ca.length; i++) {
19 var c = ca[i];
20 while (c.charAt(0) == ' ') c = c.substring(1, c.length);
21 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
22 }
23 return null;
24 }
25
26 function eraseCookie(name) {
27 createCookie(name, '', -1);
28 }
29
30 var prefersDark =
31 window.matchMedia &&
32 window.matchMedia('(prefers-color-scheme: dark)').matches;
33 var selectedNightTheme = readCookie('body_dark');
34
35 if (
36 selectedNightTheme == 'true' ||
37 (selectedNightTheme === null && prefersDark)
38 ) {
39 applyNight();
40 $('.dark_mode_switcher').prop('checked', true);
41 } else {
42 applyDay();
43 $('.dark_mode_switcher').prop('checked', false);
44 }
45
46 function applyNight() {
47 if ($('.js-darkmode-btn .ball').length) {
48 $('.js-darkmode-btn .ball').css('left', '45px');
49 }
50 $('body').addClass('body_dark');
51 }
52
53 function applyDay() {
54 if ($('.js-darkmode-btn .ball').length) {
55 $('.js-darkmode-btn .ball').css('left', '4px');
56 }
57 $('body').removeClass('body_dark');
58 }
59
60 $('.dark_mode_switcher').change(function () {
61 if ($(this).is(':checked')) {
62 applyNight();
63 createCookie('body_dark', true, 999);
64 } else {
65 applyDay();
66 createCookie('body_dark', false, 999);
67 }
68 });
69
70 // Filter Select
71 $('select').niceSelect();
72
73 // Sidebar Tabs [COOKIE]
74 $(document).on('click', '.tab-menu .easydocs-navitem', function () {
75 const target = $(this).attr('data-rel');
76 const $siblings = $(this).siblings();
77
78 if (!$(this).hasClass('is-active')) {
79 $siblings.removeClass('is-active');
80 $(this).addClass('is-active');
81
82 $('#' + target)
83 .fadeIn('slow')
84 .siblings('.easydocs-tab')
85 .hide();
86
87 createCookie('eazydocs_doc_current_tab', target, 999);
88 }
89 });
90
91 // Restore last active tab
92 function keep_last_active_doc_tab() {
93 const lastTab = readCookie('eazydocs_doc_current_tab');
94 if (lastTab) {
95 const $tab = $(`.tab-menu .easydocs-navitem[data-rel="${lastTab}"]`);
96 if (!$tab.hasClass('is-active')) {
97 $tab.siblings().removeClass('is-active');
98 $tab.addClass('is-active');
99
100 $('.easydocs-tab-content .easydocs-tab').removeClass('tab-active');
101 $(`#${lastTab}`).addClass('tab-active');
102 }
103 }
104 }
105 keep_last_active_doc_tab();
106
107 $('.tab-menu .easydocs-navitem .parent-delete').on('click', function () {
108 return false;
109 });
110
111 $(document).ready(function () {
112
113 if ( $('#bbpc-search').length ) {
114 $('#bbpc-search').on('keyup', function () {
115 var value = $(this).val().toLowerCase();
116 $('.easydocs-accordion-item').filter(function () {
117 $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
118 });
119 });
120
121 // Dropdown Classic UI Filter
122 let bbpc_classic_ui = document.getElementById('bbpc_classic_ui');
123
124 function swithToLink() {
125 window.location.href = this.value;
126 }
127
128 bbpc_classic_ui.onchange = swithToLink;
129 }
130 })
131
132 $(document).ready(function (e) {
133 function t(t) {
134 e(t).bind('click', function (t) {
135 t.preventDefault();
136 e(this).parent().fadeOut();
137 });
138 }
139
140 e('.header-notify-icon').click(function () {
141 var t = e(this)
142 .parents('.easydocs-notification')
143 .children('.easydocs-dropdown')
144 .is(':hidden');
145 e('.easydocs-notification .easydocs-dropdown').hide();
146 e('.easydocs-notification .header-notify-icon').removeClass('active');
147 if (t) {
148 e(this)
149 .parents('.easydocs-notification')
150 .children('.easydocs-dropdown')
151 .toggle()
152 .parents('.easydocs-notification')
153 .children('.header-notify-icon')
154 .addClass('active');
155 }
156 });
157 e(document).bind('click', function (t) {
158 var n = e(t.target);
159 if (!n.parents().hasClass('easydocs-notification'))
160 e('.easydocs-notification .easydocs-dropdown').hide();
161 });
162 e(document).bind('click', function (t) {
163 var n = e(t.target);
164 if (!n.parents().hasClass('easydocs-notification'))
165 e('.easydocs-notification .header-notify-icon').removeClass('active');
166 });
167
168 // CREATE FORUM
169 function create_forum() {
170 $(document).on('click', '#bbpc-forum', function (e) {
171 e.preventDefault();
172 Swal.fire({
173 title: bbp_core_local_object.create_forum_title,
174 input: 'text',
175 showCancelButton: true,
176 inputAttributes: {
177 name: 'bbp_forum_title',
178 },
179 }).then((result) => {
180 if (result.value) {
181 $.ajax({
182 url: bbp_core_local_object.ajaxurl,
183 type: 'POST',
184 data: {
185 action: 'bbp_create_forum',
186 bbp_forum_title: result.value,
187 bbpc_nonce: bbp_core_local_object.nonce
188 },
189 beforeSend: function () {
190 Swal.fire({
191 title: 'Creating Forum...',
192 icon: 'question',
193 allowOutsideClick: false,
194 showConfirmButton: true,
195 didOpen: () => {
196 Swal.showLoading();
197 },
198 });
199 },
200 success: function (response) {
201 if (response.success) {
202 location.reload();
203 } else {
204 Swal.fire({
205 title: 'Error!',
206 text: response.data,
207 icon: 'error',
208 });
209 }
210 },
211 error: function () {
212 Swal.fire({
213 title: 'Error!',
214 text: 'Something went wrong. Please try again.',
215 icon: 'error',
216 });
217 },
218 });
219 }
220 });
221 });
222 }
223 create_forum();
224
225 // CREATE TOPIC
226 function create_topic() {
227 $(document).on('click', '#bbpc-topic', function (e) {
228 e.preventDefault();
229 let forumID = $(this).attr('bbp_forum_id');
230 Swal.fire({
231 title: bbp_core_local_object.create_topic_title,
232 input: 'text',
233 showCancelButton: true,
234 inputAttributes: {
235 name: 'bbp_topic_title',
236 },
237 }).then((result) => {
238 if (result.value) {
239 $.ajax({
240 url: bbp_core_local_object.ajaxurl,
241 type: 'POST',
242 data: {
243 action: 'bbp_create_topic',
244 bbp_topic_title: result.value,
245 forum_id: forumID,
246 bbpc_nonce: bbp_core_local_object.nonce
247 },
248 beforeSend: function () {
249 Swal.fire({
250 title: 'Creating Topic...',
251 icon: 'question',
252 allowOutsideClick: false,
253 showConfirmButton: true,
254 didOpen: () => {
255 Swal.showLoading();
256 },
257 });
258 },
259 success: function (response) {
260 if (response.success) {
261 location.reload();
262 } else {
263 Swal.fire({
264 title: 'Error!',
265 text: response.data,
266 icon: 'error',
267 });
268 }
269 },
270 error: function () {
271 Swal.fire({
272 title: 'Error!',
273 text: 'Something went wrong. Please try again.',
274 icon: 'error',
275 });
276 },
277 });
278 }
279 });
280 });
281 }
282 create_topic();
283
284 // DELETE FORUM
285 function delete_forum() {
286 $('.forum-delete').on('click', function (e) {
287 e.preventDefault();
288 var forumID = $(this).attr('bbp_forum_id');
289 Swal.fire({
290 title: bbp_core_local_object.forum_delete_title,
291 text: bbp_core_local_object.forum_delete_desc,
292 icon: 'question',
293 showCancelButton: true,
294 confirmButtonColor: '#3085d6',
295 cancelButtonColor: '#d33',
296 confirmButtonText: 'Yes'
297 }).then((result) => {
298 if (result.value) {
299 $.ajax({
300 url: bbp_core_local_object.ajaxurl,
301 type: 'POST',
302 data: {
303 action: 'bbp_delete_forum',
304 forum_id: forumID,
305 bbpc_nonce: bbp_core_local_object.nonce
306 },
307 beforeSend: function () {
308 Swal.fire({
309 title: 'Deleting Forum...',
310 icon: 'question',
311 allowOutsideClick: false,
312 showConfirmButton: false,
313 didOpen: () => {
314 Swal.showLoading();
315 },
316 });
317 },
318 success: function (response) {
319 console.log(response);
320 if (response.success) {
321 location.reload();
322 } else {
323 console.log(response)
324 Swal.fire({
325 title: 'Error!',
326 text: response.data || 'Unexpected error occurred.',
327 icon: 'error',
328 });
329 }
330 },
331 error: function () {
332 Swal.fire({
333 title: 'Error!',
334 text: 'Something went wrong. Please try again.',
335 icon: 'error',
336 });
337 },
338 });
339 }
340 });
341 });
342 }
343 delete_forum();
344
345
346 // DELETE TOPIC
347 function delete_topic() {
348 $('.section-delete').on('click', function (e) {
349 e.preventDefault();
350 var topicID = $(this).attr('bbp_topic_id');
351 Swal.fire({
352 title: bbp_core_local_object.forum_delete_title,
353 text: bbp_core_local_object.topic_delete_desc,
354 icon: 'question',
355 showCancelButton: true,
356 confirmButtonColor: '#3085d6',
357 cancelButtonColor: '#d33',
358 confirmButtonText: 'Yes',
359 }).then((result) => {
360 if (result.value) {
361 $.ajax({
362 url: bbp_core_local_object.ajaxurl,
363 type: 'POST',
364 data: {
365 action: 'bbp_delete_topic',
366 topic_id: topicID,
367 bbpc_nonce: bbp_core_local_object.nonce
368 },
369 beforeSend: function () {
370 Swal.fire({
371 title: 'Deleting Topic...',
372 icon: 'question',
373 allowOutsideClick: false,
374 showConfirmButton: false,
375 didOpen: () => {
376 Swal.showLoading();
377 },
378 });
379 },
380 success: function (response) {
381 console.log(response);
382 if (response.success) {
383 location.reload();
384 } else {
385 console.log(response)
386 Swal.fire({
387 title: 'Error!',
388 text: response.data || 'Unexpected error occurred.',
389 icon: 'error',
390 });
391 }
392 },
393 error: function () {
394 Swal.fire({
395 title: 'Error!',
396 text: 'Something went wrong. Please try again.',
397 icon: 'error',
398 });
399 },
400 });
401 }
402 });
403 });
404 }
405
406 delete_topic();
407
408 // Notification pro alert
409 $('.easydocs-notification.bbp-core-pro-notification').on(
410 'click',
411 function (e) {
412 e.preventDefault();
413 let href = $(this).attr('href');
414 let assets = bbp_core_local_object.BBPC_ASSETS;
415 Swal.fire({
416 title: 'Notification is a Premium feature',
417 html:
418 '<span class="pro-notification-body-text">You need to Upgrade the Premium Version to use this feature</span><video height="400px" autoplay="autoplay" loop="loop" src="' +
419 assets +
420 '/videos/noti.mp4"></video>',
421 icon: false,
422 buttons: false,
423 dangerMode: true,
424 showCloseButton: true,
425 confirmButtonText:
426 '<a href="admin.php?page=bbp-core-pricing">Upgrade to Premium</a>',
427 footer:
428 '<a href="https://spider-themes.net/bbp-core/" target="_blank"> Learn More </a>',
429 customClass: {
430 title: 'upgrade-premium-heading',
431 confirmButton: 'upgrade-premium-button',
432 footer: 'notification-pro-footer-wrap',
433 },
434 confirmButtonColor: '#f1bd6c',
435 Borderless: true,
436 });
437 }
438 );
439 });
440
441 // Click pending replies count to show pending replies.
442 $('[click-target]').click(function () {
443 let id = $(this).attr('click-target');
444 $(`[click-target=${id}]`).toggleClass('active');
445 $(`[reply-target=${id}]`).toggle();
446 });
447
448 // Sidebar Tabs [COOKIE]
449 $(document).on('click', '[cookie-id]', function () {
450 let target = $(this).attr('cookie-id');
451 let item = `[cookie-id=${target}]`;
452 $('[cookie-id]').removeClass('is-active mixitup-control-active');
453 $(item).addClass('is-active mixitup-control-active');
454 $(target).fadeIn('slow').siblings('.easydocs-tab').hide();
455
456 let isActiveTab = $(this).hasClass('is-active');
457 if (isActiveTab === true) {
458 createCookie('bbpc_current_filter', target, 999);
459 }
460
461 return true;
462 });
463
464 $(document).ready(function () {
465 // Keep Last filter item active
466 function keepLastFilterActive() {
467 let bbpcLastActiveFilter = readCookie('bbpc_current_filter');
468 if (bbpcLastActiveFilter) {
469 // Tab item
470 $('[cookie-id]').removeClass('is-active mixitup-control-active');
471 $(`[cookie-id="${bbpcLastActiveFilter}"]`).click();
472 }
473 }
474
475 keepLastFilterActive();
476
477 });
478
479 })(jQuery);
480
481 function menuToggle() {
482 const toggleMenu = document.querySelector('.easydocs-dropdown');
483 toggleMenu.classList.toggle('is-active');
484 }