Share createCookie and readCookie methods.

This commit is contained in:
Chad Weider 2012-01-26 22:42:58 -08:00
parent 7038f9a61d
commit 34edba3adf
3 changed files with 35 additions and 50 deletions

View file

@ -20,6 +20,35 @@
* limitations under the License.
*/
function createCookie(name, value, days, path)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
if(!path)
path = "/";
document.cookie = name + "=" + value + expires + "; path=" + path;
}
function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++)
{
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
var padutils = {
escapeHtml: function(x)
{
@ -481,4 +510,6 @@ padutils.setupGlobalExceptionHandler = setupGlobalExceptionHandler;
padutils.binarySearch = require('/ace2_common').binarySearch;
exports.createCookie = createCookie;
exports.readCookie = readCookie;
exports.padutils = padutils;