From 0458d16152b25979e17f1b5fdb3e32138b21d606 Mon Sep 17 00:00:00 2001 From: Andrew Moore Date: Wed, 10 Sep 2014 10:57:45 -0300 Subject: [PATCH 1/2] Added event argument to the useTarget function call. --- jquery.kinetic.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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; }; From e2c6fb9864aba531f124608ba1fb8476fb1c6153 Mon Sep 17 00:00:00 2001 From: Andrew Moore Date: Wed, 10 Sep 2014 10:58:08 -0300 Subject: [PATCH 2/2] Added tests to ensure that target and event are passed back to the filterTarget call. --- test/specs/basic.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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++; },