Skip to content
This repository was archived by the owner on Apr 22, 2018. It is now read-only.

Commit 0d743bf

Browse files
committed
- No icon when no icon is set
- Callback after creating modal - Default values - Removed hard-coded ion- class for icons - Don't show buttons when undefined
1 parent 1c79885 commit 0d743bf

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

dist/basicModal.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/coffee/basicModal.coffee

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,39 @@ this.modal =
22

33
_valid: (data) ->
44

5-
if data?.body? and
6-
data?.closable? and
7-
data.buttons?.cancel?.title? and
8-
data.buttons?.action?.title? and
9-
data.buttons.cancel.fn and
10-
data.buttons.action.fn
5+
if data?
116

12-
data.class = '' if not data.class?
7+
# Set defaults
8+
data.body = '' if not data.body?
9+
data.class = '' if not data.class?
10+
data.closable = true if not data.closable?
1311

14-
return true
12+
return true
1513

1614
return false
1715

1816
_build: (data) ->
1917

20-
"""
21-
<div class='modalContainer fadeIn' data-closable='#{ data.closable }'>
22-
<div class='modal fadeIn #{ data.class }'>
23-
#{ data.body }
24-
<a id='cancel' class='button'>#{ data.buttons.cancel.title }</a>
25-
<a id='action' class='button #{ data.buttons.action.color }'><span class='ion-#{ data.buttons.action.icon }'></span>#{ data.buttons.action.title }</a>
26-
</div>
27-
</div>
28-
"""
18+
html = """
19+
<div class='modalContainer fadeIn' data-closable='#{ data.closable }'>
20+
<div class='modal fadeIn #{ data.class }'>
21+
#{ data.body }
22+
"""
23+
24+
if data.buttons?.cancel?
25+
html += "<a id='cancel' class='button'>#{ data.buttons.cancel.title }</a>"
26+
27+
if data.buttons?.action?
28+
html += "<a id='action' class='button #{ data.buttons.action.color }'>"
29+
if data.buttons?.action?.icon? then html += "<span class='#{ data.buttons.action.icon }'></span>"
30+
html += "#{ data.buttons.action.title }</a>"
31+
32+
html += """
33+
</div>
34+
</div>
35+
"""
36+
37+
return html
2938

3039
_getValues: ->
3140

@@ -44,24 +53,35 @@ this.modal =
4453
show: (data) ->
4554

4655
# Validate data
47-
return false if not data? or not modal._valid data
56+
return false if not modal._valid data
4857

4958
# Remove open modal
5059
if $(".modalContainer").length isnt 0
5160
modal.close true
5261
setTimeout ->
5362
modal.show data
54-
, 300
63+
, 301
5564
return false
5665

5766
# Build and append
5867
$('body').append modal._build(data)
5968

60-
# Bind buttons
61-
$('.modalContainer #cancel').click data.buttons.cancel.fn
62-
$('.modalContainer #action').click -> data.buttons.action.fn modal._getValues()
69+
# Bind cancel button
70+
if data.buttons?.cancel?.fn?
71+
$('.modalContainer #cancel').click data.buttons.cancel.fn
72+
73+
# Bind action button
74+
if data.buttons?.action?.fn?
75+
$('.modalContainer #action').click -> data.buttons.action.fn modal._getValues()
76+
77+
# Bind inputs
6378
$('.modalContainer input').keydown -> $(this).removeClass 'error'
6479

80+
# Call callback
81+
if data.callback?
82+
callback()
83+
return true
84+
6585
return true
6686

6787
error: (input) ->

0 commit comments

Comments
 (0)