{"version":3,"file":"js/chunks/dialog.js","sources":["webpack:///./org_colony/cartridge/js/dialog.js"],"sourcesContent":["const isString = require('lodash.isstring');\nconst merge = require('lodash.merge');\nconst imagesLoaded = require('imagesloaded');\nconst ajax = require('./ajax');\nconst util = require('./util');\n\nconst dialog = {\n /**\n * @function\n * @description Appends a dialog to a given container (target)\n * @param {Object} params params.target can be an id selector or an jquery object\n */\n create(params) {\n let $target; let\n id;\n\n if (!this.exists()) {\n this.uiEvents();\n }\n\n if (isString(params.target)) {\n if (params.target.charAt(0) === '#') {\n $target = $(params.target);\n } else {\n $target = $(`#${params.target}`);\n }\n } else if (params.target instanceof jQuery) {\n $target = params.target;\n } else {\n $target = $('#dialog-container');\n }\n\n // if no element found, create one\n if ($target.length === 0) {\n if ($target.selector && $target.selector.charAt(0) === '#') {\n id = $target.selector.substr(1);\n $target = $('
').attr('id', id).addClass('dialog-content').appendTo('body');\n }\n }\n\n // create the dialog\n this.$container = $target;\n this.$container.dialog(merge({}, this.settings, params.options || {}));\n },\n /**\n * @function\n * @description Opens a dialog using the given url (params.url) or html (params.html)\n * @param {Object} params\n * @param {Object} params.url should contain the url\n * @param {String} params.html contains the html of the dialog content\n */\n open(params) {\n // close any open dialog\n if (params.doClose === false) {\n // Do nothing so that the fallback is to always close it\n } else {\n this.close();\n }\n this.create(params);\n this.replace(params);\n $('#wrapper').attr('aria-hidden', 'true');\n $(document).on('click', '.ui-widget-overlay', (e) => {\n e.stopImmediatePropagation();\n const currentDialog = $('div:ui-dialog:visible').length - 1;\n $($('div:ui-dialog:visible')[currentDialog]).dialog('close');\n });\n },\n /**\n * @description populate the dialog with html content, then open it\n * */\n openWithContent(params) {\n let position;\n\n if (!this.$container) { return; }\n const content = params.content || params.html;\n if (!content) { return; }\n\n // Prevent exception in third-party tags that prevent dialog from opening\n if (window.googletag && !window.googletag.cmd) {\n window.googletag.cmd = [];\n }\n\n this.$container.empty().html(content);\n if (!this.$container.dialog('isOpen')) {\n this.$container.dialog('open');\n }\n\n if (params.options) {\n position = params.options.position;\n }\n if (!position) {\n position = this.settings.position;\n }\n imagesLoaded(this.$container).on('done', () => {\n this.$container.dialog('option', 'position', position);\n });\n\n $('.ui-dialog .ui-dialog-titlebar').focus();\n\n const callback = (typeof params.callback === 'function') ? params.callback : function emptyCallback() {};\n callback();\n $(document).on('click', '.ui-widget-overlay', (e) => {\n e.stopImmediatePropagation();\n const currentDialog = $('div:ui-dialog:visible').length - 1;\n $($('div:ui-dialog:visible')[currentDialog]).dialog('close');\n });\n },\n /**\n * @description Replace the content of current dialog\n * @param {object} params\n * @param {string} params.url - If the url property is provided, an ajax call is performed to get the content to replace\n * @param {string} params.html - If no url property is provided, use html provided to replace\n */\n replace(params) {\n if (!this.$container) {\n return;\n }\n if (params.url) {\n // eslint-disable-next-line\n params.url = util.appendParamToURL(params.url, 'format', 'ajax');\n ajax.load({\n url: params.url,\n data: params.data,\n callback: function loadCallback(response) {\n // eslint-disable-next-line\n params.content = response;\n this.openWithContent(params);\n }.bind(this),\n });\n } else if (params.html) {\n this.openWithContent(params);\n }\n },\n /**\n * @function\n * @description Closes the dialog\n */\n close() {\n if (!this.$container) {\n return;\n }\n this.$container.dialog('close');\n },\n exists() {\n return this.$container && (this.$container.length > 0);\n },\n isActive() {\n return this.exists() && (this.$container.children.length > 0);\n },\n updateOption($attrib, $value) {\n if (this.$container) {\n this.$container.dialog('option', $attrib, $value);\n }\n },\n hasActiveContainer() {\n if (typeof this.$container !== 'undefined' && this.$container.length > 0) {\n return true;\n }\n return false;\n },\n uiEvents() {\n const self = this;\n\n // Update dialog modal position on resize event\n $(window).off('resize.dialog-overlay');\n $(window).on('resize.dialog-overlay', () => {\n if (self.hasActiveContainer()) {\n const initialPosition = self.$container.dialog('option', 'position');\n self.updateOption('position', initialPosition);\n }\n });\n },\n settings: {\n autoOpen: false,\n height: 'auto',\n modal: true,\n overlay: {\n opacity: 0.5,\n background: 'black',\n },\n resizable: false,\n title: '',\n width: '800',\n close() {\n $(this).dialog('close');\n $('#wrapper').attr('aria-hidden', 'false');\n if ($('div:ui-dialog:visible').length === 0) {\n $(document).off('click', '.ui-widget-overlay');\n }\n },\n position: {\n my: 'center',\n at: 'center',\n of: window,\n collision: 'flipfit',\n },\n },\n};\n\nmodule.exports = dialog;\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAGA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AAEA;AAAA;AAAA;AACA;AACA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;;;;A","sourceRoot":""}