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;
89
79
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
82
/** Presents the text editor.
110
84
function handle_text(path, text, handler_type)
141
115
txt_elem.style.height = "100%";
142
116
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();
118
/* Always use CodeMirror (unless we find a good reason not to!) */
119
using_codemirror = true;
121
if (using_codemirror)
124
using_codemirror = true;
125
codemirror = new CodeMirror.fromTextArea(txt_elem, {
126
path: mediapath+"codemirror/",
128
mediapath+"/codemirror/contrib/python/css/pythoncolors.css",
129
basefiles: ["js/util.js",
130
"js/stringstream.js",
135
parserfile: ["contrib/python/js/parsepython.js"],
142
/* Not using CodePress, so we can already disable the Save button. */
177
147
function language_from_mime(mime)