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