1
function disable_save_if_safe()
1
function disable_save()
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)
12
var savebutton = document.getElementById("save_button");
13
savebutton.disabled = true;
14
window.onbeforeunload = null;
3
var savebutton = document.getElementById("save_button");
4
savebutton.disabled = true;
5
window.onbeforeunload = null;
18
8
function save_file(filename)
21
data = editbox.getCode();
11
data = codemirror.getCode();
23
13
data = document.getElementById("editbox").value;
15
/* Convert newlines to a single LF (mainly for IE's CRLFs) */
16
data = data.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
25
18
/* Do NOT refresh the page contents (causes problems for editarea and is
27
20
if (current_file.svnstatus != "revision" ||
68
61
function highlighting_changed(select)
70
editbox.edit(editbox.getCode(), select.value);
73
function initialise_codepress()
75
editbox.addChangeHandler(edit_text);
76
editbox.addSaveHandler(function() {document.getElementById("save_button").click()});
78
/* We can only safely disable the save button on the first load.
79
* Syntax highlighting changes will also get this function called.
80
* We unfortunately need the change handler added each time.
82
if (!initialise_codepress.already)
84
disable_save_if_safe();
85
initialise_codepress.already = true;
63
codemirror_language(select.value);
89
66
/** Presents the text editor.
139
116
txt_elem.style.height = "100%";
140
117
window.onbeforeunload = confirm_beforeunload;
142
/* XXX: Lord, please forgive me for browser sniffing.
143
CodePress only works properly in real Gecko at the moment,
144
so we must go to great and evil lengths to sniff it out.
145
It's by no means a complete check, but it has to support
146
more browsers than the previous situation.
147
This should be killed ASAP when we fix/replace CodePress.
149
using_codepress = (navigator.userAgent.match('Gecko') &&
150
!navigator.userAgent.match('WebKit') &&
151
!navigator.userAgent.match('KHTML') &&
152
!navigator.userAgent.match('Presto'))
119
/* Always use CodeMirror (unless we find a good reason not to!) */
120
using_codemirror = true;
122
if (using_codemirror)
156
/* This is probably real Gecko. Try to fire up CodePress.
157
* If it fails we'll have a horrible mess, so we'll hope.
159
txt_elem.className = "codepress autocomplete-off " + language;
125
using_codemirror = true;
126
codemirror = new CodeMirror.fromTextArea(txt_elem, {
127
path: codemirrorpath,
129
codemirrorpath + "/contrib/python/css/pythoncolors.css",
130
codemirrorpath + "/css/xmlcolors.css",
131
codemirrorpath + "/css/jscolors.css",
132
codemirrorpath + "/css/csscolors.css"
134
basefiles: ["js/util.js",
135
"js/stringstream.js",
141
parserfile: ["contrib/python/js/parsepython.js",
144
"js/tokenizejavascript.js",
145
"js/parsejavascript.js",
146
"js/parsehtmlmixed.js",
153
initCallback: function() {codemirror_language(language);},
154
saveFunction: function() {document.getElementById("save_button").click();}
162
/* And set a callback so we know that the editor iframe is loaded so
163
* we can set a callback so we know when to enable the save button.
164
* We also take this opportunity to disable the save button, if
165
* the browser is likely to reenable it as needed. */
166
editbox.onload = initialise_codepress;
170
/* Not using CodePress, so we can already disable the Save button. */
171
disable_save_if_safe();
159
/* Not using CodePress, so we can already disable the Save button. */
164
function codemirror_language(lang)
166
if(lang == 'python') {
167
codemirror.setParser("PythonParser")
168
} else if(lang == 'html') {
169
codemirror.setParser("HTMLMixedParser")
170
} else if(lang == 'css') {
171
codemirror.setParser("CSSParser")
172
} else if(lang == 'javascript') {
173
codemirror.setParser("JSParser")
175
codemirror.setParser("DummyParser")
174
178
// Show actions bar