1
1
function disable_save_if_safe()
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.
7
* Our non-CodePress mode just uses normal textarea events, so is always
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)
12
7
var savebutton = document.getElementById("save_button");
13
8
savebutton.disabled = true;
18
13
function save_file(filename)
21
data = editbox.getCode();
23
data = document.getElementById("editbox").value;
15
data = editbox.getCode();
25
16
/* Do NOT refresh the page contents (causes problems for editarea and is
27
if (current_file.svnstatus != "revision" ||
28
confirm("You are currently viewing an older version of this file. " +
29
"Saving will overwrite the current version. " +
30
"Are you sure you want to continue?"))
32
do_action("putfile", filename,
33
{"path":".", "data":data, "overwrite":"true"},
34
"multipart/form-data");
35
disable_save_if_safe();
18
do_action("putfile", filename,
19
{"path":".", "data":data, "overwrite":"true"},
20
"multipart/form-data", true);
21
disable_save_if_safe();
39
24
function save_file_as(default_filename)
89
74
editbox.edit(editbox.getCode(), select.value);
92
function initialise_codepress()
94
editbox.addChangeHandler(edit_text);
95
editbox.addSaveHandler(function() {document.getElementById("save_button").click()});
97
/* We can only safely disable the save button on the first load.
98
* Syntax highlighting changes will also get this function called.
99
* We unfortunately need the change handler added each time.
101
if (!initialise_codepress.already)
103
disable_save_if_safe();
104
initialise_codepress.already = true;
108
77
/** Presents the text editor.
110
79
function handle_text(path, text, handler_type)
119
88
var div = document.createElement("div");
120
89
div.style.height = '100%';
121
90
files.appendChild(div);
122
var txt_elem = document.createElement("textarea");
123
txt_elem.value = text.toString();
91
var txt_elem = dom_make_text_elem("textarea",
124
93
div.appendChild(txt_elem);
125
94
txt_elem.setAttribute("id", "editbox");
126
95
language = language_from_mime(current_file.type);
129
98
language = language ? language : "text";
130
99
document.getElementById("highlighting_select").value = language;
132
$(txt_elem).change(edit_text);
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.
138
$(txt_elem).keypress(edit_text);
140
txt_elem.style.width = "100%";
141
txt_elem.style.height = "100%";
101
txt_elem.className = "codepress " + language;
102
txt_elem.setAttribute("onchange", "edit_text()");
103
/* TODO: Make CSS height: 100% work */
104
txt_elem.setAttribute("rows", "35");
142
107
window.onbeforeunload = confirm_beforeunload;
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.
151
using_codepress = (navigator.userAgent.match('Gecko') &&
152
!navigator.userAgent.match('WebKit') &&
153
!navigator.userAgent.match('KHTML') &&
154
!navigator.userAgent.match('Presto'))
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.
161
txt_elem.className = "codepress autocomplete-off " + language;
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;
172
/* Not using CodePress, so we can already disable the Save button. */
173
disable_save_if_safe();
109
/* And set a callback so we know that the editor iframe is loaded so we
110
* can set a callback so we know when to enable the save button.
111
* We also take this opportunity to disable the save button, if
112
* the browser is likely to reenable it as needed. */
113
editbox.onload = function() {editbox.addChangeHandler(edit_text);
114
disable_save_if_safe(); };
177
117
function language_from_mime(mime)
179
119
return {'text/x-python': 'python',
180
'application/x-javascript': 'javascript',
181
120
'application/javascript': 'javascript',
182
121
'text/css': 'css',
183
122
'text/plain': 'text',
184
123
'text/html': 'html',
185
'application/xml': 'html',
186
124
'application/xhtml+xml': 'html'}[mime];