1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-23 17:50:19 +01:00

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 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) {
if (this.locked) {
return false;
}
this.data = data;
var _this = this;
$.ajax('/documents', {
type: 'post',
@ -18,7 +22,7 @@ heist_document.prototype.save = function(data, callback) {
dataType: 'json',
success: function(res) {
this.locked = true;
_this.locked = true;
var high = hljs.highlightAuto(data);
callback({
value: high.value,
@ -59,6 +63,15 @@ heist.prototype.newDocument = function(ext) {
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
heist.prototype.lockDocument = function() {
var _this = this;
@ -77,13 +90,21 @@ heist.prototype.lockDocument = function() {
heist.prototype.configureShortcuts = function() {
var _this = this;
this.$textarea.keyup(function(evt) {
// ^L for lock
if (evt.ctrlKey && evt.keyCode === 76) {
// ^L or ^S for lock
if (evt.ctrlKey && (evt.keyCode === 76 || evt.keyCode === 83)) {
evt.preventDefault();
_this.lockDocument();
}
// ^N for new document
else if (evt.ctrlKey && evt.keyCode === 78) {
evt.preventDefault();
_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 support for browsers without pushstate
// TODO support for push state navigation
// TODO ctrl-d for duplicate
///// Tab behavior in the textarea - 2 spaces per tab