~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/browser/editor.js

  • Committer: mattgiuca
  • Date: 2008-01-12 15:35:53 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:201
Added "test" directory.
Added make_date_test.py, a short script I wrote to test the date format
algorithm committed in the previous revision.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
function save_file()
2
 
{
3
 
    var savebutton = document.getElementById("save_button");
4
 
    var filename = document.getElementById("save_filename").value;
5
 
    data = editAreaLoader.getValue("editbox");
6
 
    /* Do NOT refresh the page contents (causes problems for editarea and is
7
 
     * unnecessary). */
8
 
    do_action("putfile", filename,
9
 
              {"path":".", "data":data, "overwrite":"true"},
10
 
              "multipart/form-data", true);
11
 
    savebutton.setAttribute("value", "Saved");
12
 
    // XXX Do not disable for now; there is a problem getting the callback
13
 
    // to edit_text.
14
 
    //savebutton.setAttribute("disabled", "disabled");
15
 
}
16
 
 
17
 
function edit_text()
18
 
{
19
 
    var savebutton = document.getElementById("save_button");
20
 
    savebutton.setAttribute("value", "Save");
21
 
    savebutton.removeAttribute("disabled");
22
 
}
23
 
 
24
 
/** Presents the "editor heading" (the part with the save box)
25
 
 * inserting it into a given element at the front.
26
 
 */
27
 
function present_editorhead(elem, path, handler_type)
28
 
{
29
 
    var div = document.getElementById("actions2");
30
 
 
31
 
    /* Set up minimal interface */
32
 
    var p = dom_make_text_elem("p", "Save as: ");
33
 
    var pathname = document.createElement("input");
34
 
    pathname.setAttribute("type", "text");
35
 
    pathname.setAttribute("size", "30");
36
 
    pathname.setAttribute("id", "save_filename");
37
 
    pathname.setAttribute("value", path);
38
 
    p.appendChild(pathname);
39
 
    var savebutton = document.createElement("input");
40
 
    savebutton.setAttribute("id", "save_button");
41
 
    savebutton.setAttribute("type", "button");
42
 
    savebutton.setAttribute("value", "Saved");
43
 
    // XXX Do not disable for now; there is a problem getting the callback
44
 
    // to edit_text.
45
 
    //savebutton.setAttribute("disabled", "disabled");
46
 
    savebutton.setAttribute("onclick", "save_file()");
47
 
    p.appendChild(savebutton);
48
 
    var t = document.createTextNode(" ");
49
 
    p.appendChild(t);
50
 
    div.appendChild(p);
51
 
 
52
 
    /* Print a warning message if this is not actually a text file.
53
 
     */
54
 
    if (handler_type != "text")
55
 
    {
56
 
        var warn = dom_make_text_elem("p",
57
 
            "Warning: You are editing a binary " +
58
 
            "file, which explains any strange characters you may see. If " +
59
 
            "you save this file, you could corrupt it.");
60
 
        div.appendChild(warn);
61
 
    }
62
 
}
63
 
 
64
 
/** Presents the text editor.
65
 
 */
66
 
function handle_text(path, text, handler_type)
67
 
{
68
 
    /* Create a textarea with the text in it
69
 
     * (The makings of a primitive editor).
70
 
     */
71
 
    var files = document.getElementById("filesbody");
72
 
    /* Put our UI at the top */
73
 
    present_editorhead(files, path, handler_type);
74
 
 
75
 
    var div = document.createElement("div");
76
 
    files.appendChild(div);
77
 
    var txt_elem = dom_make_text_elem("textarea",
78
 
        text.toString())
79
 
    div.appendChild(txt_elem);
80
 
    txt_elem.setAttribute("id", "editbox");
81
 
    txt_elem.setAttribute("onchange", "edit_text()");
82
 
    /* TODO: Make CSS height: 100% work */
83
 
    txt_elem.setAttribute("rows", "35");
84
 
 
85
 
    /* Load EditArea into the editbox */
86
 
    editAreaLoader.init({
87
 
        id : "editbox",
88
 
        syntax: "python",
89
 
        toolbar: "search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, highlight, |, help",
90
 
        start_highlight: true,
91
 
        allow_toggle: false,
92
 
        allow_resize: false,
93
 
        replace_tab_by_spaces: 4,
94
 
        change_callback: "edit_text"
95
 
    });
96
 
}
97