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;
14
var filename = document.getElementById("save_filename").value;
15
data = editbox.getCode();
16
/* Do NOT refresh the page contents (causes problems for editarea and is
18
do_action("putfile", filename,
19
{"path":".", "data":data, "overwrite":"true"},
20
"multipart/form-data", true);
21
disable_save_if_safe();
26
var savebutton = document.getElementById("save_button");
27
savebutton.disabled = false;
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.
33
function present_editorhead(elem, path, handler_type)
35
var div = document.getElementById("actions2");
37
/* Print a warning message if this is not actually a text file.
39
if (handler_type != "text")
41
var warn = dom_make_text_elem("p",
42
"Warning: You are editing a binary " +
43
"file, which explains any strange characters you may see. If " +
44
"you save this file, you could corrupt it.");
45
div.appendChild(warn);
49
/** Presents the text editor.
51
function handle_text(path, text, handler_type)
53
/* Create a textarea with the text in it
54
* (The makings of a primitive editor).
56
var files = document.getElementById("filesbody");
57
/* Put our UI at the top */
58
present_editorhead(files, path, handler_type);
60
var div = document.createElement("div");
61
div.style.height = '100%';
62
files.appendChild(div);
63
var txt_elem = dom_make_text_elem("textarea",
65
div.appendChild(txt_elem);
66
txt_elem.setAttribute("id", "editbox");
67
language = language_from_mime(current_file.type)
69
// Assume plaintext if no type can be determined.
70
txt_elem.className = "codepress " + (language ? language : 'text');
71
txt_elem.setAttribute("onchange", "edit_text()");
72
/* TODO: Make CSS height: 100% work */
73
txt_elem.setAttribute("rows", "35");
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(); };
84
function language_from_mime(mime)
86
return {'text/x-python': 'python',
87
'application/javascript': 'javascript',
91
'application/xhtml+xml': 'html'}[mime];