Skip to content

Instantly share code, notes, and snippets.

@tylerjohnst
Created August 25, 2014 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerjohnst/b8d94f5b9dd4e997514f to your computer and use it in GitHub Desktop.
Save tylerjohnst/b8d94f5b9dd4e997514f to your computer and use it in GitHub Desktop.
Ember bindings for using phonegap events
App.PhonegapBackbuttonMixin = Ember.Mixin.create({
activate: function () {
this.get('phonegapProxy').on('backbutton', this, this.goBack);
},
deactivate: function() {
this.get('phonegapProxy').off('backbutton', this, this.goBack);
},
});
App.PhoneGapEventProxy = Ember.Object.extend(Ember.Evented, {
phonegapEvents: ['backbutton'],
init: function() {
document.addEventListener("deviceready", Ember.run.bind(this, this.setupEventListeners), false);
},
setupEventListeners: function() {
var proxy = this;
proxy.get('phonegapEvents').forEach(function(eventName) {
document.addEventListener(eventName, Ember.run.bind(proxy, proxy.handleEventListener), false);
});
},
handleEventListener: function(event) {
this.trigger(event.type, event);
return true;
}
});
Ember.Application.initializer({
name: 'phonegapProxy',
initialize: function(container, application) {
var proxy = App.PhoneGapEventProxy.create({});
application.register('proxy:phonegap', proxy, { singleton: true, instantiate: false });
application.inject('route', 'phonegapProxy', 'proxy:phonegap');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment