\
\
@@ -64,15 +64,16 @@ var options = {
})
]
};
-var historyList = new List('history', options);
+const historyList = new List('history', options);
migrateHistoryFromTempCallback = pageInit;
-loginStateChangeEvent = pageInit;
+setloginStateChangeEvent(pageInit);
+
pageInit();
function pageInit() {
checkIfAuth(
- function (data) {
+ data => {
$('.ui-signin').hide();
$('.ui-or').hide();
$('.ui-welcome').show();
@@ -83,7 +84,7 @@ function pageInit() {
$(".ui-history").click();
parseServerToHistory(historyList, parseHistoryCallback);
},
- function () {
+ () => {
$('.ui-signin').show();
$('.ui-or').show();
$('.ui-welcome').hide();
@@ -100,14 +101,14 @@ $(".masthead-nav li").click(function () {
$(this).addClass("active");
});
-$(".ui-home").click(function () {
+$(".ui-home").click(() => {
if (!$("#home").is(':visible')) {
$(".section:visible").hide();
$("#home").fadeIn();
}
});
-$(".ui-history").click(function () {
+$(".ui-history").click(() => {
if (!$("#history").is(':visible')) {
$(".section:visible").hide();
$("#history").fadeIn();
@@ -120,7 +121,7 @@ function checkHistoryList() {
$(".ui-import-from-browser").hide();
} else if ($("#history-list").children().length == 0) {
$(".ui-nohistory").slideDown();
- getStorageHistory(function (data) {
+ getStorageHistory(data => {
if (data && data.length > 0 && getLoginState() && historyList.items.length == 0) {
$(".ui-import-from-browser").slideDown();
}
@@ -130,35 +131,35 @@ function checkHistoryList() {
function parseHistoryCallback(list, notehistory) {
checkHistoryList();
- //sort by pinned then timestamp
- list.sort('', {
- sortFunction: function (a, b) {
- var notea = a.values();
- var noteb = b.values();
- if (notea.pinned && !noteb.pinned) {
+ //sort by pinned then timestamp
+ list.sort('', {
+ sortFunction(a, b) {
+ const notea = a.values();
+ const noteb = b.values();
+ if (notea.pinned && !noteb.pinned) {
return -1;
} else if (!notea.pinned && noteb.pinned) {
return 1;
} else {
- if (notea.timestamp > noteb.timestamp) {
- return -1;
- } else if (notea.timestamp < noteb.timestamp) {
- return 1;
- } else {
- return 0;
- }
- }
- }
- });
+ if (notea.timestamp > noteb.timestamp) {
+ return -1;
+ } else if (notea.timestamp < noteb.timestamp) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+ }
+ });
// parse filter tags
- var filtertags = [];
- for (var i = 0, l = list.items.length; i < l; i++) {
- var tags = list.items[i]._values.tags;
+ const filtertags = [];
+ for (let i = 0, l = list.items.length; i < l; i++) {
+ const tags = list.items[i]._values.tags;
if (tags && tags.length > 0) {
- for (var j = 0; j < tags.length; j++) {
+ for (let j = 0; j < tags.length; j++) {
//push info filtertags if not found
- var found = false;
- if (filtertags.indexOf(tags[j]) != -1)
+ let found = false;
+ if (filtertags.includes(tags[j]))
found = true;
if (!found)
filtertags.push(tags[j]);
@@ -169,17 +170,17 @@ function parseHistoryCallback(list, notehistory) {
}
// update items whenever list updated
-historyList.on('updated', function (e) {
- for (var i = 0, l = e.items.length; i < l; i++) {
- var item = e.items[i];
+historyList.on('updated', e => {
+ for (let i = 0, l = e.items.length; i < l; i++) {
+ const item = e.items[i];
if (item.visible()) {
- var itemEl = $(item.elm);
- var values = item._values;
- var a = itemEl.find("a");
- var pin = itemEl.find(".ui-history-pin");
- var tagsEl = itemEl.find(".tags");
+ const itemEl = $(item.elm);
+ const values = item._values;
+ const a = itemEl.find("a");
+ const pin = itemEl.find(".ui-history-pin");
+ const tagsEl = itemEl.find(".tags");
//parse link to element a
- a.attr('href', serverurl + '/' + values.id);
+ a.attr('href', `${serverurl}/${values.id}`);
//parse pinned
if (values.pinned) {
pin.addClass('active');
@@ -187,12 +188,12 @@ historyList.on('updated', function (e) {
pin.removeClass('active');
}
//parse tags
- var tags = values.tags;
+ const tags = values.tags;
if (tags && tags.length > 0 && tagsEl.children().length <= 0) {
- var labels = [];
- for (var j = 0; j < tags.length; j++) {
+ const labels = [];
+ for (let j = 0; j < tags.length; j++) {
//push into the item label
- labels.push("
" + tags[j] + "");
+ labels.push(`
${tags[j]}`);
}
tagsEl.html(labels.join(' '));
}
@@ -206,21 +207,21 @@ historyList.on('updated', function (e) {
function historyCloseClick(e) {
e.preventDefault();
- var id = $(this).closest("a").siblings("span").html();
- var value = historyList.get('id', id)[0]._values;
+ const id = $(this).closest("a").siblings("span").html();
+ const value = historyList.get('id', id)[0]._values;
$('.ui-delete-modal-msg').text('Do you really want to delete below history?');
- $('.ui-delete-modal-item').html('
' + value.text + '
' + value.time);
+ $('.ui-delete-modal-item').html(`
${value.text}
${value.time}`);
clearHistory = false;
deleteId = id;
}
function historyPinClick(e) {
e.preventDefault();
- var $this = $(this);
- var id = $this.closest("a").siblings("span").html();
- var item = historyList.get('id', id)[0];
- var values = item._values;
- var pinned = values.pinned;
+ const $this = $(this);
+ const id = $this.closest("a").siblings("span").html();
+ const item = historyList.get('id', id)[0];
+ const values = item._values;
+ let pinned = values.pinned;
if (!values.pinned) {
pinned = true;
item._values.pinned = true;
@@ -228,10 +229,10 @@ function historyPinClick(e) {
pinned = false;
item._values.pinned = false;
}
- checkIfAuth(function () {
+ checkIfAuth(() => {
postHistoryToServer(id, {
- pinned: pinned
- }, function (err, result) {
+ pinned
+ }, (err, result) => {
if (!err) {
if (pinned)
$this.addClass('active');
@@ -239,9 +240,9 @@ function historyPinClick(e) {
$this.removeClass('active');
}
});
- }, function () {
- getHistory(function (notehistory) {
- for(var i = 0; i < notehistory.length; i++) {
+ }, () => {
+ getHistory(notehistory => {
+ for(let i = 0; i < notehistory.length; i++) {
if (notehistory[i].id == id) {
notehistory[i].pinned = pinned;
break;
@@ -260,10 +261,10 @@ function historyPinClick(e) {
setInterval(updateItemFromNow, 60000);
function updateItemFromNow() {
- var items = $('.item').toArray();
- for (var i = 0; i < items.length; i++) {
- var item = $(items[i]);
- var timestamp = parseInt(item.find('.timestamp').text());
+ const items = $('.item').toArray();
+ for (let i = 0; i < items.length; i++) {
+ const item = $(items[i]);
+ const timestamp = parseInt(item.find('.timestamp').text());
item.find('.fromNow').text(moment(timestamp).fromNow());
}
}
@@ -272,8 +273,8 @@ var clearHistory = false;
var deleteId = null;
function deleteHistory() {
- checkIfAuth(function () {
- deleteServerHistory(deleteId, function (err, result) {
+ checkIfAuth(() => {
+ deleteServerHistory(deleteId, (err, result) => {
if (!err) {
if (clearHistory) {
historyList.clear();
@@ -287,7 +288,7 @@ function deleteHistory() {
deleteId = null;
clearHistory = false;
});
- }, function () {
+ }, () => {
if (clearHistory) {
saveHistory([]);
historyList.clear();
@@ -295,8 +296,8 @@ function deleteHistory() {
deleteId = null;
} else {
if (!deleteId) return;
- getHistory(function (notehistory) {
- var newnotehistory = removeHistory(deleteId, notehistory);
+ getHistory(notehistory => {
+ const newnotehistory = removeHistory(deleteId, notehistory);
saveHistory(newnotehistory);
historyList.remove('id', deleteId);
checkHistoryList();
@@ -308,36 +309,36 @@ function deleteHistory() {
});
}
-$(".ui-delete-modal-confirm").click(function () {
+$(".ui-delete-modal-confirm").click(() => {
deleteHistory();
});
-$(".ui-import-from-browser").click(function () {
- saveStorageHistoryToServer(function () {
+$(".ui-import-from-browser").click(() => {
+ saveStorageHistoryToServer(() => {
parseStorageToHistory(historyList, parseHistoryCallback);
});
});
-$(".ui-save-history").click(function () {
- getHistory(function (data) {
- var history = JSON.stringify(data);
- var blob = new Blob([history], {
+$(".ui-save-history").click(() => {
+ getHistory(data => {
+ const history = JSON.stringify(data);
+ const blob = new Blob([history], {
type: "application/json;charset=utf-8"
});
- saveAs(blob, 'hackmd_history_' + moment().format('YYYYMMDDHHmmss'));
+ saveAs(blob, `hackmd_history_${moment().format('YYYYMMDDHHmmss')}`);
});
});
-$(".ui-open-history").bind("change", function (e) {
- var files = e.target.files || e.dataTransfer.files;
- var file = files[0];
- var reader = new FileReader();
- reader.onload = function () {
- var notehistory = JSON.parse(reader.result);
+$(".ui-open-history").bind("change", e => {
+ const files = e.target.files || e.dataTransfer.files;
+ const file = files[0];
+ const reader = new FileReader();
+ reader.onload = () => {
+ const notehistory = JSON.parse(reader.result);
//console.log(notehistory);
if (!reader.result) return;
- getHistory(function (data) {
- var mergedata = data.concat(notehistory);
+ getHistory(data => {
+ let mergedata = data.concat(notehistory);
mergedata = clearDuplicatedHistory(mergedata);
saveHistory(mergedata);
parseHistory(historyList, parseHistoryCallback);
@@ -347,18 +348,18 @@ $(".ui-open-history").bind("change", function (e) {
reader.readAsText(file);
});
-$(".ui-clear-history").click(function () {
+$(".ui-clear-history").click(() => {
$('.ui-delete-modal-msg').text('Do you really want to clear all history?');
$('.ui-delete-modal-item').html('There is no turning back.');
clearHistory = true;
deleteId = null;
});
-$(".ui-refresh-history").click(function () {
- var lastTags = $(".ui-use-tags").select2('val');
+$(".ui-refresh-history").click(() => {
+ const lastTags = $(".ui-use-tags").select2('val');
$(".ui-use-tags").select2('val', '');
historyList.filter();
- var lastKeyword = $('.search').val();
+ const lastKeyword = $('.search').val();
$('.search').val('');
historyList.search();
$('#history-list').slideUp('fast');
@@ -366,7 +367,7 @@ $(".ui-refresh-history").click(function () {
resetCheckAuth();
historyList.clear();
- parseHistory(historyList, function (list, notehistory) {
+ parseHistory(historyList, (list, notehistory) => {
parseHistoryCallback(list, notehistory);
$(".ui-use-tags").select2('val', lastTags);
$(".ui-use-tags").trigger('change');
@@ -378,16 +379,16 @@ $(".ui-refresh-history").click(function () {
});
});
-$(".ui-logout").click(function () {
+$(".ui-logout").click(() => {
clearLoginState();
- location.href = serverurl + '/logout';
+ location.href = `${serverurl}/logout`;
});
-var filtertags = [];
+let filtertags = [];
$(".ui-use-tags").select2({
placeholder: $(".ui-use-tags").attr('placeholder'),
multiple: true,
- data: function () {
+ data() {
return {
results: filtertags
};
@@ -397,7 +398,7 @@ $('.select2-input').css('width', 'inherit');
buildTagsFilter([]);
function buildTagsFilter(tags) {
- for (var i = 0; i < tags.length; i++)
+ for (let i = 0; i < tags.length; i++)
tags[i] = {
id: i,
text: S(tags[i]).unescapeHTML().s
@@ -405,17 +406,17 @@ function buildTagsFilter(tags) {
filtertags = tags;
}
$(".ui-use-tags").on('change', function () {
- var tags = [];
- var data = $(this).select2('data');
- for (var i = 0; i < data.length; i++)
+ const tags = [];
+ const data = $(this).select2('data');
+ for (let i = 0; i < data.length; i++)
tags.push(data[i].text);
if (tags.length > 0) {
- historyList.filter(function (item) {
- var values = item.values();
+ historyList.filter(item => {
+ const values = item.values();
if (!values.tags) return false;
- var found = false;
- for (var i = 0; i < tags.length; i++) {
- if (values.tags.indexOf(tags[i]) != -1) {
+ let found = false;
+ for (let i = 0; i < tags.length; i++) {
+ if (values.tags.includes(tags[i])) {
found = true;
break;
}
@@ -428,6 +429,6 @@ $(".ui-use-tags").on('change', function () {
checkHistoryList();
});
-$('.search').keyup(function () {
+$('.search').keyup(() => {
checkHistoryList();
});
--
cgit v1.2.3
From fce08cc164bb1ecc6b986fe6630381b630a1508c Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Thu, 5 Jan 2017 20:56:16 +0800
Subject: Convert history.js to es6
---
public/js/cover.js | 29 ++++----
public/js/history.js | 204 +++++++++++++++++++++++----------------------------
public/js/index.js | 13 ++--
3 files changed, 113 insertions(+), 133 deletions(-)
(limited to 'public/js')
diff --git a/public/js/cover.js b/public/js/cover.js
index ecb385ed..677d82eb 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -11,20 +11,21 @@ import {
setloginStateChangeEvent
} from './common';
-import historyModule from './history';
-const parseStorageToHistory = historyModule.parseStorageToHistory;
-const parseHistory = historyModule.parseHistory;
-const getStorageHistory = historyModule.getStorageHistory;
-const getHistory = historyModule.getHistory;
-const saveHistory = historyModule.saveHistory;
-const removeHistory = historyModule.removeHistory;
-const postHistoryToServer = historyModule.postHistoryToServer;
-const deleteServerHistory = historyModule.deleteServerHistory;
-const parseServerToHistory = historyModule.parseServerToHistory;
-const saveStorageHistoryToServer = historyModule.saveStorageHistoryToServer;
-const clearDuplicatedHistory = historyModule.clearDuplicatedHistory;
-
-import {saveAs} from 'file-saver';
+import {
+ clearDuplicatedHistory,
+ deleteServerHistory,
+ getHistory,
+ getStorageHistory,
+ parseHistory,
+ parseServerToHistory,
+ parseStorageToHistory,
+ postHistoryToServer,
+ removeHistory,
+ saveHistory,
+ saveStorageHistoryToServer
+} from './history';
+
+import { saveAs } from 'file-saver';
import List from 'list.js';
import S from 'string';
diff --git a/public/js/history.js b/public/js/history.js
index 6972f24c..f1201683 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -1,10 +1,9 @@
-var store = require('store');
-var S = require('string');
-
-var common = require('./common');
-var checkIfAuth = common.checkIfAuth;
-var urlpath = common.urlpath;
-var getLoginState = common.getLoginState;
+import store from 'store';
+import S from 'string';
+import {
+ checkIfAuth,
+ urlpath
+} from './common';
window.migrateHistoryFromTempCallback = null;
@@ -12,22 +11,22 @@ migrateHistoryFromTemp();
function migrateHistoryFromTemp() {
if (url('#tempid')) {
- $.get(serverurl + '/temp', {
+ $.get(`${serverurl}/temp`, {
tempid: url('#tempid')
})
- .done(function (data) {
+ .done(data => {
if (data && data.temp) {
- getStorageHistory(function (olddata) {
+ getStorageHistory(olddata => {
if (!olddata || olddata.length == 0) {
saveHistoryToStorage(JSON.parse(data.temp));
}
});
}
})
- .always(function () {
- var hash = location.hash.split('#')[1];
+ .always(() => {
+ let hash = location.hash.split('#')[1];
hash = hash.split('&');
- for (var i = 0; i < hash.length; i++)
+ for (let i = 0; i < hash.length; i++)
if (hash[i].indexOf('tempid') == 0) {
hash.splice(i, 1);
i--;
@@ -40,12 +39,12 @@ function migrateHistoryFromTemp() {
}
}
-function saveHistory(notehistory) {
+export function saveHistory(notehistory) {
checkIfAuth(
- function () {
+ () => {
saveHistoryToServer(notehistory);
},
- function () {
+ () => {
saveHistoryToStorage(notehistory);
}
);
@@ -65,7 +64,7 @@ function saveHistoryToCookie(notehistory) {
}
function saveHistoryToServer(notehistory) {
- $.post(serverurl + '/history', {
+ $.post(`${serverurl}/history`, {
history: JSON.stringify(notehistory)
});
}
@@ -75,37 +74,37 @@ function saveCookieHistoryToStorage(callback) {
callback();
}
-function saveStorageHistoryToServer(callback) {
- var data = store.get('notehistory');
+export function saveStorageHistoryToServer(callback) {
+ const data = store.get('notehistory');
if (data) {
- $.post(serverurl + '/history', {
+ $.post(`${serverurl}/history`, {
history: data
})
- .done(function (data) {
+ .done(data => {
callback(data);
});
}
}
function saveCookieHistoryToServer(callback) {
- $.post(serverurl + '/history', {
+ $.post(`${serverurl}/history`, {
history: Cookies.get('notehistory')
})
- .done(function (data) {
+ .done(data => {
callback(data);
});
}
-function clearDuplicatedHistory(notehistory) {
- var newnotehistory = [];
- for (var i = 0; i < notehistory.length; i++) {
- var found = false;
- for (var j = 0; j < newnotehistory.length; j++) {
- var id = notehistory[i].id.replace(/\=+$/, '');
- var newId = newnotehistory[j].id.replace(/\=+$/, '');
+export function clearDuplicatedHistory(notehistory) {
+ const newnotehistory = [];
+ for (let i = 0; i < notehistory.length; i++) {
+ let found = false;
+ for (let j = 0; j < newnotehistory.length; j++) {
+ const id = notehistory[i].id.replace(/\=+$/, '');
+ const newId = newnotehistory[j].id.replace(/\=+$/, '');
if (id == newId || notehistory[i].id == newnotehistory[j].id || !notehistory[i].id || !newnotehistory[j].id) {
- var time = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
- var newTime = (typeof newnotehistory[i].time === 'number' ? moment(newnotehistory[i].time) : moment(newnotehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
+ const time = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
+ const newTime = (typeof newnotehistory[i].time === 'number' ? moment(newnotehistory[i].time) : moment(newnotehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
if(time >= newTime) {
newnotehistory[j] = notehistory[i];
}
@@ -123,42 +122,42 @@ function addHistory(id, text, time, tags, pinned, notehistory) {
// only add when note id exists
if (id) {
notehistory.push({
- id: id,
- text: text,
- time: time,
- tags: tags,
- pinned: pinned
+ id,
+ text,
+ time,
+ tags,
+ pinned
});
}
return notehistory;
}
-function removeHistory(id, notehistory) {
- for (var i = 0; i < notehistory.length; i++) {
+export function removeHistory(id, notehistory) {
+ for (let i = 0; i < notehistory.length; i++) {
if (notehistory[i].id == id) {
notehistory.splice(i, 1);
- i--;
- }
+ i -= 1;
+ }
}
return notehistory;
}
//used for inner
-function writeHistory(title, tags) {
+export function writeHistory(title, tags) {
checkIfAuth(
- function () {
+ () => {
// no need to do this anymore, this will count from server-side
// writeHistoryToServer(title, tags);
},
- function () {
+ () => {
writeHistoryToStorage(title, tags);
}
);
}
function writeHistoryToServer(title, tags) {
- $.get(serverurl + '/history')
- .done(function (data) {
+ $.get(`${serverurl}/history`)
+ .done(data => {
try {
if (data.history) {
var notehistory = data.history;
@@ -171,10 +170,10 @@ function writeHistoryToServer(title, tags) {
if (!notehistory)
notehistory = [];
- var newnotehistory = generateHistory(title, tags, notehistory);
+ const newnotehistory = generateHistory(title, tags, notehistory);
saveHistoryToServer(newnotehistory);
})
- .fail(function (xhr, status, error) {
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
});
}
@@ -188,13 +187,13 @@ function writeHistoryToCookie(title, tags) {
if (!notehistory)
notehistory = [];
- var newnotehistory = generateHistory(title, tags, notehistory);
+ const newnotehistory = generateHistory(title, tags, notehistory);
saveHistoryToCookie(newnotehistory);
}
function writeHistoryToStorage(title, tags) {
if (store.enabled) {
- var data = store.get('notehistory');
+ let data = store.get('notehistory');
if (data) {
if (typeof data == "string")
data = JSON.parse(data);
@@ -204,7 +203,7 @@ function writeHistoryToStorage(title, tags) {
if (!notehistory)
notehistory = [];
- var newnotehistory = generateHistory(title, tags, notehistory);
+ const newnotehistory = generateHistory(title, tags, notehistory);
saveHistoryToStorage(newnotehistory);
} else {
writeHistoryToCookie(title, tags);
@@ -212,32 +211,30 @@ function writeHistoryToStorage(title, tags) {
}
if (!Array.isArray) {
- Array.isArray = function(arg) {
- return Object.prototype.toString.call(arg) === '[object Array]';
- };
+ Array.isArray = arg => Object.prototype.toString.call(arg) === '[object Array]';
}
function renderHistory(title, tags) {
//console.debug(tags);
- var id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1];
+ const id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1];
return {
- id: id,
+ id,
text: title,
time: moment().valueOf(),
- tags: tags
+ tags
};
}
function generateHistory(title, tags, notehistory) {
- var info = renderHistory(title, tags);
- //keep any pinned data
- var pinned = false;
- for (var i = 0; i < notehistory.length; i++) {
- if (notehistory[i].id == info.id && notehistory[i].pinned) {
- pinned = true;
- break;
- }
- }
+ const info = renderHistory(title, tags);
+ //keep any pinned data
+ let pinned = false;
+ for (let i = 0; i < notehistory.length; i++) {
+ if (notehistory[i].id == info.id && notehistory[i].pinned) {
+ pinned = true;
+ break;
+ }
+ }
notehistory = removeHistory(info.id, notehistory);
notehistory = addHistory(info.id, info.text, info.time, info.tags, pinned, notehistory);
notehistory = clearDuplicatedHistory(notehistory);
@@ -245,25 +242,25 @@ function generateHistory(title, tags, notehistory) {
}
//used for outer
-function getHistory(callback) {
+export function getHistory(callback) {
checkIfAuth(
- function () {
+ () => {
getServerHistory(callback);
},
- function () {
+ () => {
getStorageHistory(callback);
}
);
}
function getServerHistory(callback) {
- $.get(serverurl + '/history')
- .done(function (data) {
+ $.get(`${serverurl}/history`)
+ .done(data => {
if (data.history) {
callback(data.history);
}
})
- .fail(function (xhr, status, error) {
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
});
}
@@ -272,9 +269,9 @@ function getCookieHistory(callback) {
callback(Cookies.getJSON('notehistory'));
}
-function getStorageHistory(callback) {
+export function getStorageHistory(callback) {
if (store.enabled) {
- var data = store.get('notehistory');
+ let data = store.get('notehistory');
if (data) {
if (typeof data == "string")
data = JSON.parse(data);
@@ -286,37 +283,37 @@ function getStorageHistory(callback) {
}
}
-function parseHistory(list, callback) {
+export function parseHistory(list, callback) {
checkIfAuth(
- function () {
+ () => {
parseServerToHistory(list, callback);
},
- function () {
+ () => {
parseStorageToHistory(list, callback);
}
);
}
-function parseServerToHistory(list, callback) {
- $.get(serverurl + '/history')
- .done(function (data) {
+export function parseServerToHistory(list, callback) {
+ $.get(`${serverurl}/history`)
+ .done(data => {
if (data.history) {
parseToHistory(list, data.history, callback);
}
})
- .fail(function (xhr, status, error) {
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
});
}
function parseCookieToHistory(list, callback) {
- var notehistory = Cookies.getJSON('notehistory');
+ const notehistory = Cookies.getJSON('notehistory');
parseToHistory(list, notehistory, callback);
}
-function parseStorageToHistory(list, callback) {
+export function parseStorageToHistory(list, callback) {
if (store.enabled) {
- var data = store.get('notehistory');
+ let data = store.get('notehistory');
if (data) {
if (typeof data == "string")
data = JSON.parse(data);
@@ -332,9 +329,9 @@ function parseToHistory(list, notehistory, callback) {
if (!callback) return;
else if (!list || !notehistory) callback(list, notehistory);
else if (notehistory && notehistory.length > 0) {
- for (var i = 0; i < notehistory.length; i++) {
+ for (let i = 0; i < notehistory.length; i++) {
//parse time to timestamp and fromNow
- var timestamp = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
+ const timestamp = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
notehistory[i].timestamp = timestamp.valueOf();
notehistory[i].fromNow = timestamp.fromNow();
notehistory[i].time = timestamp.format('llll');
@@ -349,42 +346,23 @@ function parseToHistory(list, notehistory, callback) {
callback(list, notehistory);
}
-function postHistoryToServer(noteId, data, callback) {
- $.post(serverurl + '/history/' + noteId, data)
- .done(function (result) {
- return callback(null, result);
- })
- .fail(function (xhr, status, error) {
+export function postHistoryToServer(noteId, data, callback) {
+ $.post(`${serverurl}/history/${noteId}`, data)
+ .done(result => callback(null, result))
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
return callback(error, null);
});
}
-function deleteServerHistory(noteId, callback) {
+export function deleteServerHistory(noteId, callback) {
$.ajax({
- url: serverurl + '/history' + (noteId ? '/' + noteId : ""),
+ url: `${serverurl}/history${noteId ? '/' + noteId : ""}`,
type: 'DELETE'
})
- .done(function (result) {
- return callback(null, result);
- })
- .fail(function (xhr, status, error) {
+ .done(result => callback(null, result))
+ .fail((xhr, status, error) => {
console.error(xhr.responseText);
return callback(error, null);
});
}
-
-module.exports = {
- writeHistory: writeHistory,
- parseHistory: parseHistory,
- getStorageHistory: getStorageHistory,
- getHistory: getHistory,
- saveHistory: saveHistory,
- removeHistory: removeHistory,
- parseStorageToHistory: parseStorageToHistory,
- postHistoryToServer: postHistoryToServer,
- deleteServerHistory: deleteServerHistory,
- parseServerToHistory: parseServerToHistory,
- saveStorageHistoryToServer: saveStorageHistoryToServer,
- clearDuplicatedHistory: clearDuplicatedHistory
-}
diff --git a/public/js/index.js b/public/js/index.js
index 7406c9a2..660f73e4 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -59,12 +59,13 @@ import {
syncScrollToView
} from './syncscroll';
-var historyModule = require('./history');
-var writeHistory = historyModule.writeHistory;
-var deleteServerHistory = historyModule.deleteServerHistory;
-var getHistory = historyModule.getHistory;
-var saveHistory = historyModule.saveHistory;
-var removeHistory = historyModule.removeHistory;
+import {
+ writeHistory,
+ deleteServerHistory,
+ getHistory,
+ saveHistory,
+ removeHistory
+} from './history';
var renderer = require('./render');
var preventXSS = renderer.preventXSS;
--
cgit v1.2.3
From c2a8911b9c7872ea0d085020aa17e82162130f3d Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Fri, 13 Jan 2017 22:46:38 +0800
Subject: Move config variable to lib/config
---
public/js/common.js | 25 +------------------------
public/js/lib/config/index.js | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 24 deletions(-)
create mode 100644 public/js/lib/config/index.js
(limited to 'public/js')
diff --git a/public/js/common.js b/public/js/common.js
index 6d54b450..9a60122b 100644
--- a/public/js/common.js
+++ b/public/js/common.js
@@ -1,21 +1,4 @@
-// import config from './config';
-
-import {
- domain, // domain name
- urlpath, // sub url path, like: www.example.com/
- debug,
- GOOGLE_API_KEY,
- GOOGLE_CLIENT_ID,
- DROPBOX_APP_KEY
-} from './config';
-
-//common
-export const port = window.location.port;
-window.serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
-export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
-export const noteurl = `${serverurl}/${noteid}`;
-
-export const version = '0.5.0';
+import { serverurl } from './lib/config';
let checkAuth = false;
let profile = null;
@@ -101,12 +84,6 @@ export function checkIfAuth(yesCallback, noCallback) {
}
export default {
- domain,
- urlpath,
- debug,
- GOOGLE_API_KEY,
- GOOGLE_CLIENT_ID,
- DROPBOX_APP_KEY,
checkAuth,
profile,
lastLoginState,
diff --git a/public/js/lib/config/index.js b/public/js/lib/config/index.js
new file mode 100644
index 00000000..bffbadd9
--- /dev/null
+++ b/public/js/lib/config/index.js
@@ -0,0 +1,19 @@
+import configJson from '../../../../config.json'; // root path json config
+
+const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development;
+
+export const GOOGLE_API_KEY = config.google && config.google.apiKey;
+export const GOOGLE_CLIENT_ID = config.google && config.google.clientID
+export const DROPBOX_APP_KEY = config.dropbox && config.dropbox.appKey
+
+export const domain = config.domain;
+export const urlpath = config.urlpath;
+export const debug = config.debug;
+
+export const port = window.location.port;
+export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
+window.serverurl = serverurl;
+export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
+export const noteurl = `${serverurl}/${noteid}`;
+
+export const version = '0.5.0';
--
cgit v1.2.3
From 0fca629c34b83617b2d72e42aa0edb66fd2e71f6 Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Fri, 13 Jan 2017 22:51:44 +0800
Subject: Rename common.js to login.js
---
public/js/common.js | 92 -------------------------------------------
public/js/cover.js | 2 +-
public/js/extra.js | 2 +-
public/js/history.js | 8 +++-
public/js/index.js | 7 +++-
public/js/lib/common/login.js | 92 +++++++++++++++++++++++++++++++++++++++++++
6 files changed, 105 insertions(+), 98 deletions(-)
delete mode 100644 public/js/common.js
create mode 100644 public/js/lib/common/login.js
(limited to 'public/js')
diff --git a/public/js/common.js b/public/js/common.js
deleted file mode 100644
index 9a60122b..00000000
--- a/public/js/common.js
+++ /dev/null
@@ -1,92 +0,0 @@
-import { serverurl } from './lib/config';
-
-let checkAuth = false;
-let profile = null;
-let lastLoginState = getLoginState();
-let lastUserId = getUserId();
-let loginStateChangeEvent = null;
-
-export function setloginStateChangeEvent(func) {
- loginStateChangeEvent = func;
-}
-
-export function resetCheckAuth() {
- checkAuth = false;
-}
-
-export function setLoginState(bool, id) {
- Cookies.set('loginstate', bool, {
- expires: 365
- });
- if (id) {
- Cookies.set('userid', id, {
- expires: 365
- });
- } else {
- Cookies.remove('userid');
- }
- lastLoginState = bool;
- lastUserId = id;
- checkLoginStateChanged();
-}
-
-export function checkLoginStateChanged() {
- if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
- if(loginStateChangeEvent) {
- loginStateChangeEvent();
- }
- return true;
- } else {
- return false;
- }
-}
-
-export function getLoginState() {
- const state = Cookies.get('loginstate');
- return state === "true" || state === true;
-}
-
-export function getUserId() {
- return Cookies.get('userid');
-}
-
-export function clearLoginState() {
- Cookies.remove('loginstate');
-}
-
-export function checkIfAuth(yesCallback, noCallback) {
- const cookieLoginState = getLoginState();
- if (checkLoginStateChanged())
- checkAuth = false;
- if (!checkAuth || typeof cookieLoginState == 'undefined') {
- $.get(`${serverurl}/me`)
- .done(data => {
- if (data && data.status == 'ok') {
- profile = data;
- yesCallback(profile);
- setLoginState(true, data.id);
- } else {
- noCallback();
- setLoginState(false);
- }
- })
- .fail(() => {
- noCallback();
- })
- .always(() => {
- checkAuth = true;
- });
- } else if (cookieLoginState) {
- yesCallback(profile);
- } else {
- noCallback();
- }
-}
-
-export default {
- checkAuth,
- profile,
- lastLoginState,
- lastUserId,
- loginStateChangeEvent
-};
diff --git a/public/js/cover.js b/public/js/cover.js
index 677d82eb..bc04923b 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -9,7 +9,7 @@ import {
getLoginState,
resetCheckAuth,
setloginStateChangeEvent
-} from './common';
+} from './lib/common/login';
import {
clearDuplicatedHistory,
diff --git a/public/js/extra.js b/public/js/extra.js
index 6cfb5b0a..b651d9e6 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -11,7 +11,7 @@ import PDFObject from 'pdfobject';
import S from 'string';
import { saveAs } from 'file-saver';
-require('./common');
+require('./lib/common/login');
require('../vendor/md-toc');
var Viz = require("viz.js");
diff --git a/public/js/history.js b/public/js/history.js
index f1201683..34b2cba7 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -1,9 +1,13 @@
import store from 'store';
import S from 'string';
+
+import {
+ checkIfAuth
+} from './lib/common/login';
+
import {
- checkIfAuth,
urlpath
-} from './common';
+} from './lib/config';
window.migrateHistoryFromTempCallback = null;
diff --git a/public/js/index.js b/public/js/index.js
index 660f73e4..3bf42ad4 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -19,7 +19,10 @@ var List = require('list.js');
import {
checkLoginStateChanged,
- setloginStateChangeEvent,
+ setloginStateChangeEvent
+} from './lib/common/login';
+
+import {
debug,
DROPBOX_APP_KEY,
GOOGLE_API_KEY,
@@ -28,7 +31,7 @@ import {
noteurl,
urlpath,
version
-} from './common';
+} from './lib/config';
import {
autoLinkify,
diff --git a/public/js/lib/common/login.js b/public/js/lib/common/login.js
new file mode 100644
index 00000000..12cc41fc
--- /dev/null
+++ b/public/js/lib/common/login.js
@@ -0,0 +1,92 @@
+import { serverurl } from '../config';
+
+let checkAuth = false;
+let profile = null;
+let lastLoginState = getLoginState();
+let lastUserId = getUserId();
+let loginStateChangeEvent = null;
+
+export function setloginStateChangeEvent(func) {
+ loginStateChangeEvent = func;
+}
+
+export function resetCheckAuth() {
+ checkAuth = false;
+}
+
+export function setLoginState(bool, id) {
+ Cookies.set('loginstate', bool, {
+ expires: 365
+ });
+ if (id) {
+ Cookies.set('userid', id, {
+ expires: 365
+ });
+ } else {
+ Cookies.remove('userid');
+ }
+ lastLoginState = bool;
+ lastUserId = id;
+ checkLoginStateChanged();
+}
+
+export function checkLoginStateChanged() {
+ if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
+ if(loginStateChangeEvent) {
+ loginStateChangeEvent();
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+export function getLoginState() {
+ const state = Cookies.get('loginstate');
+ return state === "true" || state === true;
+}
+
+export function getUserId() {
+ return Cookies.get('userid');
+}
+
+export function clearLoginState() {
+ Cookies.remove('loginstate');
+}
+
+export function checkIfAuth(yesCallback, noCallback) {
+ const cookieLoginState = getLoginState();
+ if (checkLoginStateChanged())
+ checkAuth = false;
+ if (!checkAuth || typeof cookieLoginState == 'undefined') {
+ $.get(`${serverurl}/me`)
+ .done(data => {
+ if (data && data.status == 'ok') {
+ profile = data;
+ yesCallback(profile);
+ setLoginState(true, data.id);
+ } else {
+ noCallback();
+ setLoginState(false);
+ }
+ })
+ .fail(() => {
+ noCallback();
+ })
+ .always(() => {
+ checkAuth = true;
+ });
+ } else if (cookieLoginState) {
+ yesCallback(profile);
+ } else {
+ noCallback();
+ }
+}
+
+export default {
+ checkAuth,
+ profile,
+ lastLoginState,
+ lastUserId,
+ loginStateChangeEvent
+};
--
cgit v1.2.3
From 2408ff4ba96c929a575b34e85d5cff0a01789ca4 Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Fri, 13 Jan 2017 23:12:17 +0800
Subject: Add default value for config
---
public/js/lib/config/index.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'public/js')
diff --git a/public/js/lib/config/index.js b/public/js/lib/config/index.js
index bffbadd9..2b73679f 100644
--- a/public/js/lib/config/index.js
+++ b/public/js/lib/config/index.js
@@ -2,13 +2,13 @@ import configJson from '../../../../config.json'; // root path json config
const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development;
-export const GOOGLE_API_KEY = config.google && config.google.apiKey;
-export const GOOGLE_CLIENT_ID = config.google && config.google.clientID
-export const DROPBOX_APP_KEY = config.dropbox && config.dropbox.appKey
+export const GOOGLE_API_KEY = (config.google && config.google.apiKey) || '';
+export const GOOGLE_CLIENT_ID = (config.google && config.google.clientID) || '';
+export const DROPBOX_APP_KEY = (config.dropbox && config.dropbox.appKey) || '';
-export const domain = config.domain;
-export const urlpath = config.urlpath;
-export const debug = config.debug;
+export const domain = config.domain || ''; // domain name
+export const urlpath = config.urlpath || ''; // sub url path, like: www.example.com/
+export const debug = config.debug || false;
export const port = window.location.port;
export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
--
cgit v1.2.3
From a541569d7edbe827cae69c666079d5d1ded6790c Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Fri, 13 Jan 2017 23:12:27 +0800
Subject: Remove old config.js.example
---
public/js/config.js.example | 11 -----------
1 file changed, 11 deletions(-)
delete mode 100644 public/js/config.js.example
(limited to 'public/js')
diff --git a/public/js/config.js.example b/public/js/config.js.example
deleted file mode 100644
index c5de388f..00000000
--- a/public/js/config.js.example
+++ /dev/null
@@ -1,11 +0,0 @@
-module.exports = {
- domain: '', // domain name
- urlpath: '', // sub url path, like: www.example.com/
-
- // settings
- debug: false,
-
- GOOGLE_API_KEY: '',
- GOOGLE_CLIENT_ID: '',
- DROPBOX_APP_KEY: ''
-};
--
cgit v1.2.3
From 04292240d6a589c537afb8e9838dcc0f062d0f2c Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Sat, 14 Jan 2017 15:47:13 +0800
Subject: Minor style update
---
public/js/lib/common/login.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'public/js')
diff --git a/public/js/lib/common/login.js b/public/js/lib/common/login.js
index 12cc41fc..f1a03c72 100644
--- a/public/js/lib/common/login.js
+++ b/public/js/lib/common/login.js
@@ -32,7 +32,7 @@ export function setLoginState(bool, id) {
export function checkLoginStateChanged() {
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
- if(loginStateChangeEvent) {
+ if (loginStateChangeEvent) {
loginStateChangeEvent();
}
return true;
--
cgit v1.2.3
From 26d8942852f8d216d03138a6c3c1d350e6bc903e Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Sat, 21 Jan 2017 12:24:58 +0800
Subject: Revert experimental vue for now
---
public/js/components/HelloWorld.vue | 21 ---------------------
public/js/cover.js | 8 --------
public/js/views/Cover.vue | 15 ---------------
3 files changed, 44 deletions(-)
delete mode 100644 public/js/components/HelloWorld.vue
delete mode 100644 public/js/views/Cover.vue
(limited to 'public/js')
diff --git a/public/js/components/HelloWorld.vue b/public/js/components/HelloWorld.vue
deleted file mode 100644
index d8e3007f..00000000
--- a/public/js/components/HelloWorld.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-
- {{ message }}
-
-
-
-
-
diff --git a/public/js/cover.js b/public/js/cover.js
index 79b168d9..830564e8 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -29,14 +29,6 @@ import { saveAs } from 'file-saver';
import List from 'list.js';
import S from 'string';
-import Cover from './views/Cover';
-import Vue from 'vue';
-
-new Vue({
- el: '#cover-app',
- render: (h) => h(Cover)
-})
-
const options = {
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
item: '\
diff --git a/public/js/views/Cover.vue b/public/js/views/Cover.vue
deleted file mode 100644
index 767d087f..00000000
--- a/public/js/views/Cover.vue
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
--
cgit v1.2.3
From e98278492e3c80816d54e1a6841548409c8a4d80 Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Sat, 21 Jan 2017 12:50:02 +0800
Subject: Fix meta error not clear on before rendering
---
public/js/index.js | 1 +
public/js/pretty.js | 1 +
2 files changed, 2 insertions(+)
(limited to 'public/js')
diff --git a/public/js/index.js b/public/js/index.js
index a018e513..6e55fa17 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -3445,6 +3445,7 @@ function updateViewInner() {
var value = editor.getValue();
var lastMeta = md.meta;
md.meta = {};
+ delete md.metaError;
var rendered = md.render(value);
if (md.meta.type && md.meta.type === 'slide') {
var slideOptions = {
diff --git a/public/js/pretty.js b/public/js/pretty.js
index c1a471a1..b946d423 100644
--- a/public/js/pretty.js
+++ b/public/js/pretty.js
@@ -22,6 +22,7 @@ var markdown = $("#doc.markdown-body");
var text = markdown.text();
var lastMeta = md.meta;
md.meta = {};
+delete md.metaError;
var rendered = md.render(text);
if (md.meta.type && md.meta.type === 'slide') {
var slideOptions = {
--
cgit v1.2.3
From 3df5507589e09b9ec75fb1f8e0c750c6590fc003 Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Thu, 2 Feb 2017 23:27:34 +0800
Subject: Upgrade viz.js to fix manual workaround and get smaller file size
---
public/js/extra.js | 33 ++++++++++++---------------------
1 file changed, 12 insertions(+), 21 deletions(-)
(limited to 'public/js')
diff --git a/public/js/extra.js b/public/js/extra.js
index b651d9e6..b0a4bdcb 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -345,30 +345,21 @@ export function finishView(view) {
});
//graphviz
var graphvizs = view.find("div.graphviz.raw").removeClass("raw");
- function parseGraphviz(key, value) {
- var $value = $(value);
- var $ele = $(value).parent().parent();
-
- var graphviz = Viz($value.text());
- if (!graphviz) throw Error('viz.js output empty graph');
- $value.html(graphviz);
-
- $ele.addClass('graphviz');
- $value.children().unwrap().unwrap();
- }
graphvizs.each(function (key, value) {
try {
- parseGraphviz(key, value);
+ var $value = $(value);
+ var $ele = $(value).parent().parent();
+
+ var graphviz = Viz($value.text());
+ if (!graphviz) throw Error('viz.js output empty graph');
+ $value.html(graphviz);
+
+ $ele.addClass('graphviz');
+ $value.children().unwrap().unwrap();
} catch (err) {
- // workaround for graphviz not recover from error
- try {
- parseGraphviz(key, value);
- } catch (err) {
- var $value = $(value);
- $value.unwrap();
- $value.parent().append('' + err + '
');
- console.warn(err);
- }
+ $value.unwrap();
+ $value.parent().append('' + err + '
');
+ console.warn(err);
}
});
//mermaid
--
cgit v1.2.3
From e67a6ad3685289437e510906eeffb0d764ba4a37 Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Fri, 3 Feb 2017 00:07:08 +0800
Subject: Fix missing type declaration
---
public/js/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'public/js')
diff --git a/public/js/index.js b/public/js/index.js
index 39f28fbd..56f4fd38 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -2675,7 +2675,7 @@ editor.on('update', function () {
});
// clear tooltip which described element has been removed
$('[id^="tooltip"]').each(function (index, element) {
- $ele = $(element);
+ var $ele = $(element);
if ($('[aria-describedby="' + $ele.attr('id') + '"]').length <= 0) $ele.remove();
});
});
--
cgit v1.2.3
From 5a212b933548ccc5ef1cd45d8b86d7d86c8f7b9e Mon Sep 17 00:00:00 2001
From: NV
Date: Fri, 3 Feb 2017 17:35:16 +0900
Subject: Removed UTF-8 BOM in download function
---
public/js/cover.js | 2 +-
public/js/extra.js | 4 ++--
public/js/index.js | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
(limited to 'public/js')
diff --git a/public/js/cover.js b/public/js/cover.js
index 830564e8..bc6e73f9 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -325,7 +325,7 @@ $(".ui-save-history").click(() => {
const blob = new Blob([history], {
type: "application/json;charset=utf-8"
});
- saveAs(blob, `hackmd_history_${moment().format('YYYYMMDDHHmmss')}`);
+ saveAs(blob, `hackmd_history_${moment().format('YYYYMMDDHHmmss')}`, true);
});
});
diff --git a/public/js/extra.js b/public/js/extra.js
index b651d9e6..a657c311 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -612,7 +612,7 @@ export function exportToRawHTML(view) {
const blob = new Blob([html], {
type: "text/html;charset=utf-8"
});
- saveAs(blob, filename);
+ saveAs(blob, filename, true);
}
//extract markdown body to html and compile to template
@@ -644,7 +644,7 @@ export function exportToHTML(view) {
const blob = new Blob([html], {
type: "text/html;charset=utf-8"
});
- saveAs(blob, filename);
+ saveAs(blob, filename, true);
});
});
}
diff --git a/public/js/index.js b/public/js/index.js
index 39f28fbd..176f0da7 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -1542,7 +1542,7 @@ ui.toolbar.download.markdown.click(function (e) {
var blob = new Blob([markdown], {
type: "text/markdown;charset=utf-8"
});
- saveAs(blob, filename);
+ saveAs(blob, filename, true);
});
//html
ui.toolbar.download.html.click(function (e) {
@@ -1922,7 +1922,7 @@ $('#revisionModalDownload').click(function () {
var blob = new Blob([revision.content], {
type: "text/markdown;charset=utf-8"
});
- saveAs(blob, filename);
+ saveAs(blob, filename, true);
});
$('#revisionModalRevert').click(function () {
if (!revision) return;
--
cgit v1.2.3
From 0a3baec5b6bf6340fb7dfee3dce18807b01acfa6 Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Fri, 3 Feb 2017 21:59:26 +0800
Subject: Fix missing type declaration in text complete strategy
---
public/js/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'public/js')
diff --git a/public/js/index.js b/public/js/index.js
index dd26d379..9b42e79c 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -3953,7 +3953,7 @@ $(editor.getInputField())
match: /(?:^|\n|\s)(\>.*|\s|)((\^|)\[(\^|)\](\[\]|\(\)|\:|)\s*\w*)$/,
search: function (term, callback) {
var line = editor.getLine(editor.getCursor().line);
- quote = line.match(this.match)[1].trim();
+ var quote = line.match(this.match)[1].trim();
var list = [];
if (quote.indexOf('>') == 0) {
$.map(supportExtraTags, function (extratag) {
--
cgit v1.2.3
From 7863eec3660c7d78f9cfd5b3eee0585975faac6e Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Fri, 3 Feb 2017 22:01:30 +0800
Subject: Fix "[object HTMLCollection] is not iterable!" error in some browsers
---
public/js/extra.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'public/js')
diff --git a/public/js/extra.js b/public/js/extra.js
index 39812fd8..16235669 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -792,7 +792,8 @@ const anchorForId = id => {
const linkifyAnchors = (level, containingElement) => {
const headers = containingElement.getElementsByTagName(`h${level}`);
- for (const header of headers) {
+ for (let i = 0, l = headers.length; i < l; i++) {
+ let header = headers[i];
if (header.getElementsByClassName("anchor").length == 0) {
if (typeof header.id == "undefined" || header.id == "") {
//to escape characters not allow in css and humanize
--
cgit v1.2.3
From 1a617ddf2ee44e116a97e1bc0168af22a87d2102 Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Fri, 3 Feb 2017 22:02:12 +0800
Subject: Fix duplicated headers anchor link not been updated properly
---
public/js/extra.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'public/js')
diff --git a/public/js/extra.js b/public/js/extra.js
index 16235669..a3e840d2 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -833,7 +833,7 @@ export function deduplicatedHeaderId(view) {
const newId = id + j;
const $duplicatedHeader = $(duplicatedHeaders[j]);
$duplicatedHeader.attr('id', newId);
- const $headerLink = $duplicatedHeader.find('> .header-link');
+ const $headerLink = $duplicatedHeader.find(`> a.anchor[href="#${id}"]`);
$headerLink.attr('href', `#${newId}`);
$headerLink.attr('title', newId);
}
--
cgit v1.2.3
From 99a2cbc60461de724167c525cfc89d35c3480cec Mon Sep 17 00:00:00 2001
From: Max Wu
Date: Sat, 11 Feb 2017 00:11:21 +0800
Subject: Update google drive picker to enable setOwnedByMe to show shared
files and folders
---
public/js/google-drive-picker.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'public/js')
diff --git a/public/js/google-drive-picker.js b/public/js/google-drive-picker.js
index e653653c..94aa77ff 100644
--- a/public/js/google-drive-picker.js
+++ b/public/js/google-drive-picker.js
@@ -52,6 +52,7 @@
var view = new google.picker.DocsView();
view.setMimeTypes("text/markdown,text/html");
view.setIncludeFolders(true);
+ view.setOwnedByMe(true);
this.picker = new google.picker.PickerBuilder().
enableFeature(google.picker.Feature.NAV_HIDDEN).
addView(view).
@@ -115,4 +116,4 @@
}, callback ? callback : function() {});
}
};
-}());
\ No newline at end of file
+}());
--
cgit v1.2.3
From 1ca39d9c8e47ae2ce5a524504beb0aaed221a97c Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Fri, 17 Feb 2017 21:56:35 +0800
Subject: Update to allow li tag specify value number
---
public/js/render.js | 2 ++
1 file changed, 2 insertions(+)
(limited to 'public/js')
diff --git a/public/js/render.js b/public/js/render.js
index a61fc8fb..5d6d0aa2 100644
--- a/public/js/render.js
+++ b/public/js/render.js
@@ -9,6 +9,8 @@ var dataUriRegex = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base
var whiteList = filterXSS.whiteList;
// allow ol specify start number
whiteList['ol'] = ['start'];
+// allow li specify value number
+whiteList['li'] = ['value'];
// allow style tag
whiteList['style'] = [];
// allow kbd tag
--
cgit v1.2.3
From f7149f5a834ea79ec82f04ef2da257fe72f1b330 Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Sat, 18 Feb 2017 20:10:34 +0800
Subject: Fix to keep selections on save and restore info
---
public/js/index.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(limited to 'public/js')
diff --git a/public/js/index.js b/public/js/index.js
index 9b42e79c..3ad79d59 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -408,7 +408,8 @@ window.lastInfo = {
cursor: {
line: null,
ch: null
- }
+ },
+ selections: null
},
view: {
scroll: {
@@ -3394,6 +3395,7 @@ function saveInfo() {
break;
}
lastInfo.edit.cursor = editor.getCursor();
+ lastInfo.edit.selections = editor.listSelections();
lastInfo.needRestore = true;
}
@@ -3403,6 +3405,7 @@ function restoreInfo() {
var line = lastInfo.edit.cursor.line;
var ch = lastInfo.edit.cursor.ch;
editor.setCursor(line, ch);
+ editor.setSelections(lastInfo.edit.selections);
switch (currentMode) {
case modeType.edit:
if (scrollbarStyle == 'native') {
--
cgit v1.2.3
From 0aaa59813018847c765624bcd8cfa22e9aa57284 Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Sat, 18 Feb 2017 20:11:18 +0800
Subject: Fix not determine OT have pending operations properly
---
public/js/index.js | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
(limited to 'public/js')
diff --git a/public/js/index.js b/public/js/index.js
index 3ad79d59..f0c476ef 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -2519,7 +2519,7 @@ var addStyleRule = (function () {
}());
function updateAuthorshipInner() {
// ignore when ot not synced yet
- if (cmClient && Object.keys(cmClient.state).length > 0) return;
+ if (havePendingOperation()) return;
authorMarks = {};
for (var i = 0; i < authorship.length; i++) {
var atom = authorship[i];
@@ -2734,12 +2734,16 @@ var EditorClient = ot.EditorClient;
var SocketIOAdapter = ot.SocketIOAdapter;
var CodeMirrorAdapter = ot.CodeMirrorAdapter;
var cmClient = null;
+var synchronized_ = null;
+
+function havePendingOperation() {
+ return (cmClient && cmClient.state && cmClient.state.hasOwnProperty('outstanding')) ? true : false;
+}
socket.on('doc', function (obj) {
var body = obj.str;
var bodyMismatch = editor.getValue() !== body;
- var havePendingOperation = cmClient && Object.keys(cmClient.state).length > 0;
- var setDoc = !cmClient || (cmClient && (cmClient.revision === -1 || (cmClient.revision !== obj.revision && !havePendingOperation))) || obj.force;
+ var setDoc = !cmClient || (cmClient && (cmClient.revision === -1 || (cmClient.revision !== obj.revision && !havePendingOperation()))) || obj.force;
saveInfo();
if (setDoc && bodyMismatch) {
@@ -2764,16 +2768,17 @@ socket.on('doc', function (obj) {
obj.revision, obj.clients,
new SocketIOAdapter(socket), new CodeMirrorAdapter(editor)
);
+ synchronized_ = cmClient.state;
} else if (setDoc) {
if (bodyMismatch) {
cmClient.undoManager.undoStack.length = 0;
cmClient.undoManager.redoStack.length = 0;
}
cmClient.revision = obj.revision;
- cmClient.setState(new ot.Client.Synchronized());
+ cmClient.setState(synchronized_);
cmClient.initializeClientList();
cmClient.initializeClients(obj.clients);
- } else if (havePendingOperation) {
+ } else if (havePendingOperation()) {
cmClient.serverReconnect();
}
--
cgit v1.2.3