PageRenderTime 223ms CodeModel.GetById 110ms app.highlight 5ms RepoModel.GetById 106ms app.codeStats 0ms

/flash/MP3FileReferenceLoaderLib/asdoc-output/cookies.js

http://echo-nest-remix.googlecode.com/
JavaScript | 84 lines | 39 code | 4 blank | 41 comment | 7 complexity | 2eecae385f402eb9825fa5efc5c60dd3 MD5 | raw file
 1////////////////////////////////////////////////////////////////////////////////
 2//
 3//  ADOBE SYSTEMS INCORPORATED
 4//  Copyright 2006-2007 Adobe Systems Incorporated
 5//  All Rights Reserved.
 6//
 7//  NOTICE: Adobe permits you to use, modify, and distribute this file
 8//  in accordance with the terms of the license agreement accompanying it.
 9//
10////////////////////////////////////////////////////////////////////////////////
11
12/**
13 * Read the JavaScript cookies tutorial at:
14 *   http://www.netspade.com/articles/javascript/cookies.xml
15 */
16
17/**
18 * Sets a Cookie with the given name and value.
19 *
20 * name       Name of the cookie
21 * value      Value of the cookie
22 * [expires]  Expiration date of the cookie (default: end of current session)
23 * [path]     Path where the cookie is valid (default: path of calling document)
24 * [domain]   Domain where the cookie is valid
25 *              (default: domain of calling document)
26 * [secure]   Boolean value indicating if the cookie transmission requires a
27 *              secure transmission
28 */
29function setCookie(name, value, expires, path, domain, secure)
30{
31    document.cookie= name + "=" + escape(value) +
32        ((expires) ? "; expires=" + expires.toGMTString() : "") +
33        ((path) ? "; path=" + path : "") +
34        ((domain) ? "; domain=" + domain : "") +
35        ((secure) ? "; secure" : "");
36}
37
38/**
39 * Gets the value of the specified cookie.
40 *
41 * name  Name of the desired cookie.
42 *
43 * Returns a string containing value of specified cookie,
44 *   or null if cookie does not exist.
45 */
46function getCookie(name)
47{
48    var dc = document.cookie;
49    var prefix = name + "=";
50    var begin = dc.indexOf("; " + prefix);
51    if (begin == -1)
52    {
53        begin = dc.indexOf(prefix);
54        if (begin != 0) return null;
55    }
56    else
57    {
58        begin += 2;
59    }
60    var end = document.cookie.indexOf(";", begin);
61    if (end == -1)
62    {
63        end = dc.length;
64    }
65    return unescape(dc.substring(begin + prefix.length, end));
66}
67
68/**
69 * Deletes the specified cookie.
70 *
71 * name      name of the cookie
72 * [path]    path of the cookie (must be same as path used to create cookie)
73 * [domain]  domain of the cookie (must be same as domain used to create cookie)
74 */
75function deleteCookie(name, path, domain)
76{
77    if (getCookie(name))
78    {
79        document.cookie = name + "=" + 
80            ((path) ? "; path=" + path : "") +
81            ((domain) ? "; domain=" + domain : "") +
82            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
83    }
84}