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

« back to all changes in this revision

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

  • Committer: me at id
  • Date: 2009-01-15 01:18:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1145
Give ivle.database.User {password,account}_expired attributes, and get
ivle.dispatch.login to use them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
    {
7
7
        var savebutton = document.getElementById("save_button");
8
8
        savebutton.disabled = true;
 
9
        window.onbeforeunload = null;
9
10
    }
10
11
}
11
12
 
12
 
function save_file()
 
13
function save_file(filename)
13
14
{
14
 
    var filename = document.getElementById("save_filename").value;
15
15
    data = editbox.getCode();
16
16
    /* Do NOT refresh the page contents (causes problems for editarea and is
17
17
     * unnecessary). */
18
 
    do_action("putfile", filename,
19
 
              {"path":".", "data":data, "overwrite":"true"},
20
 
              "multipart/form-data", true);
21
 
    disable_save_if_safe();
 
18
    if (current_file.svnstatus != "revision" ||
 
19
        confirm("You are currently viewing an older version of this file. " +
 
20
                "Saving will overwrite the current version. " +
 
21
                "Are you sure you want to continue?"))
 
22
    {
 
23
        do_action("putfile", filename,
 
24
                  {"path":".", "data":data, "overwrite":"true"},
 
25
                  "multipart/form-data", true);
 
26
        disable_save_if_safe();
 
27
    }
 
28
}
 
29
 
 
30
function save_file_as(default_filename)
 
31
{
 
32
    filename = prompt("Path to save to:", default_filename);
 
33
    if (!filename) return;
 
34
 
 
35
    /* The filename will be path_joined with the app name, so needs to not
 
36
     * be absolute, lest it clobber the app name. */
 
37
    if (filename.charAt(0) == "/") filename = filename.substring(1);
 
38
    ajax_call(save_file_as_callback, "fileservice", filename, {}, "POST");
 
39
}
 
40
 
 
41
function save_file_as_callback(response)
 
42
{
 
43
    if (response.status == 404 || confirm("Are you sure you want to overwrite " + filename + "?"))
 
44
        save_file(filename);
 
45
}
 
46
 
 
47
/* Return a warning to be used in window.onbeforeunload. */
 
48
function confirm_beforeunload() {
 
49
    return 'If you continue, any unsaved changes to the current file will be lost.';
22
50
}
23
51
 
24
52
function edit_text()
25
53
{
26
54
    var savebutton = document.getElementById("save_button");
27
55
    savebutton.disabled = false;
 
56
    window.onbeforeunload = confirm_beforeunload;
28
57
}
29
58
 
30
59
/** Presents the "editor heading" inserting it into a given element at
46
75
    }
47
76
}
48
77
 
 
78
function highlighting_changed(select)
 
79
{
 
80
    editbox.edit(editbox.getCode(), select.value);
 
81
}
 
82
 
 
83
function initialise_codepress()
 
84
{
 
85
    editbox.addChangeHandler(edit_text);
 
86
    editbox.addSaveHandler(function() {document.getElementById("save_button").click()});
 
87
     
 
88
    /* We can only safely disable the save button on the first load.
 
89
     * Syntax highlighting changes will also get this function called.
 
90
     * We unfortunately need the change handler added each time.
 
91
     */
 
92
    if (!initialise_codepress.already)
 
93
    {
 
94
        disable_save_if_safe();
 
95
        initialise_codepress.already = true;
 
96
    }
 
97
}
 
98
 
49
99
/** Presents the text editor.
50
100
 */
51
101
function handle_text(path, text, handler_type)
64
114
        text.toString())
65
115
    div.appendChild(txt_elem);
66
116
    txt_elem.setAttribute("id", "editbox");
67
 
    language = language_from_mime(current_file.type)
 
117
    language = language_from_mime(current_file.type);
68
118
 
69
119
    // Assume plaintext if no type can be determined.
70
 
    txt_elem.className = "codepress " + (language ? language : 'text');
 
120
    language = language ? language : "text";
 
121
    document.getElementById("highlighting_select").value = language;
 
122
 
 
123
    txt_elem.className = "codepress autocomplete-off " + language;
71
124
    txt_elem.setAttribute("onchange", "edit_text()");
72
125
    /* TODO: Make CSS height: 100% work */
73
126
    txt_elem.setAttribute("rows", "35");
74
127
    CodePress.run();
75
128
 
 
129
    window.onbeforeunload = confirm_beforeunload;
 
130
 
76
131
    /* And set a callback so we know that the editor iframe is loaded so we
77
132
     * can set a callback so we know when to enable the save button.
78
133
     * We also take this opportunity to disable the save button, if
79
134
     * the browser is likely to reenable it as needed. */
80
 
    editbox.onload = function() {editbox.addChangeHandler(edit_text);
81
 
                                 disable_save_if_safe(); };
 
135
    editbox.onload = initialise_codepress
82
136
}
83
137
 
84
138
function language_from_mime(mime)
88
142
            'text/css': 'css',
89
143
            'text/plain': 'text',
90
144
            'text/html': 'html',
 
145
            'application/xml': 'html',
91
146
            'application/xhtml+xml': 'html'}[mime];
92
147
}