| 1 |
(function(){ |
| 2 |
//#region dev/js/modules/free/mega-script.js |
| 3 |
jQuery(document).ready(function(e) { |
| 4 |
"use strict"; |
| 5 |
if (!jQuery("#jltma-toaster-styles").length) jQuery("head").append("<style id=\"jltma-toaster-styles\">.jltma-toaster-container { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); z-index: 999999; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 12px;}.jltma-toaster { display: flex; align-items: center; gap: 14px; padding: 18px 28px; background: #fff; border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.25), 0 2px 8px rgba(0,0,0,0.15); pointer-events: auto; opacity: 0; transform: translateY(30px) scale(0.9); transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1); min-width: 350px; max-width: 550px; border: 1px solid rgba(0,0,0,0.08);}.jltma-toaster-show { opacity: 1 !important; transform: translateY(0) scale(1) !important;}.jltma-toaster .dashicons { font-size: 28px; width: 28px; height: 28px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;}.jltma-toaster-success { background: linear-gradient(135deg, #5bcc7f 0%, #48bb78 100%); border-left: 5px solid #059669;}.jltma-toaster-success .dashicons { color: #fff;}.jltma-toaster-error { background: linear-gradient(135deg, #f87171 0%, #ef4444 100%); border-left: 5px solid #dc2626;}.jltma-toaster-error .dashicons { color: #fff;}.jltma-toaster-message { font-size: 15px; font-weight: 600; color: #fff; line-height: 1.5; letter-spacing: 0.01em;}</style>"); |
| 6 |
window.showToaster = function(message, type) { |
| 7 |
type = type || "success"; |
| 8 |
var toasterClass = type === "success" ? "jltma-toaster-success" : "jltma-toaster-error"; |
| 9 |
var iconClass = type === "success" ? "dashicons-yes-alt" : "dashicons-warning"; |
| 10 |
var toaster = jQuery("<div class=\"jltma-toaster " + toasterClass + "\"><span class=\"dashicons " + iconClass + "\"></span><span class=\"jltma-toaster-message\">" + message + "</span></div>"); |
| 11 |
var container = jQuery(".jltma-toaster-container"); |
| 12 |
if (container.length === 0) container = jQuery("<div class=\"jltma-toaster-container\"></div>").appendTo("body"); |
| 13 |
container.append(toaster); |
| 14 |
setTimeout(function() { |
| 15 |
toaster.addClass("jltma-toaster-show"); |
| 16 |
}, 10); |
| 17 |
setTimeout(function() { |
| 18 |
toaster.removeClass("jltma-toaster-show"); |
| 19 |
setTimeout(function() { |
| 20 |
toaster.remove(); |
| 21 |
}, 300); |
| 22 |
}, 3e3); |
| 23 |
}; |
| 24 |
jQuery("#jltma-menu-metabox-input-is-enabled").is(":checked"); |
| 25 |
var jltma_megamenu_nonce = window.jltma_megamenu_nonce, JLTMA_Mega_Menu = { |
| 26 |
Enable_Mega_Menu: function() { |
| 27 |
var $checkbox = jQuery("#jltma-menu-metabox-input-is-enabled"); |
| 28 |
var enable_megamenu = $checkbox.is(":checked") ? 1 : 0; |
| 29 |
var $spinner = $checkbox.closest(".master-mega-menu-accordion").find(".spinner"); |
| 30 |
if (enable_megamenu) e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 31 |
else e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 32 |
$spinner.addClass("loading").css("visibility", "visible"); |
| 33 |
e.ajax({ |
| 34 |
url: ajaxurl, |
| 35 |
type: "post", |
| 36 |
data: { |
| 37 |
action: "jltma_save_megamenu_options", |
| 38 |
is_enabled: enable_megamenu, |
| 39 |
nonce: masteraddons_megamenu.nonce |
| 40 |
}, |
| 41 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce }, |
| 42 |
dataType: "json" |
| 43 |
}).done(function(response) { |
| 44 |
$spinner.removeClass("loading").css("visibility", "hidden"); |
| 45 |
if (typeof response === "string") try { |
| 46 |
response = JSON.parse(response); |
| 47 |
} catch (e) { |
| 48 |
console.error("Failed to parse response:", e); |
| 49 |
if (typeof window.showToaster === "function") window.showToaster("Mega Menu settings saved successfully!", "success"); |
| 50 |
return; |
| 51 |
} |
| 52 |
if (response && response.status == "success") { |
| 53 |
if (enable_megamenu) e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 54 |
else e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 55 |
localStorage.setItem("megamenu_enable", enable_megamenu); |
| 56 |
var message = response.message || (enable_megamenu ? "Mega Menu enabled successfully!" : "Mega Menu disabled successfully!"); |
| 57 |
if (typeof window.showToaster === "function") window.showToaster(message, "success"); |
| 58 |
} else { |
| 59 |
var errorMsg = response && response.message ? response.message : "Failed to save Mega Menu settings"; |
| 60 |
if (typeof window.showToaster === "function") window.showToaster(errorMsg, "error"); |
| 61 |
$checkbox.prop("checked", !enable_megamenu); |
| 62 |
if (!enable_megamenu) e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 63 |
else e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 64 |
} |
| 65 |
}).fail(function(xhr, status, error) { |
| 66 |
$spinner.removeClass("loading").css("visibility", "hidden"); |
| 67 |
console.error("AJAX Error:", status, error); |
| 68 |
if (typeof window.showToaster === "function") window.showToaster("Failed to save Mega Menu settings. Please try again.", "error"); |
| 69 |
$checkbox.prop("checked", !enable_megamenu); |
| 70 |
if (!enable_megamenu) e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 71 |
else e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 72 |
}); |
| 73 |
return false; |
| 74 |
}, |
| 75 |
Menu_Item_Settings_Save: function() { |
| 76 |
var t = e("#jltma-menu-metabox-input-is-enabled:checked").length, n = e("#jltma-menu-metabox-input-menu-id").val(), i = e(this).parent().find(".spinner"), m = { |
| 77 |
is_enabled: t, |
| 78 |
menu_id: n |
| 79 |
}; |
| 80 |
i.addClass("loading"), e.get(masteraddons_megamenu.resturl + "megamenu/save_megamenu_settings", m).done(function(e) { |
| 81 |
i.removeClass("loading"); |
| 82 |
}); |
| 83 |
}, |
| 84 |
Menu_Item_Save: function() { |
| 85 |
var t = e(this).parent().find(".spinner"), n = { settings: { |
| 86 |
menu_id: e("#jltma-menu-modal-menu-id").val(), |
| 87 |
menu_has_child: e("#jltma-menu-modal-menu-has-child").val(), |
| 88 |
menu_enable: e("#jltma-menu-item-enable:checked").val(), |
| 89 |
menu_label_enable: e("#mega-menu-hide-item-label:checked").val(), |
| 90 |
menu_transition: e("#mega-menu-transition-effect").val(), |
| 91 |
menu_disable_description: e("#jltma-menu-disable-description:checked").val(), |
| 92 |
menu_icon: e("#jltma-menu-icon-field").val(), |
| 93 |
menu_trigger_effect: e("#mega-menu-trigger-effect").val(), |
| 94 |
menu_icon_color: e("#jltma-menu-icon-color-field").val(), |
| 95 |
menu_badge_text: e("#jltma-menu-badge-text-field").val(), |
| 96 |
menu_width_type: e("#jltma-megamenu-width-type").val(), |
| 97 |
menu_width_size: e("#jltma-megamenu-width").val(), |
| 98 |
menu_horizontal_position: e("#jltma-megamenu-horizontal-position").val(), |
| 99 |
menu_mobile_submenu_content_type: e("#jltma-mobile-submenu-type").val(), |
| 100 |
menu_badge_color: e("#jltma-menu-badge-color-field").val(), |
| 101 |
menu_badge_background: e("#jltma-menu-badge-background-field").val() |
| 102 |
} }; |
| 103 |
t.addClass("loading"), e.ajax({ |
| 104 |
url: masteraddons_megamenu.resturl + "megamenu/jltma_save_menuitem_settings", |
| 105 |
type: "get", |
| 106 |
data: n, |
| 107 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce }, |
| 108 |
dataType: "json", |
| 109 |
success: function(n) { |
| 110 |
t.removeClass("loading"), e("#jltma-menu-item-settings-modal").modal("hide"); |
| 111 |
} |
| 112 |
}); |
| 113 |
}, |
| 114 |
/** |
| 115 |
* The width box and the Horizontal Position row belong to Custom Width |
| 116 |
* only -- a Default or Full Width panel is sized by its own row, so |
| 117 |
* there is nothing left to place. Called both when the setting changes |
| 118 |
* and when a menu item's saved settings are loaded into the modal. |
| 119 |
*/ |
| 120 |
Toggle_Custom_Width_Fields: function(e, widthType) { |
| 121 |
var isCustom = widthType == "custom_width"; |
| 122 |
e("#jltma-megamenu-width").toggleClass("hidden", !isCustom); |
| 123 |
e(".jltma-megamenu-horizontal-position-row").toggleClass("hidden", !isCustom); |
| 124 |
}, |
| 125 |
Menu_Trigger: function() { |
| 126 |
var t = e("#jltma-menu-modal-menu-id").val(), baseUrl = masteraddons_megamenu.resturl + "mastermega-content/jltma_content_editor/megamenu/menuitem/" + t, n = baseUrl + (baseUrl.indexOf("?") !== -1 ? "&" : "?") + "_wpnonce=" + jltma_megamenu_nonce; |
| 127 |
e("#jltma-menu-builder-iframe").attr("src", n); |
| 128 |
} |
| 129 |
}; |
| 130 |
e(".jltma-menu-settings-save").on("click", () => JLTMA_Mega_Menu.Menu_Item_Settings_Save(e)); |
| 131 |
e(".jltma-menu-item-save").on("click", function() { |
| 132 |
var t = e(this).parent().find(".spinner"), n = { settings: { |
| 133 |
menu_id: e("#jltma-menu-modal-menu-id").val(), |
| 134 |
menu_has_child: e("#jltma-menu-modal-menu-has-child").val(), |
| 135 |
menu_disable_description: e("#jltma-menu-disable-description:checked").val(), |
| 136 |
menu_enable: e("#jltma-menu-item-enable:checked").val(), |
| 137 |
menu_icon: e("#jltma-menu-icon-field").val(), |
| 138 |
menu_trigger_effect: e("#mega-menu-trigger-effect").val(), |
| 139 |
menu_icon_color: e("#jltma-menu-icon-color-field").val(), |
| 140 |
menu_label_enable: e("#mega-menu-hide-item-label:checked").val(), |
| 141 |
menu_transition: e("#mega-menu-transition-effect").val(), |
| 142 |
menu_badge_text: e("#jltma-menu-badge-text-field").val(), |
| 143 |
menu_width_type: e("#jltma-megamenu-width-type").val(), |
| 144 |
menu_width_size: e("#jltma-megamenu-width").val(), |
| 145 |
menu_horizontal_position: e("#jltma-megamenu-horizontal-position").val(), |
| 146 |
menu_mobile_submenu_content_type: e("#jltma-mobile-submenu-type").val(), |
| 147 |
menu_badge_color: e("#jltma-menu-badge-color-field").val(), |
| 148 |
menu_badge_background: e("#jltma-menu-badge-background-field").val() |
| 149 |
} }; |
| 150 |
t.addClass("loading"), e.ajax({ |
| 151 |
url: masteraddons_megamenu.resturl + "megamenu/jltma_save_menuitem_settings", |
| 152 |
type: "get", |
| 153 |
data: n, |
| 154 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce }, |
| 155 |
dataType: "json", |
| 156 |
success: function(n) { |
| 157 |
t.removeClass("loading"); |
| 158 |
showToaster("Settings saved successfully!", "success"); |
| 159 |
}, |
| 160 |
error: function(xhr, status, error) { |
| 161 |
t.removeClass("loading"); |
| 162 |
showToaster("Failed to save settings. Please try again.", "error"); |
| 163 |
} |
| 164 |
}); |
| 165 |
}), e("#jltma-menu-builder-trigger").on("click", () => JLTMA_Mega_Menu.Menu_Trigger(e)); |
| 166 |
e("body").on("DOMSubtreeModified", "#menu-to-edit", function() { |
| 167 |
setTimeout(function() { |
| 168 |
e("#menu-to-edit li.menu-item").each(function() { |
| 169 |
var t = e(this); |
| 170 |
t.find(".jltma_menu_trigger").length < 1 && e(".item-title", t).append("<a data-toggle='modal' data-target='#jltma_megamenu_modal' href='#' class='jltma_menu_trigger'>Master Mega</a> "); |
| 171 |
}); |
| 172 |
}, 200); |
| 173 |
}), e("#menu-to-edit").trigger("DOMSubtreeModified"), e("#menu-to-edit").on("click", ".jltma_menu_trigger", function(n) { |
| 174 |
n.preventDefault(); |
| 175 |
var i = e("#jltma_megamenu_modal"), m = e(this).parents("li.menu-item"), l = parseInt(m.attr("id").match(/[0-9]+/)[0], 10); |
| 176 |
m.find(".menu-item-title").text(), m.attr("class").match(/\menu-item-depth-(\d+)\b/)[1]; |
| 177 |
if (e(".jltma_menu_control_nav > li").removeClass("active"), e(".jltma-tab-pane").removeClass("active"), 1 == e(this).parent().find(".is-submenu").is(":hidden")) { |
| 178 |
var a = 0; |
| 179 |
i.removeClass("jltma-menu-has-child"), e("#content_nav").addClass("active"), e("#content_tab").addClass("active"); |
| 180 |
} else { |
| 181 |
a = 1; |
| 182 |
i.addClass("jltma-menu-has-child"), e("#general_nav").addClass("active"), e("#general_tab").addClass("active show"); |
| 183 |
} |
| 184 |
e("#jltma-menu-modal-menu-id").val(l), e("#jltma-menu-modal-menu-has-child").val(a); |
| 185 |
var o = { menu_id: l }; |
| 186 |
e.ajax({ |
| 187 |
url: masteraddons_megamenu.resturl + "megamenu/get_menuitem_settings", |
| 188 |
type: "get", |
| 189 |
data: o, |
| 190 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce }, |
| 191 |
dataType: "json" |
| 192 |
}).done(function(n) { |
| 193 |
e("#jltma-menu-item-enable").prop("checked", !1), e("#mega-menu-trigger-effect").val(n.menu_trigger_effect), e("#jltma-menu-icon-color-field").val(n.menu_icon_color || "").trigger("change"), (function() { |
| 194 |
var iconValue = n.menu_icon || "fas fa-chevron-down"; |
| 195 |
var $preview = e("#jltma-menu-icon-preview"); |
| 196 |
e("#jltma-menu-icon-field").val(iconValue); |
| 197 |
$preview.attr("class", iconValue); |
| 198 |
$preview.attr("style", "font-size: 20px; color: #fff; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;"); |
| 199 |
if (n.menu_icon) e(".jltma-icon-delete-btn").css({ |
| 200 |
"display": "flex", |
| 201 |
"align-items": "center", |
| 202 |
"justify-content": "center" |
| 203 |
}); |
| 204 |
else e(".jltma-icon-delete-btn").css("display", "none"); |
| 205 |
})(), e("#mega-menu-transition-effect").val(n.menu_transition), e("#mega-menu-hide-item-label").prop("checked", !1), void 0 !== typeof n.menu_label_enable && 1 == n.menu_label_enable ? e("#mega-menu-hide-item-label").prop("checked", !0) : e("#mega-menu-hide-item-label").prop("checked", !1), e("#jltma-menu-badge-text-field").val(n.menu_badge_text), e("#jltma-megamenu-width-type").val(n.menu_width_type || "full_width"), e("#jltma-megamenu-width").val(n.menu_width_size || "1000px"), e("#jltma-megamenu-horizontal-position").val(n.menu_horizontal_position || "left"), e("#jltma-mobile-submenu-type").val(n.menu_mobile_submenu_content_type || "builder_content"), e("#jltma-menu-disable-description").prop("checked", !1), void 0 !== typeof n.menu_disable_description && 1 == n.menu_disable_description ? e("#jltma-menu-disable-description").prop("checked", !0) : e("#jltma-menu-disable-description").prop("checked", !1), e("#jltma-menu-badge-color-field").val(n.menu_badge_color || "#6814cd").trigger("change"), e("#jltma-menu-badge-background-field").val(n.menu_badge_background || "#6814cd").trigger("change"), void 0 !== typeof n.menu_enable && 1 == n.menu_enable ? e("#jltma-menu-item-enable").prop("checked", !0) : e("#jltma-menu-item-enable").prop("checked", !1), e("#jltma-menu-item-enable").trigger("change"), JLTMA_Mega_Menu.Toggle_Custom_Width_Fields(e, n.menu_width_type), setTimeout(function() { |
| 206 |
i.removeClass("jltma-menu-modal-loading"); |
| 207 |
i.addClass("show"); |
| 208 |
}, 500); |
| 209 |
}); |
| 210 |
}); |
| 211 |
e("#jltma-menu-item-enable").on("change", function() { |
| 212 |
e(this).is(":checked") ? (e("#jltma-menu-builder-trigger").prop("disabled", !1), e("#jltma-menu-builder-wrapper").addClass("is_enabled")) : (e("#jltma-menu-item-enable").prop("checked", !1), e("#jltma-menu-builder-wrapper").removeClass("is_enabled"), e("#jltma-menu-builder-trigger").prop("disabled", !0)); |
| 213 |
}); |
| 214 |
e("#jltma-mega-menu-settings").on("change", "#jltma-menu-metabox-input-is-enabled", () => JLTMA_Mega_Menu.Enable_Mega_Menu(e)); |
| 215 |
e("#jltma-megamenu-width-type").on("change", function() { |
| 216 |
JLTMA_Mega_Menu.Toggle_Custom_Width_Fields(e, this.value); |
| 217 |
}); |
| 218 |
e.ajax({ |
| 219 |
url: ajaxurl, |
| 220 |
type: "get", |
| 221 |
data: { action: "jltma_get_megamenu_options" }, |
| 222 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce } |
| 223 |
}).done(function(response) { |
| 224 |
response = jQuery.parseJSON(response); |
| 225 |
if (response && response.is_enabled == "1") { |
| 226 |
e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 227 |
localStorage.setItem("megamenu_enable", "1"); |
| 228 |
e("#jltma-menu-metabox-input-is-enabled").prop("checked", true); |
| 229 |
} else { |
| 230 |
e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 231 |
localStorage.setItem("megamenu_enable", "0"); |
| 232 |
e("#jltma-menu-metabox-input-is-enabled").prop("checked", false); |
| 233 |
} |
| 234 |
}); |
| 235 |
jQuery(document).on("click", function(e) { |
| 236 |
if (jQuery("#jltma_megamenu_modal").hasClass("show") && !jQuery(e.target).closest(".jltma-modal-dialog, .jltma_menu_trigger").length) jQuery("#jltma_megamenu_modal").removeClass("show"); |
| 237 |
}); |
| 238 |
jQuery("body").on("click", ".jltma-modal-dialog", function(e) { |
| 239 |
e.stopPropagation(); |
| 240 |
}); |
| 241 |
jQuery("body").on("click", "#jltma_megamenu_modal .jltma-pop-close, #jltma_megamenu_modal .close-btn", function(e) { |
| 242 |
e.preventDefault(); |
| 243 |
jQuery("#jltma_megamenu_modal").removeClass("show"); |
| 244 |
}); |
| 245 |
jQuery("body").on("click", "#jltma-menu-builder-trigger", function(e) { |
| 246 |
jQuery("#jltma-mega-menu-builder-modal").toggleClass("show"); |
| 247 |
}); |
| 248 |
jQuery("body").on("click", "#jltma-mega-menu-builder-modal .jltma-pop-close", function(e) { |
| 249 |
e.preventDefault(); |
| 250 |
jQuery("#jltma-mega-menu-builder-modal").removeClass("show"); |
| 251 |
}); |
| 252 |
jQuery(document).on("keydown", function(e) { |
| 253 |
if (e.key === "Escape" || e.keyCode === 27) { |
| 254 |
if (jQuery("#jltma_megamenu_modal").hasClass("show")) jQuery("#jltma_megamenu_modal").removeClass("show"); |
| 255 |
if (jQuery("#jltma-mega-menu-builder-modal").hasClass("show")) jQuery("#jltma-mega-menu-builder-modal").removeClass("show"); |
| 256 |
} |
| 257 |
}); |
| 258 |
jQuery(".jltma-tab-content > div").hide(); |
| 259 |
jQuery(".jltma-tab-content > div:first-of-type").show(); |
| 260 |
jQuery(".jltma-tabs a").click(function(e) { |
| 261 |
e.preventDefault(); |
| 262 |
var jQuerythis = jQuery(this), tabgroup = "#" + jQuerythis.parents(".jltma-tabs").data("jltma-tab-content"), others = jQuerythis.closest("li").siblings().children("a"), target = jQuerythis.attr("href"); |
| 263 |
others.removeClass("active"); |
| 264 |
jQuerythis.addClass("active"); |
| 265 |
jQuery(tabgroup).children("div").hide(); |
| 266 |
jQuery(target).show(); |
| 267 |
jQuery(target).siblings().hide(); |
| 268 |
}); |
| 269 |
function initModernIconPicker() { |
| 270 |
var _masteraddons_megamen; |
| 271 |
var iconLibraryConfig = ((_masteraddons_megamen = masteraddons_megamenu) === null || _masteraddons_megamen === void 0 ? void 0 : _masteraddons_megamen.iconLibrary) || {}; |
| 272 |
var allIcons = []; |
| 273 |
var sidebarList = []; |
| 274 |
sidebarList.push({ |
| 275 |
title: "All Icons", |
| 276 |
"list-icon": "dashicons dashicons-marker", |
| 277 |
"library-id": "all" |
| 278 |
}); |
| 279 |
Object.entries(iconLibraryConfig).forEach(function([libraryName, libraryData]) { |
| 280 |
Object.entries(libraryData).forEach(function([categoryName, categoryData]) { |
| 281 |
var iconTitle = categoryName !== "" ? libraryName + " - " + categoryName : libraryName; |
| 282 |
sidebarList.push({ |
| 283 |
title: iconTitle, |
| 284 |
"list-icon": categoryData["list-icon"] || "", |
| 285 |
"library-id": categoryData["icon-style"] || "all" |
| 286 |
}); |
| 287 |
if (categoryData.icons && Array.isArray(categoryData.icons)) categoryData.icons.forEach(function(iconName) { |
| 288 |
var fullClass = categoryData.prefix + iconName; |
| 289 |
allIcons.push({ |
| 290 |
class: fullClass, |
| 291 |
name: iconName, |
| 292 |
library: categoryData["icon-style"], |
| 293 |
prefix: categoryData.prefix |
| 294 |
}); |
| 295 |
}); |
| 296 |
}); |
| 297 |
}); |
| 298 |
jQuery(document).on("click", ".jltma-icon-delete-btn", function(e) { |
| 299 |
e.preventDefault(); |
| 300 |
e.stopPropagation(); |
| 301 |
console.log("=== DELETE ICON CLICKED ==="); |
| 302 |
var $deleteBtn = jQuery(this); |
| 303 |
var $wrapper = $deleteBtn.closest(".jltma-modern-icon-picker-wrapper"); |
| 304 |
var $input = $wrapper.find(".icon-picker-input"); |
| 305 |
var $preview = jQuery("#jltma-menu-icon-preview"); |
| 306 |
var $button = $wrapper.find(".icon-picker"); |
| 307 |
console.log("Found elements:", { |
| 308 |
preview: $preview.length, |
| 309 |
input: $input.length, |
| 310 |
button: $button.length |
| 311 |
}); |
| 312 |
console.log("BEFORE - Preview state:", { |
| 313 |
class: $preview.attr("class"), |
| 314 |
style: $preview.attr("style"), |
| 315 |
display: $preview.css("display"), |
| 316 |
element: $preview[0] |
| 317 |
}); |
| 318 |
$input.val(""); |
| 319 |
console.log("Input cleared, value:", $input.val()); |
| 320 |
$preview.attr("class", ""); |
| 321 |
$preview.attr("style", "font-size: 24px; color: #fff; display: none !important;"); |
| 322 |
$preview.hide(); |
| 323 |
jQuery("#jltma-icon-preview-box").css("border-color", "#2d3748"); |
| 324 |
console.log("AFTER - Preview state:", { |
| 325 |
class: $preview.attr("class"), |
| 326 |
style: $preview.attr("style"), |
| 327 |
display: $preview.css("display"), |
| 328 |
element: $preview[0] |
| 329 |
}); |
| 330 |
$deleteBtn.hide(); |
| 331 |
$button.removeClass("has-icon"); |
| 332 |
console.log("=== DELETE COMPLETE ==="); |
| 333 |
}); |
| 334 |
jQuery(document).on("click", ".icon-picker", function(e) { |
| 335 |
var _masteraddons_megamen2; |
| 336 |
e.preventDefault(); |
| 337 |
e.stopPropagation(); |
| 338 |
console.log("Icon picker clicked"); |
| 339 |
var $button = jQuery(this); |
| 340 |
var $wrapper = $button.closest(".jltma-modern-icon-picker-wrapper"); |
| 341 |
var $input = $wrapper.find(".icon-picker-input"); |
| 342 |
$wrapper.find("#jltma-menu-icon-preview"); |
| 343 |
var $deleteBtn = $wrapper.find(".jltma-icon-delete-btn"); |
| 344 |
var currentIcon = $input.val(); |
| 345 |
console.log("Icon picker data:", { |
| 346 |
allIconsCount: allIcons.length, |
| 347 |
currentIcon, |
| 348 |
hasIconLibrary: !!((_masteraddons_megamen2 = masteraddons_megamenu) === null || _masteraddons_megamen2 === void 0 ? void 0 : _masteraddons_megamen2.iconLibrary) |
| 349 |
}); |
| 350 |
if (allIcons.length === 0) { |
| 351 |
alert("Icon library not loaded. Please refresh the page."); |
| 352 |
return; |
| 353 |
} |
| 354 |
showModernIconPickerModal(currentIcon, function(selectedIcon) { |
| 355 |
$input.val(selectedIcon); |
| 356 |
var $iconPreview = jQuery("#jltma-menu-icon-preview"); |
| 357 |
$iconPreview.attr("class", selectedIcon); |
| 358 |
$iconPreview.attr("style", "font-size: 24px; color: #fff; display: block;"); |
| 359 |
if ($deleteBtn.length > 0) $deleteBtn.css({ |
| 360 |
"display": "flex", |
| 361 |
"align-items": "center", |
| 362 |
"justify-content": "center" |
| 363 |
}); |
| 364 |
$button.addClass("has-icon"); |
| 365 |
console.log("Icon selected:", selectedIcon); |
| 366 |
}); |
| 367 |
}); |
| 368 |
function showModernIconPickerModal(currentIcon, onSelect) { |
| 369 |
var activeLibrary = "all"; |
| 370 |
var searchTerm = ""; |
| 371 |
var selectedIcon = currentIcon || ""; |
| 372 |
if (currentIcon) { |
| 373 |
var currentIconData = allIcons.find(function(icon) { |
| 374 |
return icon.class === currentIcon; |
| 375 |
}); |
| 376 |
if (currentIconData) activeLibrary = currentIconData.library; |
| 377 |
} |
| 378 |
var modalHtml = "<div class=\"aim-modal aim-open jltma-megamenu-icon-modal\"><div class=\"aim-modal--content\"><div class=\"aim-modal--header\"><div class=\"aim-modal--header-logo-area\"><span class=\"aim-modal--header-logo-title\"><img src=\"" + masteraddons_megamenu.pluginUrl + "/assets/images/logo.svg\" alt=\"Master Addons\" style=\"width: 24px; height: 24px; margin-right: 8px;\" />Master Addons Icon Picker</span></div><div class=\"aim-modal--header-close-btn\"><span class=\"dashicons dashicons-no-alt\" title=\"Close\"></span></div></div><div class=\"aim-modal--body\"><div class=\"aim-modal--sidebar\"><div class=\"aim-modal--sidebar-tabs\">" + sidebarList.map(function(item, index) { |
| 379 |
var isActive = activeLibrary === item["library-id"] ? "aesthetic-active" : ""; |
| 380 |
var icon = item["list-icon"] ? "<i class=\"" + item["list-icon"] + "\"></i>" : ""; |
| 381 |
return "<div class=\"aim-modal--sidebar-tab-item " + isActive + "\" data-library-id=\"" + item["library-id"] + "\">" + icon + item.title + "</div>"; |
| 382 |
}).join("") + "</div></div><div class=\"aim-modal--icon-preview-wrap\"><div class=\"aim-modal--icon-search\"><input type=\"text\" placeholder=\"Filter by name...\" class=\"jltma-icon-search-input\" /><i class=\"dashicons dashicons-search\"></i></div><div class=\"aim-modal--icon-preview-inner\"><div id=\"aim-modal--icon-preview\"></div></div></div></div><div class=\"aim-modal--footer\"><button class=\"aim-insert-icon-button\" type=\"button\">Insert</button></div></div></div>"; |
| 383 |
var $modal = jQuery(modalHtml); |
| 384 |
jQuery("body").append($modal); |
| 385 |
function renderIcons() { |
| 386 |
var iconsHtml = allIcons.filter(function(icon) { |
| 387 |
var matchesSearch = searchTerm === "" || icon.name.toLowerCase().includes(searchTerm.toLowerCase()); |
| 388 |
var matchesLibrary = activeLibrary === "all" || icon.library === activeLibrary; |
| 389 |
return matchesSearch && matchesLibrary; |
| 390 |
}).map(function(icon) { |
| 391 |
var isSelected = selectedIcon === icon.class ? "aesthetic-selected" : ""; |
| 392 |
var displayName = icon.name.replace(/-/g, " "); |
| 393 |
return "<div class=\"aim-icon-item " + isSelected + "\" data-icon-class=\"" + icon.class + "\"><div class=\"aim-icon-item-inner\"><i class=\"" + icon.class + "\"></i><div class=\"aim-icon-item-name\" title=\"" + icon.name + "\">" + displayName + "</div></div></div>"; |
| 394 |
}).join(""); |
| 395 |
$modal.find("#aim-modal--icon-preview").html(iconsHtml); |
| 396 |
} |
| 397 |
renderIcons(); |
| 398 |
$modal.find(".aim-modal--header-close-btn, .aim-modal").on("click", function(e) { |
| 399 |
if (e.target === this) $modal.remove(); |
| 400 |
}); |
| 401 |
$modal.find(".aim-modal--content").on("click", function(e) { |
| 402 |
e.stopPropagation(); |
| 403 |
}); |
| 404 |
$modal.find(".aim-modal--sidebar-tab-item").on("click", function() { |
| 405 |
activeLibrary = jQuery(this).data("library-id"); |
| 406 |
$modal.find(".aim-modal--sidebar-tab-item").removeClass("aesthetic-active"); |
| 407 |
jQuery(this).addClass("aesthetic-active"); |
| 408 |
renderIcons(); |
| 409 |
}); |
| 410 |
$modal.find(".jltma-icon-search-input").on("input", function() { |
| 411 |
searchTerm = jQuery(this).val(); |
| 412 |
renderIcons(); |
| 413 |
}); |
| 414 |
$modal.on("click", ".aim-icon-item", function() { |
| 415 |
selectedIcon = jQuery(this).data("icon-class"); |
| 416 |
$modal.find(".aim-icon-item").removeClass("aesthetic-selected"); |
| 417 |
jQuery(this).addClass("aesthetic-selected"); |
| 418 |
}); |
| 419 |
$modal.find(".aim-insert-icon-button").on("click", function() { |
| 420 |
if (selectedIcon) onSelect(selectedIcon); |
| 421 |
$modal.remove(); |
| 422 |
}); |
| 423 |
} |
| 424 |
} |
| 425 |
initModernIconPicker(); |
| 426 |
jQuery(document).on("click", ".jltma-color-preview", function() { |
| 427 |
jQuery(this).siblings(".jltma-color-native").click(); |
| 428 |
}); |
| 429 |
jQuery(document).on("input change", ".jltma-color-native", function() { |
| 430 |
var color = jQuery(this).val(); |
| 431 |
var $picker = jQuery(this).closest(".jltma-modern-color-picker"); |
| 432 |
var inputId = $picker.attr("data-input-id"); |
| 433 |
$picker.find(".jltma-color-preview").css("background-color", color); |
| 434 |
$picker.find(".jltma-color-input").val(color); |
| 435 |
jQuery("#" + inputId).val(color).trigger("change"); |
| 436 |
}); |
| 437 |
jQuery(document).on("input change", ".jltma-color-input", function() { |
| 438 |
var color = jQuery(this).val(); |
| 439 |
var $picker = jQuery(this).closest(".jltma-modern-color-picker"); |
| 440 |
var inputId = $picker.attr("data-input-id"); |
| 441 |
if (/^#[0-9A-F]{6}$/i.test(color) || /^#[0-9A-F]{3}$/i.test(color)) { |
| 442 |
$picker.find(".jltma-color-preview").css("background-color", color); |
| 443 |
$picker.find(".jltma-color-native").val(color); |
| 444 |
jQuery("#" + inputId).val(color).trigger("change"); |
| 445 |
} |
| 446 |
}); |
| 447 |
jQuery(document).on("click", ".jltma-color-clear", function() { |
| 448 |
var $picker = jQuery(this).closest(".jltma-modern-color-picker"); |
| 449 |
var inputId = $picker.attr("data-input-id"); |
| 450 |
$picker.find(".jltma-color-preview").css("background-color", ""); |
| 451 |
$picker.find(".jltma-color-input").val(""); |
| 452 |
$picker.find(".jltma-color-native").val("#000000"); |
| 453 |
jQuery("#" + inputId).val("").trigger("change"); |
| 454 |
}); |
| 455 |
jQuery(document).on("change", ".jltma-menu-wpcolor-picker", function() { |
| 456 |
var $hiddenInput = jQuery(this); |
| 457 |
var color = $hiddenInput.val(); |
| 458 |
var inputId = $hiddenInput.attr("id"); |
| 459 |
var $picker = jQuery(".jltma-modern-color-picker[data-input-id=\"" + inputId + "\"]"); |
| 460 |
if ($picker.length > 0 && color) { |
| 461 |
$picker.find(".jltma-color-preview").css("background-color", color); |
| 462 |
$picker.find(".jltma-color-input").val(color); |
| 463 |
$picker.find(".jltma-color-native").val(color); |
| 464 |
} |
| 465 |
}); |
| 466 |
}); |
| 467 |
//#endregion |
| 468 |
})(); |
| 469 |
|