Added duplicate functionality

This commit is contained in:
John Crepezzi 2011-11-18 15:18:38 -05:00
parent f22f347d43
commit b35c89a472
2 changed files with 26 additions and 4 deletions

View file

@ -6,6 +6,8 @@ var url = require('url');
// TODO logging // TODO logging
// TODO preparse static instead of using exists // TODO preparse static instead of using exists
// TODO split into files
// TODO only parse url once for static files
////////////// //////////////

View file

@ -7,10 +7,14 @@ var heist_document = function() {
}; };
heist_document.prototype.save = function(data, callback) { heist_document.prototype.save = function(data, callback) {
if (this.locked) { if (this.locked) {
return false; return false;
} }
this.data = data;
var _this = this;
$.ajax('/documents', { $.ajax('/documents', {
type: 'post', type: 'post',
@ -18,7 +22,7 @@ heist_document.prototype.save = function(data, callback) {
dataType: 'json', dataType: 'json',
success: function(res) { success: function(res) {
this.locked = true; _this.locked = true;
var high = hljs.highlightAuto(data); var high = hljs.highlightAuto(data);
callback({ callback({
value: high.value, value: high.value,
@ -59,6 +63,15 @@ heist.prototype.newDocument = function(ext) {
this.$textarea.val('').show().focus(); this.$textarea.val('').show().focus();
} }
// Duplicate the current document - only if locked
heist.prototype.duplicateDocument = function() {
if (this.doc.locked) {
var currentData = this.doc.data;
this.newDocument();
this.$textarea.val(currentData);
}
};
// Lock the current document // Lock the current document
heist.prototype.lockDocument = function() { heist.prototype.lockDocument = function() {
var _this = this; var _this = this;
@ -77,13 +90,21 @@ heist.prototype.lockDocument = function() {
heist.prototype.configureShortcuts = function() { heist.prototype.configureShortcuts = function() {
var _this = this; var _this = this;
this.$textarea.keyup(function(evt) { this.$textarea.keyup(function(evt) {
// ^L for lock // ^L or ^S for lock
if (evt.ctrlKey && evt.keyCode === 76) { if (evt.ctrlKey && (evt.keyCode === 76 || evt.keyCode === 83)) {
evt.preventDefault();
_this.lockDocument(); _this.lockDocument();
} }
// ^N for new document
else if (evt.ctrlKey && evt.keyCode === 78) { else if (evt.ctrlKey && evt.keyCode === 78) {
evt.preventDefault();
_this.newDocument(); _this.newDocument();
} }
// ^D for duplicate - only when locked
else if (_this.doc.locked && evt.ctrlKey && evt.keyCode === 68) {
evt.preventDefault();
_this.duplicateDocument();
}
}); });
}; };
@ -91,7 +112,6 @@ heist.prototype.configureShortcuts = function() {
// TODO refuse to lock empty documents // TODO refuse to lock empty documents
// TODO support for browsers without pushstate // TODO support for browsers without pushstate
// TODO support for push state navigation // TODO support for push state navigation
// TODO ctrl-d for duplicate
///// Tab behavior in the textarea - 2 spaces per tab ///// Tab behavior in the textarea - 2 spaces per tab