Resources/public/js/jquery.cookie.js
author cavaliet
Fri, 04 Jul 2014 16:57:17 +0200
changeset 129 65c12455ce74
parent 53 22377c9e2eae
permissions -rwxr-xr-x
adapt code to be compatible with dinosaur php 5.3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
     1
/**
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
     2
 * Cookie plugin
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
     3
 *
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
     4
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
     5
 * Dual licensed under the MIT and GPL licenses:
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
     6
 * http://www.opensource.org/licenses/mit-license.php
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
     7
 * http://www.gnu.org/licenses/gpl.html
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
     8
 *
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
     9
 */
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    10
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    11
/**
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    12
 * Create a cookie with the given name and value and other optional parameters.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    13
 *
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    14
 * @example $.cookie('the_cookie', 'the_value');
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    15
 * @desc Set the value of a cookie.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    16
 * @example $.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true});
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    17
 * @desc Create a cookie with all available options.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    18
 * @example $.cookie('the_cookie', 'the_value');
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    19
 * @desc Create a session cookie.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    20
 * @example $.cookie('the_cookie', '', {expires: -1});
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    21
 * @desc Delete a cookie by setting a date in the past.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    22
 *
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    23
 * @param String name The name of the cookie.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    24
 * @param String value The value of the cookie.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    25
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    26
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    27
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    28
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    29
 *                             when the the browser exits.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    30
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    31
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    32
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    33
 *                        require a secure protocol (like HTTPS).
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    34
 * @type undefined
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    35
 *
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    36
 * @name $.cookie
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    37
 * @cat Plugins/Cookie
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    38
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    39
 */
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    40
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    41
/**
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    42
 * Get the value of a cookie with the given name.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    43
 *
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    44
 * @example $.cookie('the_cookie');
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    45
 * @desc Get the value of a cookie.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    46
 *
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    47
 * @param String name The name of the cookie.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    48
 * @return The value of the cookie.
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    49
 * @type String
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    50
 *
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    51
 * @name $.cookie
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    52
 * @cat Plugins/Cookie
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    53
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    54
 */
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    55
jQuery.cookie = function(name, value, options) {
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    56
    if (typeof value != 'undefined') { // name and value given, set cookie
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    57
        options = options || {};
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    58
        var expires = '';
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    59
        if (options.expires && (typeof options.expires == 'number' || options.expires.toGMTString)) {
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    60
            var date;
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    61
            if (typeof options.expires == 'number') {
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    62
                date = new Date();
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    63
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    64
            } else {
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    65
                date = options.expires;
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    66
            }
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    67
            expires = '; expires=' + date.toGMTString(); // use expires attribute, max-age is not supported by IE
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    68
        }
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    69
        var path = options.path ? '; path=' + options.path : '';
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    70
        var domain = options.domain ? '; domain=' + options.domain : '';
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    71
        var secure = options.secure ? '; secure' : '';
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    72
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    73
    } else { // only name given, get cookie
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    74
        var cookieValue = null;
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    75
        if (document.cookie && document.cookie != '') {
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    76
            var cookies = document.cookie.split(';');
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    77
            for (var i = 0; i < cookies.length; i++) {
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    78
                var cookie = jQuery.trim(cookies[i]);
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    79
                // Does this cookie string begin with the name we want?
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    80
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    81
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    82
                    break;
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    83
                }
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    84
            }
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    85
        }
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    86
        return cookieValue;
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    87
    }
22377c9e2eae First step of column management in document tag list. Little debug on js for move up down.
cavaliet
parents:
diff changeset
    88
};