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;
90
80
function highlighting_changed(select)
92
editbox.edit(editbox.getCode(), select.value);
95
function initialise_codepress()
97
editbox.addChangeHandler(edit_text);
98
editbox.addSaveHandler(function() {document.getElementById("save_button").click()});
100
/* We can only safely disable the save button on the first load.
101
* Syntax highlighting changes will also get this function called.
102
* We unfortunately need the change handler added each time.
104
if (!initialise_codepress.already)
106
disable_save_if_safe();
107
initialise_codepress.already = true;
82
codemirror_language(select.value);
111
85
/** Presents the text editor.
144
118
txt_elem.style.height = "100%";
145
119
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'))
121
/* Always use CodeMirror (unless we find a good reason not to!) */
122
using_codemirror = true;
124
if (using_codemirror)
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;
127
using_codemirror = true;
128
codemirror = new CodeMirror.fromTextArea(txt_elem, {
129
path: codemirrorpath,
131
codemirrorpath + "/contrib/python/css/pythoncolors.css",
132
codemirrorpath + "/css/xmlcolors.css",
133
codemirrorpath + "/css/jscolors.css",
134
codemirrorpath + "/css/csscolors.css"
136
basefiles: ["js/util.js",
137
"js/stringstream.js",
143
parserfile: ["contrib/python/js/parsepython.js",
146
"js/tokenizejavascript.js",
147
"js/parsejavascript.js",
148
"js/parsehtmlmixed.js",
155
initCallback: function() {codemirror_language(language);},
156
saveFunction: function() {document.getElementById("save_button").click();}
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();
161
/* Not using CodePress, so we can already disable the Save button. */
166
function codemirror_language(lang)
168
if(lang == 'python') {
169
codemirror.setParser("PythonParser")
170
} else if(lang == 'html') {
171
codemirror.setParser("HTMLMixedParser")
172
} else if(lang == 'css') {
173
codemirror.setParser("CSSParser")
174
} else if(lang == 'javascript') {
175
codemirror.setParser("JSParser")
177
codemirror.setParser("DummyParser")