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

« back to all changes in this revision

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

  • Committer: wagrant
  • Date: 2008-08-09 06:02:40 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:999
browser (help): Document that Ctrl+S saves.

Show diffs side-by-side

added added

removed removed

Lines of Context:
512
512
    return make_path(path_join.apply(null, arguments));
513
513
}
514
514
 
515
 
/** Same as app_path but creates a properly-escaped site-relative URL.
516
 
 */
517
 
function app_url(app /*,...*/)
518
 
{
519
 
    return urlencode_path(app_path.apply(null, arguments));
520
 
}
521
 
 
522
515
/** Generates an absolute URL to a public application
523
516
 */
524
 
function public_app_url(app /*,...*/)
 
517
function public_app_path(app /*,...*/)
525
518
{
526
 
    return "http://" + public_host + app_url.apply(null, arguments);
 
519
    return location.protocol + "//" + public_host
 
520
        + make_path(path_join.apply(null, arguments));
527
521
}
528
522
 
529
523
/** Given a path, gets the "basename" (the last path segment).
544
538
    return str.substr(str.length - substring.length) == substring;
545
539
}
546
540
 
 
541
/** Equivalent to Python's repr.
 
542
 * Gets the JavaScript string representation.
 
543
 * Actually just calls JSON.stringify.
 
544
 */
 
545
function repr(str)
 
546
{
 
547
    return JSON.stringify(str);
 
548
}
 
549
 
547
550
/** Removes all occurences of a value from an array.
548
551
 */
549
552
Array.prototype.removeall = function(val)
628
631
 * \param app IVLE app to call (such as "fileservice").
629
632
 * \param path URL path to make the request to, within the application.
630
633
 * \param args Argument object, as described in parse_url and friends.
631
 
 * \param method String; "GET", "POST", "PUT", or "PATCH"
632
 
 * \param content_type String, optional.
 
634
 * \param method String; "GET" or "POST"
 
635
 * \param content_type String, optional. Only applies if method is "POST".
 
636
 *      May be "application/x-www-form-urlencoded" or "multipart/form-data".
633
637
 *      Defaults to "application/x-www-form-urlencoded".
634
638
 */
635
639
function ajax_call(callback, app, path, args, method, content_type)
636
640
{
637
 
    if (!content_type)
 
641
    if (content_type != "multipart/form-data")
638
642
        content_type = "application/x-www-form-urlencoded";
639
643
    path = app_path(app, path);
640
644
    var url;
664
668
    }
665
669
    else
666
670
    {
667
 
        /* POST & PUT & PATCH sends the args in the request body */
668
 
        url = urlencode_path(path);
 
671
        /* POST sends the args in application/x-www-form-urlencoded */
 
672
        url = encodeURI(path);
669
673
        xhr.open(method, url, asyncronous);
670
674
        var message;
671
675
        if (content_type == "multipart/form-data")
674
678
                "multipart/form-data; boundary=" + boundary);
675
679
            message = make_multipart_formdata(args, boundary);
676
680
        }
677
 
        else if (content_type == "application/x-www-form-urlencoded")
 
681
        else
678
682
        {
679
683
            xhr.setRequestHeader("Content-Type", content_type);
680
684
            message = make_query_string(args);
681
685
        }
682
 
        else if (content_type == "application/json")
683
 
        {
684
 
            xhr.setRequestHeader("Content-Type", content_type);
685
 
            message = JSON.stringify(args);
686
 
        }
687
 
        else
688
 
        {
689
 
            xhr.setRequestHeader("Content-Type", content_type);
690
 
            message = args;
691
 
        }
692
686
        xhr.send(message);
693
687
    }
694
688
    /* Only return the XHR for syncronous requests */