65
65
window.onbeforeunload = confirm_beforeunload;
68
/** Presents the "editor heading" inserting it into a given element at
69
* the front. Note that the save widget is handled by the Python.
71
function present_editorhead(elem, path, handler_type)
73
var div = document.getElementById("actions2");
75
/* Print a warning message if this is not actually a text file.
77
if (handler_type != "text")
79
var warn = dom_make_text_elem("p",
80
"Warning: You are editing a binary " +
81
"file, which explains any strange characters you may see. If " +
82
"you save this file, you could corrupt it.");
83
div.appendChild(warn);
87
68
function highlighting_changed(select)
89
70
editbox.edit(editbox.getCode(), select.value);
108
89
/** Presents the text editor.
110
function handle_text(path, text, handler_type)
91
function handle_text(path, content_type, url_args)
93
/* Need to make a 2nd ajax call, this time get the actual file
95
callback = function(response)
97
/* Read the response and set up the page accordingly */
98
handle_text_response(path, content_type, response.responseText);
100
/* Call the server and request the listing. */
102
args = shallow_clone_object(url_args);
105
/* This time, get the contents of the file, not its metadata */
106
args['return'] = "contents";
107
ajax_call(callback, service_app, path, args, "GET");
110
function handle_text_response(path, content_type, response_text)
112
112
/* Create a textarea with the text in it
113
113
* (The makings of a primitive editor).
115
115
var files = document.getElementById("filesbody");
116
/* Put our UI at the top */
117
present_editorhead(files, path, handler_type);
119
117
var div = document.createElement("div");
120
118
div.style.height = '100%';
121
119
files.appendChild(div);
122
120
var txt_elem = document.createElement("textarea");
123
txt_elem.value = text.toString();
121
txt_elem.value = response_text.toString();
124
122
div.appendChild(txt_elem);
125
123
txt_elem.setAttribute("id", "editbox");
126
language = language_from_mime(current_file.type);
124
language = language_from_mime(content_type);
128
126
// Assume plaintext if no type can be determined.
129
127
language = language ? language : "text";