58
58
window.onbeforeunload = confirm_beforeunload;
61
/** Presents the "editor heading" inserting it into a given element at
62
* the front. Note that the save widget is handled by the Python.
64
function present_editorhead(elem, path, handler_type)
66
var div = document.getElementById("actions2");
68
/* Print a warning message if this is not actually a text file.
70
if (handler_type != "text")
72
var warn = dom_make_text_elem("p",
73
"Warning: You are editing a binary " +
74
"file, which explains any strange characters you may see. If " +
75
"you save this file, you could corrupt it.");
76
div.appendChild(warn);
80
61
function highlighting_changed(select)
82
63
codemirror_language(select.value);
85
66
/** Presents the text editor.
87
function handle_text(path, text, handler_type)
68
function handle_text(path, content_type, url_args)
70
/* Need to make a 2nd ajax call, this time get the actual file
72
callback = function(response)
74
/* Read the response and set up the page accordingly */
75
handle_text_response(path, content_type, response.responseText);
77
/* Call the server and request the listing. */
79
args = shallow_clone_object(url_args);
82
/* This time, get the contents of the file, not its metadata */
83
args['return'] = "contents";
84
ajax_call(callback, service_app, path, args, "GET");
87
function handle_text_response(path, content_type, response_text)
89
89
/* Create a textarea with the text in it
90
90
* (The makings of a primitive editor).
92
92
var files = document.getElementById("filesbody");
93
/* Put our UI at the top */
94
present_editorhead(files, path, handler_type);
96
94
var div = document.createElement("div");
97
95
div.style.height = '100%';
98
96
files.appendChild(div);
99
97
var txt_elem = document.createElement("textarea");
100
txt_elem.value = text.toString();
98
txt_elem.value = response_text.toString();
101
99
div.appendChild(txt_elem);
102
100
txt_elem.setAttribute("id", "editbox");
103
language = language_from_mime(current_file.type);
101
language = language_from_mime(content_type);
105
103
// Assume plaintext if no type can be determined.
106
104
language = language ? language : "text";