View file File name : context-menu.min.js Content :var WPForms=window.WPForms||{};WPForms.Admin=WPForms.Admin||{},WPForms.Admin.Builder=WPForms.Admin.Builder||{},WPForms.Admin.Builder.ContextMenu=WPForms.Admin.Builder.ContextMenu||function(e,a,o){const c={},l={selectors:{contextMenu:".wpforms-context-menu",mainContextMenuContainer:"#wpforms-context-menu-container",mainContextMenu:"#wpforms-context-menu",fieldContextMenu:"#wpforms-field-context-menu",contextMenuItem:".wpforms-context-menu:not(.wpforms-context-menu-dropdown) .wpforms-context-menu-list-item",contextMenuSelectiveItem:".wpforms-context-menu-list-item-selective",contextMenuDivider:".wpforms-context-menu .wpforms-context-menu-list-divider",builder:"#wpforms-builder",sidebarToggle:".wpforms-panels .wpforms-panel-sidebar-content .wpforms-panel-sidebar-toggle"},init(){o(l.ready)},ready(){l.setup(),l.events()},setup(){c.$document=o(e),c.$contextMenu=o(l.selectors.contextMenu),c.$mainContextMenuContainer=o(l.selectors.mainContextMenuContainer),c.$mainContextMenu=o(l.selectors.mainContextMenu),c.$fieldContextMenu=o(l.selectors.fieldContextMenu),c.$contextMenuItem=o(l.selectors.contextMenuItem),c.$contextMenuSelectiveItem=o(l.selectors.contextMenuSelectiveItem),c.$contextMenuDivider=o(l.selectors.contextMenuDivider),c.$builder=o(l.selectors.builder),c.$sidebarToggle=o(l.selectors.sidebarToggle)},events(){c.$mainContextMenuContainer.on("click",e=>{e.preventDefault(),c.$mainContextMenu.fadeToggle(150,()=>{c.$mainContextMenuContainer.toggleClass("wpforms-context-menu-active")})}),c.$mainContextMenu.on("click",".wpforms-context-menu-list-item",l.mainMenuItemClickAction),c.$builder.on("click contextmenu",l.hideMainContextMenu),c.$document.on("contextmenu",l.rightClickContextMenuHandler),c.$document.on("click",l.hideMenuOnClick),c.$builder.on("wpformsFieldTabToggle",l.hideMenuOnClick)},rightClickContextMenuHandler(e){const t=o(e.target).closest(".wpforms-field");t.closest("#wpforms-panel-fields").length&&t.length&&!o(e.target).closest(l.selectors.contextMenu).length&&(l.hideMenu(),e.ctrlKey||(e.preventDefault(),setTimeout(function(){l.checkMenuItemsVisibility(t),l.checkDividerVisibility(),l.menuPositioning(e),l.menuItemClickAction(t),l.checkSelectiveMenuItemsState(t)},150)))},hideMainContextMenu(e){c.$mainContextMenu.is(":hidden")||0<o(e.target).closest(l.selectors.mainContextMenuContainer).length||c.$mainContextMenu.fadeOut(150,()=>{c.$mainContextMenuContainer.removeClass("wpforms-context-menu-active")})},mainMenuItemClickAction(){var e=o(this),t=e.data("action");const i=e.data("action-url")??"";e={"duplicate-form":()=>l.handleUrlAction(i,!1,!0),"save-as-template":()=>l.handleUrlAction(i,!1,!0),"duplicate-template":()=>l.handleUrlAction(i,!1,!0),"view-entries":()=>l.handleUrlAction(i,!0),"view-payments":()=>l.handleUrlAction(i,!0),"keyboard-shortcuts":WPFormsBuilder.openKeyboardShortcutsModal,"whats-new":l.handleWhatsNewAction}[t];e&&e()},menuItemClickAction(i){const n=i.data("field-id");c.$contextMenuItem.off("click").on("click",function(){const e=o(this);var t;e.hasClass("wpforms-context-menu-list-item-has-child")||((t={edit:()=>l.handleEditAction(i,n),duplicate:()=>l.handleDuplicateAction(i),delete:()=>l.handleDeleteAction(i),required:()=>l.handleRequiredAction(e,n),label:()=>l.handleLabelAction(e,n),"smart-logic":()=>l.handleSmartLogicAction(i,n),"field-size":()=>l.handleSizeAction(e,n)}[e.data("action")])&&t(),l.hideMenu())})},handleEditAction(e,t){e.trigger("click"),l.maybeOpenSidebar(),o(`#wpforms-field-option-basic-${t} .wpforms-field-option-group-toggle`).trigger("click")},handleDuplicateAction(e){e.find(".wpforms-field-duplicate").first().trigger("click")},handleDeleteAction(e){e.find(".wpforms-field-delete").first().trigger("click")},handleRequiredAction(e,t){o(`#wpforms-field-option-${t}-required`).trigger("click");t=l.checkRequiredState(t)?"active":"inactive";l.toggleItemText(e,t)},handleLabelAction(e,t){o(`#wpforms-field-option-${t}-label_hide`).trigger("click");t=l.checkLabelState(t)?"active":"inactive";l.toggleItemText(e,t)},handleSmartLogicAction(e,t){l.maybeOpenSidebar(),e.trigger("click"),o(`#wpforms-field-option-conditionals-${t} .wpforms-field-option-group-toggle`).trigger("click"),o(`#wpforms-field-option-${t} .wpforms-field-option-group-conditionals .education-modal`).trigger("click")},handleSizeAction(e,t){var i=e.data("value");o(`#wpforms-field-option-${t}-size`).val(i).trigger("change"),e.addClass("wpforms-context-menu-list-item-active").siblings().removeClass("wpforms-context-menu-list-item-active")},handleWhatsNewAction(){o("#tmpl-wpforms-splash-modal-content").length&&"undefined"!=typeof WPSplash&&WPSplash.openModal()},handleUrlAction(e,t=!1,i=!1){e&&(i&&wpf.savedState!==wpf.getFormState("#wpforms-builder-form")?(c.$builder.on("wpformsSaved",()=>{t?a.open(e):a.location.assign(e)}),WPFormsBuilder.formSave(!1)):t?a.open(e):a.location.assign(e))},toggleItemText(e,t){var e=e.find(".wpforms-context-menu-list-item-text"),i=e.data("active-text"),n=e.data("inactive-text")||e.text();i&&(e.data("inactive-text",n),e.text("active"===t?i:n))},checkSelectiveMenuItemsState(e){const n=e.data("field-id");c.$contextMenuSelectiveItem.each(function(){var e=o(this),t=e.data("action");const i=e.data("value");(0,{required:()=>l.checkRequiredState(n),label:()=>l.checkLabelState(n),"field-size":()=>l.checkFieldSizeState(n,i)}[t])()?(e.addClass("wpforms-context-menu-list-item-active"),l.toggleItemText(e,"active")):(e.removeClass("wpforms-context-menu-list-item-active"),l.toggleItemText(e,"inactive"))})},checkRequiredState(e){return o(`#wpforms-field-option-${e}-required[type="checkbox"]`).is(":checked")},checkLabelState(e){return o(`#wpforms-field-option-${e}-label_hide[type="checkbox"]`).is(":checked")},checkFieldSizeState(e,t){return o(`#wpforms-field-option-${e}-size`).val()===t},menuPositioning(e){var t=c.$fieldContextMenu.width(),i=c.$fieldContextMenu.height(),n=a.innerWidth,o=a.innerHeight;c.$fieldContextMenu.removeClass("wpforms-context-menu-selective-left");let l=e.pageY,s=e.pageX;e.pageY+i>o&&(l=o-i-15),e.pageX+t>n&&(s=n-t-15,c.$fieldContextMenu.addClass("wpforms-context-menu-selective-left")),c.$fieldContextMenu.css({top:l+"px",left:s+"px"}),c.$fieldContextMenu.fadeIn(150)},checkMenuItemsVisibility(e){const t=e.data("field-id"),i={edit:()=>l.shouldHideEdit(e),duplicate:()=>l.shouldHideDuplicate(e),delete:()=>l.shouldHideDelete(e),required:()=>l.shouldHideRequired(t),label:()=>l.shouldHideLabel(t),"smart-logic":()=>l.shouldHideSmartLogic(t),"field-size":()=>l.shouldHideFieldSize(t,e)};c.$contextMenuItem.each(function(){var e=o(this),t=e.data("action");(0,i[t])()&&e.hide()})},shouldHideEdit(e){return e.hasClass("internal-information-not-editable")},shouldHideDuplicate(e){e=e.find(".wpforms-field-duplicate");return 0===e.length||"none"===e.css("display")},shouldHideDelete(e){e=e.find(".wpforms-field-delete");return 0===e.length||"none"===e.css("display")},shouldHideRequired(e){return 0===o(`#wpforms-field-option-${e}-required[type="checkbox"]`).length},shouldHideLabel(e){e=o(`#wpforms-field-option-${e}-label_hide[type="checkbox"]`);return 0===e.length||e.parents(".wpforms-field-option-row").hasClass("wpforms-disabled")},shouldHideFieldSize(e,t){var i=0<t.closest(".wpforms-layout-column").length,t=0<t.closest(".wpforms-field-repeater").length,e=o(`#wpforms-field-option-${e}-size`);return 0===e.length||i||t||e.parent().hasClass("wpforms-hidden")},shouldHideSmartLogic(e){return 0===o("#wpforms-field-option-conditionals-"+e).length&&0===o(`#wpforms-field-option-${e} .wpforms-field-option-group-conditionals .education-modal`).length},checkDividerVisibility(){c.$contextMenuDivider.each(function(){var e=o(this),t=e.data("visibility")??"";let i=!0;t.split(",").forEach(function(e){"none"!==o('.wpforms-context-menu-list-item[data-action="'+e.trim()+'"]').css("display")&&(i=!1)}),i?e.hide():e.show()})},hideMenu(){c.$fieldContextMenu.fadeOut(150),setTimeout(function(){c.$contextMenuItem.show()},150)},hideMenuOnClick(e){o(e.target).closest(l.selectors.contextMenu).length||l.hideMenu()},maybeOpenSidebar(){c.$sidebarToggle.parent().hasClass("wpforms-panel-sidebar-closed")&&c.$sidebarToggle.trigger("click")}};return l}(document,window,jQuery),WPForms.Admin.Builder.ContextMenu.init();