2
* Copyright 2009 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS-IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
var padcookie = (function(){
19
function getRawCookie() {
20
// returns null if can't get cookie text
21
if (! document.cookie) {
24
// look for (start of string OR semicolon) followed by whitespace followed by prefs=(something);
25
var regexResult = document.cookie.match(/(?:^|;)\s*prefs=([^;]*)(?:;|$)/);
26
if ((! regexResult) || (! regexResult[1])) {
29
return regexResult[1];
31
function setRawCookie(safeText) {
32
var expiresDate = new Date();
33
expiresDate.setFullYear(3000);
34
document.cookie = ('prefs='+safeText+';expires='+expiresDate.toGMTString());
36
function parseCookie(text) {
37
// returns null if can't parse cookie.
40
var cookieData = JSON.parse(unescape(text));
47
function stringifyCookie(data) {
48
return escape(JSON.stringify(data));
50
function saveCookie() {
54
setRawCookie(stringifyCookie(cookieData));
56
if (pad.getIsProPad() && (! getRawCookie()) && (! alreadyWarnedAboutNoCookies)) {
57
alert("Warning: it appears that your browser does not have cookies enabled."+
58
" EtherPad uses cookies to keep track of unique users for the purpose"+
59
" of putting a quota on the number of active users. Using EtherPad without "+
60
" cookies may fill up your server's user quota faster than expected.");
61
alreadyWarnedAboutNoCookies = true;
65
var wasNoCookie = true;
67
var alreadyWarnedAboutNoCookies = false;
71
init: function(prefsToSet) {
72
var rawCookie = getRawCookie();
74
var cookieObj = parseCookie(rawCookie);
76
wasNoCookie = false; // there was a cookie
77
delete cookieObj.userId;
78
delete cookieObj.name;
79
delete cookieObj.colorId;
80
cookieData = cookieObj;
84
for(var k in prefsToSet) {
85
cookieData[k] = prefsToSet[k];
91
wasNoCookie: function() { return wasNoCookie; },
92
getPref: function(prefName) {
93
return cookieData[prefName];
95
setPref: function(prefName, value) {
96
cookieData[prefName] = value;
b'\\ No newline at end of file'