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

« back to all changes in this revision

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

  • Committer: dilshan_a
  • Date: 2008-01-24 04:52:56 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:283
Fixed a bug where variables were persistent across test cases.

Added initial minutes/report/documentation on tutorials.

Show diffs side-by-side

added added

removed removed

Lines of Context:
278
278
            query_string += "&" + encodeURIComponent(arg_key) + "=" +
279
279
                encodeURIComponent(arg_val);
280
280
    }
281
 
    if (query_string != "")
 
281
    if (query_string == "")
 
282
        query_string = null;
 
283
    else
282
284
        /* Drop the first "&" */
283
285
        query_string = query_string.substr(1);
284
286
 
319
321
    else if (("args" in obj) && obj.args != null)
320
322
        query_string = make_query_string(obj.args);
321
323
 
322
 
    if (query_string != "" && query_string != null)
 
324
    if (query_string != null)
323
325
        url += "?" + query_string;
324
326
 
325
327
    return url;
426
428
    {
427
429
        /* FIXME: Encoding not supported here (should not matter if we
428
430
         * only use ASCII names */
429
 
        data += "--" + boundary + "\r\n"
 
431
        data += "--" + boundary + "\n"
430
432
            + "Content-Disposition: form-data; name=\"" + arg_key
431
 
            + "\"\r\n\r\n"
432
 
            + arg_val + "\r\n";
 
433
            + "\"\n\n"
 
434
            + arg_val + "\n";
433
435
    }
434
436
 
435
437
    for (var arg_key in args)
444
446
            extend_data(arg_key, arg_val);
445
447
    }
446
448
    /* End boundary */
447
 
    data += "--" + boundary + "--\r\n";
 
449
    data += "--" + boundary + "--\n";
448
450
 
449
451
    return data;
450
452
}
519
521
    arr.splice(j, i-j);
520
522
}
521
523
 
522
 
/** Shallow-clones an object */
523
 
function shallow_clone_object(obj)
524
 
{
525
 
    o = {};
526
 
    for (k in obj)
527
 
        o[k] = obj[k];
528
 
    return o;
529
 
}
530
 
 
531
 
/** Returns a new XMLHttpRequest object, in a somewhat browser-agnostic
532
 
 * fashion.
533
 
 */
534
 
function new_xmlhttprequest()
535
 
{
536
 
    try
537
 
    {
538
 
        /* Real Browsers */
539
 
        return new XMLHttpRequest();
540
 
    }
541
 
    catch (e)
542
 
    {
543
 
        /* Internet Explorer */
544
 
        try
545
 
        {
546
 
            return new ActiveXObject("Msxml2.XMLHTTP");
547
 
        }
548
 
        catch (e)
549
 
        {
550
 
            try
551
 
            {
552
 
                return new ActiveXObject("Microsoft.XMLHTTP");
553
 
            }
554
 
            catch (e)
555
 
            {
556
 
                throw("Your browser does not support AJAX. "
557
 
                    + "IVLE requires a modern browser.");
558
 
            }
559
 
        }
560
 
    }
561
 
}
562
 
 
563
 
/** Makes an asynchronous XMLHttpRequest call to the server.
564
 
 * Sends the XMLHttpRequest object containing the completed response to a
565
 
 * specified callback function.
 
524
/** Makes an XMLHttpRequest call to the server. Waits (synchronously) for a
 
525
 * response, and returns an XMLHttpRequest object containing the completed
 
526
 * response.
566
527
 *
567
 
 * \param callback A callback function. Will be called when the response is
568
 
 *      complete. Passed 1 parameter, an XMLHttpRequest object containing the
569
 
 *      completed response.
570
528
 * \param app IVLE app to call (such as "fileservice").
571
529
 * \param path URL path to make the request to, within the application.
572
530
 * \param args Argument object, as described in parse_url and friends.
574
532
 * \param content_type String, optional. Only applies if method is "POST".
575
533
 *      May be "application/x-www-form-urlencoded" or "multipart/form-data".
576
534
 *      Defaults to "application/x-www-form-urlencoded".
 
535
 * \return An XMLHttpRequest object containing the completed response.
577
536
 */
578
 
function ajax_call(callback, app, path, args, method, content_type)
 
537
function ajax_call(app, path, args, method, content_type)
579
538
{
580
539
    if (content_type != "multipart/form-data")
581
540
        content_type = "application/x-www-form-urlencoded";
585
544
     * (This is not checked against anywhere else, it is solely defined and
586
545
     * used within this function) */
587
546
    var boundary = "48234n334nu7n4n2ynonjn234t683jyh80j";
588
 
    var xhr = new_xmlhttprequest();
589
 
    xhr.onreadystatechange = function()
590
 
        {
591
 
            if (xhr.readyState == 4)
592
 
            {
593
 
                callback(xhr);
594
 
            }
595
 
        }
 
547
    var xhr = new XMLHttpRequest();
596
548
    if (method == "GET")
597
549
    {
598
550
        /* GET sends the args in the URL */
599
551
        url = build_url({"path": path, "args": args});
600
 
        /* open's 3rd argument = true -> asynchronous */
601
 
        xhr.open(method, url, true);
 
552
        /* open's 3rd argument = false -> SYNCHRONOUS (wait for response)
 
553
         * (No need for a callback function) */
 
554
        xhr.open(method, url, false);
602
555
        xhr.send(null);
603
556
    }
604
557
    else
605
558
    {
606
559
        /* POST sends the args in application/x-www-form-urlencoded */
607
560
        url = encodeURI(path);
608
 
        xhr.open(method, url, true);
 
561
        xhr.open(method, url, false);
609
562
        var message;
610
563
        if (content_type == "multipart/form-data")
611
564
        {
618
571
            xhr.setRequestHeader("Content-Type", content_type);
619
572
            message = make_query_string(args);
620
573
        }
621
 
        xhr.setRequestHeader("Content-Length", message.length);
622
574
        xhr.send(message);
623
575
    }
 
576
    return xhr;
624
577
}
625
578