1
0
Fork 0
mirror of https://github.com/seejohnrun/haste-server.git synced 2024-11-24 21:41:21 +00:00

Document saving almost working

This commit is contained in:
John Crepezzi 2011-11-18 10:49:00 -05:00
parent 7cc30e4b69
commit 7756e38595
3 changed files with 63 additions and 14 deletions

View file

@ -50,9 +50,43 @@ StaticHandler.prototype.handle = function(request, response) {
/////////// ///////////
var documents = {};
var DocumentHandler = function() {
};
DocumentHandler.prototype.handle = function(request, response) {
if (request.method == 'GET') {
}
else if (request.method == 'POST') {
var key = '123';
request.on('data', function(data) {
if (!documents[key]) {
documents[key] = '';
}
documents[key] += data.toString();
});
request.on('end', function(end) {
response.end(JSON.stringify({ uuid: key }));
});
}
};
///////////
http.createServer(function(request, response) { http.createServer(function(request, response) {
var handler = new StaticHandler('./static'); var incoming = url.parse(request.url, false);
handler.handle(request, response);
if (incoming.pathname.indexOf('/documents') === 0) {
var handler = new DocumentHandler();
handler.handle(request, response);
}
else {
var handler = new StaticHandler('./static');
handler.handle(request, response);
}
}).listen(7777); }).listen(7777);

View file

@ -1,3 +1,4 @@
///// represents a single document
var heist_document = function() { var heist_document = function() {
@ -9,17 +10,29 @@ heist_document.prototype.save = function(data, callback) {
if (this.locked) { if (this.locked) {
return false; return false;
} }
var high = hljs.highlightAuto(data);
var pack = { $.ajax('/documents', {
language: high.language,
data: data type: 'post',
}; data: data,
pack.value = high.value; dataType: 'json',
pack.uuid = '123456';
this.locked = true; success: function(res) {
callback(pack); this.locked = true;
var high = hljs.highlightAuto(data);
callback({
value: high.value,
uuid: res.uuid,
language: high.language
});
}
});
}; };
///// represents the paste application
var heist = function(appName) { var heist = function(appName) {
this.appName = appName; this.appName = appName;
@ -52,7 +65,8 @@ heist.prototype.lockDocument = function() {
this.doc.save(this.$textarea.val(), function(ret) { this.doc.save(this.$textarea.val(), function(ret) {
if (ret) { if (ret) {
_this.$code.html(ret.value); _this.$code.html(ret.value);
_this.setTitle(ret.language); _this.setTitle(ret.language + '-' + ret.uuid);
// TODO add to push state
_this.$textarea.val('').hide(); _this.$textarea.val('').hide();
_this.$box.show(); _this.$box.show();
} }
@ -79,9 +93,9 @@ heist.prototype.configureShortcuts = function() {
// TODO support for push state navigation // TODO support for push state navigation
// TODO ctrl-d for duplicate // TODO ctrl-d for duplicate
$(function() { ///// Tab behavior in the textarea - 2 spaces per tab
$('textarea').focus(); $(function() {
$('textarea').keydown(function(evt) { $('textarea').keydown(function(evt) {
if (evt.keyCode === 9) { if (evt.keyCode === 9) {

View file

@ -41,6 +41,7 @@
$(function() { $(function() {
var app = new heist('heist'); var app = new heist('heist');
app.newDocument(); app.newDocument();
$('textarea').focus();
}); });
</script> </script>