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

« back to all changes in this revision

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

  • Committer: wagrant
  • Date: 2008-12-20 03:46:56 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1060
Make IVLE work fine in Firefox 3.1 (ie. Gecko/XULRunner 1.9.1). Gecko 1.9.1 has
a built-in JSON object, so our json2.js isn't used, and compatibility problems
arise. The only one significant to us is that Gecko's doesn't support having
a primitive as the root object. Unfortunately we use that sort of thing in a
few places, so IVLE ends up pretty much broken.

A few adjustments were needed both client- and server-side for proto changes:

 - consoleservice and the JS interacting with it now deal with the key returned
   by start_server in a dict like {'key': ...}.
 - tutorialservice and interacting JS deal with code returned by getattempt in
   a dict like {'code': ...}.


The JS repr() implementation used JSON.stringify on the given object, and was
used only with primitive objects in order to create function calls. This needed
to be eliminated for compatibility with the new Gecko, so these call
constructions were replaced with better events:

 - listing.js constructed events for generated file listings by repr()ing some
   strings. That is foul, so we instead use DOM operations from 'this' in a
   somewhat nicer event handler.
 - tutorial.js previously created save_exercise() call strings by repr()ing
   lots of stuff. That was really bad, and broke like the rest. I replaced it
   with something that's still bad, but not quite as awful - grabbing the call
   string from the save button. This should be fixed at some point.
 - console.js had some strange Firebug logging stuff which used repr(). I
   removed it, as it shouldn't have been in released code in the first place.

repr() itself was removed after all references were.
   

Show diffs side-by-side

added added

removed removed

Lines of Context:
533
533
 
534
534
/** END SORTING **/
535
535
 
536
 
/** Clears all selected files and causes the single file specified to become
537
 
 * selected.
538
 
 * \param filename The file in the list to select.
539
 
 */
540
 
function select_file(filename)
541
 
{
542
 
    var files_children = document.getElementById("files").childNodes;
543
 
    var checkbox;
544
 
    var tr;
545
 
    for (var i=0; i<files_children.length; i++)
546
 
    {
547
 
        tr = files_children[i];
548
 
        checkbox = tr.firstChild.firstChild;
549
 
        checkbox.checked = tr.filename == filename;
550
 
    }
551
 
    update_selection();
552
 
}
553
 
 
554
536
/** Initialises the DOM elements required to present files window,
555
537
 * assuming that clear_page has just been called or the page just
556
538
 * loaded for the first time.
652
634
    var td;
653
635
    var checkbox;
654
636
 
655
 
    var selection_string;
656
 
 
657
637
    /* Convert selected_files array into a dictionary which can be efficiently
658
638
     * searched. */
659
639
    sel_files_dict = {};
665
645
    /* Create all of the files */
666
646
    for (var filename in listing)
667
647
    {
668
 
        selection_string = "select_file(" + repr(filename) + ")";
 
648
        select_row = function() {
 
649
            var files_children = document.getElementById("files").childNodes;
 
650
            var checkbox;
 
651
            var tr;
 
652
            for (var i=0; i<files_children.length; i++)
 
653
            {
 
654
                tr = files_children[i];
 
655
                checkbox = tr.firstChild.firstChild;
 
656
                checkbox.checked = tr == this.parentNode;
 
657
            }
 
658
            update_selection();
 
659
        }
 
660
 
669
661
        file = listing[filename];
670
662
        /* Make a 'tr' element. Store the filename and fileinfo in
671
663
         * here. */
689
681
        /* Column 2: Filetype and subversion icons. */
690
682
        td = document.createElement("td");
691
683
        td.setAttribute("class", "thincol");
692
 
        td.setAttribute("onclick", selection_string);
 
684
        td.addEventListener("click", select_row, false);
693
685
        /* Directories don't really have a MIME type, so we fake one. */
694
686
        if (file.isdir) file.type = "text/directory";
695
687
        td.appendChild(dom_make_img(mime_type_to_icon(file.type),
718
710
        {
719
711
            td = dom_make_text_elem("td", filename);
720
712
        }
721
 
        td.setAttribute("onclick", selection_string);
 
713
        td.addEventListener("click", select_row, false);
722
714
        row.appendChild(td);
723
715
 
724
716
        /* Column 4: Size */
725
717
        td = dom_make_text_elem("td", nice_filesize(file.size));
726
 
        td.setAttribute("onclick", selection_string);
 
718
        td.addEventListener("click", select_row, false);
727
719
        row.appendChild(td);
728
720
 
729
721
        /* Column 5: Date */
730
722
        td = dom_make_text_elem("td", file.mtime_short, file.mtime_nice);
731
 
        td.setAttribute("onclick", selection_string);
 
723
        td.addEventListener("click", select_row, false);
732
724
        row.appendChild(td);
733
725
        files.appendChild(row);
734
726
    }