1
- // Equivalent of jQuery offset method
2
- function offset ( el ) {
3
- var boundingRect = el . getBoundingClientRect ( ) ;
4
- return {
5
- top : boundingRect . top + document . body . scrollTop ,
6
- left : boundingRect . left + document . body . scrollLeft
7
- }
8
- } ;
9
-
10
- // from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas
11
- function get_mouse_position ( e , targ ) {
12
- //this section is from http://www.quirksmode.org/js/events_properties.html
13
- if ( ! e )
14
- e = window . event ;
15
- if ( ! targ ) {
16
- if ( e . target )
17
- targ = e . target ;
18
- else if ( e . srcElement )
19
- targ = e . srcElement ;
20
- if ( targ . nodeType == 3 ) // defeat Safari bug
21
- targ = targ . parentNode ;
22
- }
1
+ // Get mouse position relative to target
2
+ function get_mouse_position ( event , targ ) {
3
+ var boundingRect = targ . getBoundingClientRect ( ) ;
23
4
24
- // offset() returns the position of the element relative to the document
25
- var targ_offset = offset ( targ ) ;
26
- var x = e . pageX - targ_offset . left ;
27
- var y = e . pageY - targ_offset . top ;
28
-
29
- return { 'x' : x , 'y' : y } ;
5
+ return {
6
+ x : event . clientX - boundingRect . left ,
7
+ y : event . clientY - boundingRect . top
8
+ } ;
30
9
} ;
31
10
32
11
/*
@@ -44,7 +23,6 @@ function get_simple_keys(original) {
44
23
45
24
46
25
module . exports = {
47
- offset : offset ,
48
26
get_mouse_position : get_mouse_position ,
49
27
get_simple_keys : get_simple_keys
50
28
}
0 commit comments