[Jspro-cvs] jsPro browser.js,NONE,1.1 CHANGES,1.14,1.15
Brought to you by:
wigleys
|
From: <gat...@us...> - 2003-09-17 08:51:01
|
Update of /cvsroot/jspro/jsPro
In directory sc8-pr-cvs1:/tmp/cvs-serv28239
Modified Files:
CHANGES
Added Files:
browser.js
Log Message:
new Browser() class
--- NEW FILE: browser.js ---
/**
* +-------------------------------------------------------------------------+
* | jsPro - Browser |
* +-------------------------------------------------------------------------+
* | Copyright (C) 2001-2003 Stuart Wigley |
* +-------------------------------------------------------------------------+
* | This library is free software; you can redistribute it and/or modify it |
* | under the terms of the GNU Lesser General Public License as published by|
* | the Free Software Foundation; either version 2.1 of the License, or (at |
* | your option) any later version. |
* | |
* | This library is distributed in the hope that it will be useful, but |
* | WITHOUT ANY WARRANTY; without even the implied warranty of |
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
* | General Public License for more details. |
* | |
* | You should have received a copy of the GNU Lesser General Public License|
* | along with this library; if not, write to the Free Software Foundation, |
* | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* +-------------------------------------------------------------------------+
* | Authors: Randolph Fielding <gat...@ci...> |
* +-------------------------------------------------------------------------+
* $Id: browser.js,v 1.1 2003/09/17 08:50:57 gator4life Exp $
*/
/**
* Creates an object that provides methods for setting, retrieving, or
* manipulating information within the current browser environment.
*
* @author Randolph Fielding
* @version 1.0, 09/15/03
* @interface <code>new Browser()</code>
*/
function Browser() { }
/**
* Retrieves the value of all cookies or of a single cookie with the specified
* name.
*
* @summary retrieve value of cookie(s)
* @author Randolph Fielding
* @version 1.0, 09/16/03
* @interface <code>Browser.getCookie()</code>
* @interface <code>Browser.getCookie(sName)</code>
* @param sName the name of a single cookie (optional)
* @return the value of all cookies or of a single cookie with
* the specified name (if the cookie with the specified
* name exists)
* @return <code>undefined</code> if the cookie with the
* specified name does not exist
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
* @throws TypeMismatchException
*/
Browser.prototype.getCookie = function() {
try {
var vError = null;
var iNumArguments = arguments.length;
var sName = '';
if (iNumArguments > 1) {
throw vError = new IllegalArgumentException('Browser.getCookie', '0 or 1', iNumArguments);
} else if (iNumArguments == 1) {
sName = arguments[0];
}
if (typeof sName != 'string') {
throw vError = new TypeMismatchException('Browser.getCookie', 'string', typeof sName);
}
var sValue = undefined;
var sCookies = document.cookie;
if (sName == '') {
sValue = unescape(sCookies);
} else {
var aCookies = sCookies.split('; ');
var iNumCookies = aCookies.length;
for (var i = 0; i < iNumCookies; i++) {
var aCookie = aCookies[i].split('=');
if (unescape(aCookie[0]) == unescape(sName)) {
sValue = unescape(aCookie[1]);
}
}
}
}
catch (vError) {
if (vError instanceof Error) {
vError.handleError();
}
}
finally {
return vError ? null : sValue;
}
}
/**
* Creates a cookie with the specified name, value, expiration date, domain,
* path, and secure-access flag, and then returns the updated value of all
* cookies.
*
* @summary create cookie
* @author Randolph Fielding
* @version 1.0, 09/16/03
* @interface <code>Browser.setCookie(sName, vValue, oExpires,
* sDomain, sPath, bSecure)</code>
* @param sName the name of the cookie
* @param vValue the value of the cookie
* @param oExpires a Date() object representing the expiration date of
* the cookie; set to <code>null</code> to default to the
* end of the current browsing session
* @param sDomain the domain in which information within the cookie may
* be accessed; set to <code>null</code> to default to
* the current domain
* @param sPath the path in which information within the cookie may be
* accessed; set to <code>null</code> to default to the
* current path
* @param bSecure a boolean value representing whether the cookie must
* be accessed from within a secure environment or not
* @return the updated value of all cookies
* @return <code>null</code> if an exception is encountered
* @throws IllegalArgumentException
* @throws TypeMismatchException
*/
Browser.prototype.setCookie = function(sName, vValue, oExpires, sDomain, sPath, bSecure) {
try {
var vError = null;
var iNumArguments = arguments.length;
if (iNumArguments != 6) {
throw vError = new IllegalArgumentException('Browser.setCookie', 6, iNumArguments);
}
if (typeof sName != 'string') {
throw vError = new TypeMismatchException('Browser.setCookie', 'string', typeof sName);
}
if (!(oExpires instanceof Date)) {
throw vError = new TypeMismatchException('Browser.setCookie', 'Date()', typeof oExpires);
}
if (typeof sDomain != 'string') {
throw vError = new TypeMismatchException('Browser.setCookie', 'string', typeof sDomain);
}
if (typeof sPath != 'string') {
throw vError = new TypeMismatchException('Browser.setCookie', 'string', typeof sPath);
}
if (typeof bSecure != 'boolean') {
throw vError = new TypeMismatchException('Browser.setCookie', 'boolean', typeof bSecure);
}
var sCookie = escape(sName) + '=' + escape(vValue.toString());
sCookie += (oExpires) ? '; expires=' + oExpires.toGMTString() : '';
sCookie += (sDomain) ? '; domain=' + sDomain : '';
sCookie += (sPath) ? '; path=' + sPath : '';
sCookie += (bSecure) ? '; secure' : '';
document.cookie = sCookie;
var sUpdatedCookie = unescape(document.cookie);
}
catch (vError) {
if (vError instanceof Error) {
vError.handleError();
}
}
finally {
return vError ? null : sUpdatedCookie;
}
}
Index: CHANGES
===================================================================
RCS file: /cvsroot/jspro/jsPro/CHANGES,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** CHANGES 15 Sep 2003 02:17:19 -0000 1.14
--- CHANGES 17 Sep 2003 08:50:57 -0000 1.15
***************
*** 8,11 ****
--- 8,16 ----
- Array.changeKeyCase()
+ browser.js:
+
+ - new Browser() class that provides methods for setting, retrieving, or
+ manipulating information within the current browser environment
+
constants.js:
|