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

« back to all changes in this revision

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

  • Committer: wagrant
  • Date: 2008-07-21 00:03:16 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:914
remakeuser.py: Destroy!
remakeallusers.py: Rename to remakeuser.py. It now takes a username to
      rebuild, or -a to rebuild everyone.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
function disable_save_if_safe()
2
2
{
3
 
    /* If we are using CodePress, we can only safely disable the save button
4
 
     * (indicating that there are no changes to save) if the engine supports
5
 
     * change notification, so the button can be enabled again.
6
 
     *
7
 
     * Our non-CodePress mode just uses normal textarea events, so is always
8
 
     * fine.
9
 
     */
10
 
    if((!using_codepress) || editbox.editor.addChangeHandler)
 
3
    /* If this is defined, this engine supports change notification, so is able
 
4
     * to enable the button again. Disable it for them. */
 
5
    if(editbox.editor.addChangeHandler)
11
6
    {
12
7
        var savebutton = document.getElementById("save_button");
13
8
        savebutton.disabled = true;
17
12
 
18
13
function save_file(filename)
19
14
{
20
 
    if (using_codepress)
21
 
        data = editbox.getCode();
22
 
    else
23
 
        data = document.getElementById("editbox").value;
24
 
 
 
15
    data = editbox.getCode();
25
16
    /* Do NOT refresh the page contents (causes problems for editarea and is
26
17
     * unnecessary). */
27
18
    if (current_file.svnstatus != "revision" ||
31
22
    {
32
23
        do_action("putfile", filename,
33
24
                  {"path":".", "data":data, "overwrite":"true"},
34
 
                  "multipart/form-data");
 
25
                  "multipart/form-data", true);
35
26
        disable_save_if_safe();
36
27
    }
37
28
}
92
83
function initialise_codepress()
93
84
{
94
85
    editbox.addChangeHandler(edit_text);
95
 
    editbox.addSaveHandler(function() {document.getElementById("save_button").click()});
96
86
     
97
87
    /* We can only safely disable the save button on the first load.
98
88
     * Syntax highlighting changes will also get this function called.
119
109
    var div = document.createElement("div");
120
110
    div.style.height = '100%';
121
111
    files.appendChild(div);
122
 
    var txt_elem = document.createElement("textarea");
123
 
    txt_elem.value = text.toString();
 
112
    var txt_elem = dom_make_text_elem("textarea",
 
113
        text.toString())
124
114
    div.appendChild(txt_elem);
125
115
    txt_elem.setAttribute("id", "editbox");
126
116
    language = language_from_mime(current_file.type);
129
119
    language = language ? language : "text";
130
120
    document.getElementById("highlighting_select").value = language;
131
121
 
132
 
    $(txt_elem).change(edit_text);
133
 
 
134
 
    /* This isn't ideal, as Opera seems to fire it even for non-textual keys.
135
 
     * But IE and WebKit don't, so this will behave properly in most browsers.
136
 
     * This makes me sad.
137
 
     */
138
 
    $(txt_elem).keypress(edit_text);
139
 
 
140
 
    txt_elem.style.width = "100%";
141
 
    txt_elem.style.height = "100%";
 
122
    txt_elem.className = "codepress " + language;
 
123
    txt_elem.setAttribute("onchange", "edit_text()");
 
124
    /* TODO: Make CSS height: 100% work */
 
125
    txt_elem.setAttribute("rows", "35");
 
126
    CodePress.run();
 
127
 
142
128
    window.onbeforeunload = confirm_beforeunload;
143
129
 
144
 
    /* XXX: Lord, please forgive me for browser sniffing.
145
 
            CodePress only works properly in real Gecko at the moment,
146
 
            so we must go to great and evil lengths to sniff it out.
147
 
            It's by no means a complete check, but it has to support
148
 
            more browsers than the previous situation.
149
 
            This should be killed ASAP when we fix/replace CodePress.
150
 
     */
151
 
    using_codepress = (navigator.userAgent.match('Gecko') &&
152
 
                       !navigator.userAgent.match('WebKit') &&
153
 
                       !navigator.userAgent.match('KHTML') &&
154
 
                       !navigator.userAgent.match('Presto'))
155
 
 
156
 
    if (using_codepress)
157
 
    {
158
 
        /* This is probably real Gecko. Try to fire up CodePress.
159
 
         * If it fails we'll have a horrible mess, so we'll hope.
160
 
         */
161
 
        txt_elem.className = "codepress autocomplete-off " + language;
162
 
        CodePress.run();
163
 
 
164
 
        /* And set a callback so we know that the editor iframe is loaded so
165
 
         * we can set a callback so we know when to enable the save button.
166
 
         * We also take this opportunity to disable the save button, if
167
 
         * the browser is likely to reenable it as needed. */
168
 
        editbox.onload = initialise_codepress;
169
 
    }
170
 
    else
171
 
    {
172
 
        /* Not using CodePress, so we can already disable the Save button. */
173
 
        disable_save_if_safe();
174
 
    }
 
130
    /* And set a callback so we know that the editor iframe is loaded so we
 
131
     * can set a callback so we know when to enable the save button.
 
132
     * We also take this opportunity to disable the save button, if
 
133
     * the browser is likely to reenable it as needed. */
 
134
    editbox.onload = initialise_codepress
175
135
}
176
136
 
177
137
function language_from_mime(mime)
178
138
{
179
139
    return {'text/x-python': 'python',
180
 
            'application/x-javascript': 'javascript',
181
140
            'application/javascript': 'javascript',
182
141
            'text/css': 'css',
183
142
            'text/plain': 'text',
184
143
            'text/html': 'html',
185
 
            'application/xml': 'html',
186
144
            'application/xhtml+xml': 'html'}[mime];
187
145
}