~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 01:15:26 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:218
console.js: Removed alert.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    if (href == null) href = "";
78
78
    var elem = document.createElement(tagname);
79
79
    var link = document.createElement("a");
80
 
    link.setAttribute("href", urlencode_path(href));
 
80
    link.setAttribute("href", encodeURI(href));
81
81
    if (title != null)
82
82
        link.setAttribute("title", title);
83
83
    if (onclick != null)
93
93
function dom_make_img(src, width, height, title, alt)
94
94
{
95
95
    var img = document.createElement("img");
96
 
    img.setAttribute("src", urlencode_path(src));
 
96
    img.setAttribute("src", src);
97
97
    if (width != null)
98
98
        img.setAttribute("width", width);
99
99
    if (height != null)
149
149
 * args is never null, though it may be empty.
150
150
 *
151
151
 * All strings are decoded/unescaped. Reserved characters
152
 
 * (; , / ? : @ & = + * $) are not decoded except in args and path.
 
152
 * (; , / ? : @ & = + * $) are not decoded except in args.
153
153
 *
154
154
 * \param url String. A URL. To read from the current browser window, use
155
155
 *  window.location.href.
162
162
    var serverpart;
163
163
    var args;
164
164
 
 
165
    url = decodeURI(url);
 
166
 
165
167
    /* Split scheme from rest */
166
168
    index = url.indexOf("://");
167
169
    if (index < 0)
218
220
            obj.query_string = url.substr(index+1);
219
221
        }
220
222
    }
221
 
    obj.path = decodeURIComponent(obj.path);
222
223
 
223
224
    /* Split query string into arguments */
224
225
    args = {};
306
307
        url += ":" + obj.server_port.toString();
307
308
    if (("path" in obj) && obj.path != null)
308
309
    {
309
 
        var path = urlencode_path(obj.path.toString());
 
310
        var path = obj.path.toString();
310
311
        if (url.length > 0 && path.length > 0 && path[0] != "/")
311
312
            path = "/" + path;
312
313
        url += path;
313
314
    }
314
315
    if (("query_string" in obj) && obj.query_string != null)
315
 
        query_string = encodeURI(obj.query_string.toString());
 
316
        query_string = obj.query_string.toString();
316
317
    else if (("args" in obj) && obj.args != null)
317
318
        query_string = make_query_string(obj.args);
318
319
 
319
320
    if (query_string != null)
320
321
        url += "?" + query_string;
321
322
 
322
 
    return url;
323
 
}
324
 
 
325
 
/** URL-encodes a path. This is a special case of URL encoding as all
326
 
 * characters *except* the slash must be encoded.
327
 
 */
328
 
function urlencode_path(path)
329
 
{
330
 
    /* Split up the path, URLEncode each segment with encodeURIComponent,
331
 
     * and rejoin.
332
 
     */
333
 
    var split = path.split('/');
334
 
    for (var i=0; i<split.length; i++)
335
 
        split[i] = encodeURIComponent(split[i]);
336
 
    path = path_join.apply(null, split);
337
 
    if (split[0] == "" && split.length > 1) path = "/" + path;
338
 
    return path;
 
323
    return encodeURI(url);
339
324
}
340
325
 
341
326
/** Given an argument map, as output in the args parameter of the return of
466
451
    return path_join(root_dir, path);
467
452
}
468
453
 
469
 
/** Shorthand for make_path(path_join(app, ...))
470
 
 * Creates an absolute path for a given path within a given app.
471
 
 */
472
 
function app_path(app /*,...*/)
473
 
{
474
 
    return make_path(path_join.apply(null, arguments));
475
 
}
476
 
 
477
454
/** Given a path, gets the "basename" (the last path segment).
478
455
 */
479
456
function path_basename(path)
518
495
{
519
496
    if (content_type != "multipart/form-data")
520
497
        content_type = "application/x-www-form-urlencoded";
521
 
    path = app_path(app, path);
 
498
    path = make_path(path_join(app, path));
522
499
    var url;
523
500
    /* A random string, for multipart/form-data
524
501
     * (This is not checked against anywhere else, it is solely defined and