From d6ae7a36aeef3b5c261bb521f5e3f48898b65ede Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 24 Dec 2016 11:09:07 +0800 Subject: Fix module variable require --- public/js/index.js | 1 + 1 file changed, 1 insertion(+) (limited to 'public/js/index.js') diff --git a/public/js/index.js b/public/js/index.js index 96580fe3..4a466245 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -29,6 +29,7 @@ var DROPBOX_APP_KEY = common.DROPBOX_APP_KEY; var noteurl = common.noteurl; var checkLoginStateChanged = common.checkLoginStateChanged; +var loginStateChangeEvent = common.loginStateChangeEvent; var extra = require('./extra'); var md = extra.md; -- cgit v1.3.1 From 781f495f3e04b863be58226b5af8e6ab94d9355a Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Wed, 4 Jan 2017 23:01:44 +0800 Subject: Convert synscroll to es6 --- public/js/index.js | 12 ++-- public/js/syncscroll.js | 169 ++++++++++++++++++++++-------------------------- 2 files changed, 85 insertions(+), 96 deletions(-) (limited to 'public/js/index.js') diff --git a/public/js/index.js b/public/js/index.js index 8921eda3..46dfffd9 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -51,11 +51,12 @@ var parseMeta = extra.parseMeta; var exportToHTML = extra.exportToHTML; var exportToRawHTML = extra.exportToRawHTML; -var syncScroll = require('./syncscroll'); -var setupSyncAreas = syncScroll.setupSyncAreas; -var clearMap = syncScroll.clearMap; -var syncScrollToEdit = syncScroll.syncScrollToEdit; -var syncScrollToView = syncScroll.syncScrollToView; +import { + clearMap, + setupSyncAreas, + syncScrollToEdit, + syncScrollToView +} from './syncscroll'; var historyModule = require('./history'); var writeHistory = historyModule.writeHistory; @@ -3693,6 +3694,7 @@ function checkCursorMenuInner() { var offsetLeft = 0; var offsetTop = defaultTextHeight; // set up side down + window.upSideDown = false; var lastUpSideDown = upSideDown = false; // only do when have width and height if (width > 0 && height > 0) { diff --git a/public/js/syncscroll.js b/public/js/syncscroll.js index 47d0e1c4..c9693176 100644 --- a/public/js/syncscroll.js +++ b/public/js/syncscroll.js @@ -1,12 +1,13 @@ // Inject line numbers for sync scroll. -var extra = require('./extra'); -var md = extra.md; +import markdownitContainer from 'markdown-it-container'; + +import { md } from './extra'; function addPart(tokens, idx) { if (tokens[idx].map && tokens[idx].level === 0) { - var startline = tokens[idx].map[0] + 1; - var endline = tokens[idx].map[1]; + const startline = tokens[idx].map[0] + 1; + const endline = tokens[idx].map[1]; tokens[idx].attrJoin('class', 'part'); tokens[idx].attrJoin('data-startline', startline); tokens[idx].attrJoin('data-endline', endline); @@ -16,48 +17,48 @@ function addPart(tokens, idx) { md.renderer.rules.blockquote_open = function (tokens, idx, options, env, self) { tokens[idx].attrJoin('class', 'raw'); addPart(tokens, idx); - return self.renderToken.apply(self, arguments); + return self.renderToken(...arguments); }; md.renderer.rules.table_open = function (tokens, idx, options, env, self) { addPart(tokens, idx); - return self.renderToken.apply(self, arguments); + return self.renderToken(...arguments); }; md.renderer.rules.bullet_list_open = function (tokens, idx, options, env, self) { addPart(tokens, idx); - return self.renderToken.apply(self, arguments); + return self.renderToken(...arguments); }; md.renderer.rules.list_item_open = function (tokens, idx, options, env, self) { tokens[idx].attrJoin('class', 'raw'); if (tokens[idx].map) { - var startline = tokens[idx].map[0] + 1; - var endline = tokens[idx].map[1]; + const startline = tokens[idx].map[0] + 1; + const endline = tokens[idx].map[1]; tokens[idx].attrJoin('data-startline', startline); tokens[idx].attrJoin('data-endline', endline); } - return self.renderToken.apply(self, arguments); + return self.renderToken(...arguments); }; md.renderer.rules.ordered_list_open = function (tokens, idx, options, env, self) { addPart(tokens, idx); - return self.renderToken.apply(self, arguments); + return self.renderToken(...arguments); }; md.renderer.rules.link_open = function (tokens, idx, options, env, self) { addPart(tokens, idx); - return self.renderToken.apply(self, arguments); + return self.renderToken(...arguments); }; md.renderer.rules.paragraph_open = function (tokens, idx, options, env, self) { addPart(tokens, idx); - return self.renderToken.apply(self, arguments); + return self.renderToken(...arguments); }; md.renderer.rules.heading_open = function (tokens, idx, options, env, self) { tokens[idx].attrJoin('class', 'raw'); addPart(tokens, idx); - return self.renderToken.apply(self, arguments); + return self.renderToken(...arguments); }; -md.renderer.rules.fence = function (tokens, idx, options, env, self) { - var token = tokens[idx], - info = token.info ? md.utils.unescapeAll(token.info).trim() : '', - langName = '', - highlighted; +md.renderer.rules.fence = (tokens, idx, options, env, self) => { + const token = tokens[idx]; + const info = token.info ? md.utils.unescapeAll(token.info).trim() : ''; + let langName = ''; + let highlighted; if (info) { langName = info.split(/\s+/g)[0]; @@ -74,38 +75,33 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) { } if (highlighted.indexOf('
'
- + highlighted
- + '\n';
+ const startline = tokens[idx].map[0] + 1;
+ const endline = tokens[idx].map[1];
+ return `${highlighted}\n`;
}
- return ''
- + highlighted
- + '\n';
+ return `${highlighted}\n`;
};
-md.renderer.rules.code_block = function (tokens, idx, options, env, self) {
+md.renderer.rules.code_block = (tokens, idx, options, env, self) => {
if (tokens[idx].map && tokens[idx].level === 0) {
- var startline = tokens[idx].map[0] + 1;
- var endline = tokens[idx].map[1];
- return '' + md.utils.escapeHtml(tokens[idx].content) + '\n';
+ const startline = tokens[idx].map[0] + 1;
+ const endline = tokens[idx].map[1];
+ return `${md.utils.escapeHtml(tokens[idx].content)}\n`;
}
- return '' + md.utils.escapeHtml(tokens[idx].content) + '\n';
+ return `${md.utils.escapeHtml(tokens[idx].content)}\n`;
};
function renderContainer(tokens, idx, options, env, self) {
tokens[idx].attrJoin('role', 'alert');
tokens[idx].attrJoin('class', 'alert');
- tokens[idx].attrJoin('class', 'alert-' + tokens[idx].info.trim());
+ tokens[idx].attrJoin('class', `alert-${tokens[idx].info.trim()}`);
addPart(tokens, idx);
- return self.renderToken.apply(self, arguments);
+ return self.renderToken(...arguments);
}
-var markdownitContainer = require('markdown-it-container');
md.use(markdownitContainer, 'success', { render: renderContainer });
md.use(markdownitContainer, 'info', { render: renderContainer });
md.use(markdownitContainer, 'warning', { render: renderContainer });
@@ -117,18 +113,18 @@ window.syncscroll = true;
window.preventSyncScrollToEdit = false;
window.preventSyncScrollToView = false;
-var editScrollThrottle = 5;
-var viewScrollThrottle = 5;
-var buildMapThrottle = 100;
+const editScrollThrottle = 5;
+const viewScrollThrottle = 5;
+const buildMapThrottle = 100;
-var viewScrolling = false;
-var editScrolling = false;
+let viewScrolling = false;
+let editScrolling = false;
-var editArea = null;
-var viewArea = null;
-var markdownArea = null;
+let editArea = null;
+let viewArea = null;
+let markdownArea = null;
-function setupSyncAreas(edit, view, markdown) {
+export function setupSyncAreas(edit, view, markdown) {
editArea = edit;
viewArea = view;
markdownArea = markdown;
@@ -136,26 +132,24 @@ function setupSyncAreas(edit, view, markdown) {
viewArea.on('scroll', _.throttle(syncScrollToEdit, viewScrollThrottle));
}
-var scrollMap, lineHeightMap, viewTop, viewBottom;
-
-window.viewAjaxCallback = clearMap;
+let scrollMap, lineHeightMap, viewTop, viewBottom;
-function clearMap() {
+export function clearMap() {
scrollMap = null;
lineHeightMap = null;
viewTop = null;
viewBottom = null;
}
+window.viewAjaxCallback = clearMap;
-var buildMap = _.throttle(buildMapInner, buildMapThrottle);
+const buildMap = _.throttle(buildMapInner, buildMapThrottle);
// Build offsets for each line (lines can be wrapped)
// That's a bit dirty to process each line everytime, but ok for demo.
// Optimizations are required only for big texts.
function buildMapInner(callback) {
if (!viewArea || !markdownArea) return;
- var i, offset, nonEmptyList, pos, a, b, _lineHeightMap, linesCount,
- acc, _scrollMap;
+ let i, offset, nonEmptyList, pos, a, b, _lineHeightMap, linesCount, acc, _scrollMap;
offset = viewArea.scrollTop() - viewArea.offset().top;
_scrollMap = [];
@@ -165,10 +159,10 @@ function buildMapInner(callback) {
viewBottom = viewArea[0].scrollHeight - viewArea.height();
acc = 0;
- var lines = editor.getValue().split('\n');
- var lineHeight = editor.defaultTextHeight();
+ const lines = editor.getValue().split('\n');
+ const lineHeight = editor.defaultTextHeight();
for (i = 0; i < lines.length; i++) {
- var str = lines[i];
+ const str = lines[i];
_lineHeightMap.push(acc);
@@ -177,7 +171,7 @@ function buildMapInner(callback) {
continue;
}
- var h = editor.heightAtLine(i + 1) - editor.heightAtLine(i);
+ const h = editor.heightAtLine(i + 1) - editor.heightAtLine(i);
acc += Math.round(h / lineHeight);
}
_lineHeightMap.push(acc);
@@ -191,10 +185,10 @@ function buildMapInner(callback) {
// make the first line go top
_scrollMap[0] = viewTop;
- var parts = markdownArea.find('.part').toArray();
+ const parts = markdownArea.find('.part').toArray();
for (i = 0; i < parts.length; i++) {
- var $el = $(parts[i]),
- t = $el.attr('data-startline') - 1;
+ const $el = $(parts[i]);
+ let t = $el.attr('data-startline') - 1;
if (t === '') {
return;
}
@@ -229,9 +223,9 @@ function buildMapInner(callback) {
}
// sync view scroll progress to edit
-var viewScrollingTimer = null;
+let viewScrollingTimer = null;
-function syncScrollToEdit(event, preventAnimate) {
+export function syncScrollToEdit(event, preventAnimate) {
if (currentMode != modeType.both || !syncscroll || !editArea) return;
if (preventSyncScrollToEdit) {
if (typeof preventSyncScrollToEdit === 'number') {
@@ -242,15 +236,15 @@ function syncScrollToEdit(event, preventAnimate) {
return;
}
if (!scrollMap || !lineHeightMap) {
- buildMap(function () {
+ buildMap(() => {
syncScrollToEdit(event, preventAnimate);
});
return;
}
if (editScrolling) return;
- var scrollTop = viewArea[0].scrollTop;
- var lineIndex = 0;
+ const scrollTop = viewArea[0].scrollTop;
+ let lineIndex = 0;
for (var i = 0, l = scrollMap.length; i < l; i++) {
if (scrollMap[i] > scrollTop) {
break;
@@ -258,8 +252,8 @@ function syncScrollToEdit(event, preventAnimate) {
lineIndex = i;
}
}
- var lineNo = 0;
- var lineDiff = 0;
+ let lineNo = 0;
+ let lineDiff = 0;
for (var i = 0, l = lineHeightMap.length; i < l; i++) {
if (lineHeightMap[i] > lineIndex) {
break;
@@ -269,14 +263,14 @@ function syncScrollToEdit(event, preventAnimate) {
}
}
- var posTo = 0;
- var topDiffPercent = 0;
- var posToNextDiff = 0;
- var scrollInfo = editor.getScrollInfo();
- var textHeight = editor.defaultTextHeight();
- var preLastLineHeight = scrollInfo.height - scrollInfo.clientHeight - textHeight;
- var preLastLineNo = Math.round(preLastLineHeight / textHeight);
- var preLastLinePos = scrollMap[preLastLineNo];
+ let posTo = 0;
+ let topDiffPercent = 0;
+ let posToNextDiff = 0;
+ const scrollInfo = editor.getScrollInfo();
+ const textHeight = editor.defaultTextHeight();
+ const preLastLineHeight = scrollInfo.height - scrollInfo.clientHeight - textHeight;
+ const preLastLineNo = Math.round(preLastLineHeight / textHeight);
+ const preLastLinePos = scrollMap[preLastLineNo];
if (scrollInfo.height > scrollInfo.clientHeight && scrollTop >= preLastLinePos) {
posTo = preLastLineHeight;
@@ -293,7 +287,7 @@ function syncScrollToEdit(event, preventAnimate) {
if (preventAnimate) {
editArea.scrollTop(posTo);
} else {
- var posDiff = Math.abs(scrollInfo.top - posTo);
+ const posDiff = Math.abs(scrollInfo.top - posTo);
var duration = posDiff / 50;
duration = duration >= 100 ? duration : 100;
editArea.stop(true, true).animate({
@@ -311,9 +305,9 @@ function viewScrollingTimeoutInner() {
}
// sync edit scroll progress to view
-var editScrollingTimer = null;
+let editScrollingTimer = null;
-function syncScrollToView(event, preventAnimate) {
+export function syncScrollToView(event, preventAnimate) {
if (currentMode != modeType.both || !syncscroll || !viewArea) return;
if (preventSyncScrollToView) {
if (typeof preventSyncScrollToView === 'number') {
@@ -324,20 +318,20 @@ function syncScrollToView(event, preventAnimate) {
return;
}
if (!scrollMap || !lineHeightMap) {
- buildMap(function () {
+ buildMap(() => {
syncScrollToView(event, preventAnimate);
});
return;
}
if (viewScrolling) return;
- var lineNo, posTo;
- var topDiffPercent, posToNextDiff;
- var scrollInfo = editor.getScrollInfo();
- var textHeight = editor.defaultTextHeight();
+ let lineNo, posTo;
+ let topDiffPercent, posToNextDiff;
+ const scrollInfo = editor.getScrollInfo();
+ const textHeight = editor.defaultTextHeight();
lineNo = Math.floor(scrollInfo.top / textHeight);
// if reach the last line, will start lerp to the bottom
- var diffToBottom = (scrollInfo.top + scrollInfo.clientHeight) - (scrollInfo.height - textHeight);
+ const diffToBottom = (scrollInfo.top + scrollInfo.clientHeight) - (scrollInfo.height - textHeight);
if (scrollInfo.height > scrollInfo.clientHeight && diffToBottom > 0) {
topDiffPercent = diffToBottom / textHeight;
posTo = scrollMap[lineNo + 1];
@@ -353,7 +347,7 @@ function syncScrollToView(event, preventAnimate) {
if (preventAnimate) {
viewArea.scrollTop(posTo);
} else {
- var posDiff = Math.abs(viewArea.scrollTop() - posTo);
+ const posDiff = Math.abs(viewArea.scrollTop() - posTo);
var duration = posDiff / 50;
duration = duration >= 100 ? duration : 100;
viewArea.stop(true, true).animate({
@@ -369,10 +363,3 @@ function syncScrollToView(event, preventAnimate) {
function editScrollingTimeoutInner() {
editScrolling = false;
}
-
-module.exports = {
- setupSyncAreas: setupSyncAreas,
- clearMap: clearMap,
- syncScrollToEdit: syncScrollToEdit,
- syncScrollToView: syncScrollToView
-};
--
cgit v1.3.1
From 6a06c0bb9fea6d499d7fd2f7e6a65e16099cfb05 Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Thu, 5 Jan 2017 16:48:23 +0800
Subject: Convert common.js to es6
---
public/js/common.js | 107 +++++++++++++++++++++++++---------------------------
public/js/index.js | 28 +++++++-------
2 files changed, 65 insertions(+), 70 deletions(-)
(limited to 'public/js/index.js')
diff --git a/public/js/common.js b/public/js/common.js
index f5bfc8ec..6d54b450 100644
--- a/public/js/common.js
+++ b/public/js/common.js
@@ -1,30 +1,37 @@
-var config = require('./config');
-var domain = config.domain; // domain name
-var urlpath = config.urlpath; // sub url path, like: www.example.com/'
- + highlighted
- + '\n';
+ return `${highlighted}\n`;
};
/* Defined regex markdown it plugins */
-var Plugin = require('markdown-it-regexp');
+import Plugin from 'markdown-it-regexp';
//youtube
-var youtubePlugin = new Plugin(
+const youtubePlugin = new Plugin(
// regexp to match
/{%youtube\s*([\d\D]*?)\s*%}/,
- // this function will be called when something matches
- function (match, utils) {
- var videoid = match[1];
+ (match, utils) => {
+ const videoid = match[1];
if (!videoid) return;
- var div = $('');
+ const div = $('');
div.attr('data-videoid', videoid);
- var thumbnail_src = '//img.youtube.com/vi/' + videoid + '/hqdefault.jpg';
- var image = '';
+ (match, utils) => {
+ const gistid = match[1];
+ const code = ``;
return code;
}
);
//TOC
-var tocPlugin = new Plugin(
+const tocPlugin = new Plugin(
// regexp to match
/^\[TOC\]$/i,
- // this function will be called when something matches
- function (match, utils) {
- return '';
- }
+ (match, utils) => ''
);
//slideshare
-var slidesharePlugin = new Plugin(
+const slidesharePlugin = new Plugin(
// regexp to match
/{%slideshare\s*([\d\D]*?)\s*%}/,
- // this function will be called when something matches
- function (match, utils) {
- var slideshareid = match[1];
- var div = $('');
+ (match, utils) => {
+ const slideshareid = match[1];
+ const div = $('');
div.attr('data-slideshareid', slideshareid);
return div[0].outerHTML;
}
);
//speakerdeck
-var speakerdeckPlugin = new Plugin(
+const speakerdeckPlugin = new Plugin(
// regexp to match
/{%speakerdeck\s*([\d\D]*?)\s*%}/,
- // this function will be called when something matches
- function (match, utils) {
- var speakerdeckid = match[1];
- var div = $('');
+ (match, utils) => {
+ const speakerdeckid = match[1];
+ const div = $('');
div.attr('data-speakerdeckid', speakerdeckid);
return div[0].outerHTML;
}
);
//pdf
-var pdfPlugin = new Plugin(
+const pdfPlugin = new Plugin(
// regexp to match
/{%pdf\s*([\d\D]*?)\s*%}/,
- // this function will be called when something matches
- function (match, utils) {
- var pdfurl = match[1];
+ (match, utils) => {
+ const pdfurl = match[1];
if (!isValidURL(pdfurl)) return match[0];
- var div = $('');
+ const div = $('');
div.attr('data-pdfurl', pdfurl);
return div[0].outerHTML;
}
@@ -1090,8 +1081,8 @@ var pdfPlugin = new Plugin(
//yaml meta, from https://github.com/eugeneware/remarkable-meta
function get(state, line) {
- var pos = state.bMarks[line];
- var max = state.eMarks[line];
+ const pos = state.bMarks[line];
+ const max = state.eMarks[line];
return state.src.substr(pos, max - pos);
}
@@ -1100,9 +1091,9 @@ function meta(state, start, end, silent) {
if (state.tShift[start] < 0) return false;
if (!get(state, start).match(/^---$/)) return false;
- var data = [];
+ const data = [];
for (var line = start + 1; line < end; line++) {
- var str = get(state, line);
+ const str = get(state, line);
if (str.match(/^(\.{3}|-{3})$/)) break;
if (state.tShift[line] < 0) break;
data.push(str);
@@ -1138,24 +1129,6 @@ md.use(slidesharePlugin);
md.use(speakerdeckPlugin);
md.use(pdfPlugin);
-module.exports = {
- md: md,
- updateLastChange: updateLastChange,
- postProcess: postProcess,
- finishView: finishView,
- autoLinkify: autoLinkify,
- deduplicatedHeaderId: deduplicatedHeaderId,
- renderTOC: renderTOC,
- renderTitle: renderTitle,
- renderFilename: renderFilename,
- renderTags: renderTags,
- isValidURL: isValidURL,
- generateToc: generateToc,
- smoothHashScroll: smoothHashScroll,
- scrollToHash: scrollToHash,
- updateLastChangeUser: updateLastChangeUser,
- updateOwner: updateOwner,
- parseMeta: parseMeta,
- exportToHTML: exportToHTML,
- exportToRawHTML: exportToRawHTML
+export default {
+ md
};
diff --git a/public/js/index.js b/public/js/index.js
index 381f051e..7406c9a2 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -30,26 +30,27 @@ import {
version
} from './common';
-var extra = require('./extra');
-var md = extra.md;
-var updateLastChange = extra.updateLastChange;
-var postProcess = extra.postProcess;
-var finishView = extra.finishView;
-var autoLinkify = extra.autoLinkify;
-var generateToc = extra.generateToc;
-var smoothHashScroll = extra.smoothHashScroll;
-var deduplicatedHeaderId = extra.deduplicatedHeaderId;
-var renderTOC = extra.renderTOC;
-var renderTitle = extra.renderTitle;
-var renderFilename = extra.renderFilename;
-var renderTags = extra.renderTags;
-var isValidURL = extra.isValidURL;
-var scrollToHash = extra.scrollToHash;
-var updateLastChangeUser = extra.updateLastChangeUser;
-var updateOwner = extra.updateOwner;
-var parseMeta = extra.parseMeta;
-var exportToHTML = extra.exportToHTML;
-var exportToRawHTML = extra.exportToRawHTML;
+import {
+ autoLinkify,
+ deduplicatedHeaderId,
+ exportToHTML,
+ exportToRawHTML,
+ finishView,
+ generateToc,
+ isValidURL,
+ md,
+ parseMeta,
+ postProcess,
+ renderFilename,
+ renderTOC,
+ renderTags,
+ renderTitle,
+ scrollToHash,
+ smoothHashScroll,
+ updateLastChange,
+ updateLastChangeUser,
+ updateOwner
+} from './extra';
import {
clearMap,
--
cgit v1.3.1
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/index.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.3.1
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/index.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.3.1
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/index.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.3.1
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/index.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.3.1
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/index.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.3.1
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/index.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.3.1
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/index.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.3.1
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/index.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.3.1