Содержимое окна редактирования доступно с помощью метода getValue сессии.Например, вот расширение стандартной демонстрации ACE для файла сохранения:
saveFile = function() {
var contents = env.editor.getSession().getValue();
$.post("write.php",
{contents: contents },
function() {
// add error checking
alert('successful save');
}
);
};
Я добавил вызов saveFile к уже существующему «Fake Save», которое находится в demo.js.Я заменяю предупреждение следующим кодом:
// Fake-Save, works from the editor and the command line.
canon.addCommand({
name: "save",
bindKey: {
win: "Ctrl-S",
mac: "Command-S",
sender: "editor|cli"
},
exec: function() {
saveFile();
}
});
Файл php состоит из одной строки:
$r = file_put_contents("foo.txt", $_POST["contents"]) or die("can't open file");