221
by mattgiuca
editor: Made saving work. |
1 |
saved_status = null; |
2 |
||
3 |
function save_file() |
|
4 |
{
|
|
5 |
filename = document.getElementById("save_filename").value; |
|
233
by mattgiuca
Added a shaky implementation of EditArea as the text editor. |
6 |
data = editAreaLoader.getValue("editbox"); |
385
by mattgiuca
browser/editor: Clicking "Save" in the editor does not cause a page refresh |
7 |
/* Do NOT refresh the page contents (causes problems for editarea and is
|
8 |
* unnecessary). */
|
|
9 |
do_action("putfile", filename, {"path":".", "data":data}, null, true); |
|
221
by mattgiuca
editor: Made saving work. |
10 |
saved_status.data = "Saved."; |
11 |
}
|
|
12 |
||
13 |
function edit_text() |
|
14 |
{
|
|
15 |
saved_status.data = "Not saved."; |
|
16 |
}
|
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
17 |
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
18 |
/** Presents the "editor heading" (the part with the save box)
|
19 |
* inserting it into a given element at the front.
|
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
20 |
*/
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
21 |
function present_editorhead(elem, path, handler_type) |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
22 |
{
|
23 |
var div = document.createElement("div"); |
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
24 |
/* Insert as the head element */
|
25 |
elem.insertBefore(div, elem.firstChild) |
|
26 |
div.setAttribute("id", "editorhead"); |
|
221
by mattgiuca
editor: Made saving work. |
27 |
|
28 |
/* Set up minimal interface */
|
|
29 |
var p = dom_make_text_elem("p", "Path: "); |
|
30 |
var pathname = document.createElement("input"); |
|
31 |
pathname.setAttribute("type", "text"); |
|
32 |
pathname.setAttribute("size", "30"); |
|
33 |
pathname.setAttribute("id", "save_filename"); |
|
34 |
pathname.setAttribute("value", path); |
|
35 |
p.appendChild(pathname); |
|
36 |
var savebutton = document.createElement("input"); |
|
37 |
savebutton.setAttribute("type", "button"); |
|
38 |
savebutton.setAttribute("value", "Save"); |
|
39 |
savebutton.setAttribute("onclick", "save_file()"); |
|
40 |
p.appendChild(savebutton); |
|
41 |
var t = document.createTextNode(" "); |
|
42 |
p.appendChild(t); |
|
43 |
saved_status = document.createTextNode("Saved."); |
|
44 |
//p.appendChild(saved_status);
|
|
45 |
div.appendChild(p); |
|
46 |
||
47 |
/* Print a warning message if this is not actually a text file.
|
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
48 |
*/
|
49 |
if (handler_type != "text") |
|
50 |
{
|
|
51 |
var warn = dom_make_text_elem("p", |
|
52 |
"Warning: You are editing a binary " + |
|
53 |
"file, which explains any strange characters you may see. If " + |
|
54 |
"you save this file, you could corrupt it."); |
|
55 |
div.appendChild(warn); |
|
56 |
}
|
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
57 |
}
|
58 |
||
59 |
/** Presents the text editor.
|
|
60 |
*/
|
|
61 |
function handle_text(path, text, handler_type) |
|
62 |
{
|
|
63 |
/* Create a textarea with the text in it
|
|
64 |
* (The makings of a primitive editor).
|
|
65 |
*/
|
|
66 |
var files = document.getElementById("filesbody"); |
|
67 |
/* Put our UI at the top */
|
|
68 |
present_editorhead(files, path, handler_type); |
|
69 |
||
70 |
var div = document.createElement("div"); |
|
71 |
files.appendChild(div); |
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
72 |
var txt_elem = dom_make_text_elem("textarea", |
73 |
text.toString()) |
|
74 |
div.appendChild(txt_elem); |
|
75 |
txt_elem.setAttribute("id", "editbox"); |
|
221
by mattgiuca
editor: Made saving work. |
76 |
txt_elem.setAttribute("onchange", "edit_text()"); |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
77 |
/* TODO: Make CSS height: 100% work */
|
254
by mattgiuca
editor.js: Extended edit box to 35 lines (was too small). |
78 |
txt_elem.setAttribute("rows", "35"); |
233
by mattgiuca
Added a shaky implementation of EditArea as the text editor. |
79 |
|
80 |
/* Load EditArea into the editbox */
|
|
81 |
editAreaLoader.init({ |
|
82 |
id : "editbox", |
|
83 |
syntax: "python", |
|
572
by agdimech
browser/editor.js: Changed leading whitespace. |
84 |
toolbar: "search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, highlight, |, help", |
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
85 |
start_highlight: true, |
86 |
allow_toggle: false, |
|
87 |
allow_resize: false, |
|
489
by agdimech
browser.js, editor.js: Fixed the syntax error which was resulting due to a trailing comma. |
88 |
replace_tab_by_spaces: 4 |
233
by mattgiuca
Added a shaky implementation of EditArea as the text editor. |
89 |
});
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
90 |
}
|
91 |