Last active
December 17, 2015 19:18
-
-
Save wimleers/5658972 to your computer and use it in GitHub Desktop.
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
/** | |
* Parse the user ID from the Drupal.visitor.user.uid cookie. | |
* | |
* @return Number | |
* The user id: nonzero if it is an authenticated user, zero if it is the | |
* anonymous user, in which case the Drupal.visitor.user.uid cookie value will | |
* not exist either. | |
* | |
* @see user_user_login() | |
* @see user_user_logout() | |
*/ | |
Drupal.getUserID = function () { | |
var userID; | |
function parseUserID () { | |
var values = document.cookie.split(';'); | |
for (var i = 0; i < values.length; i++) { | |
var parts = values[i].trim().split('='); | |
if (parts[0] === 'Drupal.visitor.user.uid') { | |
return parseInt(parts[1], 10); | |
} | |
} | |
return 0; | |
} | |
if (userID === undefined) { | |
userID = parseUserID(); | |
} | |
return userID; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment