Skip to content

Commit

Permalink
Can optionally use a <body> mousemove event instead of one for just t…
Browse files Browse the repository at this point in the history
…he canvas element
  • Loading branch information
rcarver committed Feb 19, 2009
1 parent 2683c40 commit 8c04093
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions primer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Primer = function(container, width, height) {
Primer = function(container, width, height, useGlobalMouseMove) {
this.container = container
this.width = width
this.height = height
this.primer = this
this.useGlobalMouseMove = useGlobalMouseMove

this.actions = []

Expand Down Expand Up @@ -33,12 +35,26 @@ Primer.prototype = {

var self = this

jelc.eq(0).bind("mousemove", function(e){
var bounds = $(e.currentTarget).offset()
e.localX = e.pageX - bounds.left
e.localY = e.pageY - bounds.top
self.ghost(e)
})
if (this.useGlobalMouseMove) {
$('body').bind("mousemove", function(e) {
if (e.target == elc) {
var $target = $(e.target);
var bounds = $target.offset()
e.localX = e.pageX - bounds.left
e.localY = e.pageY - bounds.top
self.ghost(e)
} else {
self.outOfBounds();
}
})
} else {
jelc.eq(0).bind("mousemove", function(e){
var bounds = $(e.currentTarget).offset()
e.localX = e.pageX - bounds.left
e.localY = e.pageY - bounds.top
self.ghost(e)
})
}

},

Expand Down Expand Up @@ -91,6 +107,10 @@ Primer.prototype = {
this.actions = []
},

outOfBounds: function() {
// Do nothing by default
},

setupExt: function() {
this.context.ext = {
textAlign: "left",
Expand Down

0 comments on commit 8c04093

Please sign in to comment.