Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
298 aurelien 1
/**
2
* jQuery Cookie plugin
3
*
4
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
5
* Dual licensed under the MIT and GPL licenses:
6
* http://www.opensource.org/licenses/mit-license.php
7
* http://www.gnu.org/licenses/gpl.html
8
*
9
*/
10
(function($) {
11
    $.cookie = function(key, value, options) {
12
 
13
        // key and at least value given, set cookie...
14
        if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
15
            options = $.extend({}, options);
16
 
17
            if (value === null || value === undefined) {
18
                options.expires = -1;
19
            }
20
 
21
            if (typeof options.expires === 'number') {
22
                var days = options.expires, t = options.expires = new Date();
23
                t.setDate(t.getDate() + days);
24
            }
25
 
26
            value = String(value);
27
 
28
            return (document.cookie = [
29
                encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
30
                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
31
                options.path ? '; path=' + options.path : '',
32
                options.domain ? '; domain=' + options.domain : '',
33
                options.secure ? '; secure' : ''
34
            ].join(''));
35
        }
36
 
37
        // key and possibly options given, get cookie...
38
        options = value || {};
39
        var decode = options.raw ? function(s) { return s; } : decodeURIComponent;
40
 
41
        var pairs = document.cookie.split('; ');
42
        for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
43
            if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
44
        }
45
        return null;
46
    };
47
})(jQuery);