aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-09 00:47:04 +0000
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-09 00:47:04 +0000
commita029ab8eb677ea075267fefaaa61fcf1fa484956 (patch)
tree873127b1a91e240c62fbc8ceacecede7457cb677 /js
parent932eacfba30061f3abc31bc4d328d27dcad7efca (diff)
downloadelgg-a029ab8eb677ea075267fefaaa61fcf1fa484956.tar.gz
elgg-a029ab8eb677ea075267fefaaa61fcf1fa484956.tar.bz2
jsLinted session.js, employed elgg type-checker functions, and did some more miscellaneous cleanup
git-svn-id: http://code.elgg.org/elgg/trunk@7261 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'js')
-rw-r--r--js/lib/session.js38
1 files changed, 19 insertions, 19 deletions
diff --git a/js/lib/session.js b/js/lib/session.js
index 227c607eb..fc61144be 100644
--- a/js/lib/session.js
+++ b/js/lib/session.js
@@ -15,19 +15,21 @@ elgg.provide('elgg.session');
*
* @return {string} The value of the cookie, if only name is specified
*/
-elgg.session.cookie = function(name, value, options) {
+elgg.session.cookie = function (name, value, options) {
+ var cookies = [], cookie = [], i = 0, date, valid = true;
+
//elgg.session.cookie()
- if(typeof name == 'undefined') {
+ if (elgg.isUndefined(name)) {
return document.cookie;
}
//elgg.session.cookie(name)
- if (typeof value == 'undefined') {
- if (document.cookie && document.cookie != '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]).split('=');
- if (cookie[0] == name) {
+ if (elgg.isUndefined(value)) {
+ if (document.cookie && document.cookie !== '') {
+ cookies = document.cookie.split(';');
+ for (i = 0; i < cookies.length; i += 1) {
+ cookie = jQuery.trim(cookies[i]).split('=');
+ if (cookie[0] === name) {
return decodeURIComponent(cookie[1]);
}
}
@@ -36,30 +38,28 @@ elgg.session.cookie = function(name, value, options) {
}
// elgg.session.cookie(name, value[, opts])
- var cookies = [];
-
options = options || {};
- if (value === null) {
+ if (elgg.isNull(value)) {
value = '';
options.expires = -1;
}
cookies.push(name + '=' + value);
- if (typeof options.expires == 'number') {
- var date, valid = true;
-
- if (typeof options.expires == 'number') {
+ if (elgg.isNumber(options.expires)) {
+ if (elgg.isNumber(options.expires)) {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
- } else if(options.expires.toUTCString) {
+ } else if (options.expires.toUTCString) {
date = options.expires;
} else {
valid = false;
}
- valid ? cookies.push('expires=' + date.toUTCString()) : 0;
+ if (valid) {
+ cookies.push('expires=' + date.toUTCString());
+ }
}
// CAUTION: Needed to parenthesize options.path and options.domain
@@ -107,10 +107,10 @@ elgg.isloggedin = function() {
*/
elgg.isadminloggedin = function() {
var user = elgg.get_loggedin_user();
- return (user instanceof ElggUser) && user.isAdmin();
+ return (user instanceof elgg.ElggUser) && user.isAdmin();
};
/**
* @deprecated Use elgg.session.cookie instead
*/
-$.cookie = elgg.session.cookie; \ No newline at end of file
+jQuery.cookie = elgg.session.cookie; \ No newline at end of file