diff --git a/demo/kitchen-sink/doclist.js b/demo/kitchen-sink/doclist.js
index 567c62cd..abdc9a3e 100644
--- a/demo/kitchen-sink/doclist.js
+++ b/demo/kitchen-sink/doclist.js
@@ -182,7 +182,7 @@ function saveDoc(name, callback) {
else if (parts[0] == "ace")
path = "lib/" + path;
- net.put(path, doc.session.getValue(), callback);
+ net.request('PUT', path, doc.session.getValue(), callback);
}
module.exports = {
diff --git a/lib/ace/lib/net.js b/lib/ace/lib/net.js
index 4c07ec2b..357fcb9d 100644
--- a/lib/ace/lib/net.js
+++ b/lib/ace/lib/net.js
@@ -9,22 +9,9 @@ define(function(require, exports, module) {
"use strict";
var dom = require("./dom");
-exports.get = function (url, callback) {
+exports.request = function (verb, url, data, callback) {
var xhr = new XMLHttpRequest();
- xhr.open('GET', url, true);
- xhr.onreadystatechange = function () {
- //Do not explicitly handle errors, those should be
- //visible via console output in the browser.
- if (xhr.readyState === 4) {
- callback(xhr.responseText);
- }
- };
- xhr.send(null);
-};
-
-exports.put = function (url, data, callback) {
- var xhr = new XMLHttpRequest();
- xhr.open('PUT', url, true);
+ xhr.open(verb, url, true);
xhr.onreadystatechange = function () {
//Do not explicitly handle errors, those should be
//visible via console output in the browser.
@@ -35,6 +22,10 @@ exports.put = function (url, data, callback) {
xhr.send(data);
};
+exports.get = function (url, callback) {
+ this.request('GET', url, null, callback);
+};
+
exports.loadScript = function(path, callback) {
var head = dom.getDocumentHead();
var s = document.createElement('script');
diff --git a/tool/mode_creator.html b/tool/mode_creator.html
index cd6b2461..b4c66715 100644
--- a/tool/mode_creator.html
+++ b/tool/mode_creator.html
@@ -59,7 +59,7 @@
-
+
@@ -71,7 +71,7 @@
-
+
diff --git a/tool/mode_creator.js b/tool/mode_creator.js
index ee235eca..c78345ac 100644
--- a/tool/mode_creator.js
+++ b/tool/mode_creator.js
@@ -96,24 +96,14 @@ var uploadEl2 = document.getElementById("uploadToServer2");
uploadEl1.onclick = function() {
var text = savedLeadingComments + editor1.getValue();
var url = "./lib/ace/mode/" + modeEl.value + "_highlight_rules.js";
- net.put(url, text, function(text) {
- if (text.trim().length > 0)
- log(text);
- else {
- uploadEl1.disabled = true;
- editor1.getSession().getUndoManager().markClean();
- }
+ net.request('PUT', url, text, function(text) {
+ handle_put_result(text, editor1, uploadEl1);
});
};
editor1.commands.bindKey("Ctrl-S", uploadEl1.onclick);
uploadEl2.onclick = function() {
doclist.saveDoc(docEl.value, function(text) {
- if (text.trim().length > 0)
- log(text);
- else {
- uploadEl2.disabled = true;
- editor2.getSession().getUndoManager().markClean();
- }
+ handle_put_result(text, editor2, uploadEl2);
});
};
editor2.commands.bindKey("Ctrl-S", uploadEl2.onclick);
@@ -124,6 +114,22 @@ editor2.on('change', function() {
uploadEl2.disabled = false;
});
+function handle_put_result(text, editor, buttonEl) {
+ text = text.trim();
+ if (text.length == 0) {
+ buttonEl.disabled = true;
+ editor.getSession().getUndoManager().markClean();
+ } else {
+ if (text.indexOf("405") == 0) {
+ log("Write access to this file is disabled.\n"+
+ "To enable saving your changes to disk, clone the Ace repository"+
+ "\nand run the included static.py web server with the option\n"+
+ "--puttable='lib/ace/mode/*_highlight_rules.js,demo/kitchen-sink/docs/*'");
+ } else
+ log(text);
+ }
+}
+
document.getElementById("perfTest").onclick = function() {
var lines = editor2.session.doc.getAllLines();
if (!lines.length)