From 3a5dd47e1b7d89bd0f7586b5339c0c019dc4b86b Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 27 Feb 2006 17:00:29 +0000 Subject: [PATCH] removed the older Cookie.js code. we now rely on a global cookieManager object for all cookies we're using exclusive the JSON Cookies.js code, which is slightly smaller (after i removed the inline docs) and has a better interface git-svn-id: svn://svn.open-ils.org/ILS/trunk@3198 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/opac/common/js/Cookie.js | 139 ------------------ Open-ILS/web/opac/common/js/Cookies.js | 67 +-------- Open-ILS/web/opac/common/js/opac_utils.js | 31 ++-- .../web/opac/locale/en-US/opac_common.dtd | 2 +- Open-ILS/web/opac/skin/default/js/mresult.js | 11 +- 5 files changed, 23 insertions(+), 227 deletions(-) delete mode 100644 Open-ILS/web/opac/common/js/Cookie.js diff --git a/Open-ILS/web/opac/common/js/Cookie.js b/Open-ILS/web/opac/common/js/Cookie.js deleted file mode 100644 index 3b00acfafc..0000000000 --- a/Open-ILS/web/opac/common/js/Cookie.js +++ /dev/null @@ -1,139 +0,0 @@ -/* -DISCLAIMER: THESE JAVASCRIPT FUNCTIONS ARE SUPPLIED 'AS IS', WITH -NO WARRANTY EXPRESSED OR IMPLIED. YOU USE THEM AT YOUR OWN RISK. -PAUL STEPHENS DOES NOT ACCEPT ANY LIABILITY FOR -ANY LOSS OR DAMAGE RESULTING FROM THEIR USE, HOWEVER CAUSED. - -Paul Stephens' cookie-handling object library - -Version 2.1 -2.0 - Introduces field names -2.1 - Fixes bug where undefined embedded fields[] elements weren't written to disk - -www.paulspages.co.uk - -TO USE THIS LIBRARY, INSERT ITS CONTENTS IN THE SECTION -OF YOUR WEB PAGE SOURCE, BEFORE ANY OTHER JAVASCRIPT ROUTINES. - -(C) Paul Stephens, 2001-2003. Feel free to use this code, but please leave this comment block in. This code must not be sold, either alone or as part of an application, without the consent of the author. -*/ - -function cookieObject(name, expires, accessPath) { -var i, j -this.name = name -this.fieldSeparator = "#" -this.found = false -this.expires = expires -this.accessPath = accessPath -this.rawValue = "" -this.fields = new Array() -this.fieldnames = new Array() -if (arguments.length > 3) { - j = 0 - for (i = 3; i < arguments.length; i++) { - this.fieldnames[j] = arguments[i] - j++ - } - this.fields.length = this.fieldnames.length -} -this.read = ucRead -this.write = ucWrite -this.remove = ucDelete -this.get = ucFieldGet -this.put = ucFieldPut -this.namepos = ucNamePos -this.read() -} - -function ucFieldGet(fieldname) { -var i = this.namepos(fieldname) -if (i >=0) { - return this.fields[i] -} else { - return "BadFieldName!" -} -} -function ucFieldPut (fieldname, fieldval) { -var i = this.namepos(fieldname) -if(i < 0) { - i = this.fieldnames.length; - this.fieldnames[i] = fieldname; -} -this.fields[i] = fieldval -return true -} -function ucNamePos(fieldname) { -var i -for (i = 0; i < this.fieldnames.length; i++) { - if (fieldname == this.fieldnames[i]) { - return i - } -} -return -1 -} -function ucWrite() { - var cookietext = this.name + "=" -if (this.fields.length == 1) { - cookietext += escape(this.fields[0]) - } else { - for (i= 0; i < this.fields.length; i++) { - cookietext += escape(this.fields[i]) + this.fieldSeparator } - } - if (this.expires != null) { - if (typeof(this.expires) == "number") { - var today=new Date() - var expiredate = new Date() - expiredate.setTime(today.getTime() + 1000*60*60*24*this.expires) - cookietext += "; expires=" + expiredate.toGMTString() - } else { - cookietext += "; expires=" + this.expires.toGMTString() - } - } - if (this.accessPath != null) { - cookietext += "; PATH="+this.accessPath } - document.cookie = cookietext - return null -} -function ucRead() { - var search = this.name + "=" - var CookieString = document.cookie - if(CookieString == null) CookieString = ""; - this.rawValue = null - this.found = false - if (CookieString.length > 0) { - offset = CookieString.indexOf(search) - if (offset != -1) { - offset += search.length - end = CookieString.indexOf(";", offset) - if (end == -1) { - end = CookieString.length } - this.rawValue = CookieString.substring(offset, end) - this.found = true - } - } -if (this.rawValue != null) { // unpack into fields - var sl = this.rawValue.length - var startidx = 0 - var endidx = 0 - var i = 0 -if (this.rawValue.substr(sl-1, 1) != this.fieldSeparator) { - this.fields[0] = unescape(this.rawValue) - } else { - do - { - endidx = this.rawValue.indexOf(this.fieldSeparator, startidx) - if (endidx !=-1) { - this.fields[i] = unescape(this.rawValue.substring(startidx, endidx)) - i++ - startidx = endidx + 1} - } - while (endidx !=-1 & endidx != (this.rawValue.length -1)); -} -} - return this.found -} -function ucDelete() { - this.expires = -10 - this.write() - return this.read() -} diff --git a/Open-ILS/web/opac/common/js/Cookies.js b/Open-ILS/web/opac/common/js/Cookies.js index 172400908b..97c6d480dd 100644 --- a/Open-ILS/web/opac/common/js/Cookies.js +++ b/Open-ILS/web/opac/common/js/Cookies.js @@ -1,4 +1,10 @@ // HTTP.Cookies - Burak Gürsoy + +/* +I removed all the docs (except author and license info) to reduce download size +-bill erickson +*/ + if (!HTTP) var HTTP = {}; // create base class if undefined HTTP.Cookies = function () { // HTTP.Cookies constructor @@ -98,67 +104,6 @@ HTTP.Cookies.prototype.remove = function (name, path, domain, secure) { HTTP.Cookies - JavaScript class for reading, writing and deleting cookies -=head1 SYNOPSIS - - var cookie = new HTTP.Cookies; - var password = cookie.read('password'); - var lastvisit = cookie.read('lastvisit'); - cookie.write('lastvisit',1079383075,'+1y'); - cookie.remove('password'); - -=head1 DESCRIPTION - -HTTP.Cookies is a class for http cookies manipulation. It defines -three object methods to read, write and remove cookies. Implementation -is somehow similar to the Perl module CGI.pm' s C method. - -=head1 METHODS - -=head2 read NAME - -Reads the cookie named C and returns it's value or an empty -string upon failure. - -=head2 write NAME, VALUE [, EXPIRES, PATH, DOMAIN, SECURE] - -Creates a new cookie with C and C. Optional C -value sets the cookie lifetime. - -Expire date format: you can use negative or positive numbers combined -with 's', 'm', 'h', 'd', 'w', 'M', 'y' or you can use 'now' to -expire as soon as possible. Meanings: - - s = second - m = minute - h = hour - d = day - w = week - M = month - y = year - now = immediately - -for a session cookie; pass "-1" as the expires value. - -Optional parameter C can be used to define the domain -for which the HTTP cookie is valid. - -Optional parameter C can be used to make it a secure cookie -(secure cookies can only be used with HTTPS protocol). - -=head2 remove NAME [, PATH, DOMAIN, SECURE] - -Deletes/removes the named cookie from the client. - -=head1 SEE ALSO - -=head1 BUGS - -Contact the author if you find any. - -This library is tested with: Opera 8.01, MSIE 6.0, -Netscape Communicator 4.77, Mozilla 1.7.8 -and Mozilla FireFox 1.0.4 under Windows XP Professional SP2. - =head1 AUTHOR Burak Gürsoy, EburakE<64>cpan.orgE diff --git a/Open-ILS/web/opac/common/js/opac_utils.js b/Open-ILS/web/opac/common/js/opac_utils.js index b0dcec71ca..142cdbfd96 100644 --- a/Open-ILS/web/opac/common/js/opac_utils.js +++ b/Open-ILS/web/opac/common/js/opac_utils.js @@ -3,6 +3,8 @@ /* define it again here for pages that don't load RemoteRequest */ function isXUL() { try { if(IAMXUL) return true;}catch(e){return false;}; } +var cookieManager = new HTTP.Cookies(); + var __ilsEvent; /* the last event the occurred */ function Request(type) { @@ -101,9 +103,9 @@ function initParams() { function initCookies() { FONTSIZE = "medium"; - var font = fontCookie.get(COOKIE_FONT); + var font = cookieManager.read(COOKIE_FONT); if(font) FONTSIZE = font; - SKIN = skinCookie.get(COOKIE_SKIN); + SKIN = cookieManager.read(COOKIE_SKIN); } /* URL param accessors */ @@ -252,11 +254,10 @@ function buildSearchLink(type, string, linknode, trunc) { to find one in the cookies. If 'force' is true we retrieve the user from the server even if there is already a global user present. if ses != G.user.session, we also force a grab */ -var cookie = new cookieObject("ses", 1, "/", COOKIE_SES); function grabUser(ses, force) { if(!ses && isXUL()) ses = xulG['authtoken']; - if(!ses) ses = cookie.get(COOKIE_SES); + if(!ses) ses = cookieManager.read(COOKIE_SES); if(!ses) return false; if(!force) @@ -282,8 +283,7 @@ function grabUser(ses, force) { G.user = user; G.user.fleshed = false; G.user.session = ses; - cookie.put(COOKIE_SES, ses); - cookie.write(); + cookieManager.write(COOKIE_SES, ses, '+1y'); grabUserPrefs(); if(G.user.prefs['opac.hits_per_page']) @@ -325,19 +325,16 @@ function grabFleshedUser() { if(!G.user || G.user.length == 0) { G.user = null; return false; - cookie.remove(COOKIE_SES); + cookieManager.remove(COOKIE_SES); } G.user.session = ses; G.user.fleshed = true; - cookie.put(COOKIE_SES, ses); /* update the cookie */ - cookie.write(); - + cookieManager.write(COOKIE_SES, ses, '+1y'); /* update the cookie */ return G.user; } -var skinCookie = new cookieObject("skin", 1, "/", COOKIE_SKIN); function checkUserSkin(new_skin) { return; /* XXX do some debugging with this... */ @@ -352,8 +349,7 @@ function checkUserSkin(new_skin) { if(grabUser()) { if(grabUserPrefs()) { user_skin = G.user.prefs["opac.skin"]; - skinCookie.put( COOKIE_SKIN, user_skin ); - skinCookie.write(); + cookieManager.write( COOKIE_SKIN, user_skin, '+1y' ); } } } @@ -444,8 +440,8 @@ function doLogout(noredirect) { } G.user = null; - cookie.remove(COOKIE_SES); - skinCookie.remove(COOKIE_SKIN); + cookieManager.remove(COOKIE_SES); + cookieManager.remove(COOKIE_SKIN); checkUserSkin("default"); COUNT = 10; @@ -501,11 +497,10 @@ function orgSelect(id) { G.ui.common.now_searching.appendChild(text(findOrgUnit(id).name())); } -var fontCookie = new cookieObject("fonts", 1, "/", COOKIE_FONT); +var fontCookie = new HTTP.Cookies(); function setFontSize(size) { scaleFonts(size); - fontCookie.put(COOKIE_FONT, size); - fontCookie.write(); + fontCookie.write(COOKIE_FONT, size, '+1y'); } diff --git a/Open-ILS/web/opac/locale/en-US/opac_common.dtd b/Open-ILS/web/opac/locale/en-US/opac_common.dtd index 4d0f166367..36acf7369f 100644 --- a/Open-ILS/web/opac/locale/en-US/opac_common.dtd +++ b/Open-ILS/web/opac/locale/en-US/opac_common.dtd @@ -9,7 +9,7 @@ + "Your login session will timeout in 1 minute unless there is activity."> diff --git a/Open-ILS/web/opac/skin/default/js/mresult.js b/Open-ILS/web/opac/skin/default/js/mresult.js index 69248b45f8..0635e14479 100644 --- a/Open-ILS/web/opac/skin/default/js/mresult.js +++ b/Open-ILS/web/opac/skin/default/js/mresult.js @@ -4,9 +4,6 @@ var ranks = []; var onlyrecord = {}; var table; var mresultPreCache = 200; -//var idsCookie = new cookieObject("ids", 1, "/", COOKIE_IDS); -//var idsCookie; -var idsCookie = new HTTP.Cookies(); var searchTimer; attachEvt("common", "unload", mresultUnload); @@ -14,7 +11,6 @@ attachEvt("common", "run", mresultDoSearch); attachEvt("result", "idsReceived", mresultSetRecords); attachEvt("result", "idsReceived", mresultCollectRecords); - function mresultUnload() { removeChildren(table); table = null;} function mresultDoSearch() { @@ -75,7 +71,7 @@ function mresultHandleCount(r) { function mresultLoadCachedSearch() { if( (getOffset() > 0) && (getOffset() < mresultPreCache) ) { - var c = JSON2js(idsCookie.read(COOKIE_IDS)); + var c = JSON2js(cookieManager.read(COOKIE_IDS)); if(c) { records = c[0]; ranks = c[1]; } } } @@ -169,9 +165,8 @@ function mresultSetRecords(idstruct) { } if(getOffset() == 0) { - idsCookie.remove(COOKIE_IDS); - idsCookie.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' ); - //alert('Set cookies: ' + idsCookie.read(COOKIE_IDS) + ' : ' + idsCookie.read(COOKIE_IDS).length ); + cookieManager.remove(COOKIE_IDS); + cookieManager.write(COOKIE_IDS, js2JSON([ records, ranks ]), '+1d' ); } TOPRANK = ranks[getOffset()]; -- 2.43.2