mirror of
https://github.com/seejohnrun/haste-server
synced 2025-08-20 13:13:10 -07:00
Add base url support (#140)
This commit is contained in:
parent
ccc5049b07
commit
b52b394bad
2 changed files with 18 additions and 14 deletions
|
@ -2,8 +2,9 @@
|
|||
|
||||
///// represents a single document
|
||||
|
||||
var haste_document = function() {
|
||||
var haste_document = function(app) {
|
||||
this.locked = false;
|
||||
this.app = app;
|
||||
};
|
||||
|
||||
// Escapes HTML tag characters
|
||||
|
@ -18,7 +19,7 @@ haste_document.prototype.htmlEscape = function(s) {
|
|||
// Get this document from the server and lock it here
|
||||
haste_document.prototype.load = function(key, callback, lang) {
|
||||
var _this = this;
|
||||
$.ajax('/documents/' + key, {
|
||||
$.ajax(_this.app.baseUrl + 'documents/' + key, {
|
||||
type: 'get',
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
|
@ -60,7 +61,7 @@ haste_document.prototype.save = function(data, callback) {
|
|||
}
|
||||
this.data = data;
|
||||
var _this = this;
|
||||
$.ajax('/documents', {
|
||||
$.ajax(_this.app.baseUrl + 'documents', {
|
||||
type: 'post',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
|
@ -101,7 +102,8 @@ var haste = function(appName, options) {
|
|||
// If twitter is disabled, hide the button
|
||||
if (!options.twitter) {
|
||||
$('#box2 .twitter').hide();
|
||||
}
|
||||
};
|
||||
this.baseUrl = options.baseUrl || '/';
|
||||
};
|
||||
|
||||
// Set the page title - include the appName
|
||||
|
@ -148,9 +150,9 @@ haste.prototype.configureKey = function(enable) {
|
|||
// and set up for a new one
|
||||
haste.prototype.newDocument = function(hideHistory) {
|
||||
this.$box.hide();
|
||||
this.doc = new haste_document();
|
||||
this.doc = new haste_document(this);
|
||||
if (!hideHistory) {
|
||||
window.history.pushState(null, this.appName, '/');
|
||||
window.history.pushState(null, this.appName, this.baseUrl);
|
||||
}
|
||||
this.setTitle();
|
||||
this.lightKey();
|
||||
|
@ -209,7 +211,7 @@ haste.prototype.loadDocument = function(key) {
|
|||
var parts = key.split('.', 2);
|
||||
// Ask for what we want
|
||||
var _this = this;
|
||||
_this.doc = new haste_document();
|
||||
_this.doc = new haste_document(this);
|
||||
_this.doc.load(parts[0], function(ret) {
|
||||
if (ret) {
|
||||
_this.$code.html(ret.value);
|
||||
|
@ -244,7 +246,7 @@ haste.prototype.lockDocument = function() {
|
|||
else if (ret) {
|
||||
_this.$code.html(ret.value);
|
||||
_this.setTitle(ret.key);
|
||||
var file = '/' + ret.key;
|
||||
var file = _this.baseUrl + ret.key;
|
||||
if (ret.language) {
|
||||
file += '.' + _this.lookupExtensionByType(ret.language);
|
||||
}
|
||||
|
@ -303,7 +305,7 @@ haste.prototype.configureButtons = function() {
|
|||
},
|
||||
shortcutDescription: 'control + shift + r',
|
||||
action: function() {
|
||||
window.location.href = '/raw/' + _this.doc.key;
|
||||
window.location.href = _this.baseUrl + 'raw/' + _this.doc.key;
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue