mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(gestureDirectives): fix problem with event being passed in
This commit is contained in:
32
js/angular/directive/gesture.js
vendored
32
js/angular/directive/gesture.js
vendored
@@ -239,26 +239,22 @@ function gestureDirective(directiveName) {
|
||||
return ['$ionicGesture', '$parse', function($ionicGesture, $parse) {
|
||||
var eventType = directiveName.substr(2).toLowerCase();
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
compile: function($element, attr) {
|
||||
var fn = $parse( attr[directiveName] );
|
||||
return function(scope, element, attr) {
|
||||
var fn = $parse( attr[directiveName] );
|
||||
|
||||
return function(scope, element, attr) {
|
||||
|
||||
var listener = function(ev) {
|
||||
scope.$apply(function() {
|
||||
fn(scope, {$event:event});
|
||||
});
|
||||
};
|
||||
|
||||
var gesture = $ionicGesture.on(eventType, listener, $element);
|
||||
|
||||
scope.$on('$destroy', function() {
|
||||
$ionicGesture.off(gesture, eventType, listener);
|
||||
var listener = function(ev) {
|
||||
scope.$apply(function() {
|
||||
fn(scope, {
|
||||
$event: ev
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var gesture = $ionicGesture.on(eventType, listener, element);
|
||||
|
||||
scope.$on('$destroy', function() {
|
||||
$ionicGesture.off(gesture, eventType, listener);
|
||||
});
|
||||
};
|
||||
}];
|
||||
}
|
||||
|
||||
36
test/unit/angular/directive/gesture.unit.js
Normal file
36
test/unit/angular/directive/gesture.unit.js
Normal file
@@ -0,0 +1,36 @@
|
||||
describe('gesture directive', function() {
|
||||
beforeEach(module('ionic'));
|
||||
|
||||
'onHold onTap onTouch onRelease onDrag onDragUp onDragRight onDragDown onDragLeft onSwipe onSwipeUp onSwipeRight onSwipeBottom onSwipeLeft'
|
||||
.split(' ')
|
||||
.map(function(directiveName) {
|
||||
return {
|
||||
gestureName: directiveName.substr(2).toLowerCase(),
|
||||
directiveName: directiveName,
|
||||
htmlName: directiveName.replace(/[A-Z]/g, function(match, i) {
|
||||
return '-' + match.toLowerCase();
|
||||
})
|
||||
};
|
||||
})
|
||||
.forEach(function(directive){
|
||||
it('should compile', inject(function($compile, $rootScope, $ionicGesture) {
|
||||
var fakeGesture = {};
|
||||
spyOn($ionicGesture, 'on').andCallFake(function(eventType, listener, el) {
|
||||
callback = listener;
|
||||
return fakeGesture;
|
||||
});
|
||||
spyOn($ionicGesture, 'off');
|
||||
var el = $compile('<div ' + directive.htmlName + '="foo(1, $event)">')($rootScope.$new());
|
||||
$rootScope.$apply();
|
||||
|
||||
el.scope().foo = jasmine.createSpy('foo');
|
||||
|
||||
expect($ionicGesture.on.mostRecentCall.args[0]).toBe(directive.gestureName);
|
||||
var event = {};
|
||||
callback(event);
|
||||
expect(el.scope().foo).toHaveBeenCalledWith(1, event);
|
||||
el.scope().$destroy();
|
||||
expect($ionicGesture.off).toHaveBeenCalledWith(fakeGesture, directive.gestureName, callback);
|
||||
}));
|
||||
});
|
||||
});
|
||||
0
test/unit/angular/directive/gestures.js
vendored
0
test/unit/angular/directive/gestures.js
vendored
Reference in New Issue
Block a user