1/** 2 * å°è£ æä½cookieçæ¹æ³ 3 * 4 * @name ucb.Cookie 5 * @author Ican Cheung <[email protected]> 6 * 7 */ 8var ucb = ucb || {}; 9 10ucb.Supports = { 11 /** 12 * @property æ¯å¦æ¯æè§¦æ§ 13 * @type {Boolean} 14 */ 15 Touch: ('ontouchstart' in window) 16}; 17 18ucb.Cookie = ucb.Cookie || {}; 19 20(function(cookie) { 21 22 /** 23 * éªè¯å符串æ¯å¦åæ³çcookieé®å 24 * 25 * @param {string} source éè¦éªè¯çkey 26 * @return {bool} æ¯å¦åæ³çcookieé®å 27 */ 28 cookie._isValidKey = function(key) { 29 30 return (new RegExp("^[^\\x00-\\x20\\x7f\\(\\)<>@,;:\\\\\\\"\\[\\]\\?=\\{\\}\\/\\u0080-\\uffff]+\x24")) 31 .test(key); 32 }; 33 34 /** 35 * è·åcookieçå¼ï¼ä¸å¯¹å¼è¿è¡è§£ç 36 * 37 * @function 38 * @param {string} key éè¦è·åCookieçé®å 39 * 40 * @returns {string|null} è·åçCookieå¼ï¼è·åä¸å°æ¶è¿ånull 41 */ 42 cookie.getRaw = function(key) { 43 if (cookie._isValidKey(key)) { 44 var reg = new RegExp("(^| )" + key + "=([^;]*)(;|\x24)"), result = reg.exec(document.cookie); 45 46 if (result) { 47 return result[2] || null; 48 } 49 } 50 51 return null; 52 }; 53 54 /** 55 * è·åcookieçå¼ï¼ç¨decodeURIComponentè¿è¡è§£ç 56 * 57 * @function 58 * @param {string} key éè¦è·åCookieçé®å 59 * @description <b>注æï¼</b>è¯¥æ¹æ³ä¼å¯¹cookieå¼è¿è¡decodeURIComponentè§£ç ã妿æ³è·å¾cookieæºå符串ï¼è¯·ä½¿ç¨getRawæ¹æ³ã 60 * 61 * @returns {string|null} cookieçå¼ï¼è·åä¸å°æ¶è¿ånull 62 */ 63 cookie.get = function(key) { 64 var value = cookie.getRaw(key); 65 if ('string' == typeof value) { 66 value = decodeURIComponent(value); 67 return value; 68 } 69 return null; 70 }; 71 72 /** 73 * 设置cookieçå¼ï¼ä¸å¯¹å¼è¿è¡ç¼ç 74 * 75 * @function 76 * @param {string} key éè¦è®¾ç½®Cookieçé®å 77 * @param {string} value éè¦è®¾ç½®Cookieçå¼ 78 * @param {Object} [options] 设置Cookieçå ¶ä»å¯éåæ° 79 * @config {string} [path] cookieè·¯å¾ 80 * @config {Date|number}
80 [expires] cookieè¿ææ¶é´,å¦æç±»åæ¯æ°åçè¯, å使¯æ¯«ç§ 81 * @config {string} [domain] cookieåå 82 * @config {string} [secure] cookieæ¯å¦å®å ¨ä¼ è¾ 83 */ 84 cookie.setRaw = function(key, value, options) { 85 if (!cookie._isValidKey(key)) { 86 return; 87 } 88 89 options = options || {}; 90 91 // 计ç®cookieè¿ææ¶é´ 92 var expires = options.expires; 93 if ('number' == typeof options.expires) { 94 expires = new Date(); 95 expires.setTime(expires.getTime() + options.expires); 96 } 97 98 document.cookie = key + "=" + value + (options.path ? "; path=" + options.path : "") 99 + (expires ? "; expires=" + expires.toGMTString() : "") 100 + (options.domain ? "; domain=" + options.domain : "") + (options.secure ? "; secure" : ''); 101 }; 102 103 /** 104 * 设置cookieçå¼ï¼ç¨encodeURIComponentè¿è¡ç¼ç 105 * 106 * @function 107 * @param {string} key éè¦è®¾ç½®Cookieçé®å 108 * @param {string} value éè¦è®¾ç½®Cookieçå¼ 109 * @param {Object} [options] 设置Cookieçå ¶ä»å¯éåæ° 110 * @config {string} [path] cookieè·¯å¾ 111 * @config {Date|number}
111 [expires] cookieè¿ææ¶é´,å¦æç±»åæ¯æ°åçè¯, å使¯æ¯«ç§ 112 * @config {string} [domain] cookieåå 113 * @config {string} [secure] cookieæ¯å¦å®å ¨ä¼ è¾ 114 */ 115 cookie.set = function(key, value, options) { 116 cookie.setRaw(key, encodeURIComponent(value), options); 117 }; 118 119 /** 120 * å é¤cookieçå¼ 121 * 122 * @function 123 * @param {string} key éè¦å é¤Cookieçé®å 124 * @param {Object} options éè¦å é¤çcookie对åºç path domain çå¼ 125 */ 126 cookie.remove = function(key, options) { 127 options = options || {}; 128 options.expires = new Date(0); 129 cookie.setRaw(key, '', options); 130 }; 131 132})(ucb.Cookie); 133
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.