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

« back to all changes in this revision

Viewing changes to www/media/browser/browser.js

  • Committer: mattgiuca
  • Date: 2008-02-28 06:49:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:603
Console now starts up in the user's home directory.
scripts/python-console: Now accepts an optional argument <working-dir>.
    If supplied, it will chdir into that dir before launching the console.
consoleservice: Now passes working-dir as an argument - this is the user's
    home directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
157
157
 * Called "navigate", can also be used for a simple refresh.
158
158
 * Always makes a GET request.
159
159
 * No return value.
160
 
 * \param editmode Optional boolean. If true, then the user navigated here
161
 
 * with an "edit" URL so we should favour using the editor.
162
160
 */
163
 
function navigate(path, editmode)
 
161
function navigate(path)
164
162
{
165
163
    callback = function(response)
166
164
        {
283
281
    /* Treat this as an ordinary file. Get the file type. */
284
282
    var content_type = response.getResponseHeader("Content-Type");
285
283
    var handler_type = get_handler_type(content_type);
286
 
    /* If we're in "edit mode", always treat this file as text */
287
284
    would_be_handler_type = handler_type;
288
285
    /* handler_type should now be set to either
289
286
     * "text", "image", "audio" or "binary". */
329
326
    dom_removechildren(document.getElementById("sidepanel"));
330
327
}
331
328
 
332
 
/** Sets the mode to either "file browser" or "text editor" mode.
333
 
 * This modifies the window icon, and selected tab.
334
 
 * \param editmode If True, editor mode. Else, file browser mode.
335
 
 */
336
 
function setmode(editmode)
337
 
{
338
 
    /* Find the DOM elements for the file browser and editor tabs */
339
 
    var tabs = document.getElementById("apptabs");
340
 
    var tab_files = null;
341
 
    var tab_edit = null;
342
 
    var a;
343
 
    var href;
344
 
    for (var i=0; i<tabs.childNodes.length; i++)
345
 
    {
346
 
        /* Find the href of the link within */
347
 
        if (!tabs.childNodes[i].getElementsByTagName) continue;
348
 
        a = tabs.childNodes[i].getElementsByTagName("a");
349
 
        if (a.length == 0) continue;
350
 
        href = a[0].getAttribute("href");
351
 
        if (href == null) continue;
352
 
        if (endswith(href, this_app))
353
 
            tab_files = tabs.childNodes[i];
354
 
        else if (endswith(href, edit_app))
355
 
            tab_edit = tabs.childNodes[i];
356
 
    }
357
 
 
358
 
    if (editmode)
359
 
    {
360
 
        tab_files.removeAttribute("class");
361
 
        tab_edit.setAttribute("class", "thisapp");
362
 
    }
363
 
    else
364
 
    {
365
 
        tab_edit.removeAttribute("class");
366
 
        tab_files.setAttribute("class", "thisapp");
367
 
    }
368
 
}
369
 
 
370
329
/*** HANDLERS for different types of responses (such as dir listing, file,
371
330
 * etc). */
372
331
 
373
332
function handle_error(message)
374
333
{
375
 
    setmode(false);
376
334
    var files = document.getElementById("filesbody");
377
335
    var txt_elem = dom_make_text_elem("div", "Error: "
378
336
        + message.toString() + ".")
429
387
 */
430
388
function handle_binary(path)
431
389
{
432
 
    setmode(false);
433
390
    var files = document.getElementById("filesbody");
434
391
    var div = document.createElement("div");
435
392
    files.appendChild(div);
689
646
        var handler_type = null;
690
647
        if ("type" in file)
691
648
            handler_type = get_handler_type(file.type);
692
 
        /* Action: Use the "files" / "edit" app */
 
649
        /* Action: Use the "files" app */
693
650
        var path;
694
651
        if (selected_files.length == 1)
695
652
        {
700
657
                    app_path(this_app, current_path, filename));
701
658
            else if (handler_type == "text")
702
659
                p = dom_make_link_elem("p", "Edit", "Edit this file",
703
 
                    app_path(edit_app, current_path, filename));
 
660
                    app_path(this_app, current_path, filename));
704
661
            else
705
662
                p = dom_make_link_elem("p", "Browse",
706
663
                    "View this file in the file browser",
914
871
    var path = parse_url(window.location.href).path;
915
872
    /* Strip out root_dir + "/files" from the front of the path */
916
873
    var strip = make_path(this_app);
917
 
    var editmode = false;
918
874
    if (path.substr(0, strip.length) == strip)
919
875
        path = path.substr(strip.length+1);
920
876
    else
924
880
        if (path.substr(0, strip.length) == strip)
925
881
        {
926
882
            path = path.substr(strip.length+1);
927
 
            editmode = true;
928
883
        }
929
884
    }
930
885
 
935
890
        path = username;
936
891
    }
937
892
 
938
 
    navigate(path, editmode);
 
893
    navigate(path);
939
894
}