Created
June 22, 2012 10:17
-
-
Save ozten/2971878 to your computer and use it in GitHub Desktop.
Newer watch based API for Drupal module
This file contains hidden or 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
| (function ($) { | |
| // currentUser is null or '[email protected]' | |
| var currentUser = "<?= loggedInUser ?>", | |
| handleLogin, | |
| handleLogout; | |
| handleLogin = function (assertion) { | |
| if (assertion) { | |
| $.post(Drupal.settings.basePath +'index.php?q=browserid/verify', { | |
| 'assertion': assertion, | |
| 'token': Drupal.settings.browserid.token | |
| }, function (data) { | |
| if (data.reload) { | |
| window.location.reload(); | |
| } | |
| else if (data.destination) { | |
| window.location.href = data.destination; | |
| } | |
| else { | |
| alert(Drupal.t('An unknown error occurred while attempting to validate your BrowserID login. After clicking "OK," you will be redirected to a page where you can log in without BrowserID or try logging in with BrowserID again.')); | |
| window.location.href = Drupal.settings.basePath + 'index.php?q=user/login'; | |
| } | |
| }); | |
| } | |
| }; | |
| handleLogout = function () { | |
| window.location.href = Drupal.settings.basePath + 'index.php?q=user/logout'; | |
| }; | |
| navigator.id.watch({ | |
| loggedInEmail: currentUser, | |
| onlogin: handleLogin, | |
| onlogout: handleLogout, | |
| onready: function () { | |
| $(context).find('.browserid-button').show(); | |
| $(context).find('.browserid-button').click(function(e) {performLogin()}); | |
| } | |
| }); | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment