Skip to content

Commit

Permalink
feat(cordovaEvents): $ionicPlatform.on method
Browse files Browse the repository at this point in the history
Create $ionicPlatform.on(type, callback) to make it easier to add
Cordova event listeners. Closes #2219
  • Loading branch information
adamdbradley committed Sep 16, 2014
1 parent 37d75f7 commit 046ad53
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions js/angular/service/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ IonicModule
return ionic.Platform.is(type);
},

/**
* @ngdoc method
* @name $ionicPlatform#on
* @description
* Add Cordova event listeners, such as `pause`, `resume`, `volumedownbutton`, `batterylow`,
* `offline`, etc. More information about available event types can be found in
* [Cordova's event documentation](https://cordova.apache.org/docs/en/edge/cordova_events_events.md.html#Events).
* @param {string} type Cordova [event type](https://cordova.apache.org/docs/en/edge/cordova_events_events.md.html#Events).
* @param {function} callback Called when the Cordova event is fired.
* @returns {function} Returns a deregistration function to remove the event listener.
*/
on: function(type, cb) {
ionic.Platform.ready(function(){
document.addEventListener(type, cb, false);
});
return function() {
ionic.Platform.ready(function(){
document.removeEventListener(type, cb);
});
};
},

/**
* @ngdoc method
* @name $ionicPlatform#ready
Expand Down

0 comments on commit 046ad53

Please sign in to comment.