/*! * jquery cookie plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * * copyright 2013 klaus hartl * released under the mit license */ (function (factory) { if (typeof define === 'function' && define.amd) { // amd define(['jquery'], factory); } else if (typeof exports === 'object') { // commonjs factory(require('jquery')); } else { // browser globals factory(jquery); } }(function ($) { var pluses = /\+/g; function encode(s) { return config.raw ? s : encodeuricomponent(s); } function decode(s) { return config.raw ? s : decodeuricomponent(s); } function stringifycookievalue(value) { return encode(config.json ? json.stringify(value) : string(value)); } function parsecookievalue(s) { if (s.indexof('"') === 0) { // this is a quoted cookie as according to rfc2068, unescape... s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); } try { // replace server-side written pluses with spaces. // if we can't decode the cookie, ignore it, it's unusable. // if we can't parse the cookie, ignore it, it's unusable. s = decodeuricomponent(s.replace(pluses, ' ')); return config.json ? json.parse(s) : s; } catch(e) {} } function read(s, converter) { var value = config.raw ? s : parsecookievalue(s); return $.isfunction(converter) ? converter(value) : value; } var config = $.cookie = function (key, value, options) { // write if (value !== undefined && !$.isfunction(value)) { options = $.extend({}, config.defaults, options); if (typeof options.expires === 'number') { var days = options.expires, t = options.expires = new date(); t.settime(+t + days * 864e+5); } return (document.cookie = [ encode(key), '=', stringifycookievalue(value), options.expires ? '; expires=' + options.expires.toutcstring() : '', // use expires attribute, max-age is not supported by ie options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : '' ].join('')); } // read var result = key ? undefined : {}; // to prevent the for loop in the first place assign an empty array // in case there are no cookies at all. also prevents odd result when // calling $.cookie(). var cookies = document.cookie ? document.cookie.split('; ') : []; for (var i = 0, l = cookies.length; i < l; i++) { var parts = cookies[i].split('='); var name = decode(parts.shift()); var cookie = parts.join('='); if (key && key === name) { // if second argument (value) is a function it's a converter... result = read(cookie, value); break; } // prevent storing a cookie that we couldn't decode. if (!key && (cookie = read(cookie)) !== undefined) { result[name] = cookie; } } return result; }; config.defaults = {}; $.removecookie = function (key, options) { if ($.cookie(key) === undefined) { return false; } // must not alter options, thus extending a fresh object... $.cookie(key, '', $.extend({}, options, { expires: -1 })); return !$.cookie(key); }; }));