1 /** 2 * cookie 3 * 4 * @fileOverView core/cookie 5 * 6 */ 7 define("core/cookie", function() { 8 /** 9 * jQuery Cookie Plugin v1.2 10 * https://github.com/carhartl/jquery-cookie 11 * 12 * Copyright 2011, Klaus Hartl 13 * Dual licensed under the MIT or GPL Version 2 licenses. 14 * http://www.opensource.org/licenses/mit-license.php 15 * http://www.opensource.org/licenses/GPL-2.0 16 */ 17 (function ($, document, undefined) { 18 19 var pluses = /\+/g; 20 21 function raw(s) { 22 return s; 23 } 24 25 function decoded(s) { 26 return decodeURIComponent(s.replace(pluses, ' ')); 27 } 28 29 var config = $.cookie = function (key, value, options) { 30 31 // write 32 if (value !== undefined) { 33 options = $.extend({}, config.defaults, options); 34 35 if (value === null) { 36 options.expires = -1; 37 } 38 39 if (typeof options.expires === 'number') { 40 var days = options.expires, t = options.expires = new Date(); 41 t.setDate(t.getDate() + days); 42 } 43 44 value = config.json ? JSON.stringify(value) : String(value); 45 46 return (document.cookie = [ 47 encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value), 48 options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE 49 options.path ? '; path=' + options.path : '', 50 options.domain ? '; domain=' + options.domain : '', 51 options.secure ? '; secure' : '' 52 ].join('')); 53 } 54 55 // read 56 var decode = config.raw ? raw : decoded; 57 var cookies = document.cookie.split('; '); 58 for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) { 59 if (decode(parts.shift()) === key) { 60 var cookie = decode(parts.join('=')); 61 return config.json ? JSON.parse(cookie) : cookie; 62 } 63 } 64 65 return null; 66 }; 67 68 config.defaults = {}; 69 70 $.removeCookie = function (key, options) { 71 if ($.cookie(key) !== null) { 72 $.cookie(key, null, options); 73 return true; 74 } 75 return false; 76 }; 77 78 })(jQuery, document); 79 }); 80