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;
25
/* Convert newlines to a single LF (mainly for IE's CRLFs) */
26
data = data.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
15
data = editbox.getCode();
28
16
/* Do NOT refresh the page contents (causes problems for editarea and is
30
18
if (current_file.svnstatus != "revision" ||
122
110
var div = document.createElement("div");
123
111
div.style.height = '100%';
124
112
files.appendChild(div);
125
var txt_elem = document.createElement("textarea");
126
txt_elem.value = text.toString();
113
var txt_elem = dom_make_text_elem("textarea",
127
115
div.appendChild(txt_elem);
128
116
txt_elem.setAttribute("id", "editbox");
129
117
language = language_from_mime(current_file.type);
132
120
language = language ? language : "text";
133
121
document.getElementById("highlighting_select").value = language;
135
$(txt_elem).change(edit_text);
137
/* This isn't ideal, as Opera seems to fire it even for non-textual keys.
138
* But IE and WebKit don't, so this will behave properly in most browsers.
141
$(txt_elem).keypress(edit_text);
143
txt_elem.style.width = "100%";
144
txt_elem.style.height = "100%";
123
txt_elem.className = "codepress autocomplete-off " + language;
124
txt_elem.setAttribute("onchange", "edit_text()");
125
/* TODO: Make CSS height: 100% work */
126
txt_elem.setAttribute("rows", "35");
145
129
window.onbeforeunload = confirm_beforeunload;
147
/* XXX: Lord, please forgive me for browser sniffing.
148
CodePress only works properly in real Gecko at the moment,
149
so we must go to great and evil lengths to sniff it out.
150
It's by no means a complete check, but it has to support
151
more browsers than the previous situation.
152
This should be killed ASAP when we fix/replace CodePress.
154
using_codepress = (navigator.userAgent.match('Gecko') &&
155
!navigator.userAgent.match('WebKit') &&
156
!navigator.userAgent.match('KHTML') &&
157
!navigator.userAgent.match('Presto'))
161
/* This is probably real Gecko. Try to fire up CodePress.
162
* If it fails we'll have a horrible mess, so we'll hope.
164
txt_elem.className = "codepress autocomplete-off " + language;
167
/* And set a callback so we know that the editor iframe is loaded so
168
* we can set a callback so we know when to enable the save button.
169
* We also take this opportunity to disable the save button, if
170
* the browser is likely to reenable it as needed. */
171
editbox.onload = initialise_codepress;
175
/* Not using CodePress, so we can already disable the Save button. */
176
disable_save_if_safe();
131
/* And set a callback so we know that the editor iframe is loaded so we
132
* can set a callback so we know when to enable the save button.
133
* We also take this opportunity to disable the save button, if
134
* the browser is likely to reenable it as needed. */
135
editbox.onload = initialise_codepress
180
138
function language_from_mime(mime)
182
140
return {'text/x-python': 'python',
183
'application/x-javascript': 'javascript',
184
141
'application/javascript': 'javascript',
185
142
'text/css': 'css',
186
143
'text/plain': 'text',