Autoría | Ultima modificación | Ver Log |
{"version":3,"file":"modal_backdrop.min.js","sources":["../src/modal_backdrop.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 * Contain the logic for modal backdrops.\n *\n * @module core/modal_backdrop\n * @copyright 2016 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimpor
t $ from 'jquery';\nimport * as Notification from './notification';\nimport * as Fullscreen from './fullscreen';\n\nconst SELECTORS = {\n ROOT: '[data-region=\"modal-backdrop\"]',\n};\n\nexport default class ModalBackdrop {\n root = null;\n isAttached = false;\n attachmentPoint = null;\n\n /**\n * Constructor for ModalBackdrop.\n *\n * @class core/modal_backdrop\n * @param {HTMLElement|jQuery} root The root element for the modal backdrop\n */\n constructor(root) {\n this.root = $(root);\n this.isAttached = false;\n this.attachmentPoint = document.createElement('div');\n document.body.append(this.attachmentPoint);\n\n if (!this.root.is(SELECTORS.ROOT)) {\n Notification.exception({message: 'Element is not a modal backdrop'});\n }\n }\n\n /**\n * Get the root element of this modal backdrop.\n *\n * @method getRoot\n * @return {object} jQuery object\n */\n getRoot() {\n return this.root;
\n }\n\n /**\n * Gets the jQuery wrapped node that the Modal should be attached to.\n *\n * @returns {jQuery}\n */\n getAttachmentPoint() {\n return $(Fullscreen.getElement() || this.attachmentPoint);\n }\n\n /**\n * Add the modal backdrop to the page, if it hasn't already been added.\n *\n * @method attachToDOM\n */\n attachToDOM() {\n this.getAttachmentPoint().append(this.root);\n\n if (this.isAttached) {\n return;\n }\n\n this.isAttached = true;\n }\n\n /**\n * Set the z-index value for this backdrop.\n *\n * @method setZIndex\n * @param {int} value The z-index value\n */\n setZIndex(value) {\n this.root.css('z-index', value);\n }\n\n /**\n * Check if this backdrop is visible.\n *\n * @method isVisible\n * @return {bool}\n */\n isVisible() {\n return this.root.hasClass('show');\n }\n\n /**\n * Check if this backdrop has CSS transi
tions applied.\n *\n * @method hasTransitions\n * @return {bool}\n */\n hasTransitions() {\n return this.getRoot().hasClass('fade');\n }\n\n /**\n * Display this backdrop. The backdrop will be attached to the DOM if it hasn't\n * already been.\n *\n * @method show\n */\n show() {\n if (this.isVisible()) {\n return;\n }\n\n this.attachToDOM();\n this.root.removeClass('hide').addClass('show');\n }\n\n /**\n * Hide this backdrop.\n *\n * @method hide\n */\n hide() {\n if (!this.isVisible()) {\n return;\n }\n\n if (this.hasTransitions()) {\n // Wait for CSS transitions to complete before hiding the element.\n this.getRoot().one('transitionend webkitTransitionEnd oTransitionEnd', () => {\n this.getRoot().removeClass('show').addClass('hide');\n });\n } else {\n this.getRoot().removeClass('show').addCl
ass('hide');\n }\n\n // Ensure the modal is moved onto the body node if it is still attached to the DOM.\n if ($(document.body).find(this.getRoot()).length) {\n $(document.body).append(this.getRoot());\n }\n }\n\n /**\n * Remove this backdrop from the DOM.\n *\n * @method destroy\n */\n destroy() {\n this.root.remove();\n this.attachmentPoint.remove();\n }\n}\n"],"names":["SELECTORS","constructor","root","isAttached","attachmentPoint","document","createElement","body","append","this","is","Notification","exception","message","getRoot","getAttachmentPoint","Fullscreen","getElement","attachToDOM","setZIndex","value","css","isVisible","hasClass","hasTransitions","show","removeClass","addClass","hide","one","find","length","destroy","remove"],"mappings":"y9CA0BMA,eACI,+DAcNC,YAAYC,kCAVL,yCACM,0CACK,WASTA,MAAO,mBAAEA,WACTC,YAAa,OACbC,gBAAkBC,SAASC,cAAc,OAC9CD,SAASE,KAAKC,OAAOC,KAAKL,iBAErBK,KAAKP,KAAKQ,GAAGV,iBACdW,aAAaC,UAAU,CAACC,Q
AAS,oCAUzCC,iBACWL,KAAKP,KAQhBa,4BACW,mBAAEC,WAAWC,cAAgBR,KAAKL,iBAQ7Cc,mBACSH,qBAAqBP,OAAOC,KAAKP,MAElCO,KAAKN,kBAIJA,YAAa,GAStBgB,UAAUC,YACDlB,KAAKmB,IAAI,UAAWD,OAS7BE,mBACWb,KAAKP,KAAKqB,SAAS,QAS9BC,wBACWf,KAAKK,UAAUS,SAAS,QASnCE,OACQhB,KAAKa,mBAIJJ,mBACAhB,KAAKwB,YAAY,QAAQC,SAAS,SAQ3CC,OACSnB,KAAKa,cAINb,KAAKe,sBAEAV,UAAUe,IAAI,oDAAoD,UAC9Df,UAAUY,YAAY,QAAQC,SAAS,gBAG3Cb,UAAUY,YAAY,QAAQC,SAAS,SAI5C,mBAAEtB,SAASE,MAAMuB,KAAKrB,KAAKK,WAAWiB,4BACpC1B,SAASE,MAAMC,OAAOC,KAAKK,YASrCkB,eACS9B,KAAK+B,cACL7B,gBAAgB6B"}