add data-modal-create to force modal to be open in a new container
This commit is contained in:
parent
1ba3f9d721
commit
d4533e780f
|
@ -1,13 +1,19 @@
|
||||||
const $ = require('jquery')
|
const $ = require('jquery')
|
||||||
|
|
||||||
const openModal = function (url) {
|
const openModal = function (url, createModal) {
|
||||||
let container = $('#modal-container')
|
if (createModal) {
|
||||||
|
var id = 'modal-container-' + parseInt(Math.floor(Math.random() * 1000))
|
||||||
|
} else {
|
||||||
|
var id = 'modal-container'
|
||||||
|
}
|
||||||
|
|
||||||
|
let container = $(`#${id}`)
|
||||||
const body = $('body')
|
const body = $('body')
|
||||||
let doTrigger = true
|
let doTrigger = true
|
||||||
|
|
||||||
if (!container.length) {
|
if (!container.length) {
|
||||||
let doTrigger = false
|
let doTrigger = false
|
||||||
container = $('<div id="modal-container" class="modal">')
|
container = $(`<div id="${id}" class="modal">`)
|
||||||
|
|
||||||
body.append(container)
|
body.append(container)
|
||||||
}
|
}
|
||||||
|
@ -54,13 +60,11 @@ module.exports = function () {
|
||||||
|
|
||||||
click = 0
|
click = 0
|
||||||
|
|
||||||
let url = $(e.target).attr('data-modal')
|
let element = $(e.target).is('[data-modal]') ? $(e.target) : $(e.target).parents('*[data-modal]').first()
|
||||||
|
let url = element.attr('data-modal')
|
||||||
|
let createModal = element.is('[data-modal-create]')
|
||||||
|
|
||||||
if (!url) {
|
openModal(url, createModal)
|
||||||
url = $(e.target).parents('*[data-modal]').first().attr('data-modal')
|
|
||||||
}
|
|
||||||
|
|
||||||
openModal(url)
|
|
||||||
}, 250)
|
}, 250)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue