Permalink
Browse files

Triggering login event on init if logged in, fixes for cachedAPI

  • Loading branch information...
1 parent b3735fb commit 63fe5d11be4baf8edf01db3a7797e727d818398b @winton committed Aug 18, 2010
Showing with 18 additions and 10 deletions.
  1. +14 −7 public/js/jquery.facehugger.js
  2. +4 −3 public/js/qunit.facehugger.js
@@ -60,19 +60,26 @@ jQuery.fb = new function() {
response.status = 'not_connected';
events.trigger('status_' + response.status, response);
});
+ FB.getLoginStatus(function(response) {
+ if (response.status == 'connected')
+ events.trigger('login');
+ });
});
}
function cachedAPI(path, values, method, data, fn) {
var key = 'fb' + path.replace(/\W/g, '_');
- if (values == undefined)
- return fromJson(cookie(key));
- else {
- var args = compressArgs([ path, method, data, fn ]);
-
- if (typeof args[args.length-1] == 'function')
- fn = args[args.length-1];
+ var args = compressArgs([ path, values, method, data, fn ]);
+
+ if (typeof args[args.length-1] == 'function')
+ fn = args[args.length-1];
+ if (values.constructor != Array)
+ values = this.cached_values;
+
+ if (cookie(key))
+ fn(fromJson(cookie(key)));
+ else {
var replacement_fn = function(response) {
var data = {};
$.each(values, function(i, item) {
@@ -263,9 +263,10 @@ $(function() {
equals(typeof response.id, 'string');
equals(typeof response.name, 'string');
- var cached = $.fb.cachedAPI('/me');
- equals(typeof cached.id, 'string');
- equals(typeof cached.name, 'string');
+ $.fb.cachedAPI('/me', function() {
+ equals(typeof cached.id, 'string');
+ equals(typeof cached.name, 'string');
+ });
});
});
});

0 comments on commit 63fe5d1

Please sign in to comment.