diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index 71eab01cb5..7a5c249786 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -23095,6 +23095,9 @@ angular.module('ionic.service.gesture', []) return { on: function(eventType, cb, $element) { return window.ionic.onGesture(eventType, cb, $element[0]); + }, + off: function(gesture, eventType, cb) { + return window.ionic.offGesture(gesture, eventType, cb); } }; }]); diff --git a/dist/js/ionic.js b/dist/js/ionic.js index 60660d0b7f..4c35542184 100644 --- a/dist/js/ionic.js +++ b/dist/js/ionic.js @@ -291,8 +291,8 @@ window.ionic = { ionic.on = function() { ionic.EventController.on.apply(ionic.EventController, arguments); }; ionic.off = function() { ionic.EventController.off.apply(ionic.EventController, arguments); }; ionic.trigger = function() { ionic.EventController.trigger.apply(ionic.EventController.trigger, arguments); }; - ionic.onGesture = function() { ionic.EventController.onGesture.apply(ionic.EventController.onGesture, arguments); }; - ionic.offGesture = function() { ionic.EventController.offGesture.apply(ionic.EventController.offGesture, arguments); }; + ionic.onGesture = function() { return ionic.EventController.onGesture.apply(ionic.EventController.onGesture, arguments); }; + ionic.offGesture = function() { return ionic.EventController.offGesture.apply(ionic.EventController.offGesture, arguments); }; // DISABLING FOR NOW. THE TAP CODE AT THE EXT LEVEL SHOULD BE DOING THIS // Set up various listeners diff --git a/js/ext/angular/src/service/ionicGesture.js b/js/ext/angular/src/service/ionicGesture.js index ba2126afe9..a3d7d9650c 100644 --- a/js/ext/angular/src/service/ionicGesture.js +++ b/js/ext/angular/src/service/ionicGesture.js @@ -4,6 +4,9 @@ angular.module('ionic.service.gesture', []) return { on: function(eventType, cb, $element) { return window.ionic.onGesture(eventType, cb, $element[0]); + }, + off: function(gesture, eventType, cb) { + return window.ionic.offGesture(gesture, eventType, cb); } }; }]); diff --git a/js/ext/angular/test/service/ionicGesture.unit.js b/js/ext/angular/test/service/ionicGesture.unit.js new file mode 100644 index 0000000000..0155e59628 --- /dev/null +++ b/js/ext/angular/test/service/ionicGesture.unit.js @@ -0,0 +1,48 @@ +describe('Ionic Gesture Service', function() { + var gesture; + + beforeEach(module('ionic.service.gesture')); + + beforeEach(inject(function(Gesture) { + gesture = Gesture; + })); + + iit('Should bind', function() { + var el = document.createElement('div'); + + var handlers = { + dragHandle: function(e) { + } + }; + spyOn(handlers, 'dragHandle'); + gesture.on('drag', handlers.dragHandle, angular.element(el)); + + var event = new CustomEvent('drag', { target: el }); + el.dispatchEvent(event); + + expect(handlers.dragHandle).toHaveBeenCalled(); + }); + iit('Should unbind', function() { + var el = document.createElement('div'); + + var handlers = { + dragHandle: function(e) { + } + }; + spyOn(handlers, 'dragHandle'); + + var g = gesture.on('drag', handlers.dragHandle, angular.element(el)); + + var event = new CustomEvent('drag', { target: el }); + el.dispatchEvent(event); + + expect(handlers.dragHandle).toHaveBeenCalled(); + + gesture.off(g, 'drag', handlers.dragHandle); + + var event = new CustomEvent('drag', { target: el }); + el.dispatchEvent(event); + + expect(handlers.dragHandle).toHaveBeenCalled(); + }); +}) diff --git a/js/utils/events.js b/js/utils/events.js index f80a237985..d7d9d6a878 100644 --- a/js/utils/events.js +++ b/js/utils/events.js @@ -98,8 +98,8 @@ ionic.on = function() { ionic.EventController.on.apply(ionic.EventController, arguments); }; ionic.off = function() { ionic.EventController.off.apply(ionic.EventController, arguments); }; ionic.trigger = function() { ionic.EventController.trigger.apply(ionic.EventController.trigger, arguments); }; - ionic.onGesture = function() { ionic.EventController.onGesture.apply(ionic.EventController.onGesture, arguments); }; - ionic.offGesture = function() { ionic.EventController.offGesture.apply(ionic.EventController.offGesture, arguments); }; + ionic.onGesture = function() { return ionic.EventController.onGesture.apply(ionic.EventController.onGesture, arguments); }; + ionic.offGesture = function() { return ionic.EventController.offGesture.apply(ionic.EventController.offGesture, arguments); }; // DISABLING FOR NOW. THE TAP CODE AT THE EXT LEVEL SHOULD BE DOING THIS // Set up various listeners