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

« back to all changes in this revision

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

Move ivle.webapp.tutorial's media to the new framework. This also fixes the
omission of tutorial.css from SubjectView, which made it rather ugly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
538
538
    return str.substr(str.length - substring.length) == substring;
539
539
}
540
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
 
 
550
541
/** Removes all occurences of a value from an array.
551
542
 */
552
543
Array.prototype.removeall = function(val)
631
622
 * \param app IVLE app to call (such as "fileservice").
632
623
 * \param path URL path to make the request to, within the application.
633
624
 * \param args Argument object, as described in parse_url and friends.
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".
 
625
 * \param method String; "GET", "POST", "PUT", or "PATCH"
 
626
 * \param content_type String, optional.
637
627
 *      Defaults to "application/x-www-form-urlencoded".
638
628
 */
639
629
function ajax_call(callback, app, path, args, method, content_type)
640
630
{
641
 
    if (content_type != "multipart/form-data")
 
631
    if (!content_type)
642
632
        content_type = "application/x-www-form-urlencoded";
643
633
    path = app_path(app, path);
644
634
    var url;
668
658
    }
669
659
    else
670
660
    {
671
 
        /* POST sends the args in application/x-www-form-urlencoded */
 
661
        /* POST & PUT & PATCH sends the args in the request body */
672
662
        url = encodeURI(path);
673
663
        xhr.open(method, url, asyncronous);
674
664
        var message;
678
668
                "multipart/form-data; boundary=" + boundary);
679
669
            message = make_multipart_formdata(args, boundary);
680
670
        }
681
 
        else
 
671
        else if (content_type == "application/x-www-form-urlencoded")
682
672
        {
683
673
            xhr.setRequestHeader("Content-Type", content_type);
684
674
            message = make_query_string(args);
685
675
        }
 
676
        else if (content_type == "application/json")
 
677
        {
 
678
            xhr.setRequestHeader("Content-Type", content_type);
 
679
            message = JSON.stringify(args);
 
680
        }
 
681
        else
 
682
        {
 
683
            xhr.setRequestHeader("Content-Type", content_type);
 
684
            message = args;
 
685
        }
686
686
        xhr.send(message);
687
687
    }
688
688
    /* Only return the XHR for syncronous requests */