Proyectos de Subversion Moodle

Rev

Rev 11 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

{"version":3,"file":"popover.min.js","sources":["../src/popover.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Javascript popover for the `core_calendar` subsystem.\n *\n * @module core_calendar/popover\n * @copyright 2021 Huong Nguyen <huongnv13@gmail.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 4.0\n */\n\nimport Popover from 'theme_boost/bootstrap/popover';\nimport * as CalendarSelectors from 'core_calendar/selectors';\n\n/**\n * Check if we are allowing to enable the popover or not.\n * @param {Element} dateContainer\n * @returns {boolean}\n */\nconst isPopoverAvailable = (dateContainer) => {\n    return window.getComputedStyle(dateContainer.querySelector(CalendarSelectors.elements.dateContent)).display === 'none';\n};\n\nconst isPopoverConfigured = new Map();\nconst showPopover = target => {\n    const dateContainer = target.closest(CalendarSelectors.elements.dateContainer);\n    if (!isPopoverConfigured.has(dateContainer)) {\n        const config = {\n            trigger: 'manual',\n            placement: 'top',\n            html: true,\n            title: dateContainer.dataset.title,\n            content: () => {\n                const source = dateContainer.querySelector(CalendarSelectors.elements.dateContent);\n                return source ? source.querySelector('.hidden').innerHTML : '';\n            },\n            'animation': false,\n        };\n        new Popover(target, config);\n\n        isPopoverConfigured.set(dateContainer, true);\n    }\n\n    if (isPopoverAvailable(dateContainer)) {\n        Popover.getInstance(target).show();\n        target.addEventListener('mouseleave', hidePopover);\n        target.addEventListener('focusout', hidePopover);\n        // Set up the hide function to the click event type.\n        target.addEventListener('click', hidePopover);\n    }\n};\n\nconst hidePopover = e => {\n    const target = e.target;\n    const dateContainer = e.target.closest(CalendarSelectors.elements.dateContainer);\n    if (!dateContainer) {\n        return;\n    }\n    if (isPopoverConfigured.has(dateContainer)) {\n        const isTargetActive = target.contains(document.activeElement);\n        const isTargetHover = target.matches(':hover');\n\n        // Checks if a target element is clicked or pressed.\n        const isTargetClicked = document.activeElement.contains(target);\n\n        let removeListener = true;\n        if (!isTargetActive && !isTargetHover) {\n            Popover.getOrCreateInstance(target).hide();\n        } else if (isTargetClicked) {\n            Popover.getOrCreateInstance(document.activeElement).hide();\n        } else {\n            removeListener = false;\n        }\n\n        if (removeListener) {\n            target.removeEventListener('mouseleave', hidePopover);\n            target.removeEventListener('focusout', hidePopover);\n            target.removeEventListener('click', hidePopover);\n        }\n    }\n};\n\n/**\n * Register events for date container.\n */\nconst registerEventListeners = () => {\n    const showPopoverHandler = (e) => {\n        const dayLink = e.target.closest(CalendarSelectors.links.dayLink);\n        if (!dayLink) {\n            return;\n        }\n\n        e.preventDefault();\n        showPopover(dayLink);\n    };\n\n    document.addEventListener('mouseover', showPopoverHandler);\n    document.addEventListener('focusin', showPopoverHandler);\n};\n\nlet listenersRegistered = false;\nif (!listenersRegistered) {\n    registerEventListeners();\n    listenersRegistered = true;\n}\n"],"names":["isPopoverConfigured","Map","showPopover","target","dateContainer","closest","CalendarSelectors","elements","has","config","trigger","placement","html","title","dataset","content","source","querySelector","dateContent","innerHTML","Popover","set","window","getComputedStyle","display","isPopoverAvailable","getInstance","show","addEventListener","hidePopover","e","isTargetActive","contains","document","activeElement","isTargetHover","matches","isTargetClicked","removeListener","getOrCreateInstance","hide","removeEventListener","listenersRegistered","showPopoverHandler","dayLink","links","preventDefault","registerEventListeners"],"mappings":";;;;;;;;0gCAoCMA,oBAAsB,IAAIC,IAC1BC,YAAcC,eACVC,cAAgBD,OAAOE,QAAQC,kBAAkBC,SAASH,mBAC3DJ,oB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