116
117
* Called "navigate", can also be used for a simple refresh.
117
118
* Always makes a GET request.
118
119
* No return value.
120
* \param editmode Optional boolean. If true, then the user navigated here
121
* with an "edit" URL so we should favour using the editor.
120
function navigate(path)
123
function navigate(path, editmode)
122
125
/* Call the server and request the listing. This mutates the server. */
123
126
response = ajax_call(service_app, path, null, "GET");
124
127
/* Now read the response and set up the page accordingly */
125
handle_response(path, response);
128
handle_response(path, response, editmode);
128
131
/** Given an HTTP response object, cleans up and rebuilds the contents of the
135
138
* things) be used to update the URL in the location bar.
136
139
* \param response XMLHttpRequest object returned by the server. Should
137
140
* contain all the response data.
141
* \param editmode Optional boolean. If true, then the user navigated here
142
* with an "edit" URL so we should favour using the editor.
139
function handle_response(path, response)
144
function handle_response(path, response, editmode)
141
146
/* TODO: Set location bar to "path" */
143
149
/* Clear away the existing page contents */
186
192
handler_type != "audio")
187
193
handler_type = "binary";
195
/* If we're in "edit mode", always treat this file as text */
196
would_be_handler_type = handler_type;
197
if (editmode) handler_type = "text";
189
198
/* handler_type should now be set to either
190
199
* "text", "image", "audio" or "binary". */
191
200
switch (handler_type)
194
handle_text(path, response.responseText);
203
handle_text(path, response.responseText, would_be_handler_type);
197
206
/* TODO: Custom image handler */
231
240
dom_removechildren(document.getElementById("sidepanel"));
243
/** Sets the mode to either "file browser" or "text editor" mode.
244
* This modifies the window icon, and selected tab.
245
* \param editmode If True, editor mode. Else, file browser mode.
247
function setmode(editmode)
249
/* Find the DOM elements for the file browser and editor tabs */
250
var tabs = document.getElementById("apptabs");
251
var tab_files = null;
255
for (var i=0; i<tabs.childNodes.length; i++)
257
/* Find the href of the link within */
258
if (!tabs.childNodes[i].getElementsByTagName) continue;
259
a = tabs.childNodes[i].getElementsByTagName("a");
260
if (a.length == 0) continue;
261
href = a[0].getAttribute("href");
262
if (href == null) continue;
263
if (endswith(href, this_app))
264
tab_files = tabs.childNodes[i];
265
else if (endswith(href, edit_app))
266
tab_edit = tabs.childNodes[i];
271
tab_files.removeAttribute("class");
272
tab_edit.setAttribute("class", "thisapp");
276
tab_edit.removeAttribute("class");
277
tab_files.setAttribute("class", "thisapp");
281
function settitle(path)
283
document.title = path_basename(path) + " - IVLE";
234
286
/*** HANDLERS for different types of responses (such as dir listing, file,
237
289
function handle_error(message)
239
292
var files = document.getElementById("filesbody");
240
293
var txt_elem = dom_make_text_elem("div", "Error: "
241
294
+ message.toString() + ".")
466
520
/** Presents the text editor.
468
function handle_text(path, text)
522
function handle_text(path, text, handler_type)
470
524
/* Create a textarea with the text in it
471
525
* (The makings of a primitive editor).
473
529
var files = document.getElementById("filesbody");
474
530
var div = document.createElement("div");
475
531
files.appendChild(div);
476
532
div.setAttribute("class", "padding");
533
/* First, print a warning message if this is not actually a text file.
535
if (handler_type != "text")
537
var warn = dom_make_text_elem("p",
538
"Warning: You are editing a binary " +
539
"file, which explains any strange characters you may see. If " +
540
"you save this file, you could corrupt it.");
541
div.appendChild(warn);
477
543
var txt_elem = dom_make_text_elem("textarea",
479
545
div.appendChild(txt_elem);
512
578
var path = parse_url(window.location.href).path;
513
579
/* Strip out root_dir + "/files" from the front of the path */
514
strip_chars = make_path(this_app).length + 1;
515
path = path.substr(strip_chars);
580
var strip = make_path(this_app);
581
var editmode = false;
582
if (path.substr(0, strip.length) == strip)
583
path = path.substr(strip.length+1);
586
/* See if this is an edit path */
587
strip = make_path(edit_app);
588
if (path.substr(0, strip.length) == strip)
590
path = path.substr(strip.length+1);
517
595
if (path.length == 0)