forked from mbraak/jqTree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse.widget.coffee
81 lines (58 loc) · 1.83 KB
/
mouse.widget.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
###
This widget does the same a the mouse widget in jqueryui.
###
class MouseWidget extends SimpleWidget
@is_mouse_handled = false
_init: ->
@$el.bind('mousedown.mousewidget', $.proxy(@_mouseDown, this))
@is_mouse_started = false
_deinit: ->
@$el.unbind('mousedown.mousewidget')
$document = $(document)
$document.unbind('mousemove.mousewidget')
$document.unbind('mouseup.mousewidget')
_mouseDown: (e) ->
# Don't let more than one widget handle mouseStart
if MouseWidget.is_mouse_handled
return
# We may have missed mouseup (out of window)
if not @is_mouse_started
@_mouseUp(e)
# Is left mouse button?
if e.which != 1
return
if not @_mouseCapture(e)
return
@mouse_down_event = e
$document = $(document)
$document.bind('mousemove.mousewidget', $.proxy(@_mouseMove, this))
$document.bind('mouseup.mousewidget', $.proxy(@_mouseUp, this))
e.preventDefault();
@is_mouse_handled = true
return true
_mouseMove: (e) ->
if @is_mouse_started
@_mouseDrag(e)
return e.preventDefault()
@is_mouse_started = @_mouseStart(@mouse_down_event) != false
if @is_mouse_started
@_mouseDrag(e)
else
@_mouseUp(e)
return not @is_mouse_started
_mouseUp: (e) ->
$document = $(document)
$document.unbind('mousemove.mousewidget')
$document.unbind('mouseup.mousewidget')
if @is_mouse_started
@is_mouse_started = false
@_mouseStop(e)
return false
_mouseCapture: (e) ->
return true
_mouseStart: (e) ->
null
_mouseDrag: (e) ->
null
_mouseStop: (e) ->
null