| 1 |
(function(){ |
| 2 |
jQuery(document).ready(function(e) { |
| 3 |
"use strict"; |
| 4 |
if (!jQuery("#jltma-toaster-styles").length) { |
| 5 |
var toasterStyles = '<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 |
jQuery("head").append(toasterStyles); |
| 7 |
} |
| 8 |
window.showToaster = function(message, type) { |
| 9 |
type = type || "success"; |
| 10 |
var toasterClass = type === "success" ? "jltma-toaster-success" : "jltma-toaster-error"; |
| 11 |
var iconClass = type === "success" ? "dashicons-yes-alt" : "dashicons-warning"; |
| 12 |
var toaster = jQuery('<div class="jltma-toaster ' + toasterClass + '"><span class="dashicons ' + iconClass + '"></span><span class="jltma-toaster-message">' + message + "</span></div>"); |
| 13 |
var container = jQuery(".jltma-toaster-container"); |
| 14 |
if (container.length === 0) { |
| 15 |
container = jQuery('<div class="jltma-toaster-container"></div>').appendTo("body"); |
| 16 |
} |
| 17 |
container.append(toaster); |
| 18 |
setTimeout(function() { |
| 19 |
toaster.addClass("jltma-toaster-show"); |
| 20 |
}, 10); |
| 21 |
setTimeout(function() { |
| 22 |
toaster.removeClass("jltma-toaster-show"); |
| 23 |
setTimeout(function() { |
| 24 |
toaster.remove(); |
| 25 |
}, 300); |
| 26 |
}, 3e3); |
| 27 |
}; |
| 28 |
var megamenu_enable = "megamenu_enable", enable_megamenu = jQuery("#jltma-menu-metabox-input-is-enabled").is( |
| 29 |
":checked" |
| 30 |
) ? 1 : 0, jltma_megamenu_nonce = window.jltma_megamenu_nonce, JLTMA_Mega_Menu = { |
| 31 |
Enable_Mega_Menu: function() { |
| 32 |
var $checkbox = jQuery("#jltma-menu-metabox-input-is-enabled"); |
| 33 |
var enable_megamenu2 = $checkbox.is(":checked") ? 1 : 0; |
| 34 |
var $spinner = $checkbox.closest(".master-mega-menu-accordion").find(".spinner"); |
| 35 |
if (enable_megamenu2) { |
| 36 |
e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 37 |
} else { |
| 38 |
e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 39 |
} |
| 40 |
$spinner.addClass("loading").css("visibility", "visible"); |
| 41 |
e.ajax({ |
| 42 |
url: ajaxurl, |
| 43 |
type: "post", |
| 44 |
data: { |
| 45 |
action: "jltma_save_megamenu_options", |
| 46 |
is_enabled: enable_megamenu2 |
| 47 |
}, |
| 48 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce }, |
| 49 |
dataType: "json" |
| 50 |
}).done(function(response) { |
| 51 |
$spinner.removeClass("loading").css("visibility", "hidden"); |
| 52 |
if (typeof response === "string") { |
| 53 |
try { |
| 54 |
response = JSON.parse(response); |
| 55 |
} catch (e2) { |
| 56 |
console.error("Failed to parse response:", e2); |
| 57 |
if (typeof window.showToaster === "function") { |
| 58 |
window.showToaster("Mega Menu settings saved successfully!", "success"); |
| 59 |
} |
| 60 |
return; |
| 61 |
} |
| 62 |
} |
| 63 |
if (response && response.status == "success") { |
| 64 |
if (enable_megamenu2) { |
| 65 |
e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 66 |
} else { |
| 67 |
e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 68 |
} |
| 69 |
localStorage.setItem("megamenu_enable", enable_megamenu2); |
| 70 |
var message = response.message || (enable_megamenu2 ? "Mega Menu enabled successfully!" : "Mega Menu disabled successfully!"); |
| 71 |
if (typeof window.showToaster === "function") { |
| 72 |
window.showToaster(message, "success"); |
| 73 |
} |
| 74 |
} else { |
| 75 |
var errorMsg = response && response.message ? response.message : "Failed to save Mega Menu settings"; |
| 76 |
if (typeof window.showToaster === "function") { |
| 77 |
window.showToaster(errorMsg, "error"); |
| 78 |
} |
| 79 |
$checkbox.prop("checked", !enable_megamenu2); |
| 80 |
if (!enable_megamenu2) { |
| 81 |
e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 82 |
} else { |
| 83 |
e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 84 |
} |
| 85 |
} |
| 86 |
}).fail(function(xhr, status, error) { |
| 87 |
$spinner.removeClass("loading").css("visibility", "hidden"); |
| 88 |
console.error("AJAX Error:", status, error); |
| 89 |
if (typeof window.showToaster === "function") { |
| 90 |
window.showToaster("Failed to save Mega Menu settings. Please try again.", "error"); |
| 91 |
} |
| 92 |
$checkbox.prop("checked", !enable_megamenu2); |
| 93 |
if (!enable_megamenu2) { |
| 94 |
e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 95 |
} else { |
| 96 |
e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 97 |
} |
| 98 |
}); |
| 99 |
return false; |
| 100 |
}, |
| 101 |
Menu_Item_Settings_Save: function() { |
| 102 |
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 = { |
| 103 |
is_enabled: t, |
| 104 |
menu_id: n |
| 105 |
}; |
| 106 |
i.addClass("loading"), e.get( |
| 107 |
masteraddons_megamenu.resturl + "megamenu/save_megamenu_settings", |
| 108 |
m |
| 109 |
).done(function(e2) { |
| 110 |
i.removeClass("loading"); |
| 111 |
}); |
| 112 |
}, |
| 113 |
Menu_Item_Save: function() { |
| 114 |
var t = e(this).parent().find(".spinner"), n = { |
| 115 |
settings: { |
| 116 |
menu_id: e("#jltma-menu-modal-menu-id").val(), |
| 117 |
menu_has_child: e("#jltma-menu-modal-menu-has-child").val(), |
| 118 |
menu_enable: e("#jltma-menu-item-enable:checked").val(), |
| 119 |
menu_label_enable: e("#mega-menu-hide-item-label:checked").val(), |
| 120 |
menu_transition: e("#mega-menu-transition-effect").val(), |
| 121 |
menu_disable_description: e( |
| 122 |
"#jltma-menu-disable-description:checked" |
| 123 |
).val(), |
| 124 |
menu_icon: e("#jltma-menu-icon-field").val(), |
| 125 |
menu_trigger_effect: e("#mega-menu-trigger-effect").val(), |
| 126 |
menu_icon_color: e("#jltma-menu-icon-color-field").val(), |
| 127 |
menu_badge_text: e("#jltma-menu-badge-text-field").val(), |
| 128 |
menu_width_type: e("#jltma-megamenu-width-type").val(), |
| 129 |
menu_width_size: e("#jltma-megamenu-width").val(), |
| 130 |
menu_mobile_submenu_content_type: e( |
| 131 |
"#jltma-mobile-submenu-type" |
| 132 |
).val(), |
| 133 |
menu_badge_color: e("#jltma-menu-badge-color-field").val(), |
| 134 |
// menu_mobile_submenu_content_type:e("#jltma-mobile-submenu-type").val(), |
| 135 |
menu_badge_background: e( |
| 136 |
"#jltma-menu-badge-background-field" |
| 137 |
).val() |
| 138 |
} |
| 139 |
}; |
| 140 |
t.addClass("loading"), e.ajax({ |
| 141 |
url: masteraddons_megamenu.resturl + "megamenu/jltma_save_menuitem_settings", |
| 142 |
type: "get", |
| 143 |
data: n, |
| 144 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce }, |
| 145 |
dataType: "json", |
| 146 |
success: function(n2) { |
| 147 |
t.removeClass("loading"), e("#jltma-menu-item-settings-modal").modal("hide"); |
| 148 |
} |
| 149 |
}); |
| 150 |
}, |
| 151 |
Menu_Trigger: function() { |
| 152 |
var t = e("#jltma-menu-modal-menu-id").val(), baseUrl = masteraddons_megamenu.resturl + "mastermega-content/jltma_content_editor/megamenu/menuitem/" + t, separator = baseUrl.indexOf("?") !== -1 ? "&" : "?", n = baseUrl + separator + "_wpnonce=" + jltma_megamenu_nonce; |
| 153 |
e("#jltma-menu-builder-iframe").attr("src", n); |
| 154 |
} |
| 155 |
}; |
| 156 |
e(".jltma-menu-settings-save").on( |
| 157 |
"click", |
| 158 |
() => JLTMA_Mega_Menu.Menu_Item_Settings_Save(e) |
| 159 |
); |
| 160 |
e(".jltma-menu-item-save").on("click", function() { |
| 161 |
var t = e(this).parent().find(".spinner"), n = { |
| 162 |
settings: { |
| 163 |
menu_id: e("#jltma-menu-modal-menu-id").val(), |
| 164 |
menu_has_child: e("#jltma-menu-modal-menu-has-child").val(), |
| 165 |
menu_disable_description: e( |
| 166 |
"#jltma-menu-disable-description:checked" |
| 167 |
).val(), |
| 168 |
menu_enable: e("#jltma-menu-item-enable:checked").val(), |
| 169 |
menu_icon: e("#jltma-menu-icon-field").val(), |
| 170 |
menu_trigger_effect: e("#mega-menu-trigger-effect").val(), |
| 171 |
menu_icon_color: e("#jltma-menu-icon-color-field").val(), |
| 172 |
menu_label_enable: e("#mega-menu-hide-item-label:checked").val(), |
| 173 |
menu_transition: e("#mega-menu-transition-effect").val(), |
| 174 |
menu_badge_text: e("#jltma-menu-badge-text-field").val(), |
| 175 |
menu_width_type: e("#jltma-megamenu-width-type").val(), |
| 176 |
menu_width_size: e("#jltma-megamenu-width").val(), |
| 177 |
menu_mobile_submenu_content_type: e( |
| 178 |
"#jltma-mobile-submenu-type" |
| 179 |
).val(), |
| 180 |
menu_badge_color: e("#jltma-menu-badge-color-field").val(), |
| 181 |
// menu_mobile_submenu_content_type:e("#jltma-mobile-submenu-type").val(), |
| 182 |
menu_badge_background: e("#jltma-menu-badge-background-field").val() |
| 183 |
} |
| 184 |
}; |
| 185 |
t.addClass("loading"), e.ajax({ |
| 186 |
url: masteraddons_megamenu.resturl + "megamenu/jltma_save_menuitem_settings", |
| 187 |
type: "get", |
| 188 |
data: n, |
| 189 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce }, |
| 190 |
dataType: "json", |
| 191 |
success: function(n2) { |
| 192 |
t.removeClass("loading"); |
| 193 |
showToaster("Settings saved successfully!", "success"); |
| 194 |
}, |
| 195 |
error: function(xhr, status, error) { |
| 196 |
t.removeClass("loading"); |
| 197 |
showToaster("Failed to save settings. Please try again.", "error"); |
| 198 |
} |
| 199 |
}); |
| 200 |
}), e("#jltma-menu-builder-trigger").on( |
| 201 |
"click", |
| 202 |
() => JLTMA_Mega_Menu.Menu_Trigger(e) |
| 203 |
); |
| 204 |
e("body").on("DOMSubtreeModified", "#menu-to-edit", function() { |
| 205 |
setTimeout(function() { |
| 206 |
e("#menu-to-edit li.menu-item").each(function() { |
| 207 |
var t = e(this); |
| 208 |
t.find(".jltma_menu_trigger").length < 1 && e(".item-title", t).append( |
| 209 |
"<a data-toggle='modal' data-target='#jltma_megamenu_modal' href='#' class='jltma_menu_trigger'>Master Mega</a> " |
| 210 |
); |
| 211 |
}); |
| 212 |
}, 200); |
| 213 |
}), e("#menu-to-edit").trigger("DOMSubtreeModified"), e("#menu-to-edit").on("click", ".jltma_menu_trigger", function(n) { |
| 214 |
n.preventDefault(); |
| 215 |
var i = e("#jltma_megamenu_modal"), m = e(this).parents("li.menu-item"), l = parseInt(m.attr("id").match(/[0-9]+/)[0], 10); |
| 216 |
m.find(".menu-item-title").text(), m.attr("class").match(/\menu-item-depth-(\d+)\b/)[1]; |
| 217 |
if (e(".jltma_menu_control_nav > li").removeClass("active"), e(".jltma-tab-pane").removeClass("active"), 1 == e(this).parent().find(".is-submenu").is(":hidden")) { |
| 218 |
var a = 0; |
| 219 |
i.removeClass("jltma-menu-has-child"), e("#content_nav").addClass("active"), e("#content_tab").addClass("active"); |
| 220 |
} else { |
| 221 |
a = 1; |
| 222 |
i.addClass("jltma-menu-has-child"), e("#general_nav").addClass("active"), e("#general_tab").addClass("active show"); |
| 223 |
} |
| 224 |
e("#jltma-menu-modal-menu-id").val(l), e("#jltma-menu-modal-menu-has-child").val(a); |
| 225 |
var o = { menu_id: l }; |
| 226 |
e.ajax({ |
| 227 |
url: masteraddons_megamenu.resturl + "megamenu/get_menuitem_settings", |
| 228 |
type: "get", |
| 229 |
data: o, |
| 230 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce }, |
| 231 |
dataType: "json" |
| 232 |
}).done(function(n2) { |
| 233 |
e("#jltma-menu-item-enable").prop("checked", false), e("#mega-menu-trigger-effect").val(n2.menu_trigger_effect), // e("#jltma-mobile-submenu-type").val(n.menu_mobile_submenu_content_type), |
| 234 |
// Set color picker values - modern color picker compatible |
| 235 |
e("#jltma-menu-icon-color-field").val(n2.menu_icon_color || "").trigger("change"), // Set icon field - use default if empty |
| 236 |
(function() { |
| 237 |
var defaultIcon = "fas fa-chevron-down"; |
| 238 |
var iconValue = n2.menu_icon || defaultIcon; |
| 239 |
var $preview = e("#jltma-menu-icon-preview"); |
| 240 |
e("#jltma-menu-icon-field").val(iconValue); |
| 241 |
$preview.attr("class", iconValue); |
| 242 |
$preview.attr("style", "font-size: 20px; color: #fff; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;"); |
| 243 |
if (n2.menu_icon) { |
| 244 |
e(".jltma-icon-delete-btn").css({ "display": "flex", "align-items": "center", "justify-content": "center" }); |
| 245 |
} else { |
| 246 |
e(".jltma-icon-delete-btn").css("display", "none"); |
| 247 |
} |
| 248 |
})(), e("#mega-menu-transition-effect").val(n2.menu_transition), e("#mega-menu-hide-item-label").prop("checked", false), void 0 !== typeof n2.menu_label_enable && 1 == n2.menu_label_enable ? e("#mega-menu-hide-item-label").prop("checked", true) : e("#mega-menu-hide-item-label").prop("checked", false), e("#jltma-menu-badge-text-field").val(n2.menu_badge_text), e("#jltma-megamenu-width-type").val(n2.menu_width_type || "default"), e("#jltma-megamenu-width").val(n2.menu_width_size || "1000px"), e("#jltma-mobile-submenu-type").val( |
| 249 |
n2.menu_mobile_submenu_content_type || "builder_content" |
| 250 |
), e("#jltma-menu-disable-description").prop("checked", false), void 0 !== typeof n2.menu_disable_description && 1 == n2.menu_disable_description ? e("#jltma-menu-disable-description").prop("checked", true) : e("#jltma-menu-disable-description").prop("checked", false), // Set color picker values - modern color picker compatible |
| 251 |
e("#jltma-menu-badge-color-field").val(n2.menu_badge_color || "#6814cd").trigger("change"), e("#jltma-menu-badge-background-field").val(n2.menu_badge_background || "#6814cd").trigger("change"), void 0 !== typeof n2.menu_enable && 1 == n2.menu_enable ? e("#jltma-menu-item-enable").prop("checked", true) : e("#jltma-menu-item-enable").prop("checked", false), // void 0!==typeof n.menu_mobile_submenu_content_type&&1==n.menu_mobile_submenu_content_type?e("#menu_mobile_submenu_content_type").prop("checked", !0): e("#menu_mobile_submenu_content_type").prop("checked", !1), |
| 252 |
// e("#menu_mobile_submenu_content_type input").prop("checked", !1), void 0===typeof n.menu_mobile_submenu_content_type||"builder_content"==n.menu_mobile_submenu_content_type?e("#menu_mobile_submenu_content_type input[value=builder_content]").prop("checked", !0):e("#menu_mobile_submenu_content_type input[value=submenu_list]").prop("checked", !0), |
| 253 |
e("#jltma-menu-item-enable").trigger("change"), n2.menu_width_type == "custom_width" ? e("#jltma-megamenu-width").removeClass("hidden") : e("#jltma-megamenu-width").addClass("hidden"), setTimeout(function() { |
| 254 |
i.removeClass("jltma-menu-modal-loading"); |
| 255 |
i.addClass("show"); |
| 256 |
}, 500); |
| 257 |
}); |
| 258 |
}); |
| 259 |
e("#jltma-menu-item-enable").on("change", function() { |
| 260 |
e(this).is(":checked") ? (e("#jltma-menu-builder-trigger").prop("disabled", false), e("#jltma-menu-builder-wrapper").addClass("is_enabled")) : (e("#jltma-menu-item-enable").prop("checked", false), e("#jltma-menu-builder-wrapper").removeClass("is_enabled"), e("#jltma-menu-builder-trigger").prop("disabled", true)); |
| 261 |
}); |
| 262 |
e("#jltma-mega-menu-settings").on( |
| 263 |
"change", |
| 264 |
"#jltma-menu-metabox-input-is-enabled", |
| 265 |
() => JLTMA_Mega_Menu.Enable_Mega_Menu(e) |
| 266 |
); |
| 267 |
e("#jltma-megamenu-width-type").on("change", function() { |
| 268 |
if (this.value == "custom_width") { |
| 269 |
e(this).siblings("#jltma-megamenu-width").removeClass("hidden"); |
| 270 |
} else { |
| 271 |
e(this).siblings("#jltma-megamenu-width").addClass("hidden"); |
| 272 |
} |
| 273 |
}); |
| 274 |
e.ajax({ |
| 275 |
url: ajaxurl, |
| 276 |
type: "get", |
| 277 |
data: { |
| 278 |
action: "jltma_get_megamenu_options" |
| 279 |
}, |
| 280 |
headers: { "X-WP-Nonce": jltma_megamenu_nonce } |
| 281 |
}).done(function(response) { |
| 282 |
response = jQuery.parseJSON(response); |
| 283 |
var isMegaEnabled = response && response.is_enabled == "1"; |
| 284 |
if (isMegaEnabled) { |
| 285 |
e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"); |
| 286 |
localStorage.setItem("megamenu_enable", "1"); |
| 287 |
e("#jltma-menu-metabox-input-is-enabled").prop("checked", true); |
| 288 |
} else { |
| 289 |
e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled"); |
| 290 |
localStorage.setItem("megamenu_enable", "0"); |
| 291 |
e("#jltma-menu-metabox-input-is-enabled").prop("checked", false); |
| 292 |
} |
| 293 |
}); |
| 294 |
jQuery(document).on("click", function(e2) { |
| 295 |
if (jQuery("#jltma_megamenu_modal").hasClass("show") && !jQuery(e2.target).closest(".jltma-modal-dialog, .jltma_menu_trigger").length) { |
| 296 |
jQuery("#jltma_megamenu_modal").removeClass("show"); |
| 297 |
} |
| 298 |
}); |
| 299 |
jQuery("body").on("click", ".jltma-modal-dialog", function(e2) { |
| 300 |
e2.stopPropagation(); |
| 301 |
}); |
| 302 |
jQuery("body").on("click", "#jltma_megamenu_modal .jltma-pop-close, #jltma_megamenu_modal .close-btn", function(e2) { |
| 303 |
e2.preventDefault(); |
| 304 |
jQuery("#jltma_megamenu_modal").removeClass("show"); |
| 305 |
}); |
| 306 |
jQuery("body").on("click", "#jltma-menu-builder-trigger", function(e2) { |
| 307 |
jQuery("#jltma-mega-menu-builder-modal").toggleClass("show"); |
| 308 |
}); |
| 309 |
jQuery("body").on("click", "#jltma-mega-menu-builder-modal .jltma-pop-close", function(e2) { |
| 310 |
e2.preventDefault(); |
| 311 |
jQuery("#jltma-mega-menu-builder-modal").removeClass("show"); |
| 312 |
}); |
| 313 |
jQuery(document).on("keydown", function(e2) { |
| 314 |
if (e2.key === "Escape" || e2.keyCode === 27) { |
| 315 |
if (jQuery("#jltma_megamenu_modal").hasClass("show")) { |
| 316 |
jQuery("#jltma_megamenu_modal").removeClass("show"); |
| 317 |
} |
| 318 |
if (jQuery("#jltma-mega-menu-builder-modal").hasClass("show")) { |
| 319 |
jQuery("#jltma-mega-menu-builder-modal").removeClass("show"); |
| 320 |
} |
| 321 |
} |
| 322 |
}); |
| 323 |
jQuery(".jltma-tab-content > div").hide(); |
| 324 |
jQuery(".jltma-tab-content > div:first-of-type").show(); |
| 325 |
jQuery(".jltma-tabs a").click(function(e2) { |
| 326 |
e2.preventDefault(); |
| 327 |
var jQuerythis = jQuery(this), tabgroup = "#" + jQuerythis.parents(".jltma-tabs").data("jltma-tab-content"), others = jQuerythis.closest("li").siblings().children("a"), target = jQuerythis.attr("href"); |
| 328 |
others.removeClass("active"); |
| 329 |
jQuerythis.addClass("active"); |
| 330 |
jQuery(tabgroup).children("div").hide(); |
| 331 |
jQuery(target).show(); |
| 332 |
jQuery(target).siblings().hide(); |
| 333 |
}); |
| 334 |
function initModernIconPicker() { |
| 335 |
var iconLibraryConfig = (masteraddons_megamenu == null ? void 0 : masteraddons_megamenu.iconLibrary) || {}; |
| 336 |
var allIcons = []; |
| 337 |
var sidebarList = []; |
| 338 |
sidebarList.push({ |
| 339 |
title: "All Icons", |
| 340 |
"list-icon": "dashicons dashicons-marker", |
| 341 |
"library-id": "all" |
| 342 |
}); |
| 343 |
Object.entries(iconLibraryConfig).forEach(function([libraryName, libraryData]) { |
| 344 |
Object.entries(libraryData).forEach(function([categoryName, categoryData]) { |
| 345 |
var iconTitle = categoryName !== "" ? libraryName + " - " + categoryName : libraryName; |
| 346 |
sidebarList.push({ |
| 347 |
title: iconTitle, |
| 348 |
"list-icon": categoryData["list-icon"] || "", |
| 349 |
"library-id": categoryData["icon-style"] || "all" |
| 350 |
}); |
| 351 |
if (categoryData.icons && Array.isArray(categoryData.icons)) { |
| 352 |
categoryData.icons.forEach(function(iconName) { |
| 353 |
var fullClass = categoryData.prefix + iconName; |
| 354 |
allIcons.push({ |
| 355 |
class: fullClass, |
| 356 |
name: iconName, |
| 357 |
library: categoryData["icon-style"], |
| 358 |
prefix: categoryData.prefix |
| 359 |
}); |
| 360 |
}); |
| 361 |
} |
| 362 |
}); |
| 363 |
}); |
| 364 |
jQuery(document).on("click", ".jltma-icon-delete-btn", function(e2) { |
| 365 |
e2.preventDefault(); |
| 366 |
e2.stopPropagation(); |
| 367 |
console.log("=== DELETE ICON CLICKED ==="); |
| 368 |
var $deleteBtn = jQuery(this); |
| 369 |
var $wrapper = $deleteBtn.closest(".jltma-modern-icon-picker-wrapper"); |
| 370 |
var $input = $wrapper.find(".icon-picker-input"); |
| 371 |
var $preview = jQuery("#jltma-menu-icon-preview"); |
| 372 |
var $button = $wrapper.find(".icon-picker"); |
| 373 |
console.log("Found elements:", { |
| 374 |
preview: $preview.length, |
| 375 |
input: $input.length, |
| 376 |
button: $button.length |
| 377 |
}); |
| 378 |
console.log("BEFORE - Preview state:", { |
| 379 |
class: $preview.attr("class"), |
| 380 |
style: $preview.attr("style"), |
| 381 |
display: $preview.css("display"), |
| 382 |
element: $preview[0] |
| 383 |
}); |
| 384 |
$input.val(""); |
| 385 |
console.log("Input cleared, value:", $input.val()); |
| 386 |
$preview.attr("class", ""); |
| 387 |
$preview.attr("style", "font-size: 24px; color: #fff; display: none !important;"); |
| 388 |
$preview.hide(); |
| 389 |
jQuery("#jltma-icon-preview-box").css("border-color", "#2d3748"); |
| 390 |
console.log("AFTER - Preview state:", { |
| 391 |
class: $preview.attr("class"), |
| 392 |
style: $preview.attr("style"), |
| 393 |
display: $preview.css("display"), |
| 394 |
element: $preview[0] |
| 395 |
}); |
| 396 |
$deleteBtn.hide(); |
| 397 |
$button.removeClass("has-icon"); |
| 398 |
console.log("=== DELETE COMPLETE ==="); |
| 399 |
}); |
| 400 |
jQuery(document).on("click", ".icon-picker", function(e2) { |
| 401 |
e2.preventDefault(); |
| 402 |
e2.stopPropagation(); |
| 403 |
console.log("Icon picker clicked"); |
| 404 |
var $button = jQuery(this); |
| 405 |
var $wrapper = $button.closest(".jltma-modern-icon-picker-wrapper"); |
| 406 |
var $input = $wrapper.find(".icon-picker-input"); |
| 407 |
var $preview = $wrapper.find("#jltma-menu-icon-preview"); |
| 408 |
var $deleteBtn = $wrapper.find(".jltma-icon-delete-btn"); |
| 409 |
var currentIcon = $input.val(); |
| 410 |
console.log("Icon picker data:", { |
| 411 |
allIconsCount: allIcons.length, |
| 412 |
currentIcon, |
| 413 |
hasIconLibrary: !!(masteraddons_megamenu == null ? void 0 : masteraddons_megamenu.iconLibrary) |
| 414 |
}); |
| 415 |
if (allIcons.length === 0) { |
| 416 |
alert("Icon library not loaded. Please refresh the page."); |
| 417 |
return; |
| 418 |
} |
| 419 |
showModernIconPickerModal(currentIcon, function(selectedIcon) { |
| 420 |
$input.val(selectedIcon); |
| 421 |
var $iconPreview = jQuery("#jltma-menu-icon-preview"); |
| 422 |
$iconPreview.attr("class", selectedIcon); |
| 423 |
$iconPreview.attr("style", "font-size: 24px; color: #fff; display: block;"); |
| 424 |
if ($deleteBtn.length > 0) { |
| 425 |
$deleteBtn.css({ "display": "flex", "align-items": "center", "justify-content": "center" }); |
| 426 |
} |
| 427 |
$button.addClass("has-icon"); |
| 428 |
console.log("Icon selected:", selectedIcon); |
| 429 |
}); |
| 430 |
}); |
| 431 |
function showModernIconPickerModal(currentIcon, onSelect) { |
| 432 |
var activeLibrary = "all"; |
| 433 |
var searchTerm = ""; |
| 434 |
var selectedIcon = currentIcon || ""; |
| 435 |
if (currentIcon) { |
| 436 |
var currentIconData = allIcons.find(function(icon) { |
| 437 |
return icon.class === currentIcon; |
| 438 |
}); |
| 439 |
if (currentIconData) { |
| 440 |
activeLibrary = currentIconData.library; |
| 441 |
} |
| 442 |
} |
| 443 |
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) { |
| 444 |
var isActive = activeLibrary === item["library-id"] ? "aesthetic-active" : ""; |
| 445 |
var icon = item["list-icon"] ? '<i class="' + item["list-icon"] + '"></i>' : ""; |
| 446 |
return '<div class="aim-modal--sidebar-tab-item ' + isActive + '" data-library-id="' + item["library-id"] + '">' + icon + item.title + "</div>"; |
| 447 |
}).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>'; |
| 448 |
var $modal = jQuery(modalHtml); |
| 449 |
jQuery("body").append($modal); |
| 450 |
function renderIcons() { |
| 451 |
var filteredIcons = allIcons.filter(function(icon) { |
| 452 |
var matchesSearch = searchTerm === "" || icon.name.toLowerCase().includes(searchTerm.toLowerCase()); |
| 453 |
var matchesLibrary = activeLibrary === "all" || icon.library === activeLibrary; |
| 454 |
return matchesSearch && matchesLibrary; |
| 455 |
}); |
| 456 |
var iconsHtml = filteredIcons.map(function(icon) { |
| 457 |
var isSelected = selectedIcon === icon.class ? "aesthetic-selected" : ""; |
| 458 |
var displayName = icon.name.replace(/-/g, " "); |
| 459 |
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>"; |
| 460 |
}).join(""); |
| 461 |
$modal.find("#aim-modal--icon-preview").html(iconsHtml); |
| 462 |
} |
| 463 |
renderIcons(); |
| 464 |
$modal.find(".aim-modal--header-close-btn, .aim-modal").on("click", function(e2) { |
| 465 |
if (e2.target === this) { |
| 466 |
$modal.remove(); |
| 467 |
} |
| 468 |
}); |
| 469 |
$modal.find(".aim-modal--content").on("click", function(e2) { |
| 470 |
e2.stopPropagation(); |
| 471 |
}); |
| 472 |
$modal.find(".aim-modal--sidebar-tab-item").on("click", function() { |
| 473 |
activeLibrary = jQuery(this).data("library-id"); |
| 474 |
$modal.find(".aim-modal--sidebar-tab-item").removeClass("aesthetic-active"); |
| 475 |
jQuery(this).addClass("aesthetic-active"); |
| 476 |
renderIcons(); |
| 477 |
}); |
| 478 |
$modal.find(".jltma-icon-search-input").on("input", function() { |
| 479 |
searchTerm = jQuery(this).val(); |
| 480 |
renderIcons(); |
| 481 |
}); |
| 482 |
$modal.on("click", ".aim-icon-item", function() { |
| 483 |
selectedIcon = jQuery(this).data("icon-class"); |
| 484 |
$modal.find(".aim-icon-item").removeClass("aesthetic-selected"); |
| 485 |
jQuery(this).addClass("aesthetic-selected"); |
| 486 |
}); |
| 487 |
$modal.find(".aim-insert-icon-button").on("click", function() { |
| 488 |
if (selectedIcon) { |
| 489 |
onSelect(selectedIcon); |
| 490 |
} |
| 491 |
$modal.remove(); |
| 492 |
}); |
| 493 |
} |
| 494 |
} |
| 495 |
initModernIconPicker(); |
| 496 |
var colorPickerInitialized = false; |
| 497 |
function initModernColorPicker() { |
| 498 |
if (colorPickerInitialized) return; |
| 499 |
jQuery(".jltma-menu-wpcolor-picker").each(function() { |
| 500 |
var $input = jQuery(this); |
| 501 |
if (!$input.hasClass("wp-color-picker")) { |
| 502 |
$input.wpColorPicker(); |
| 503 |
} |
| 504 |
}); |
| 505 |
setTimeout(function() { |
| 506 |
jQuery(".jltma-menu-wpcolor-picker").each(function() { |
| 507 |
var $input = jQuery(this); |
| 508 |
if ($input.attr("type") === "hidden" && $input.siblings(".jltma-modern-color-picker").length > 0) { |
| 509 |
return; |
| 510 |
} |
| 511 |
var initialColor = $input.val() || ""; |
| 512 |
var colorPickerHtml = '<div class="jltma-modern-color-picker"><input type="text" class="jltma-color-input" value="' + initialColor + '" placeholder="#000000" /><div class="jltma-color-preview" style="background-color: ' + initialColor + ';"><div class="jltma-color-preview-inner"></div></div><input type="color" class="jltma-color-native" value="' + initialColor + '" /></div>'; |
| 513 |
var inputId = $input.attr("id"); |
| 514 |
var $container = $input.closest(".wp-picker-container"); |
| 515 |
if ($container.length > 0) { |
| 516 |
$container.replaceWith(colorPickerHtml); |
| 517 |
var $modernPicker = jQuery(".jltma-modern-color-picker").last(); |
| 518 |
$modernPicker.attr("data-input-id", inputId); |
| 519 |
$input.attr("type", "hidden").insertAfter($modernPicker); |
| 520 |
} |
| 521 |
}); |
| 522 |
colorPickerInitialized = true; |
| 523 |
}, 500); |
| 524 |
} |
| 525 |
jQuery(document).on("click", ".jltma-color-preview", function() { |
| 526 |
jQuery(this).siblings(".jltma-color-native").click(); |
| 527 |
}); |
| 528 |
jQuery(document).on("input change", ".jltma-color-native", function() { |
| 529 |
var color = jQuery(this).val(); |
| 530 |
var $picker = jQuery(this).closest(".jltma-modern-color-picker"); |
| 531 |
var inputId = $picker.attr("data-input-id"); |
| 532 |
$picker.find(".jltma-color-preview").css("background-color", color); |
| 533 |
$picker.find(".jltma-color-input").val(color); |
| 534 |
jQuery("#" + inputId).val(color).trigger("change"); |
| 535 |
}); |
| 536 |
jQuery(document).on("input change", ".jltma-color-input", function() { |
| 537 |
var color = jQuery(this).val(); |
| 538 |
var $picker = jQuery(this).closest(".jltma-modern-color-picker"); |
| 539 |
var inputId = $picker.attr("data-input-id"); |
| 540 |
if (/^#[0-9A-F]{6}$/i.test(color) || /^#[0-9A-F]{3}$/i.test(color)) { |
| 541 |
$picker.find(".jltma-color-preview").css("background-color", color); |
| 542 |
$picker.find(".jltma-color-native").val(color); |
| 543 |
jQuery("#" + inputId).val(color).trigger("change"); |
| 544 |
} |
| 545 |
}); |
| 546 |
jQuery(document).on("click", ".jltma-color-clear", function() { |
| 547 |
var $picker = jQuery(this).closest(".jltma-modern-color-picker"); |
| 548 |
var inputId = $picker.attr("data-input-id"); |
| 549 |
$picker.find(".jltma-color-preview").css("background-color", ""); |
| 550 |
$picker.find(".jltma-color-input").val(""); |
| 551 |
$picker.find(".jltma-color-native").val("#000000"); |
| 552 |
jQuery("#" + inputId).val("").trigger("change"); |
| 553 |
}); |
| 554 |
jQuery(document).on("change", ".jltma-menu-wpcolor-picker", function() { |
| 555 |
var $hiddenInput = jQuery(this); |
| 556 |
var color = $hiddenInput.val(); |
| 557 |
var inputId = $hiddenInput.attr("id"); |
| 558 |
var $picker = jQuery('.jltma-modern-color-picker[data-input-id="' + inputId + '"]'); |
| 559 |
if ($picker.length > 0 && color) { |
| 560 |
$picker.find(".jltma-color-preview").css("background-color", color); |
| 561 |
$picker.find(".jltma-color-input").val(color); |
| 562 |
$picker.find(".jltma-color-native").val(color); |
| 563 |
} |
| 564 |
}); |
| 565 |
}); |
| 566 |
})(); |
| 567 |
|