diff --git a/jquery.kinetic.js b/jquery.kinetic.js index ecba2ca..ceb7c4e 100644 --- a/jquery.kinetic.js +++ b/jquery.kinetic.js @@ -161,7 +161,7 @@ this.settings.events = { touchStart: function (e){ var touch; - if (self._useTarget(e.target)){ + if (self._useTarget(e.target, e)){ touch = e.originalEvent.touches[0]; self._start(touch.clientX, touch.clientY); e.stopPropagation(); @@ -178,7 +178,7 @@ } }, inputDown: function (e){ - if (self._useTarget(e.target)){ + if (self._useTarget(e.target, e)){ self._start(e.clientX, e.clientY); self.elementFocused = e.target; if (e.target.nodeName === 'IMG'){ @@ -188,7 +188,7 @@ } }, inputEnd: function (e){ - if (self._useTarget(e.target)){ + if (self._useTarget(e.target, e)){ self._end(); self.elementFocused = null; if (e.preventDefault){ @@ -220,7 +220,7 @@ }, // prevent drag and drop images in ie dragStart: function (e){ - if (self._useTarget(e.target) && self.elementFocused){ + if (self._useTarget(e.target, e) && self.elementFocused){ return false; } } @@ -284,9 +284,9 @@ } }; - Kinetic.prototype._useTarget = function (target){ + Kinetic.prototype._useTarget = function (target, event){ if ($.isFunction(this.settings.filterTarget)){ - return this.settings.filterTarget.call(this, target) !== false; + return this.settings.filterTarget.call(this, target, event) !== false; } return true; }; diff --git a/test/specs/basic.spec.js b/test/specs/basic.spec.js index bd0392a..046cba5 100644 --- a/test/specs/basic.spec.js +++ b/test/specs/basic.spec.js @@ -50,6 +50,24 @@ test('we can prevent drag with filterTarget', function(){ dragOver($wrapper, img, [100,100], [10,10]); equal($wrapper.data().kinetic.velocity, 0, 'there should be no velocity'); }); +test('filterTarget is passed both a target and event', function() { + var targetValid = false; + var eventValid = false; + + var $wrapper = $('#wrapper').kinetic({ + filterTarget: function(target, event){ + if (target) targetValid = true; + if (event) eventValid = true; + } + }); + + var img = $wrapper.find('img')[0]; + + dragOver($wrapper, img, [100, 100], [10, 10]); + equal(targetValid, true, 'there should be a target passed to filterTarget'); + equal(eventValid, true, 'there should be a event passed to filterTarget'); + +}); test('we can listen for events', function(){ var $wrapper = $('#wrapper').kinetic({ moved: function(){ moved++; },