1
function disable_save_if_safe()
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)
7
var savebutton = document.getElementById("save_button");
8
savebutton.disabled = true;
1
12
function save_file()
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
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
14
//savebutton.setAttribute("disabled", "disabled");
21
disable_save_if_safe();
17
24
function edit_text()
19
26
var savebutton = document.getElementById("save_button");
20
savebutton.setAttribute("value", "Save");
21
savebutton.removeAttribute("disabled");
27
savebutton.disabled = false;
24
30
/** Presents the "editor heading" inserting it into a given element at
52
58
present_editorhead(files, path, handler_type);
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",
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");
64
/* Load EditArea into the editbox */
68
toolbar: "search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, highlight, |, help",
69
start_highlight: true,
72
replace_tab_by_spaces: 4,
73
change_callback: "edit_text"
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(); };