~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-07-02 04:34:46 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:800
Docs: Updated docs to show debootstrap dependency and relect changes to jail 
building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
/* Expects the following variables to have been declared by JavaScript in
26
26
 * the HTML generated by the server:
27
27
 * - root_dir
 
28
 * - public_host
28
29
 * - username
29
30
 */
30
31
 
310
311
    if (("path" in obj) && obj.path != null)
311
312
    {
312
313
        var path = urlencode_path(obj.path.toString());
313
 
        if (url.length > 0 && path.length > 0 && path[0] != "/")
 
314
        if (url.length > 0 && path.length > 0 && path.charAt(0) != "/")
314
315
            path = "/" + path;
315
316
        url += path;
316
317
    }
425
426
    {
426
427
        arg = arguments[i];
427
428
        if (arg.length == 0) continue;
428
 
        if (arg[0] == '/')
 
429
        if (arg.charAt(0) == '/')
429
430
            path = arg;
430
431
        else
431
432
        {
432
 
            if (path.length > 0 && path[path.length-1] != '/')
 
433
            if (path.length > 0 && path.charAt(path.length-1) != '/')
433
434
                path += '/';
434
435
            path += arg;
435
436
        }
490
491
function pathlist_to_path(pathlist)
491
492
{
492
493
    ret = path_join.apply(null, pathlist);
493
 
    if (ret[ret.length-1] != '/')
 
494
    if (ret.charAt(ret.length-1) != '/')
494
495
        ret += '/';
495
496
    return ret;
496
497
}
511
512
    return make_path(path_join.apply(null, arguments));
512
513
}
513
514
 
 
515
/** Generates an absolute URL to a public application
 
516
 */
 
517
function public_app_path(app /*,...*/)
 
518
{
 
519
    return location.protocol + "//" + public_host
 
520
        + make_path(path_join.apply(null, arguments));
 
521
}
 
522
 
514
523
/** Given a path, gets the "basename" (the last path segment).
515
524
 */
516
525
function path_basename(path)
594
603
    }
595
604
}
596
605
 
 
606
/** Creates a random string of length length,
 
607
 * consisting of alphanumeric characters.
 
608
 */
 
609
var rand_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"
 
610
               + "abcdefghiklmnopqrstuvwxyz";
 
611
function random_string(length)
 
612
{
 
613
    var str = Array(length);
 
614
    var v;
 
615
    for (var i=0; i<length; i++)
 
616
    {
 
617
        v = Math.floor(Math.random() * rand_chars.length);
 
618
        str[i] = rand_chars.charAt(v);
 
619
    }
 
620
    return str.join('');
 
621
}
 
622
 
597
623
/** Makes an asynchronous XMLHttpRequest call to the server.
598
624
 * Sends the XMLHttpRequest object containing the completed response to a
599
625
 * specified callback function.
618
644
    /* A random string, for multipart/form-data
619
645
     * (This is not checked against anywhere else, it is solely defined and
620
646
     * used within this function) */
621
 
    var boundary = "48234n334nu7n4n2ynonjn234t683jyh80j";
 
647
    var boundary = random_string(20);
622
648
    var xhr = new_xmlhttprequest();
623
649
    xhr.onreadystatechange = function()
624
650
        {
644
670
        if (content_type == "multipart/form-data")
645
671
        {
646
672
            xhr.setRequestHeader("Content-Type",
647
 
                "multipart/form-data, boundary=" + boundary);
 
673
                "multipart/form-data; boundary=" + boundary);
648
674
            message = make_multipart_formdata(args, boundary);
649
675
        }
650
676
        else
652
678
            xhr.setRequestHeader("Content-Type", content_type);
653
679
            message = make_query_string(args);
654
680
        }
655
 
        xhr.setRequestHeader("Content-Length", message.length);
656
681
        xhr.send(message);
657
682
    }
658
683
}