Support set url path and use relative url, move raphael to bower and fixed minor issue in history

This commit is contained in:
Cheng-Han, Wu
2016-02-16 20:08:44 -08:00
parent 3f2f063e9b
commit b2b1be3dda
22 changed files with 222 additions and 198 deletions

View File

@@ -1,5 +1,12 @@
//common
var domain = 'change this';
var domain = 'change this'; // domain name
var urlpath = ''; // sub url path, like: www.example.com/<urlpath>
var port = window.location.port;
var serverurl = window.location.protocol + '//' + domain + (port ? ':' + port : '') + (urlpath ? '/' + urlpath : '');
var noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
var noteurl = serverurl + '/' + noteid;
var checkAuth = false;
var profile = null;
var lastLoginState = getLoginState();
@@ -53,7 +60,7 @@ function checkIfAuth(yesCallback, noCallback) {
if (checkLoginStateChanged())
checkAuth = false;
if (!checkAuth || typeof cookieLoginState == 'undefined') {
$.get('/me')
$.get(serverurl + '/me')
.done(function (data) {
if (data && data.status == 'ok') {
profile = data;

View File

@@ -120,7 +120,7 @@ function parseHistoryCallback(list, notehistory) {
pin.removeClass('active');
}
//parse link to element a
a.attr('href', '/' + values.id);
a.attr('href', serverurl + '/' + values.id);
//parse tags
if (values.tags) {
var tags = values.tags;

View File

@@ -402,10 +402,11 @@ function exportToHTML(view) {
var tocAffix = $('#toc-affix').clone();
tocAffix.find('*').removeClass('active');
//generate html via template
$.get('/css/html.min.css', function (css) {
$.get('/views/html.hbs', function (data) {
$.get(serverurl + '/css/html.min.css', function (css) {
$.get(serverurl + '/views/html.hbs', function (data) {
var template = Handlebars.compile(data);
var context = {
url: serverurl,
title: title,
css: css,
html: src[0].outerHTML,
@@ -657,7 +658,7 @@ emojify.setConfig({
elements: ['script', 'textarea', 'a', 'pre', 'code', 'svg'],
classes: ['no-emojify']
},
img_dir: '/vendor/emojify/images',
img_dir: serverurl + '/vendor/emojify/images',
ignore_emoticons: true
});

View File

@@ -4,7 +4,7 @@ migrateHistoryFromTemp();
function migrateHistoryFromTemp() {
if (url('#tempid')) {
$.get('/temp', {
$.get(serverurl + '/temp', {
tempid: url('#tempid')
})
.done(function (data) {
@@ -57,7 +57,7 @@ function saveHistoryToCookie(notehistory) {
}
function saveHistoryToServer(notehistory) {
$.post('/history', {
$.post(serverurl + '/history', {
history: JSON.stringify(notehistory)
});
}
@@ -70,7 +70,7 @@ function saveCookieHistoryToStorage(callback) {
function saveStorageHistoryToServer(callback) {
var data = store.get('notehistory');
if (data) {
$.post('/history', {
$.post(serverurl + '/history', {
history: data
})
.done(function (data) {
@@ -80,7 +80,7 @@ function saveStorageHistoryToServer(callback) {
}
function saveCookieHistoryToServer(callback) {
$.post('/history', {
$.post(serverurl + '/history', {
history: Cookies.get('notehistory')
})
.done(function (data) {
@@ -112,13 +112,16 @@ function clearDuplicatedHistory(notehistory) {
}
function addHistory(id, text, time, tags, pinned, notehistory) {
notehistory.push({
id: id,
text: text,
time: time,
tags: tags,
pinned: pinned
});
// only add when note id exists
if (id) {
notehistory.push({
id: id,
text: text,
time: time,
tags: tags,
pinned: pinned
});
}
return notehistory;
}
@@ -145,7 +148,7 @@ function writeHistory(view) {
}
function writeHistoryToServer(view) {
$.get('/history')
$.get(serverurl + '/history')
.done(function (data) {
try {
if (data.history) {
@@ -223,8 +226,9 @@ function renderHistory(view) {
tags.push(rawtags[i].innerHTML);
}
//console.debug(tags);
var id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1];
return {
id: location.pathname.split('/')[1],
id: id,
text: title,
time: moment().format('MMMM Do YYYY, h:mm:ss a'),
tags: tags
@@ -260,7 +264,7 @@ function getHistory(callback) {
}
function getServerHistory(callback) {
$.get('/history')
$.get(serverurl + '/history')
.done(function (data) {
if (data.history) {
callback(data.history);
@@ -301,7 +305,7 @@ function parseHistory(list, callback) {
}
function parseServerToHistory(list, callback) {
$.get('/history')
$.get(serverurl + '/history')
.done(function (data) {
if (data.history) {
parseToHistory(list, data.history, callback);
@@ -340,7 +344,7 @@ function parseToHistory(list, notehistory, callback) {
notehistory[i].timestamp = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').valueOf();
notehistory[i].fromNow = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').fromNow();
notehistory[i].time = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').format('llll');
if (list.get('id', notehistory[i].id).length == 0)
if (notehistory[i].id && list.get('id', notehistory[i].id).length == 0)
list.add(notehistory[i]);
}
}

View File

@@ -288,7 +288,7 @@ var statusLength = null;
var statusKeymap = null;
var statusIndent = null;
$.get('/views/statusbar.html', function (template) {
$.get(serverurl + '/views/statusbar.html', function (template) {
statusBarTemplate = template;
});
@@ -994,9 +994,8 @@ function closestIndex(arr, closestTo) {
}
//button actions
var url = window.location.protocol + '//' + window.location.host + window.location.pathname;
//share
ui.toolbar.publish.attr("href", url + "/publish");
ui.toolbar.publish.attr("href", noteurl + "/publish");
//download
//markdown
ui.toolbar.download.markdown.click(function (e) {
@@ -1021,7 +1020,7 @@ ui.toolbar.export.dropbox.click(function () {
var options = {
files: [
{
'url': url + "/download",
'url': noteurl + "/download",
'filename': filename
}
],
@@ -1032,7 +1031,7 @@ ui.toolbar.export.dropbox.click(function () {
Dropbox.save(options);
});
//export to gist
ui.toolbar.export.gist.attr("href", url + "/gist");
ui.toolbar.export.gist.attr("href", noteurl + "/gist");
//import from dropbox
ui.toolbar.import.dropbox.click(function () {
var options = {
@@ -1064,9 +1063,9 @@ ui.toc.dropdown.click(function (e) {
});
//beta
//pdf
ui.toolbar.beta.pdf.attr("download", "").attr("href", url + "/pdf");
ui.toolbar.beta.pdf.attr("download", "").attr("href", noteurl + "/pdf");
//slide
ui.toolbar.beta.slide.attr("href", url + "/slide");
ui.toolbar.beta.slide.attr("href", noteurl + "/slide");
function scrollToTop() {
if (currentMode == modeType.both) {
@@ -1325,6 +1324,7 @@ function havePermission() {
//socket.io actions
var socket = io.connect({
path: urlpath ? '/' + urlpath + '/socket.io/' : '',
timeout: 10000 //10 secs to timeout
});
//overwrite original event for checking login state
@@ -2450,7 +2450,7 @@ $(editor.getInputField())
checkCursorMenu();
},
template: function (value) {
return '<img class="emoji" src="/vendor/emojify/images/' + value + '.png"></img> ' + value;
return '<img class="emoji" src="' + serverurl + '/vendor/emojify/images/' + value + '.png"></img> ' + value;
},
replace: function (value) {
return ':' + value + ':';