Loading server.js +36 −2 Original line number Diff line number Diff line Loading @@ -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) { var incoming = url.parse(request.url, false); 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); static/application.js +26 −12 Original line number Diff line number Diff line ///// represents a single document var heist_document = function() { Loading @@ -9,17 +10,29 @@ heist_document.prototype.save = function(data, callback) { if (this.locked) { return false; } var high = hljs.highlightAuto(data); var pack = { language: high.language, data: data }; pack.value = high.value; pack.uuid = '123456'; $.ajax('/documents', { type: 'post', data: data, dataType: 'json', success: function(res) { this.locked = true; callback(pack); var high = hljs.highlightAuto(data); callback({ value: high.value, uuid: res.uuid, language: high.language }); } }); }; ///// represents the paste application var heist = function(appName) { this.appName = appName; Loading Loading @@ -52,7 +65,8 @@ heist.prototype.lockDocument = function() { this.doc.save(this.$textarea.val(), function(ret) { if (ret) { _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.$box.show(); } Loading @@ -79,9 +93,9 @@ heist.prototype.configureShortcuts = function() { // TODO support for push state navigation // TODO ctrl-d for duplicate $(function() { ///// Tab behavior in the textarea - 2 spaces per tab $('textarea').focus(); $(function() { $('textarea').keydown(function(evt) { if (evt.keyCode === 9) { Loading static/index.html +1 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ $(function() { var app = new heist('heist'); app.newDocument(); $('textarea').focus(); }); </script> Loading Loading
server.js +36 −2 Original line number Diff line number Diff line Loading @@ -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) { var incoming = url.parse(request.url, false); 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);
static/application.js +26 −12 Original line number Diff line number Diff line ///// represents a single document var heist_document = function() { Loading @@ -9,17 +10,29 @@ heist_document.prototype.save = function(data, callback) { if (this.locked) { return false; } var high = hljs.highlightAuto(data); var pack = { language: high.language, data: data }; pack.value = high.value; pack.uuid = '123456'; $.ajax('/documents', { type: 'post', data: data, dataType: 'json', success: function(res) { this.locked = true; callback(pack); var high = hljs.highlightAuto(data); callback({ value: high.value, uuid: res.uuid, language: high.language }); } }); }; ///// represents the paste application var heist = function(appName) { this.appName = appName; Loading Loading @@ -52,7 +65,8 @@ heist.prototype.lockDocument = function() { this.doc.save(this.$textarea.val(), function(ret) { if (ret) { _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.$box.show(); } Loading @@ -79,9 +93,9 @@ heist.prototype.configureShortcuts = function() { // TODO support for push state navigation // TODO ctrl-d for duplicate $(function() { ///// Tab behavior in the textarea - 2 spaces per tab $('textarea').focus(); $(function() { $('textarea').keydown(function(evt) { if (evt.keyCode === 9) { Loading
static/index.html +1 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ $(function() { var app = new heist('heist'); app.newDocument(); $('textarea').focus(); }); </script> Loading