forked from facebookarchive/connect-js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MochiKit version based on JQuery version.
- Can't find a public MochiKit repository so resorting to alerting the user that a link to a local copy of MochiKit is required
- Loading branch information
1 parent
ab5f3a1
commit be8dfc6
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,88 @@ | |||
<!doctype html> | |||
<html xmlns:fb="http://www.facebook.com/2008/fbml"> | |||
<!-- | |||
Copyright Facebook Inc. | |||
Licensed under the Apache License, Version 2.0 (the "License"); | |||
you may not use this file except in compliance with the License. | |||
You may obtain a copy of the License at | |||
http://www.apache.org/licenses/LICENSE-2.0 | |||
Unless required by applicable law or agreed to in writing, software | |||
distributed under the License is distributed on an "AS IS" BASIS, | |||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
See the License for the specific language governing permissions and | |||
limitations under the License. | |||
--> | |||
<head> | |||
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |||
<title>Connect JavaScript - jQuery Login Example</title> | |||
</head> | |||
<body> | |||
<h1>Connect JavaScript - jQuery Login Example</h1> | |||
<div> | |||
<button id="login">Login</button> | |||
<button id="logout">Logout</button> | |||
<button id="disconnect">Disconnect</button> | |||
</div> | |||
<div id="user-info" style="display: none;"></div> | |||
|
|||
<script src="/javascript/mochikit/packed/MochiKit/MochiKit.js"></script> | |||
|
|||
<div id="fb-root"></div> | |||
<script src="http://connect.facebook.net/en_US/all.js"></script> | |||
<script> | |||
if (!('MochiKit' in window)) { | |||
alert("Can't find packed MochiKit.js file"); | |||
} | |||
|
|||
// initialize the library with the API key | |||
FB.init({ apiKey: '48f06bc570aaf9ed454699ec4fe416df' }); | |||
|
|||
// fetch the status on load | |||
FB.getLoginStatus(handleSessionResponse); | |||
|
|||
connect('login', 'onclick', function(e) { | |||
FB.login(handleSessionResponse); | |||
}); | |||
|
|||
connect('logout', 'onclick', function(e) { | |||
FB.logout(handleSessionResponse); | |||
}); | |||
|
|||
connect('disconnect', 'onclick', function(e) { | |||
FB.api({ method: 'Auth.revokeAuthorization' }, function(response) { | |||
clearDisplay(); | |||
}); | |||
}); | |||
|
|||
// no user, clear display | |||
function clearDisplay() { | |||
hideElement('user-info'); | |||
} | |||
|
|||
// handle a session response from any of the auth related calls | |||
function handleSessionResponse(response) { | |||
// if we dont have a session, just hide the user info | |||
if (!response.session) { | |||
clearDisplay(); | |||
return; | |||
} | |||
|
|||
// if we have a session, query for the user's profile picture and name | |||
FB.api( | |||
{ | |||
method: 'fql.query', | |||
query: 'SELECT name, pic FROM profile WHERE id=' + FB.getSession().uid | |||
}, | |||
function(response) { | |||
var user = response[0]; | |||
replaceChildNodes('user-info', IMG({'src': user.pic}), user.name); | |||
showElement('user-info'); | |||
} | |||
); | |||
} | |||
</script> | |||
</body> | |||
</html> |