Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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...
commit be8dfc6e893486255d56cc60e2984046c99d3275 1 parent ab5f3a1
@eoghanmurray authored
Showing with 88 additions and 0 deletions.
  1. +88 −0 examples/mochikit/login.html
View
88 examples/mochikit/login.html
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.