\r
$.extend($.simulate.prototype, {\r
simulateEvent: function(el, type, options) {\r
- // creates a individual option for each simulation inside this instance\r
- options = $.extend({}, this.options, options);\r
var evt = this.createEvent(type, options);\r
- return this.dispatchEvent(el, type, evt, options);\r
+ this.dispatchEvent(el, type, evt, options);\r
+ return evt;\r
},\r
createEvent: function(type, options) {\r
if (/^mouse(over|out|down|up|move)|(dbl)?click$/.test(type)) {\r
return evt;\r
},\r
\r
- dispatchEvent: function(el, type, evt, options) {\r
+ dispatchEvent: function(el, type, evt) {\r
if (el.dispatchEvent) {\r
el.dispatchEvent(evt);\r
} else if (el.fireEvent) {\r
el.fireEvent('on' + type, evt);\r
}\r
- // trigget complete for all events - not drag.\r
- this.triggerComplete(evt, options);\r
return evt;\r
},\r
\r
var self = this, center = this.findCenter(this.target), \r
options = this.options, x = center.x, y = center.y, \r
dx = options.dx || 0, dy = options.dy || 0, target = this.target;\r
-\r
- var coord = { clientX: x, clientX: y, complete: null }, evt;\r
- this.simulateEvent(target, "mouseover", coord);\r
+ var coord = { clientX: x, clientY: y };\r
+ this.simulateEvent(target, "mouseover");\r
this.simulateEvent(target, "mousedown", coord);\r
- \r
- var drag = function(x, y) {\r
- evt = self.simulateEvent(target, "mousemove", $.extend(coord, { x: x, y: y }));\r
- // triggering drag callback\r
- (self.options.drag && self.options.drag($.event.fix(evt)));\r
- };\r
- \r
- if (/^sync$/.test(options.speed)) {\r
- // trigger synchronous simulation\r
- this.triggerSync(center, dx, dy, drag);\r
- }\r
- else {\r
- // trigger asynchronous simulation - animated\r
- this.triggerAsync(center, dx, dy, drag);\r
- }\r
- \r
+ coord = { clientX: x + dx, clientY: y + dy };\r
+ this.simulateEvent(document, "mousemove", coord);\r
+ this.simulateEvent(document, "mousemove", coord);\r
this.simulateEvent(target, "mouseup", coord);\r
- this.simulateEvent(target, "mouseout", coord);\r
- this.triggerComplete(evt, options);\r
+ this.simulateEvent(target, "mouseout");\r
},\r
- \r
- triggerComplete: function(evt, options) {\r
- evt = $.event.fix(evt);\r
- (options.complete && options.complete(evt)); return evt;\r
- },\r
- \r
- triggerSync: function(center, dx, dy, fn) {\r
- var x = center.x, y = center.y, mdx = Math.abs(dx) || 0, mdy = Math.abs(dy) || 0;\r
- var range = Math.max(mdx, mdy), sigx = dx/mdx || 1, sigy = dy/mdy || 1;\r
- \r
- for (var dt = 1; dt <= range; dt++) {\r
- if (dt <= mdx) x = center.x + sigx*dt;\r
- if (dt <= mdy) y = center.y + sigy*dt;\r
- (fn && fn(x, y));\r
- }\r
- },\r
- \r
- triggerAsync: function(center, dx, dy, fn) {\r
- /*TODO*/\r
- // this method just have to call: (fn && fn(x, y));\r
- // return the x, y of the mousemove.\r
- // idea: $.animate({ step: function() { var x,y; (fn && fn(x, y)); } });\r
- },\r
- \r
findCenter: function(el) {\r
var el = $(this.target), o = el.offset();\r
return {\r