-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dropdown.coffee
51 lines (38 loc) · 1.14 KB
/
Dropdown.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
# Dropdown function
exports.Dropdown = (layerA, layerB, layerAbgColour, updateSelector) ->
# Reset the cursor to normal
document.body.style.cursor = "auto"
defaultColour = layerA.backgroundColor.color
if layerB.visible
layerB.visible = false
# Mouse Hover
layerA.style =
"cursor": "pointer"
layerA.onMouseOver ->
if layerAbgColour == undefined
layerA.backgroundColor = defaultColour
else
layerA.backgroundColor = layerAbgColour
# Instantly switch to the state
layerA.onMouseOut ->
layerA.backgroundColor = defaultColour
# Show or hide its menu
layerA.onClick ->
if layerB.visible
layerB.visible = false
else
layerB.visible = true
layerB.opacity = 1
# For each menu option
for option, i in layerB.children
if updateSelector == true
# When it's clicked
layerB.children[i].onClick (event, layer) ->
# Show the selected option in the drop down
layerA.selectChild("text").text = layer.text
# Update the cursor on hover
layerB.children[i].style =
"cursor": "pointer"
# Close modal after selection
layerB.children[i].onClick ->
layerB.visible = false