~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/common/util.js

  • Committer: mattgiuca
  • Date: 2008-03-16 02:46:19 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:712
setup: Added config option "motd_path" to hold the path for message-of-the-day
    announcements.
dispatch.login: Now tries to send the file in motd_path at the bottom of the
    login page.
This allows our admins to post system-wide announcements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
341
341
    return path;
342
342
}
343
343
 
 
344
/** Writes a JSONable object to the cookie under a particular key
 
345
 * (JSON encoded and URL encoded).
 
346
 */
 
347
function write_cookie(key, value)
 
348
{
 
349
    var sendstr = encodeURIComponent(key) + "="
 
350
        + encodeURIComponent(JSON.stringify(value))
 
351
        + "; path=" + urlencode_path(root_dir);
 
352
    /* This actually just assigns to the key, not replacing the whole cookie
 
353
     * as it appears to. */
 
354
    document.cookie = sendstr;
 
355
}
 
356
/** Reads a cookie which has a JSONable object encoded as its value.
 
357
 * Returns the object, parsed from JSON.
 
358
 */
 
359
function read_cookie(key)
 
360
{
 
361
    var cookies = document.cookie.split(";");
 
362
    var checkstart = encodeURIComponent(key) + "=";
 
363
    var checklen = checkstart.length;
 
364
    for (var i=0; i<cookies.length; i++)
 
365
    {
 
366
        var cookie = cookies[i];
 
367
        while (cookie[0] == ' ')
 
368
            cookie = cookie.substr(1);
 
369
        if (cookie.substr(0, checklen) == checkstart)
 
370
        {
 
371
            var valstr = cookie.substr(checklen);
 
372
            valstr = decodeURIComponent(valstr);
 
373
            return JSON.parse(valstr);
 
374
        }
 
375
    }
 
376
}
 
377
 
344
378
/** Given an argument map, as output in the args parameter of the return of
345
379
 * parseurl, gets the first occurence of an argument in the URL string.
346
380
 * If the argument was not found, returns null.
519
553
    arr.splice(j, i-j);
520
554
}
521
555
 
 
556
/** Shallow-clones an object */
 
557
function shallow_clone_object(obj)
 
558
{
 
559
    o = {};
 
560
    for (k in obj)
 
561
        o[k] = obj[k];
 
562
    return o;
 
563
}
 
564
 
522
565
/** Returns a new XMLHttpRequest object, in a somewhat browser-agnostic
523
566
 * fashion.
524
567
 */