This commit is contained in:
Colin 2024-07-24 15:08:48 -07:00
commit e58dfc8074
3 changed files with 429 additions and 430 deletions

View file

@ -176,4 +176,3 @@ textarea {
#messages li.error { #messages li.error {
background:rgba(102,8,0,0.8); background:rgba(102,8,0,0.8);
} }

View file

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

View file

@ -18,7 +18,7 @@
var isHashChange=false; var isHashChange=false;
var isDragging=false; var isDragging=false;
// Handle pops // Handle pops
var handlePop = function (evt) { var handlePop = function(evt) {
if (isHashChange||isDragging) { if (isHashChange||isDragging) {
evt.preventDefault(); evt.preventDefault();
// reset // reset