Skip to content

Commit

Permalink
Merge branch 'moore0n-filter-target-event-argument'
Browse files Browse the repository at this point in the history
* moore0n-filter-target-event-argument:
  Added tests to ensure that target and event are passed back to the filterTarget call.
  Added event argument to the useTarget function call.
  • Loading branch information
davetayls committed Sep 11, 2014
2 parents 0f262b3 + 1241a69 commit 6e20403
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions jquery.kinetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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'){
Expand All @@ -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){
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
};
Expand Down
18 changes: 18 additions & 0 deletions test/specs/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++; },
Expand Down

0 comments on commit 6e20403

Please sign in to comment.