Authored by xuqi

function of get cookie

@@ -10,23 +10,11 @@ var $body = $('body'); @@ -10,23 +10,11 @@ var $body = $('body');
10 10
11 require('./footer'); 11 require('./footer');
12 12
13 -  
14 -  
15 function cookie(name) { 13 function cookie(name) {
16 - var cookies = document.cookie,  
17 - cookieVal,  
18 - offset;  
19 -  
20 - if (document.cookie && document.cookie !== '') {  
21 - offset = cookies.indexOf(name + '=');  
22 - if (offset > -1) {  
23 - offset += name.length + 1;  
24 -  
25 - cookieVal = decodeURIComponent($.trim(cookies.substring(offset, cookies.indexOf(';', offset))));  
26 - }  
27 - } 14 + var re = new RegExp(name + '=([^;$]*)', 'i'),
  15 + matchPattern = '$1';
28 16
29 - return cookieVal; 17 + return re.test(decodeURIComponent(document.cookie)) ? RegExp[matchPattern] : '';
30 } 18 }
31 19
32 function setCookie(name, value, options) { 20 function setCookie(name, value, options) {