~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-01-12 16:13:31 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:203
browser: Removed all directory-listing specific HTML from the Python-generated
    html. This can't be static because different handlers need different
    content inside the page body (eg. binary files don't use a table).
    The JavaScript now clears a lot more of the page and rebuilds the entire
    directory listing table dynamically.

Show diffs side-by-side

added added

removed removed

Lines of Context:
212
212
 */
213
213
function clearpage()
214
214
{
215
 
    /* Note: For now clear just enough to repopulate with a dir listing.
216
 
     * Later, will have to clear more to make way for other handlers.
217
 
     * Possibly have a "full clear" for all handlers, and special
218
 
     * less-violent clearers for each handler if the same handler is going to
219
 
     * be used that was used last time. */
 
215
    dom_removechildren(document.getElementById("path"));
 
216
    dom_removechildren(document.getElementById("filesbody"));
 
217
}
 
218
 
 
219
/** Deletes all "dynamic" content on the page necessary to navigate from
 
220
 * one directory listing to another (does not clear as much as clearpage
 
221
 * does).
 
222
 * This is the equivalent of calling clearpage() then
 
223
 * setup_for_dir_listing(), assuming the page is already on a dir listing.
 
224
 */
 
225
function clearpage_dir()
 
226
{
220
227
    dom_removechildren(document.getElementById("path"));
221
228
    dom_removechildren(document.getElementById("files"));
222
229
    dom_removechildren(document.getElementById("sidepanel"));
303
310
    return make_path(path_join(svn_icons_path, filename));
304
311
}
305
312
 
 
313
/** Initialises the DOM elements required to present a dir listing,
 
314
 * assuming that clear_page has just been called or the page just
 
315
 * loaded for the first time.
 
316
 */
 
317
function setup_for_dir_listing()
 
318
{
 
319
    var filesbody = document.getElementById("filesbody");
 
320
 
 
321
    /* Using a table-based layout, for reasons of sanity */
 
322
    /* One row, 2 columns */
 
323
    var middle = document.createElement("table");
 
324
    filesbody.appendChild(middle);
 
325
    middle.setAttribute("id", "middle");
 
326
    var middle_tbody = document.createElement("tbody");
 
327
    middle.appendChild(middle_tbody);
 
328
    var middle_tr = document.createElement("tr");
 
329
    middle_tbody.appendChild(middle_tr);
 
330
 
 
331
    /* Column 1: File table */
 
332
    var filetable = document.createElement("td");
 
333
    middle_tr.appendChild(filetable);
 
334
    filetable.setAttribute("id", "filetable");
 
335
    var filetablediv = document.createElement("div");
 
336
    filetable.appendChild(filetablediv);
 
337
    filetablediv.setAttribute("id", "filetablediv");
 
338
    /* A nested table within this div - the actual files listing */
 
339
    var filetabletable = document.createElement("table");
 
340
    filetablediv.appendChild(filetabletable);
 
341
    filetabletable.setAttribute("width", "100%");
 
342
    var filetablethead = document.createElement("thead");
 
343
    filetabletable.appendChild(filetablethead);
 
344
    var filetablethead_tr = document.createElement("tr");
 
345
    filetablethead.appendChild(filetablethead_tr);
 
346
    filetablethead_tr.setAttribute("class", "rowhead");
 
347
    /* Row headers */
 
348
    var filetablethead_th = document.createElement("th");
 
349
    filetablethead_tr.appendChild(filetablethead_th);
 
350
    filetablethead_th.setAttribute("class", "col-check");
 
351
    filetablethead_th = dom_make_link_elem("th", "Filename",
 
352
        "Sort by filename", "")
 
353
    filetablethead_tr.appendChild(filetablethead_th);
 
354
    filetablethead_th.setAttribute("class", "col-filename");
 
355
    filetablethead_th.setAttribute("colspan", 3);
 
356
    filetablethead_th = dom_make_link_elem("th", "Size",
 
357
        "Sort by file size", "")
 
358
    filetablethead_tr.appendChild(filetablethead_th);
 
359
    filetablethead_th.setAttribute("class", "col-size");
 
360
    filetablethead_th = dom_make_link_elem("th", "Modified",
 
361
        "Sort by date modified", "")
 
362
    filetablethead_tr.appendChild(filetablethead_th);
 
363
    filetablethead_th.setAttribute("class", "col-date");
 
364
    /* Empty body */
 
365
    var filetabletbody = document.createElement("tbody");
 
366
    filetabletable.appendChild(filetabletbody);
 
367
    filetabletbody.setAttribute("id", "files");
 
368
 
 
369
    /* Column 2: Side-panel */
 
370
    var sidepanel = document.createElement("td");
 
371
    middle_tr.appendChild(sidepanel);
 
372
    sidepanel.setAttribute("id", "sidepanel");
 
373
 
 
374
 
 
375
    /* Now after the table "middle", there is a status bar */
 
376
    var statusbar = dom_make_text_elem("div", "5 files, 14 kB");
 
377
    filesbody.appendChild(statusbar);
 
378
    statusbar.setAttribute("id", "statusbar");
 
379
}
 
380
 
306
381
/** Presents the directory listing.
307
382
 */
308
383
function handle_dir_listing(path, listing)
309
384
{
 
385
    setup_for_dir_listing();
310
386
    var row_toggle = 1;
311
387
    /* Nav through the top-level of the JSON to the actual listing object. */
312
388
    var listing = listing.listing;