Skip to content

Instantly share code, notes, and snippets.

@weizhu
Created January 13, 2012 17:54
Show Gist options
  • Save weizhu/1607776 to your computer and use it in GitHub Desktop.
Save weizhu/1607776 to your computer and use it in GitHub Desktop.
Sample implementation for a PhoneGap FB Plugin that hook up necessary events from regular Facebook JS SDK so it override behavior for Auth and UI.
FB.Event.subscribe('FB.init.start',
function(options) {
if (options.nativeInterface) {
FB._nativeInterface = options.nativeInterface;
FB._nativeInterface.init(FB._apiKey);
}
});
FB.Event.subscribe('FB.auth.staticAuthCheck.start',
function(eventProps) {
// cancel default static auth check
eventProps.returnValue = false;
});
FB.Event.subscribe('FB.ui.start',
function(eventProps, params, cb) {
if (!FB._nativeInterface) {
return;
}
switch (params.method) {
case 'permissions.request':
FB._nativeInterface.login(cb, params);
break;
case 'permissions.oauth':
FB._nativeInterface.login(cb, params);
break;
case 'auth.logout':
FB._nativeInterface.logout(cb);
break;
case 'auth.status':
FB._nativeInterface.getLoginStatus(cb);
break;
}
// Stop default handling
eventProps.returnValue = false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment