| 1 |
; (function ($) { |
| 2 |
|
| 3 |
$(document).ready(function () { |
| 4 |
|
| 5 |
// Initialize frmx-nice-select on all bbPress/Forumax select elements |
| 6 |
if (typeof $.fn.frmxNiceSelect === 'function') { |
| 7 |
// Initialize on all forum form selects |
| 8 |
$('.bbp-form select, .bbp-topic-form select, .bbp-reply-form select, .bbp-forum-form select').frmxNiceSelect(); |
| 9 |
|
| 10 |
// Initialize on specific select elements (only if they are actual select elements) |
| 11 |
$('select#bbp_forum_id, select#bbp_stick_topic_select, select#bbp_topic_status_select, select#sort-replies').frmxNiceSelect(); |
| 12 |
$('select#bbp_destination_topic, select#bbp_forum_parent_id, select#bbp_forum_status, select#bbp_forum_visibility').frmxNiceSelect(); |
| 13 |
|
| 14 |
// Initialize on admin dropdown menus (only select elements) |
| 15 |
$('select.bbp-admin-dropdown-menu').frmxNiceSelect(); |
| 16 |
|
| 17 |
// Enhance admin dropdown items with data-action attributes and SVG icons. |
| 18 |
frmxEnhanceAdminDropdowns(); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Inject data-action attributes and SVG icons into NiceSelect admin dropdown items. |
| 23 |
* |
| 24 |
* NiceSelect does not copy data-action from <option> elements, so we cross-reference |
| 25 |
* by index and manually apply them to the rendered .option list items. |
| 26 |
*/ |
| 27 |
function frmxEnhanceAdminDropdowns() { |
| 28 |
var iconMap = { |
| 29 |
edit: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>', |
| 30 |
move: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="5 9 2 12 5 15"/><polyline points="9 5 12 2 15 5"/><polyline points="15 19 12 22 9 19"/><polyline points="19 9 22 12 19 15"/><line x1="2" y1="12" x2="22" y2="12"/><line x1="12" y1="2" x2="12" y2="22"/></svg>', |
| 31 |
split: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 3h5v5"/><path d="M8 3H3v5"/><path d="M12 22v-8.3a4 4 0 0 0-1.172-2.872L3 3"/><path d="m15 9 6-6"/></svg>', |
| 32 |
close: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>', |
| 33 |
stick: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="17" x2="12" y2="22"/><path d="M5 17h14v-1.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1v4.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24Z"/></svg>', |
| 34 |
merge: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3"/><path d="M21 8V5a2 2 0 0 0-2-2h-3"/><path d="M3 16v3a2 2 0 0 0 2 2h3"/><path d="M16 21h3a2 2 0 0 0 2-2v-3"/></svg>', |
| 35 |
trash: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>', |
| 36 |
spam: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="4.93" y1="4.93" x2="19.07" y2="19.07"/></svg>', |
| 37 |
approve: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><polyline points="9 12 11 14 15 10"/></svg>', |
| 38 |
reply: '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 17 4 12 9 7"/><path d="M20 18v-2a4 4 0 0 0-4-4H4"/></svg>' |
| 39 |
}; |
| 40 |
|
| 41 |
$('.bbp-admin-links-dropdown').each(function () { |
| 42 |
var $dropdown = $(this); |
| 43 |
var $select = $dropdown.find('select'); |
| 44 |
var $niceSelect = $dropdown.find('.frmx-nice-select'); |
| 45 |
|
| 46 |
if (!$select.length || !$niceSelect.length) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
var $options = $select.find('option'); |
| 51 |
var $listItems = $niceSelect.find('.list .option'); |
| 52 |
|
| 53 |
$listItems.each(function (i) { |
| 54 |
var $li = $(this); |
| 55 |
var $origOpt = $options.eq(i); |
| 56 |
var action = $origOpt.data('action'); |
| 57 |
|
| 58 |
if (!action) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
// Apply data-action to the NiceSelect list item for CSS targeting. |
| 63 |
$li.attr('data-action', action); |
| 64 |
|
| 65 |
// Convert separator items into visual dividers. |
| 66 |
if (action === 'separator') { |
| 67 |
$li.addClass('frmx-dropdown-separator').html('<hr/>'); |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
// Prepend SVG icon if available. |
| 72 |
if (iconMap[action]) { |
| 73 |
var text = $li.text(); |
| 74 |
$li.html('<span class="frmx-dropdown-icon">' + iconMap[action] + '</span><span class="frmx-dropdown-label">' + text + '</span>'); |
| 75 |
} |
| 76 |
}); |
| 77 |
}); |
| 78 |
} |
| 79 |
|
| 80 |
// Expose for re-use after AJAX re-initializations. |
| 81 |
window.frmxEnhanceAdminDropdowns = frmxEnhanceAdminDropdowns; |
| 82 |
|
| 83 |
// Toggle dropdown - using frmx- prefixed classes to avoid theme conflicts |
| 84 |
$('.forumax-sort-lists .frmx-dropdown-toggle').on('click', function (e) { |
| 85 |
e.preventDefault(); |
| 86 |
e.stopPropagation(); // prevent document click |
| 87 |
|
| 88 |
const $currentMenu = $(this).siblings('.frmx-dropdown-menu'); |
| 89 |
|
| 90 |
// Close all others |
| 91 |
$('.forumax-sort-lists .frmx-dropdown-menu').not($currentMenu).removeClass('frmx-show'); |
| 92 |
|
| 93 |
// Toggle current |
| 94 |
$currentMenu.toggleClass('frmx-show'); |
| 95 |
|
| 96 |
// Update aria-expanded attribute |
| 97 |
$(this).attr('aria-expanded', $currentMenu.hasClass('frmx-show')); |
| 98 |
}); |
| 99 |
|
| 100 |
// Allow clicks inside dropdown (including links) |
| 101 |
$('.forumax-sort-lists .frmx-dropdown-menu').on('click', function (e) { |
| 102 |
// Only prevent propagation if not clicking a link |
| 103 |
if (!$(e.target).is('a')) { |
| 104 |
e.stopPropagation(); |
| 105 |
} |
| 106 |
}); |
| 107 |
|
| 108 |
// Click outside → close all dropdowns |
| 109 |
$(document).on('click', function () { |
| 110 |
$('.forumax-sort-lists .frmx-dropdown-menu').removeClass('frmx-show'); |
| 111 |
$('.forumax-sort-lists .frmx-dropdown-toggle').attr('aria-expanded', 'false'); |
| 112 |
}); |
| 113 |
|
| 114 |
// Forumax Social Share Modal |
| 115 |
$(document).on('click', '.modal-toggle[data-id="forumax_share_modal"]', function (e) { |
| 116 |
e.preventDefault(); |
| 117 |
$('#forumax_share_modal').fadeIn(); |
| 118 |
}); |
| 119 |
|
| 120 |
$(document).on('click', '#forumax_share_modal .forumax-close, #forumax_share_modal .forumax-modal-overlay', function () { |
| 121 |
$('#forumax_share_modal').fadeOut(); |
| 122 |
}); |
| 123 |
|
| 124 |
// Forumax Copy Link Logic |
| 125 |
$('#forumax_share_modal .share-this-doc').on('click', function () { |
| 126 |
var copyText = $(this).closest('.copy-url-wrap').find('input.word-wrap'); |
| 127 |
var $sourceToast = $(this).siblings('.forumax-link-copied-wrap'); |
| 128 |
|
| 129 |
// Remove any existing active toasts to prevent duplicates |
| 130 |
$('.forumax-link-copied-wrap.active-body-toast').remove(); |
| 131 |
|
| 132 |
// Clone to body to escape modal stacking context |
| 133 |
var $toast = $sourceToast.clone(); |
| 134 |
$toast.addClass('active-body-toast'); |
| 135 |
$toast.appendTo('body'); |
| 136 |
|
| 137 |
copyText.select(); |
| 138 |
document.execCommand("copy"); |
| 139 |
|
| 140 |
// Feedback: Show toast |
| 141 |
$toast.fadeIn().css('display', 'flex'); |
| 142 |
|
| 143 |
// Hide after 3 seconds AND remove |
| 144 |
setTimeout(function () { |
| 145 |
$toast.fadeOut(function () { |
| 146 |
$(this).remove(); |
| 147 |
}); |
| 148 |
}, 3000); |
| 149 |
}); |
| 150 |
|
| 151 |
// Close Toast manually |
| 152 |
$('body').on('click', '.forumax-link-copied-wrap .close-notice', function () { |
| 153 |
$(this).closest('.forumax-link-copied-wrap').fadeOut(function () { |
| 154 |
$(this).remove(); |
| 155 |
}); |
| 156 |
}); |
| 157 |
|
| 158 |
// Open specific social links in a popup window |
| 159 |
$('#forumax_share_modal .social-links a').on('click', function (e) { |
| 160 |
var href = $(this).attr('href'); |
| 161 |
// If it's a mailto link, let it behave normally |
| 162 |
if (href.indexOf('mailto:') === 0) { |
| 163 |
return; |
| 164 |
} |
| 165 |
e.preventDefault(); |
| 166 |
var width = 600; |
| 167 |
var height = 400; |
| 168 |
var left = (screen.width - width) / 2; |
| 169 |
var top = (screen.height - height) / 2; |
| 170 |
window.open(href, 'sharer', 'toolbar=0,status=0,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left); |
| 171 |
}); |
| 172 |
}); |
| 173 |
|
| 174 |
})(jQuery); |