PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.3.2
Adminify – White Label, Admin Menu Editor, Login Customizer v4.3.2
4.3.2 4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 All 165 releases
adminify / assets / admin / js / wp-adminify--popup-folder.js

wp-adminify--popup-folder.js in Adminify – White Label, Admin Menu Editor, Login Customizer 4.3.2, at assets/admin/js/wp-adminify--popup-folder.js

32 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*
2 * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
3 * This devtool is neither made for production nor for readable output files.
4 * It uses "eval()" calls to create a separate source file in the browser devtools.
5 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
6 * or disable the default devtool with "devtool: false".
7 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
8 */
9 /******/ (() => { // webpackBootstrap
10 /******/ var __webpack_modules__ = ({
11
12 /***/ "./dev/admin/modules/folder/modal-popup-folder.js":
13 /*!********************************************************!*\
14 !*** ./dev/admin/modules/folder/modal-popup-folder.js ***!
15 \********************************************************/
16 /***/ (() => {
17
18 eval("var $ = window.jQuery;\n\n// Track React roots for cleanup - exposed globally for cross-module access\nwindow.wpAdminifyModalRoots = window.wpAdminifyModalRoots || new Map();\n\n// Initialize when DOM is ready\n$(function () {\n initMediaModalSidebar();\n});\n\n/**\n * Get the currently visible/active .media-modal element.\n * Elementor can leave old hidden modals in the DOM while creating new ones,\n * so we must always target the visible one.\n */\nfunction getActiveMediaModal() {\n var modals = document.querySelectorAll('.media-modal');\n for (var i = modals.length - 1; i >= 0; i--) {\n var style = window.getComputedStyle(modals[i]);\n if (style.display !== 'none' && style.visibility !== 'hidden') {\n return modals[i];\n }\n }\n return null;\n}\n\n/**\n * Clean up folder containers and React roots from stale/hidden modals.\n * This prevents old containers in hidden modals from blocking injection\n * into the current visible modal.\n */\nfunction cleanupStaleModalContainers() {\n var activeModal = getActiveMediaModal();\n var roots = window.wpAdminifyModalRoots;\n\n // Remove folder containers from ALL modals that are NOT the active one\n $('.media-modal').each(function () {\n if (this !== activeModal) {\n var staleContainer = $(this).find('.wp-adminify--modal-folder-container');\n var staleNotice = $(this).find('.wp-adminify--modal-pro-notice');\n if (staleContainer.length || staleNotice.length) {\n // Unmount any React roots in stale containers\n if (roots && roots.size > 0) {\n roots.forEach(function (root, id) {\n var el = document.getElementById(id);\n if (el && !(activeModal !== null && activeModal !== void 0 && activeModal.contains(el))) {\n try {\n root.unmount();\n } catch (e) {}\n roots[\"delete\"](id);\n }\n });\n }\n staleContainer.remove();\n staleNotice.remove();\n }\n $(this).closest('.wp-core-ui').removeClass('wp-adminify-has-folders');\n }\n });\n}\n\n/**\n * Add pro upsell notice to media modal menu (when license is inactive)\n */\nfunction addProUpsellNotice() {\n var activeModal = getActiveMediaModal();\n if (!activeModal) return;\n if ($(activeModal).find('.wp-adminify--modal-pro-notice').length) {\n return;\n }\n var initialData = window.PXLBSADMINIFY_FOLDER_DATA;\n if (!initialData) return;\n var proNotice = $('<div>', {\n \"class\": 'wp-adminify--modal-pro-notice'\n });\n proNotice.html('<button class=\"wp-adminify--modal-pro-notice-close\" type=\"button\">' + '<svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"none\"><path d=\"M1 1l12 12M13 1L1 13\" stroke=\"currentColor\" stroke-width=\"1.8\" stroke-linecap=\"round\"/></svg>' + '</button>' + '<div class=\"wp-adminify--modal-pro-notice-icon\">' + '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"lucide lucide-crown-icon lucide-crown\"><path d=\"M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z\"/><path d=\"M5 21h14\"/></svg>' + '</div>' + '<h4>Unlock Pro Features</h4>' + '<p>Use WP Adminify folders with page builders by upgrading to PRO.</p>' + '<div class=\"wp-adminify--modal-pro-notice-actions\">' + '<a href=\"https://wpadminify.com/pricing\" class=\"wp-adminify--modal-pro-btn\" target=\"_blank\">Upgrade to Pro</a>' + '</div>');\n proNotice.on('click', '.wp-adminify--modal-pro-notice-close', function () {\n proNotice.slideUp(200);\n });\n var mediaMenu = $(activeModal).find('.media-frame-menu .media-menu');\n if (!mediaMenu.length) return;\n $(activeModal).closest('.wp-core-ui').addClass('wp-adminify-has-folders');\n var isElementor = document.body.classList.contains('elementor-editor-active');\n var menuItemEmbed = mediaMenu.find('#menu-item-embed');\n if (isElementor && menuItemEmbed.length) {\n menuItemEmbed.after(proNotice);\n } else {\n mediaMenu.append(proNotice);\n }\n}\n\n/**\n * Add folder container to the active/visible media modal menu\n */\nfunction addCustomDivToMediaModal() {\n // Clean up containers stuck in old/hidden modals first\n cleanupStaleModalContainers();\n var activeModal = getActiveMediaModal();\n if (!activeModal) return;\n\n // Skip if already injected in the ACTIVE modal\n if ($(activeModal).find('.wp-adminify--modal-folder-container').length) {\n return;\n }\n var initialData = window.PXLBSADMINIFY_FOLDER_DATA;\n var isPro = initialData && initialData.is_pro;\n var isGutenberg = document.body.classList.contains('block-editor-page');\n\n // Gutenberg editor: always show folder module (free feature)\n // Other editors (Elementor, Customizer, etc.): show upsell notice if not pro\n if (!isPro && !isGutenberg) {\n addProUpsellNotice();\n return;\n }\n var uniqueId = 'wp-adminify--modal-folder-container';\n var appId = 'wp-adminify--folder-app-modal';\n\n // Remove any leftover elements with these IDs (from destroyed modals)\n $('#' + uniqueId).remove();\n $('#' + appId).remove();\n var newDiv = $('<div>', {\n id: uniqueId,\n \"class\": 'wp-adminify--modal-folder-container'\n });\n var appDivEle = $('<div>', {\n id: appId\n });\n newDiv.append(appDivEle);\n var mediaMenu = $(activeModal).find('.media-frame-menu .media-menu');\n if (!mediaMenu.length) {\n return;\n }\n\n // Mark modal as having folder widget so CSS only targets this modal\n $(activeModal).closest('.wp-core-ui').addClass('wp-adminify-has-folders');\n\n // In Elementor: insert after \"Insert from URL\" (#menu-item-embed)\n var isElementor = document.body.classList.contains('elementor-editor-active');\n var menuItemEmbed = mediaMenu.find('#menu-item-embed');\n if (isElementor && menuItemEmbed.length) {\n menuItemEmbed.after(newDiv);\n } else {\n // Gutenberg / Customizer / other: append to end of menu\n mediaMenu.append(newDiv);\n }\n\n // Initialize React folder module after DOM is added\n setTimeout(function () {\n if (typeof window.wpAdminifyInitFolderModule === 'function') {\n window.wpAdminifyInitFolderModule(true, appId);\n }\n // Adjust folder list height to fit within modal\n setTimeout(adjustModalFolderListHeight, 200);\n }, 50);\n}\n\n/**\n * Attempt to inject the folder container with retries.\n */\nfunction addCustomDivToMediaModalWithRetry(maxAttempts) {\n maxAttempts = maxAttempts || 6;\n var attempt = 0;\n function tryInject() {\n var activeModal = getActiveMediaModal();\n if (activeModal) {\n var hasContainer = $(activeModal).find('.wp-adminify--modal-folder-container').length > 0;\n var hasNotice = $(activeModal).find('.wp-adminify--modal-pro-notice').length > 0;\n if (hasContainer || hasNotice) return;\n }\n attempt++;\n addCustomDivToMediaModal();\n\n // Check again on the active modal after injection attempt\n activeModal = getActiveMediaModal();\n var injected = activeModal && ($(activeModal).find('.wp-adminify--modal-folder-container').length > 0 || $(activeModal).find('.wp-adminify--modal-pro-notice').length > 0);\n if (!injected && attempt < maxAttempts) {\n setTimeout(tryInject, 300);\n }\n }\n tryInject();\n}\n\n/**\n * Calculate and set dynamic max-height for folder list inside media modal\n */\nfunction adjustModalFolderListHeight() {\n var modal = getActiveMediaModal();\n if (!modal) return;\n var container = modal.querySelector('.wp-adminify--modal-folder-container');\n if (!container) return;\n var folderList = container.querySelector('ul.folder--lists');\n if (!folderList) return;\n var menuFrame = modal.querySelector('.media-frame-menu');\n if (!menuFrame) return;\n var menuHeight = menuFrame.getBoundingClientRect().height;\n var folderWidget = container.querySelector('.wp-adminify--folder-widget');\n if (!folderWidget) return;\n var menuTop = menuFrame.getBoundingClientRect().top;\n var listTop = folderList.getBoundingClientRect().top;\n var usedAbove = listTop - menuTop;\n var bottomPadding = 44;\n var availableHeight = menuHeight - usedAbove - bottomPadding;\n if (availableHeight > 100) {\n folderList.style.maxHeight = availableHeight + 'px';\n }\n}\n\n/**\n * Initialize media modal folder sidebar\n * Extends wp.media.view.AttachmentsBrowser and Modal to inject folder sidebar\n */\nvar initMediaModalSidebar = function initMediaModalSidebar() {\n if (typeof wp === 'undefined' || !wp.media || !wp.media.view) {\n return;\n }\n var initialData = window.PXLBSADMINIFY_FOLDER_DATA;\n if (!initialData || !initialData.folders) {\n return;\n }\n\n // Store reference to original AttachmentsBrowser\n var AttachmentsBrowser = wp.media.view.AttachmentsBrowser;\n\n // Extend AttachmentsBrowser to add folder sidebar\n wp.media.view.AttachmentsBrowser = AttachmentsBrowser.extend({\n createSidebar: function createSidebar() {\n AttachmentsBrowser.prototype.createSidebar.apply(this, arguments);\n var isInModal = this.controller && this.controller.$el && this.controller.$el.hasClass('wp-core-ui');\n if (!isInModal) return;\n setTimeout(function () {\n addCustomDivToMediaModal();\n }, 300);\n }\n });\n\n // Patch Modal.prototype.open to detect every modal open (including reopens)\n var originalModalOpen = wp.media.view.Modal.prototype.open;\n wp.media.view.Modal.prototype.open = function () {\n var result = originalModalOpen.apply(this, arguments);\n\n // Use retry logic — DOM may not be fully ready on reopen (especially in Elementor)\n setTimeout(function () {\n addCustomDivToMediaModalWithRetry(6);\n }, 200);\n return result;\n };\n\n // Fallback: periodically check for visible modals missing the folder container\n setInterval(function () {\n var activeModal = getActiveMediaModal();\n if (activeModal && !activeModal.querySelector('.wp-adminify--modal-folder-container') && !activeModal.querySelector('.wp-adminify--modal-pro-notice')) {\n addCustomDivToMediaModal();\n }\n }, 1000);\n\n // Recalculate folder list height on window resize\n $(window).on('resize', adjustModalFolderListHeight);\n};\n\n//# sourceURL=webpack://adminify/./dev/admin/modules/folder/modal-popup-folder.js?");
19
20 /***/ })
21
22 /******/ });
23 /************************************************************************/
24 /******/
25 /******/ // startup
26 /******/ // Load entry module and return exports
27 /******/ // This entry module can't be inlined because the eval devtool is used.
28 /******/ var __webpack_exports__ = {};
29 /******/ __webpack_modules__["./dev/admin/modules/folder/modal-popup-folder.js"]();
30 /******/
31 /******/ })()
32 ;