All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.uncompressed-js-resources.oam.custom.tree2.javascript.cookielib.js Maven / Gradle / Ivy

Go to download

JSF components and utilities that can be used with any JSF implementation. This library is based on the JSF1.1 version of Tomahawk, but with minor source code and build changes to take advantage of JSF2.1 features. A JSF2.1 implementation is required to use this version of the Tomahawk library.

The newest version!
//=============================================================================
// CookieLib Definition
// Contains general purpose javascript methods for managing html cookies
//=============================================================================

function CookieLib(){}

CookieLib.COOKIE_DELIM = ";";
CookieLib.COOKIE_KEYVAL = "=";
CookieLib.ATTRIB_DELIM = ";";
CookieLib.ATTRIB_KEYVAL = "=";

/**
 * Retrieves the specified cookie as a String of text
 * @param String name - name of cookie to retrieve
 * @return String cookie value or null if not found
 */
function CookieLib_getRawCookie(name) {
    var search = name + CookieLib.COOKIE_KEYVAL;
    if (document.cookie)
    {
        if (document.cookie.length > 0)
        {
            offset = document.cookie.indexOf(search);
            if (offset != -1)
            {
               offset += search.length;
               end = document.cookie.indexOf(CookieLib.COOKIE_DELIM, offset);
               if (end == -1) end = document.cookie.length;
               return unescape(document.cookie.substring(offset, end));
            }
        }
    }
    return null;
}
CookieLib.getRawCookie = CookieLib_getRawCookie;

/**
 * Cookies can hold multiple pieces of information.  This methods saves a key/value pair to
 * the specified cookie.  Each key/value pair is separated by a special character
 * defined by the ATTRIB_DELIM constant.  Setting an attribute's value to null or empty string
 * will remove it from the cookie.
 * @param cookieName String - name of cookie that will hold the key/value pair
 * @param attribName String - attribute key
 * @param attribValue String - attribute value
 */
function CookieLib_setCookieAttrib(cookieName, attribName, attribValue)
{
    var attribMap = CookieLib.getCookie(cookieName);
    attribMap[attribName] = attribValue;
    CookieLib.setCookie(cookieName,attribMap);
}
CookieLib.setCookieAttrib = CookieLib_setCookieAttrib;

/**
 * Cookies can hold multiple pieces of information.  This methods retrieves a value from the
 * specified cookie using the specified key (attribName).  Each key/value pair is separated by a
 * special character defined by the ATTRIB_DELIM constant.
 * @param cookieName String - name of cookie that that holds the key/value pair
 * @param attribName String - attribute key
 * @param attribValue String - attribute value
 * @return String value
 */
function CookieLib_getCookieAttrib(cookieName, attribName)
{
    var attribMap = CookieLib.getCookie(cookieName);
    return attribMap[attribName];
}
CookieLib.getCookieAttrib = CookieLib_getCookieAttrib;

/**
 * Retrieves a map of all key/value pairs (attributes) stored in the specified cookie.
 * @param cookieName String - name of cookie
 * @return Array of all attributes
 */
function CookieLib_getCookie(cookieName)
{
    var attribMap = new Array();
    var cookie = CookieLib.getRawCookie(cookieName);
    if (typeof( cookie ) != "undefined"  && cookie != null)
    {
        var attribArray = cookie.split(CookieLib.ATTRIB_DELIM);
        for (var i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy