/
Hints.coffee
49 lines (35 loc) · 1.15 KB
/
Hints.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
class Hints
constructor: ->
@_context = new Framer.Context(name:"Hints")
@_context.index = 10000
@_context.run =>
if Utils.isTouch()
Events.wrap(document).addEventListener("touchstart", @_handleDown, capture=true)
Events.wrap(document).addEventListener("touchend", @_handleUp, capture=true)
else
Events.wrap(document).addEventListener("mousedown", @_handleDown, capture=true)
Events.wrap(document).addEventListener("mouseup", @_handleUp, capture=true)
_handleDown: (event) =>
@_target = event.target
_handleUp: (event) =>
# See what layer we actually tapped
layer = Framer.CurrentContext.layerForElement(@_target)
# If this is a layer with interaction, we do not show any hints
if layer and layer.willSeemToDoSomething()
return
@showHints()
showHints: ->
context = Framer.CurrentContext
@_context.run => _.invokeMap(context.rootLayers, "_showHint")
destroy: ->
@_context.destroy()
hints = null
exports.enable = ->
hints ?= new Hints(Framer.CurrentContext)
exports.disable = ->
return unless hints
hints.destroy()
hints = null
exports.showHints = ->
return unless hints
Utils.delay 0.5, -> hints.showHints()