Add base url support
This commit is contained in:
parent
eb5c8eef6a
commit
98f917fd23
|
@ -1,7 +1,8 @@
|
|||
///// represents a single document
|
||||
|
||||
var haste_document = function() {
|
||||
var haste_document = function(app) {
|
||||
this.locked = false;
|
||||
this.app = app;
|
||||
};
|
||||
|
||||
// Escapes HTML tag characters
|
||||
|
@ -16,7 +17,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) {
|
||||
|
@ -58,7 +59,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',
|
||||
|
@ -99,7 +100,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
|
||||
|
@ -146,9 +148,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();
|
||||
|
@ -208,7 +210,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);
|
||||
|
@ -243,7 +245,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);
|
||||
}
|
||||
|
@ -302,7 +304,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;
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
var app = null;
|
||||
// Handle pops
|
||||
var handlePop = function(evt) {
|
||||
var path = evt.target.location.pathname;
|
||||
if (path === '/') { app.newDocument(true); }
|
||||
else { app.loadDocument(path.substring(1, path.length)); }
|
||||
var path = evt.target.location.href;
|
||||
if (path === app.baseUrl) { app.newDocument(true); }
|
||||
else { app.loadDocument(path.split('/').slice(-1)[0]); }
|
||||
};
|
||||
// Set up the pop state to handle loads, skipping the first load
|
||||
// to make chrome behave like others:
|
||||
|
@ -31,7 +31,9 @@
|
|||
}, 1000);
|
||||
// Construct app and load initial path
|
||||
$(function() {
|
||||
app = new haste('hastebin', { twitter: true });
|
||||
var baseUrl = window.location.href.split('/');
|
||||
baseUrl = baseUrl.slice(0, baseUrl.length - 1).join('/') + '/';
|
||||
app = new haste('hastebin', { twitter: true, baseUrl: baseUrl });
|
||||
handlePop({ target: window });
|
||||
});
|
||||
</script>
|
||||
|
@ -44,7 +46,7 @@
|
|||
<div id="key">
|
||||
<div id="pointer" style="display:none;"></div>
|
||||
<div id="box1">
|
||||
<a href="/about.md" class="logo"></a>
|
||||
<a href="about.md" class="logo"></a>
|
||||
</div>
|
||||
<div id="box2">
|
||||
<button class="save function button-picture">Save</button>
|
||||
|
|
Loading…
Reference in New Issue