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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2008-07-07 12:01:03 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:820
lib: Added new package pulldown_subj, a collection of modules designed to
    pull student subject enrolments from the server.
    Note that the actual code to do this is not included (since that is
    specific to the organisation running IVLE) - just a pluggable interface
    and an example plugin module.
configure.py: Added new config option: subject_pulldown_modules, which allows
    you to specify which modules are plugged in here.
    (Actually that was added accidentally in a previous commit; but this
    revision fixes some comments).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
saved_status = null;
 
1
function disable_save_if_safe()
 
2
{
 
3
    /* If this is defined, this engine supports change notification, so is able
 
4
     * to enable the button again. Disable it for them. */
 
5
    if(editbox.editor.addChangeHandler)
 
6
    {
 
7
        var savebutton = document.getElementById("save_button");
 
8
        savebutton.disabled = true;
 
9
    }
 
10
}
2
11
 
3
12
function save_file()
4
13
{
5
 
    filename = document.getElementById("save_filename").value;
6
 
    data = editAreaLoader.getValue("editbox");
 
14
    var filename = document.getElementById("save_filename").value;
 
15
    data = editbox.getCode();
7
16
    /* Do NOT refresh the page contents (causes problems for editarea and is
8
17
     * unnecessary). */
9
 
    do_action("putfile", filename, {"path":".", "data":data}, null, true);
10
 
    saved_status.data = "Saved.";
 
18
    do_action("putfile", filename,
 
19
              {"path":".", "data":data, "overwrite":"true"},
 
20
              "multipart/form-data", true);
 
21
    disable_save_if_safe();
11
22
}
12
23
 
13
24
function edit_text()
14
25
{
15
 
    saved_status.data = "Not saved.";
 
26
    var savebutton = document.getElementById("save_button");
 
27
    savebutton.disabled = false;
16
28
}
17
29
 
18
 
/** Presents the "editor heading" (the part with the save box)
19
 
 * inserting it into a given element at the front.
 
30
/** Presents the "editor heading" inserting it into a given element at
 
31
 *  the front. Note that the save widget is handled by the Python.
20
32
 */
21
33
function present_editorhead(elem, path, handler_type)
22
34
{
23
 
    var div = document.createElement("div");
24
 
    /* Insert as the head element */
25
 
    elem.insertBefore(div, elem.firstChild)
26
 
    div.setAttribute("id", "editorhead");
27
 
 
28
 
    /* Set up minimal interface */
29
 
    var p = dom_make_text_elem("p", "Path: ");
30
 
    var pathname = document.createElement("input");
31
 
    pathname.setAttribute("type", "text");
32
 
    pathname.setAttribute("size", "30");
33
 
    pathname.setAttribute("id", "save_filename");
34
 
    pathname.setAttribute("value", path);
35
 
    p.appendChild(pathname);
36
 
    var savebutton = document.createElement("input");
37
 
    savebutton.setAttribute("type", "button");
38
 
    savebutton.setAttribute("value", "Save");
39
 
    savebutton.setAttribute("onclick", "save_file()");
40
 
    p.appendChild(savebutton);
41
 
    var t = document.createTextNode(" ");
42
 
    p.appendChild(t);
43
 
    saved_status = document.createTextNode("Saved.");
44
 
    //p.appendChild(saved_status);
45
 
    div.appendChild(p);
 
35
    var div = document.getElementById("actions2");
46
36
 
47
37
    /* Print a warning message if this is not actually a text file.
48
38
     */
68
58
    present_editorhead(files, path, handler_type);
69
59
 
70
60
    var div = document.createElement("div");
 
61
    div.style.height = '100%';
71
62
    files.appendChild(div);
72
63
    var txt_elem = dom_make_text_elem("textarea",
73
64
        text.toString())
74
65
    div.appendChild(txt_elem);
75
66
    txt_elem.setAttribute("id", "editbox");
 
67
    language = language_from_mime(current_file.type)
 
68
 
 
69
    // Assume plaintext if no type can be determined.
 
70
    txt_elem.className = "codepress " + (language ? language : 'text');
76
71
    txt_elem.setAttribute("onchange", "edit_text()");
77
72
    /* TODO: Make CSS height: 100% work */
78
73
    txt_elem.setAttribute("rows", "35");
79
 
 
80
 
    /* Load EditArea into the editbox */
81
 
    editAreaLoader.init({
82
 
        id : "editbox",
83
 
        syntax: "python",
84
 
        toolbar: "search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, highlight, |, help",
85
 
        start_highlight: true,
86
 
        allow_toggle: false,
87
 
        allow_resize: false,
88
 
        replace_tab_by_spaces: 4
89
 
    });
90
 
}
91
 
 
 
74
    CodePress.run();
 
75
 
 
76
    /* And set a callback so we know that the editor iframe is loaded so we
 
77
     * can set a callback so we know when to enable the save button.
 
78
     * We also take this opportunity to disable the save button, if
 
79
     * the browser is likely to reenable it as needed. */
 
80
    editbox.onload = function() {editbox.addChangeHandler(edit_text);
 
81
                                 disable_save_if_safe(); };
 
82
}
 
83
 
 
84
function language_from_mime(mime)
 
85
{
 
86
    return {'text/x-python': 'python',
 
87
            'application/javascript': 'javascript',
 
88
            'text/css': 'css',
 
89
            'text/plain': 'text',
 
90
            'text/html': 'html',
 
91
            'application/xhtml+xml': 'html'}[mime];
 
92
}