PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / trunk
Forumax – AI Powered Advanced Community Forum Plugin vtrunk
2.5.0 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 All 30 releases
bbp-core / assets / frontend / js / forum.js

forum.js in Forumax – AI Powered Advanced Community Forum Plugin trunk, at assets/frontend/js/forum.js

311 lines 12.0 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 $(window).on("load", function () {
5 $(".post-pagination > li:nth-child(1) > a").addClass("current");
6 $(".newest_posts").addClass("active-short");
7 forumax_forum.forumax_search(
8 "#search_field",
9 "#UserList .userlist",
10 ".current-user"
11 );
12 forumax_forum.forumax_search(
13 "#search_fields",
14 "#tagList .tagList",
15 ".frmx-dropdown-item"
16 );
17 forumax_forum.forumax_loading_forum();
18 forumax_forum.forumax_open_forum();
19 forumax_forum.forumax_sort_forum();
20 });
21
22 var forumax_forum = {
23 forumax_search: function (
24 search_field,
25 searchable_elements,
26 searchable_text_class
27 ) {
28 $(search_field).keyup(function (e) {
29 e.preventDefault();
30 var query = $(this).val().toLowerCase();
31 if (query) {
32 $.each($(searchable_elements), function () {
33 var title = $(this)
34 .find(searchable_text_class)
35 .text()
36 .toLowerCase();
37 if (title.indexOf(query) == -1) {
38 $(this).hide();
39 } else {
40 $(this).show();
41 }
42 });
43 } else {
44 $(searchable_elements).show();
45 }
46 });
47 },
48 forumax_auth_select: function () {
49 $(document).on("click", ".data-auth", function () {
50 var _this = $(this),
51 text = _this.text();
52 $(".UserList").html(text);
53 });
54 },
55 forumax_tag_select: function () {
56 $(document).on("click", ".data-tag", function () {
57 var _this = $(this),
58 text = _this.text();
59 $(".tagLista").html(text);
60 });
61 },
62 forumax_loading_forum: function () {
63 $(document).on("click", ".forumax-data", function () {
64 $(".forumax-data").removeClass("loading");
65 $(".close-ticket.reset-btn").addClass("reset-btn-active");
66 var _this = $(this),
67 _ajaxUrl = forumax_localize_script.ajaxurl,
68 _class = _this.addClass("loading selected"),
69 _a = "forumax_loading_post",
70 _n = forumax_localize_script.nonce,
71 _t = _this.data("type"),
72 _id = _this.data("id"),
73 _parent = _this.data("parent"),
74 _count = _this.data("count"),
75 data = {
76 type: _t,
77 action: _a,
78 nonce: _n,
79 a_t_id: _id,
80 count: _count,
81 parent: _parent,
82 };
83
84 if ($(this).hasClass("loading")) {
85 $.ajax({
86 url: _ajaxUrl,
87 method: "post",
88 data: data,
89 beforeSend: function () {
90 $(".load-forum").html(
91 "<div class='forum-loading'><div class='configure-border-1'><div class='configure-core'></div></div><div class='configure-border-2'><div class='configure-core'></div></div></div>"
92 );
93 },
94 success: function (response) {
95 $(".load-forum").html(response);
96 },
97 error: function () {
98 console.log("Oops! Something wrong, try again!");
99 },
100 });
101 }
102
103 return false;
104 });
105 },
106 forumax_open_forum: function () {
107 $(document).on("click", ".open-data", function () {
108 $(".open-data").removeClass("loading");
109 $(this).parent().removeClass("reset-btn-active");
110 $('.sort-by').removeClass('active-short');
111 $('.newest_posts').addClass('active-short');
112 var _this = $(this),
113 _ajaxUrl = forumax_localize_script.ajaxurl,
114 _class = _this.addClass("loading selected"),
115 _a = "forumax_open_post",
116 _n = forumax_localize_script.nonce,
117 _t = _this.data("type"),
118 _id = _this.data("id"),
119 _count = _this.data("count"),
120 _parent = _this.data("parent"),
121 data = {
122 type: _t,
123 action: _a,
124 nonce: _n,
125 a_t_id: _id,
126 count: _count,
127 parent: _parent,
128 };
129
130 if ($(this).hasClass("loading")) {
131 $.ajax({
132 url: _ajaxUrl,
133 method: "post",
134 data: data,
135 beforeSend: function () {
136 $(".load-forum").html(
137 "<div class='forum-loading'><div class='configure-border-1'><div class='configure-core'></div></div><div class='configure-border-2'><div class='configure-core'></div></div></div>"
138 );
139 },
140 success: function (response) {
141 $(".load-forum").html(response);
142 },
143 error: function () {
144 console.log("Oops! Something wrong, try again!");
145 },
146 });
147 }
148
149 return false;
150 });
151 },
152 forumax_sort_forum: function () {
153 $(document).on("click", ".sort-by", function () {
154 $(".sort-by").removeClass("loading active-short");
155 $(".close-ticket.reset-btn").addClass("reset-btn-active");
156 var _this = $(this),
157 _ajaxUrl = forumax_localize_script.ajaxurl,
158 _class = _this.addClass("loading active-short"),
159 _parent = _this.data("parent"),
160 _a = "forumax_loading_sort_post",
161 _n = forumax_localize_script.nonce,
162 _sort = _this.data("sort"),
163 data = {
164 action: _a,
165 nonce: _n,
166 sort: _sort,
167 parent: _parent,
168 };
169 if ($(this).hasClass("loading")) {
170 $.ajax({
171 url: _ajaxUrl,
172 method: "post",
173 data: data,
174 beforeSend: function () {
175 $(".load-forum").html(
176 "<div class='forum-loading'><div class='configure-border-1'><div class='configure-core'></div></div><div class='configure-border-2'><div class='configure-core'></div></div></div>"
177 );
178 },
179 success: function (response) {
180 $(".load-forum").html(response);
181 },
182 error: function () {
183 console.log("Oops! Something wrong, try again!");
184 },
185 });
186 }
187
188 return false;
189 });
190 },
191 };
192
193 // Do not strip duplicate IDs globally — forum pages can render multiple
194 // login forms (subscribe modal + topic/reply prompt). Unique IDs are
195 // generated in the shortcode; removing nodes here breaks those forms.
196
197 $('a.prev.page-numbers').html('<i class="arrow_carrot-left"></i>');
198 $('a.next.page-numbers').html('<i class="arrow_carrot-right"></i>');
199
200 // Scroll guest to the single on-page login form.
201 function frmxScrollToLoginForm() {
202 var $prompt = $('.frmx-inline-login-prompt').first();
203 if (!$prompt.length) {
204 $prompt = $('.frmx-auth-tabs').first();
205 }
206 if (!$prompt.length) {
207 return false;
208 }
209
210 var offset = $prompt.offset();
211 if (offset) {
212 $('html, body').animate({ scrollTop: Math.max(offset.top - 100, 0) }, 400);
213 }
214 $prompt.addClass('frmx-login-highlight');
215 setTimeout(function () {
216 $prompt.removeClass('frmx-login-highlight');
217 }, 1600);
218 return true;
219 }
220
221 // Login Modal for subscription — prefer one shared login form on the page.
222 $(document).on('click', '.subscription-login-btn', function (e) {
223 e.preventDefault();
224
225 var $btn = $(this);
226 var modalSelector = $btn.data('modal');
227 var $modal = $();
228
229 if (modalSelector) {
230 $modal = $(modalSelector);
231 }
232
233 // Fallback: open the closest sibling modal near the clicked button.
234 if (!$modal.length) {
235 $modal = $btn.closest('#subscription-toggle, .frmx-forum-subscription-action, .action-button-container, .bbp-no-reply, .bbp-no-topic')
236 .find('.subscription-login-modal')
237 .first();
238 }
239
240 // Last fallback: keep old behavior.
241 if (!$modal.length) {
242 $modal = $('.subscription-login-modal').first();
243 }
244
245 // If an inline login form already exists, scroll there instead of
246 // duplicating the shortcode inside the modal.
247 if ($('.frmx-inline-login-prompt').length && !$modal.find('.frmx-auth-tabs, .forumax_login_form, .bbp-login-form').length) {
248 if (frmxScrollToLoginForm()) {
249 return;
250 }
251 }
252
253 $modal.addClass('active');
254 });
255
256 $(document).on('click', '.frmx-scroll-to-login', function (e) {
257 e.preventDefault();
258 $(this).closest('.subscription-login-modal').removeClass('active');
259 frmxScrollToLoginForm();
260 });
261
262 $(document).on('click', '.subscription-login-modal-close', function () {
263
264 $(this).closest('.subscription-login-modal').removeClass('active');
265 });
266
267 // Outside click
268 $(document).on('mouseup', function (e) {
269
270 $('.subscription-login-modal.active').each(function () {
271 var $modal = $(this);
272 var $container = $modal.find('.subscription-login-modal-inner');
273 if (!$container.is(e.target) && $container.has(e.target).length === 0) {
274 $modal.removeClass('active');
275 }
276 });
277 });
278
279 // Handle tab click
280 $('.support-total-info li a').on('click', function (e) {
281 e.preventDefault(); // Prevent default link behavior
282
283 const $this = $(this);
284 const activeTabUrl = $this.attr('href'); // Get tab URL (e.g., ?tab=open)
285 const contentContainer = $('.load-forum'); // The content container for AJAX response
286
287 // Remove 'active' class from all tabs and add to the clicked tab
288 $('.support-total-info li').removeClass('active');
289 $this.parent().addClass('active');
290
291 // Update the browser URL to reflect the selected tab
292 window.history.pushState(null, '', activeTabUrl);
293
294 // Perform AJAX request to fetch new content
295 $.ajax({
296 url: activeTabUrl,
297 method: 'GET',
298 beforeSend: function () {
299 contentContainer.html('<p>Loading...</p>'); // Show a loading message
300 },
301 success: function (response) {
302 // Parse the returned HTML and replace the forum content
303 const newContent = $(response).find('.load-forum').html();
304 contentContainer.html(newContent);
305 },
306 error: function () {
307 contentContainer.html('<p>Error loading content. Please try again.</p>');
308 }
309 });
310 });
311 })(jQuery);