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

« back to all changes in this revision

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

  • Committer: dcoles
  • Date: 2008-02-25 02:26:39 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:562
Added new app: Diff (SVN diff application)
setup.py: Added diffservice script to jail scripts

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
 
 
378
344
/** Given an argument map, as output in the args parameter of the return of
379
345
 * parseurl, gets the first occurence of an argument in the URL string.
380
346
 * If the argument was not found, returns null.
553
519
    arr.splice(j, i-j);
554
520
}
555
521
 
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
 
 
565
522
/** Returns a new XMLHttpRequest object, in a somewhat browser-agnostic
566
523
 * fashion.
567
524
 */