forked from GetmeUK/ContentTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal.coffee
More file actions
60 lines (44 loc) · 1.96 KB
/
Copy pathmodal.coffee
File metadata and controls
60 lines (44 loc) · 1.96 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
49
50
51
52
53
54
55
56
57
58
59
60
class ContentTools.ModalUI extends ContentTools.WidgetUI
# The modal UI component provides an element over the page. The modal layer
# prevents the user from interacting with the page whilst allowing them to
# interact with UI components above the layer, for example a dialog.
constructor: (transparent, allowScrolling) ->
super()
# If true the modal we be displayed completely transparently. This can
# be useful when displaying an UI component above the page that is
# close if the user clicks away from it, for example the add link
# (caption) dialog.
@_transparent = transparent
# If true then scrolling the page whilst the modal is open is not
# disabled (the default behavior is to disable scrolling when a modal is
# overlayed over the page content).
@_allowScrolling = allowScrolling
# Methods
mount: () ->
# Mount the widget to the DOM
# Modal
@_domElement = @constructor.createDiv([
'ct-widget',
'ct-modal'
])
@parent().domElement().appendChild(@_domElement)
# If set to transparent add the modifier
if @_transparent
@addCSSClass('ct-modal--transparent')
# Unless scrolling is set as allowed disable page scrolling
if not @_allowScrolling
ContentEdit.addCSSClass(document.body, 'ct--no-scroll')
# Add interaction handlers
@_addDOMEventListeners()
unmount: () ->
# Unmount the widget from the DOM
# Allow the page to be scrolled again
if not @_allowScrolling
ContentEdit.removeCSSClass(document.body, 'ct--no-scroll')
super()
# Private methods
_addDOMEventListeners: () ->
# Add DOM event listeners for the widget
# Trigger a custom event for clicks on the modal
@_domElement.addEventListener 'click', (ev) =>
@dispatchEvent(@createEvent('click'))