-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdialog.coffee
52 lines (40 loc) · 1.44 KB
/
dialog.coffee
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
###
Base for Dialogs
@namespace Atoms.Molecule
@class Dialog
@author Javier Jimenez Villar <[email protected]> || @soyjavi
###
"use strict"
class Atoms.Organism.Dialog extends Atoms.Class.Organism
@template : """<article {{#if.id}}id="{{id}}"{{/if.id}} {{#if.style}}class="{{style}}"{{/if.style}}></article>"""
@available: ["Organism.Header", "Molecule.Navigation", "Organism.Section", "Organism.Footer"]
@base : "Dialog"
@events : ["show", "hide"]
constructor: (attributes = {}, scaffold) ->
super attributes, scaffold
block_el = Atoms.$(document.createElement("div")).attr "data-system", "dialog"
Atoms.$(@attributes.container or document.body).prepend block_el
@attributes.container = block_el
Atoms.App.Dialog[@attributes.id?.toClassName() or @constructor.name] = @
do @render
for animation_end in __.Constants.ANIMATION.END.split " "
@el.bind animation_end, @onAnimationEnd
# Publics
show: ->
@el.parent().addClass "active"
@el.addClass "show"
@trigger "show"
#@TODO: Hack for Firefox AnimationEnd listener fails
setTimeout (=> do @onAnimationEnd), __.Constants.ANIMATION.DURATION
__.Url.current()?.back()
hide: ->
@el.addClass "hide"
@trigger "hide"
__.Url.current()?.front()
# Privates
onAnimationEnd: =>
if @el.hasClass "show"
@el.removeClass "show"
if @el.hasClass "hide"
@el.removeClass "hide"
@el.parent().removeClass "active"