1
function disable_save()
1
function disable_save_if_safe()
3
var savebutton = document.getElementById("save_button");
4
savebutton.disabled = true;
5
window.onbeforeunload = null;
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)
7
var savebutton = document.getElementById("save_button");
8
savebutton.disabled = true;
9
window.onbeforeunload = null;
8
13
function save_file(filename)
11
data = codemirror.getCode();
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');
15
data = editbox.getCode();
18
16
/* Do NOT refresh the page contents (causes problems for editarea and is
20
18
if (current_file.svnstatus != "revision" ||
80
78
function highlighting_changed(select)
82
codemirror_language(select.value);
80
editbox.edit(editbox.getCode(), select.value);
83
function initialise_codepress()
85
editbox.addChangeHandler(edit_text);
86
editbox.addSaveHandler(function() {document.getElementById("save_button").click()});
88
/* We can only safely disable the save button on the first load.
89
* Syntax highlighting changes will also get this function called.
90
* We unfortunately need the change handler added each time.
92
if (!initialise_codepress.already)
94
disable_save_if_safe();
95
initialise_codepress.already = true;
85
99
/** Presents the text editor.
96
110
var div = document.createElement("div");
97
111
div.style.height = '100%';
98
112
files.appendChild(div);
99
var txt_elem = document.createElement("textarea");
100
txt_elem.value = text.toString();
113
var txt_elem = dom_make_text_elem("textarea",
101
115
div.appendChild(txt_elem);
102
116
txt_elem.setAttribute("id", "editbox");
103
117
language = language_from_mime(current_file.type);
106
120
language = language ? language : "text";
107
121
document.getElementById("highlighting_select").value = language;
109
$(txt_elem).change(edit_text);
111
/* This isn't ideal, as Opera seems to fire it even for non-textual keys.
112
* But IE and WebKit don't, so this will behave properly in most browsers.
115
$(txt_elem).keypress(edit_text);
117
txt_elem.style.width = "100%";
118
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");
119
129
window.onbeforeunload = confirm_beforeunload;
121
/* Always use CodeMirror (unless we find a good reason not to!) */
122
using_codemirror = true;
124
if (using_codemirror)
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();}
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")
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
181
138
function language_from_mime(mime)
183
140
return {'text/x-python': 'python',
184
'application/x-javascript': 'javascript',
185
141
'application/javascript': 'javascript',
186
142
'text/css': 'css',
187
143
'text/plain': 'text',