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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2008-01-14 06:04:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:227
Added "ignore" property for consoleservice (*.pyc).

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
 *  it will automatically be URL-encoded.
70
70
 * \param onclick Optional string. Will be set as the "onclick" attribute
71
71
 *  of the "a" element.
72
 
 * \param dontencode Optional boolean. If true, will not encode the href.
73
 
 *  if including query strings, you must set this to true and use build_url
74
 
 *  to escape the URI correctly.
75
72
 * \return DOM Element object.
76
73
 */
77
 
function dom_make_link_elem(tagname, text, title, href, onclick, dontencode)
 
74
function dom_make_link_elem(tagname, text, title, href, onclick)
78
75
{
79
76
    if (text == null) text = "";
80
77
    if (href == null) href = "";
81
78
    var elem = document.createElement(tagname);
82
79
    var link = document.createElement("a");
83
 
    if (dontencode != true)
84
 
        href = urlencode_path(href);
85
 
    link.setAttribute("href", href);
 
80
    link.setAttribute("href", urlencode_path(href));
86
81
    if (title != null)
87
82
        link.setAttribute("title", title);
88
83
    if (onclick != null)
98
93
function dom_make_img(src, width, height, title, alt)
99
94
{
100
95
    var img = document.createElement("img");
101
 
    img.setAttribute("src", urlencode_path(src));
 
96
    img.setAttribute("src", src);
102
97
    if (width != null)
103
98
        img.setAttribute("width", width);
104
99
    if (height != null)
278
273
            query_string += "&" + encodeURIComponent(arg_key) + "=" +
279
274
                encodeURIComponent(arg_val);
280
275
    }
281
 
    if (query_string != "")
 
276
    if (query_string == "")
 
277
        query_string = null;
 
278
    else
282
279
        /* Drop the first "&" */
283
280
        query_string = query_string.substr(1);
284
281
 
319
316
    else if (("args" in obj) && obj.args != null)
320
317
        query_string = make_query_string(obj.args);
321
318
 
322
 
    if (query_string != "" && query_string != null)
 
319
    if (query_string != null)
323
320
        url += "?" + query_string;
324
321
 
325
322
    return url;
337
334
    for (var i=0; i<split.length; i++)
338
335
        split[i] = encodeURIComponent(split[i]);
339
336
    path = path_join.apply(null, split);
340
 
    if (split[0] == "" && split.length > 1) path = "/" + path;
 
337
    if (split[0] == "") path = "/" + path;
341
338
    return path;
342
339
}
343
340
 
426
423
    {
427
424
        /* FIXME: Encoding not supported here (should not matter if we
428
425
         * only use ASCII names */
429
 
        data += "--" + boundary + "\r\n"
 
426
        data += "--" + boundary + "\n"
430
427
            + "Content-Disposition: form-data; name=\"" + arg_key
431
 
            + "\"\r\n\r\n"
432
 
            + arg_val + "\r\n";
 
428
            + "\"\n\n"
 
429
            + arg_val + "\n";
433
430
    }
434
431
 
435
432
    for (var arg_key in args)
444
441
            extend_data(arg_key, arg_val);
445
442
    }
446
443
    /* End boundary */
447
 
    data += "--" + boundary + "--\r\n";
 
444
    data += "--" + boundary + "--\n";
448
445
 
449
446
    return data;
450
447
}
504
501
    return JSON.stringify(str);
505
502
}
506
503
 
507
 
/** Removes all occurences of a value from an array.
508
 
 */
509
 
Array.prototype.removeall = function(val)
510
 
{
511
 
    var i, j;
512
 
    var arr = this;
513
 
    j = 0;
514
 
    for (i=0; i<arr.length; i++)
515
 
    {
516
 
        arr[j] = arr[i];
517
 
        if (arr[i] != val) j++;
518
 
    }
519
 
    arr.splice(j, i-j);
520
 
}
521
 
 
522
504
/** Makes an XMLHttpRequest call to the server. Waits (synchronously) for a
523
505
 * response, and returns an XMLHttpRequest object containing the completed
524
506
 * response.
569
551
            xhr.setRequestHeader("Content-Type", content_type);
570
552
            message = make_query_string(args);
571
553
        }
572
 
        xhr.setRequestHeader("Content-Length", message.length);
573
554
        xhr.send(message);
574
555
    }
575
556
    return xhr;