~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 04:50:29 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:223
util.js: Added "urlencode_path" which is specially designed to encode paths.
         Added convenience function encoded_app_path.
         Ajax call now correctly encodes path.
listing, browser.js: All URLs generated are now correctly encoded (where they
        were sent unencoded before).

Show diffs side-by-side

added added

removed removed

Lines of Context:
323
323
    return encodeURI(url);
324
324
}
325
325
 
 
326
/** URL-encodes a path. This is a special case of URL encoding as all
 
327
 * characters *except* the slash must be encoded.
 
328
 */
 
329
function urlencode_path(path)
 
330
{
 
331
    /* Split up the path, URLEncode each segment with encodeURIComponent,
 
332
     * and rejoin.
 
333
     */
 
334
    var split = path.split('/');
 
335
    for (var i=0; i<split.length; i++)
 
336
        split[i] = encodeURIComponent(split[i]);
 
337
    path = path_join.apply(null, split);
 
338
    if (split[0] == "") path = "/" + path;
 
339
    return path;
 
340
}
 
341
 
326
342
/** Given an argument map, as output in the args parameter of the return of
327
343
 * parseurl, gets the first occurence of an argument in the URL string.
328
344
 * If the argument was not found, returns null.
451
467
    return path_join(root_dir, path);
452
468
}
453
469
 
 
470
/** Shorthand for urlencode_path(make_path(path_join(app, ...)))
 
471
 * Creates a URL-encoded path for a given path within a given app.
 
472
 */
 
473
function encoded_app_path(app /*,...*/)
 
474
{
 
475
    return urlencode_path(make_path(path_join.apply(null, arguments)));
 
476
}
 
477
 
454
478
/** Given a path, gets the "basename" (the last path segment).
455
479
 */
456
480
function path_basename(path)
495
519
{
496
520
    if (content_type != "multipart/form-data")
497
521
        content_type = "application/x-www-form-urlencoded";
498
 
    path = make_path(path_join(app, path));
 
522
    path = encoded_app_path(app, path);
499
523
    var url;
500
524
    /* A random string, for multipart/form-data
501
525
     * (This is not checked against anywhere else, it is solely defined and