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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2008-07-07 01:45:11 UTC
  • mfrom: (unknown (missing))
  • Revision ID: wgrant@ugrad.unimelb.edu.au-20080707014511-xyy43p6y8jiqrsh9
Merge killall-editarea branch. We now use CodePress instead, which is
somewhat less slothful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}
 
11
 
1
12
function save_file()
2
13
{
3
 
    var savebutton = document.getElementById("save_button");
4
14
    var filename = document.getElementById("save_filename").value;
5
 
    data = editAreaLoader.getValue("editbox");
 
15
    data = editbox.getCode();
6
16
    /* Do NOT refresh the page contents (causes problems for editarea and is
7
17
     * unnecessary). */
8
18
    do_action("putfile", filename,
9
19
              {"path":".", "data":data, "overwrite":"true"},
10
20
              "multipart/form-data", true);
11
 
    savebutton.setAttribute("value", "Saved");
12
 
    // XXX Do not disable for now; there is a problem getting the callback
13
 
    // to edit_text.
14
 
    //savebutton.setAttribute("disabled", "disabled");
 
21
    disable_save_if_safe();
15
22
}
16
23
 
17
24
function edit_text()
18
25
{
19
26
    var savebutton = document.getElementById("save_button");
20
 
    savebutton.setAttribute("value", "Save");
21
 
    savebutton.removeAttribute("disabled");
 
27
    savebutton.disabled = false;
22
28
}
23
29
 
24
30
/** Presents the "editor heading" inserting it into a given element at
52
58
    present_editorhead(files, path, handler_type);
53
59
 
54
60
    var div = document.createElement("div");
 
61
    div.style.height = '100%';
55
62
    files.appendChild(div);
56
63
    var txt_elem = dom_make_text_elem("textarea",
57
64
        text.toString())
58
65
    div.appendChild(txt_elem);
59
66
    txt_elem.setAttribute("id", "editbox");
 
67
    txt_elem.className = "codepress python";
60
68
    txt_elem.setAttribute("onchange", "edit_text()");
61
69
    /* TODO: Make CSS height: 100% work */
62
70
    txt_elem.setAttribute("rows", "35");
 
71
    CodePress.run();
63
72
 
64
 
    /* Load EditArea into the editbox */
65
 
    editAreaLoader.init({
66
 
        id : "editbox",
67
 
        syntax: "python",
68
 
        toolbar: "search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, highlight, |, help",
69
 
        start_highlight: true,
70
 
        allow_toggle: false,
71
 
        allow_resize: false,
72
 
        replace_tab_by_spaces: 4,
73
 
        change_callback: "edit_text"
74
 
    });
 
73
    /* And set a callback so we know that the editor iframe is loaded so we
 
74
     * can set a callback so we know when to enable the save button.
 
75
     * We also take this opportunity to disable the save button, if
 
76
     * the browser is likely to reenable it as needed. */
 
77
    editbox.onload = function() {editbox.addChangeHandler(edit_text);
 
78
                                 disable_save_if_safe(); };
75
79
}
76
80