PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.4.0
Forumax – AI Powered Advanced Community Forum Plugin v2.4.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 2.1.0 All 29 releases
bbp-core / assets / frontend / js / forum.js

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

276 lines 10.6 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 $('[id]').each(function () {
194 $('[id="' + this.id + '"]:gt(0)').remove();
195 });
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 // Login Modal for subscription
201 $(document).on('click', '.subscription-login-btn', function (e) {
202 e.preventDefault();
203
204 var $btn = $(this);
205 var modalSelector = $btn.data('modal');
206 var $modal = $();
207
208 if (modalSelector) {
209 $modal = $(modalSelector);
210 }
211
212 // Fallback: open the closest sibling modal near the clicked button.
213 if (!$modal.length) {
214 $modal = $btn.closest('#subscription-toggle, .frmx-forum-subscription-action, .action-button-container, .bbp-no-reply, .bbp-no-topic')
215 .find('.subscription-login-modal')
216 .first();
217 }
218
219 // Last fallback: keep old behavior.
220 if (!$modal.length) {
221 $modal = $('.subscription-login-modal').first();
222 }
223
224 $modal.addClass('active');
225 });
226
227 $(document).on('click', '.subscription-login-modal-close', function () {
228
229 $(this).closest('.subscription-login-modal').removeClass('active');
230 });
231
232 // Outside click
233 $(document).on('mouseup', function (e) {
234
235 $('.subscription-login-modal.active').each(function () {
236 var $modal = $(this);
237 var $container = $modal.find('.subscription-login-modal-inner');
238 if (!$container.is(e.target) && $container.has(e.target).length === 0) {
239 $modal.removeClass('active');
240 }
241 });
242 });
243
244 // Handle tab click
245 $('.support-total-info li a').on('click', function (e) {
246 e.preventDefault(); // Prevent default link behavior
247
248 const $this = $(this);
249 const activeTabUrl = $this.attr('href'); // Get tab URL (e.g., ?tab=open)
250 const contentContainer = $('.load-forum'); // The content container for AJAX response
251
252 // Remove 'active' class from all tabs and add to the clicked tab
253 $('.support-total-info li').removeClass('active');
254 $this.parent().addClass('active');
255
256 // Update the browser URL to reflect the selected tab
257 window.history.pushState(null, '', activeTabUrl);
258
259 // Perform AJAX request to fetch new content
260 $.ajax({
261 url: activeTabUrl,
262 method: 'GET',
263 beforeSend: function () {
264 contentContainer.html('<p>Loading...</p>'); // Show a loading message
265 },
266 success: function (response) {
267 // Parse the returned HTML and replace the forum content
268 const newContent = $(response).find('.load-forum').html();
269 contentContainer.html(newContent);
270 },
271 error: function () {
272 contentContainer.html('<p>Error loading content. Please try again.</p>');
273 }
274 });
275 });
276 })(jQuery);