1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * 26 * @private 27 */ 28 AjxCookie = function() { 29 } 30 31 AjxCookie.prototype.toString = 32 function() { 33 return "AjxCookie"; 34 } 35 36 AjxCookie.getCookie = 37 function(doc, name) { 38 var arg = name + "="; 39 var alen = arg.length; 40 var clen = doc.cookie.length; 41 var cookie = doc.cookie; 42 var i = 0; 43 while (i < clen) { 44 var j = i + alen; 45 if (cookie.substring(i, j) == arg) { 46 var endstr = cookie.indexOf (";", j); 47 if (endstr == -1) 48 endstr = cookie.length; 49 return unescape(cookie.substring(j, endstr)); 50 } 51 i = cookie.indexOf(" ", i) + 1; 52 if (i == 0) 53 break; 54 } 55 return null; 56 } 57 58 AjxCookie.setCookie = 59 function(doc, name, value, expires, path, domain, secure) { 60 doc.cookie = name + "=" + escape (value) + 61 ((expires) ? "; expires=" + expires.toGMTString() : "") + 62 ((path) ? "; path=" + path : "") + 63 ((domain) ? "; domain=" + domain : "") + 64 ((secure) ? "; secure" : ""); 65 } 66 67 AjxCookie.deleteCookie = 68 function (doc, name, path, domain) { 69 doc.cookie = name + "=" + 70 ((path) ? "; path=" + path : "") + 71 ((domain) ? "; domain=" + domain : "") + "; expires=Fri, 31 Dec 1999 23:59:59 GMT"; 72 } 73 74 AjxCookie.areCookiesEnabled = 75 function (doc) { 76 var name = "ZM_COOKIE_TEST"; 77 var value = "Zimbra"; 78 AjxCookie.setCookie(doc, name, value); 79 var cookie = AjxCookie.getCookie(doc, name); 80 AjxCookie.deleteCookie(doc, name); 81 return cookie == value; 82 } 83 84