mirror of
https://github.com/seejohnrun/haste-server
synced 2025-08-21 02:23:11 -07:00
cleanup
This commit is contained in:
parent
bc62766bef
commit
e58dfc8074
3 changed files with 429 additions and 430 deletions
|
@ -176,4 +176,3 @@ textarea {
|
|||
#messages li.error {
|
||||
background:rgba(102,8,0,0.8);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,19 +5,19 @@
|
|||
var haste_document = function(app) {
|
||||
this.locked = false;
|
||||
this.app = app;
|
||||
};
|
||||
};
|
||||
|
||||
// Escapes HTML tag characters
|
||||
haste_document.prototype.htmlEscape = function(s) {
|
||||
// Escapes HTML tag characters
|
||||
haste_document.prototype.htmlEscape = function(s) {
|
||||
return s
|
||||
.replace(/&/g, '&')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/</g, '<')
|
||||
.replace(/"/g, '"');
|
||||
};
|
||||
};
|
||||
|
||||
// Get this document from the server and lock it here
|
||||
haste_document.prototype.load = function(key, callback, lang) {
|
||||
// Get this document from the server and lock it here
|
||||
haste_document.prototype.load = function(key, callback, lang) {
|
||||
var _this = this;
|
||||
var selectedLines = this.app.selectedLines;
|
||||
$.ajax(_this.app.baseUrl + 'documents/' + key, {
|
||||
|
@ -77,10 +77,10 @@ var haste_document = function(app) {
|
|||
callback(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
// Save this document to the server and lock it here
|
||||
haste_document.prototype.save = function(data, callback) {
|
||||
// Save this document to the server and lock it here
|
||||
haste_document.prototype.save = function(data, callback) {
|
||||
if (this.locked) {
|
||||
return false;
|
||||
}
|
||||
|
@ -111,11 +111,11 @@ var haste_document = function(app) {
|
|||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
///// represents the paste application
|
||||
///// represents the paste application
|
||||
|
||||
var haste = function(appName, options) {
|
||||
var haste = function(appName, options) {
|
||||
this.appName = appName;
|
||||
this.$textarea = $('textarea');
|
||||
this.$box = $('#box');
|
||||
|
@ -130,35 +130,35 @@ var haste_document = function(app) {
|
|||
};
|
||||
this.baseUrl = options.baseUrl || '/';
|
||||
this.selectedLines = options.selectedLines;
|
||||
};
|
||||
};
|
||||
|
||||
// Set the page title - include the appName
|
||||
haste.prototype.setTitle = function(ext) {
|
||||
// Set the page title - include the appName
|
||||
haste.prototype.setTitle = function(ext) {
|
||||
var title = ext ? this.appName + ' - ' + ext : this.appName;
|
||||
document.title = title;
|
||||
};
|
||||
};
|
||||
|
||||
// Show a message box
|
||||
haste.prototype.showMessage = function(msg, cls) {
|
||||
// Show a message box
|
||||
haste.prototype.showMessage = function(msg, cls) {
|
||||
var msgBox = $('<li class="'+(cls || 'info')+'">'+msg+'</li>');
|
||||
$('#messages').prepend(msgBox);
|
||||
setTimeout(function() {
|
||||
msgBox.slideUp('fast', function() { $(this).remove(); });
|
||||
}, 3000);
|
||||
};
|
||||
};
|
||||
|
||||
// Show the light key
|
||||
haste.prototype.lightKey = function() {
|
||||
// Show the light key
|
||||
haste.prototype.lightKey = function() {
|
||||
this.configureKey(['new', 'save']);
|
||||
};
|
||||
};
|
||||
|
||||
// Show the full key
|
||||
haste.prototype.fullKey = function() {
|
||||
// Show the full key
|
||||
haste.prototype.fullKey = function() {
|
||||
this.configureKey(['new', 'duplicate', 'twitter', 'raw']);
|
||||
};
|
||||
};
|
||||
|
||||
// Set the key up for certain things to be enabled
|
||||
haste.prototype.configureKey = function(enable) {
|
||||
// Set the key up for certain things to be enabled
|
||||
haste.prototype.configureKey = function(enable) {
|
||||
var $this, i = 0;
|
||||
$('#box2 .function').each(function() {
|
||||
$this = $(this);
|
||||
|
@ -170,11 +170,11 @@ var haste_document = function(app) {
|
|||
}
|
||||
$this.removeClass('enabled');
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
// Remove the current document (if there is one)
|
||||
// and set up for a new one
|
||||
haste.prototype.newDocument = function(hideHistory) {
|
||||
// Remove the current document (if there is one)
|
||||
// and set up for a new one
|
||||
haste.prototype.newDocument = function(hideHistory) {
|
||||
this.$box.hide();
|
||||
this.doc = new haste_document(this);
|
||||
if (!hideHistory) {
|
||||
|
@ -187,39 +187,39 @@ var haste_document = function(app) {
|
|||
});
|
||||
this.selectedLines = { startLine: null, endLine: null };
|
||||
this.removeLineNumbers();
|
||||
};
|
||||
};
|
||||
|
||||
// Map of common extensions
|
||||
// Note: this list does not need to include anything that IS its extension,
|
||||
// due to the behavior of lookupTypeByExtension and lookupExtensionByType
|
||||
// Note: optimized for lookupTypeByExtension
|
||||
haste.extensionMap = {
|
||||
// Map of common extensions
|
||||
// Note: this list does not need to include anything that IS its extension,
|
||||
// due to the behavior of lookupTypeByExtension and lookupExtensionByType
|
||||
// Note: optimized for lookupTypeByExtension
|
||||
haste.extensionMap = {
|
||||
rb: 'ruby', py: 'python', pl: 'perl', php: 'php', scala: 'scala', go: 'go',
|
||||
xml: 'xml', html: 'xml', htm: 'xml', css: 'css', js: 'javascript', vbs: 'vbscript',
|
||||
lua: 'lua', pas: 'delphi', java: 'java', cpp: 'cpp', cc: 'cpp', m: 'objectivec',
|
||||
vala: 'vala', sql: 'sql', sm: 'smalltalk', lisp: 'lisp', ini: 'ini',
|
||||
diff: 'diff', bash: 'bash', sh: 'bash', tex: 'tex', erl: 'erlang', hs: 'haskell',
|
||||
md: 'markdown', txt: '', coffee: 'coffee', swift: 'swift'
|
||||
};
|
||||
};
|
||||
|
||||
// Look up the extension preferred for a type
|
||||
// If not found, return the type itself - which we'll place as the extension
|
||||
haste.prototype.lookupExtensionByType = function(type) {
|
||||
// Look up the extension preferred for a type
|
||||
// If not found, return the type itself - which we'll place as the extension
|
||||
haste.prototype.lookupExtensionByType = function(type) {
|
||||
for (var key in haste.extensionMap) {
|
||||
if (haste.extensionMap[key] === type) return key;
|
||||
}
|
||||
return type;
|
||||
};
|
||||
};
|
||||
|
||||
// Look up the type for a given extension
|
||||
// If not found, return the extension - which we'll attempt to use as the type
|
||||
haste.prototype.lookupTypeByExtension = function(ext) {
|
||||
// Look up the type for a given extension
|
||||
// If not found, return the extension - which we'll attempt to use as the type
|
||||
haste.prototype.lookupTypeByExtension = function(ext) {
|
||||
return haste.extensionMap[ext] || ext;
|
||||
};
|
||||
};
|
||||
|
||||
// Add line numbers to the document
|
||||
// For the specified number of lines
|
||||
haste.prototype.addLineNumbers = function(lineCount) {
|
||||
// Add line numbers to the document
|
||||
// For the specified number of lines
|
||||
haste.prototype.addLineNumbers = function(lineCount) {
|
||||
var h = '';
|
||||
for (var i = 0; i < lineCount; i++) {
|
||||
h +=
|
||||
|
@ -240,15 +240,15 @@ var haste_document = function(app) {
|
|||
"</span><br/>";
|
||||
}
|
||||
$('#linenos').html(h);
|
||||
};
|
||||
};
|
||||
|
||||
// Remove the line numbers
|
||||
haste.prototype.removeLineNumbers = function() {
|
||||
// Remove the line numbers
|
||||
haste.prototype.removeLineNumbers = function() {
|
||||
$('#linenos').html('>');
|
||||
};
|
||||
};
|
||||
|
||||
// Load a document and show it
|
||||
haste.prototype.loadDocument = function(key) {
|
||||
// Load a document and show it
|
||||
haste.prototype.loadDocument = function(key) {
|
||||
// Split the key up
|
||||
var parts = key.split('.', 2);
|
||||
// Ask for what we want
|
||||
|
@ -267,19 +267,19 @@ var haste_document = function(app) {
|
|||
_this.newDocument();
|
||||
}
|
||||
}, this.lookupTypeByExtension(parts[1]));
|
||||
};
|
||||
};
|
||||
|
||||
// Duplicate the current document - only if locked
|
||||
haste.prototype.duplicateDocument = function() {
|
||||
// Duplicate the current document - only if locked
|
||||
haste.prototype.duplicateDocument = function() {
|
||||
if (this.doc.locked) {
|
||||
var currentData = this.doc.data;
|
||||
this.newDocument();
|
||||
this.$textarea.val(currentData);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Lock the current document
|
||||
haste.prototype.lockDocument = function() {
|
||||
// Lock the current document
|
||||
haste.prototype.lockDocument = function() {
|
||||
var _this = this;
|
||||
this.doc.save(this.$textarea.val(), function(err, ret) {
|
||||
if (err) {
|
||||
|
@ -302,9 +302,9 @@ var haste_document = function(app) {
|
|||
_this.loadDocument(path.split('#')[0].split('/').slice(-1)[0]);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
haste.prototype.configureButtons = function() {
|
||||
haste.prototype.configureButtons = function() {
|
||||
var _this = this;
|
||||
this.buttons = [
|
||||
{
|
||||
|
@ -368,9 +368,9 @@ var haste_document = function(app) {
|
|||
for (var i = 0; i < this.buttons.length; i++) {
|
||||
this.configureButton(this.buttons[i]);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
haste.prototype.configureButton = function(options) {
|
||||
haste.prototype.configureButton = function(options) {
|
||||
// Handle the click action
|
||||
options.$where.click(function(evt) {
|
||||
evt.preventDefault();
|
||||
|
@ -390,10 +390,10 @@ var haste_document = function(app) {
|
|||
$('#box3').hide();
|
||||
$('#pointer').hide();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
// Configure keyboard shortcuts for the textarea
|
||||
haste.prototype.configureShortcuts = function() {
|
||||
// Configure keyboard shortcuts for the textarea
|
||||
haste.prototype.configureShortcuts = function() {
|
||||
var _this = this;
|
||||
$(document.body).keydown(function(evt) {
|
||||
var button;
|
||||
|
@ -406,10 +406,10 @@ var haste_document = function(app) {
|
|||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
///// Tab behavior in the textarea - 2 spaces per tab
|
||||
$(function() {
|
||||
///// Tab behavior in the textarea - 2 spaces per tab
|
||||
$(function() {
|
||||
|
||||
$('textarea').keydown(function(evt) {
|
||||
if (evt.keyCode === 9) {
|
||||
|
@ -442,4 +442,4 @@ var haste_document = function(app) {
|
|||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
|
@ -18,7 +18,7 @@
|
|||
var isHashChange=false;
|
||||
var isDragging=false;
|
||||
// Handle pops
|
||||
var handlePop = function (evt) {
|
||||
var handlePop = function(evt) {
|
||||
if (isHashChange||isDragging) {
|
||||
evt.preventDefault();
|
||||
// reset
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue