Repository navigation
Expand file tree
/
Copy pathmodal.coffee
More file actions
48 lines (35 loc) · 1.34 KB
/
Copy pathmodal.coffee
File metadata and controls
48 lines (35 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
BULMA.toggleModal = (el, options) ->
if !options.target
#Throw error if no target is passed
throw new Error 'Found [BULMA-MODAL] but there is no target defined!'
el.addEventListener 'click', (e) ->
#Prevent default behaviour
e.preventDefault()
e.stopPropagation()
#Find the modal to toggle
modal = document.getElementById(options.target)
#Find the elements to close the modal
backdrop = modal.querySelector('.modal-background')
closeBtn = modal.querySelector('.modal-close')
#Modal close event
closeModal = () ->
if BULMA.hasClass(modal, 'is-active')
BULMA.removeClass(modal, 'is-active')
#Detach the close event listeners to prevent multiple calls
BULMA.unclick this, closeModal
#Attach the close events
if options.closeByBackdrop is undefined or options.closeByBackdrop
BULMA.click backdrop, closeModal
if options.closeByButton is undefined or options.closeByButton
BULMA.click closeBtn, closeModal
#Open the modal by adding the 'is-active' class
BULMA.addClass modal, 'is-active'
return
return
unless BULMA.isReady
#Get all bulma menus of the current page
modals = BULMA.getElements('modal')
if modals and modals.length > 0
for modal in modals
options = BULMA.parseOptions(modal)
BULMA.toggleModal(modal, options)