~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-11 09:11:07 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:190
util: Added function dom_make_img, creates <img> elements.
browser: Now displays icons for file types and svn status.
         Added lots of constants at the top which can be configured to display
        icons as necessary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    "application/xml" : "text",
44
44
};
45
45
 
 
46
/* Mapping MIME types to icons, just the file's basename */
 
47
type_icons = {
 
48
    "text/directory": "dir.png",
 
49
    "text/x-python": "py.png",
 
50
};
 
51
 
 
52
default_type_icon = "txt.png";
 
53
 
 
54
/* Relative to IVLE root */
 
55
type_icons_path = "media/images/mime";
 
56
type_icons_path_large = "media/images/mime/large";
 
57
 
 
58
/* Mapping SVN status to icons, just the file's basename */
 
59
svn_icons = {
 
60
    "unversioned": "unversioned.png",
 
61
    "normal": "normal.png",
 
62
    "modified": "modified.png",
 
63
};
 
64
 
 
65
default_svn_icon = "normal.png";
 
66
 
 
67
svn_icons_path = "media/images/svn";
 
68
 
46
69
/* List of MIME types considered "executable" by the system.
47
70
 * Executable files offer a "run" link, implying that the "serve"
48
71
 * application can interpret them.
246
269
    }
247
270
}
248
271
 
 
272
/** Given a mime type, returns the path to the icon.
 
273
 * \param type String, Mime type.
 
274
 * \param sizelarge Boolean, optional.
 
275
 * \return Path to the icon. Has applied make_path, so it is relative to site
 
276
 * root.
 
277
 */
 
278
function mime_type_to_icon(type, sizelarge)
 
279
{
 
280
    var filename;
 
281
    if (type in type_icons)
 
282
        filename = type_icons[type];
 
283
    else
 
284
        filename = default_type_icon;
 
285
    if (sizelarge)
 
286
        return make_path(path_join(type_icons_path_large, filename));
 
287
    else
 
288
        return make_path(path_join(type_icons_path, filename));
 
289
}
 
290
 
 
291
/** Given an svnstatus, returns the path to the icon.
 
292
 * \param type String, svn status.
 
293
 * \return Path to the icon. Has applied make_path, so it is relative to site
 
294
 * root.
 
295
 */
 
296
function svnstatus_to_icon(svnstatus)
 
297
{
 
298
    var filename;
 
299
    if (svnstatus in svn_icons)
 
300
        filename = svn_icons[svnstatus];
 
301
    else
 
302
        filename = default_svn_icon;
 
303
    return make_path(path_join(svn_icons_path, filename));
 
304
}
 
305
 
249
306
/** Presents the directory listing.
250
307
 */
251
308
function handle_dir_listing(path, listing)
286
343
            /* Column 2: Filetype and subversion icons. */
287
344
            td = document.createElement("td");
288
345
            td.setAttribute("class", "thincol");
289
 
            td.appendChild(document.createTextNode("dir"));
 
346
            td.appendChild(dom_make_img(mime_type_to_icon("text/directory"),
 
347
                22, 22, file.type));
290
348
            row.appendChild(td);
291
349
            td = document.createElement("td");
292
350
            td.setAttribute("class", "thincol");
293
351
            if (under_subversion)
294
 
                td.appendChild(document.createTextNode(file.svnstatus));
 
352
                td.appendChild(dom_make_img(svnstatus_to_icon(file.svnstatus),
 
353
                    22, 22, file.svnstatus));
295
354
            row.appendChild(td);
296
355
            /* Column 3: Filename */
297
356
            row.appendChild(dom_make_link_elem("td", filename,
303
362
            /* Column 2: Filetype and subversion icons. */
304
363
            td = document.createElement("td");
305
364
            td.setAttribute("class", "thincol");
306
 
            td.appendChild(document.createTextNode(file.type));
 
365
            td.appendChild(dom_make_img(mime_type_to_icon(file.type),
 
366
                22, 22, file.type));
307
367
            row.appendChild(td);
308
368
            td = document.createElement("td");
309
369
            td.setAttribute("class", "thincol");
310
370
            if (under_subversion)
311
 
                td.appendChild(document.createTextNode(file.svnstatus));
 
371
                td.appendChild(dom_make_img(svnstatus_to_icon(file.svnstatus),
 
372
                    22, 22, file.svnstatus));
312
373
            row.appendChild(td);
313
374
            /* Column 3: Filename */
314
375
            row.appendChild(dom_make_text_elem("td", filename));