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') 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.2.3
From eb5e7ba0d10cf559d73335102513b4c5783e239b Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Thu, 5 Jan 2017 16:17:28 +0800
Subject: Convert slide.js to es6
---
public/js/slide.js | 64 ++++++++++++++++++++++++++----------------------------
1 file changed, 31 insertions(+), 33 deletions(-)
(limited to 'public/js')
diff --git a/public/js/slide.js b/public/js/slide.js
index 1ff388a5..63cf64c6 100644
--- a/public/js/slide.js
+++ b/public/js/slide.js
@@ -1,67 +1,65 @@
require('../css/extra.css');
require('../css/site.css');
-var extraModule = require('./extra');
-var md = extraModule.md;
-var updateLastChange = extraModule.updateLastChange;
-var finishView = extraModule.finishView;
+import { md, updateLastChange, finishView } from './extra';
-var preventXSS = require('./render').preventXSS;
+import { preventXSS } from './render';
-var body = $(".slides").text();
+const body = $(".slides").text();
createtime = lastchangeui.time.attr('data-createtime');
lastchangetime = lastchangeui.time.attr('data-updatetime');
updateLastChange();
-var url = window.location.pathname;
-$('.ui-edit').attr('href', url + '/edit');
+const url = window.location.pathname;
+$('.ui-edit').attr('href', `${url}/edit`);
-$(document).ready(function () {
+$(document).ready(() => {
//tooltip
$('[data-toggle="tooltip"]').tooltip();
});
function extend() {
- var target = {};
- for (var i = 0; i < arguments.length; i++) {
- var source = arguments[i];
- for (var key in source) {
+ const target = {};
+
+ for (const source of arguments) {
+ for (const key in source) {
if (source.hasOwnProperty(key)) {
target[key] = source[key];
}
}
}
+
return target;
}
// Optional libraries used to extend on reveal.js
-var deps = [{
- src: serverurl + '/build/reveal.js/lib/js/classList.js',
- condition: function() {
+const deps = [{
+ src: `${serverurl}/build/reveal.js/lib/js/classList.js`,
+ condition() {
return !document.body.classList;
}
}, {
- src: serverurl + '/js/reveal-markdown.js',
- callback: function () {
- var slideOptions = {
+ src: `${serverurl}/js/reveal-markdown.js`,
+ callback() {
+ const slideOptions = {
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
};
- var slides = RevealMarkdown.slidify(body, slideOptions);
+ const slides = RevealMarkdown.slidify(body, slideOptions);
$(".slides").html(slides);
RevealMarkdown.initialize();
$(".slides").show();
}
}, {
- src: serverurl + '/build/reveal.js/plugin/notes/notes.js',
+ src: `${serverurl}/build/reveal.js/plugin/notes/notes.js`,
async: true,
- condition: function() {
+ condition() {
return !!document.body.classList;
}
}];
// default options to init reveal.js
-var defaultOptions = {
+const defaultOptions = {
controls: true,
progress: true,
slideNumber: true,
@@ -72,10 +70,10 @@ var defaultOptions = {
};
// options from yaml meta
-var meta = JSON.parse($("#meta").text());
+const meta = JSON.parse($("#meta").text());
var options = meta.slideOptions || {};
-var view = $('.reveal');
+const view = $('.reveal');
//text language
if (meta.lang && typeof meta.lang == "string") {
@@ -97,24 +95,24 @@ if (typeof meta.breaks === 'boolean' && !meta.breaks) {
}
// options from URL query string
-var queryOptions = Reveal.getQueryHash() || {};
+const queryOptions = Reveal.getQueryHash() || {};
var options = extend(defaultOptions, options, queryOptions);
Reveal.initialize(options);
-window.viewAjaxCallback = function () {
+window.viewAjaxCallback = () => {
Reveal.layout();
};
function renderSlide(event) {
if (window.location.search.match( /print-pdf/gi )) {
- var slides = $('.slides');
+ const slides = $('.slides');
var title = document.title;
finishView(slides);
document.title = title;
Reveal.layout();
} else {
- var markdown = $(event.currentSlide);
+ const markdown = $(event.currentSlide);
if (!markdown.attr('data-rendered')) {
var title = document.title;
finishView(markdown);
@@ -125,16 +123,16 @@ function renderSlide(event) {
}
}
-Reveal.addEventListener('ready', function (event) {
+Reveal.addEventListener('ready', event => {
renderSlide(event);
- var markdown = $(event.currentSlide);
+ const markdown = $(event.currentSlide);
// force browser redraw
- setTimeout(function () {
+ setTimeout(() => {
markdown.hide().show(0);
}, 0);
});
Reveal.addEventListener('slidechanged', renderSlide);
-var isMacLike = navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) ? true : false;
+const isMacLike = navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) ? true : false;
if (!isMacLike) $('.container').addClass('hidescrollbar');
--
cgit v1.2.3
From 45c202172ed293564925d10782ea65d415cb513c Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Thu, 5 Jan 2017 16:19:13 +0800
Subject: Convert pretty.js to es6
---
public/js/pretty.js | 87 ++++++++++++++++++++++++++---------------------------
1 file changed, 43 insertions(+), 44 deletions(-)
(limited to 'public/js')
diff --git a/public/js/pretty.js b/public/js/pretty.js
index c1a471a1..64d41c43 100644
--- a/public/js/pretty.js
+++ b/public/js/pretty.js
@@ -4,31 +4,33 @@ require('../css/site.css');
require('highlight.js/styles/github-gist.css');
-var extra = require('./extra');
-var md = extra.md;
-var finishView = extra.finishView;
-var autoLinkify = extra.autoLinkify;
-var deduplicatedHeaderId = extra.deduplicatedHeaderId;
-var renderTOC = extra.renderTOC;
-var generateToc = extra.generateToc;
-var smoothHashScroll = extra.smoothHashScroll;
-var postProcess = extra.postProcess;
-var updateLastChange = extra.updateLastChange;
-var parseMeta = extra.parseMeta;
-var scrollToHash = extra.scrollToHash;
-var preventXSS = require('./render').preventXSS;
+import {
+ autoLinkify,
+ deduplicatedHeaderId,
+ finishView,
+ generateToc,
+ md,
+ parseMeta,
+ postProcess,
+ renderTOC,
+ scrollToHash,
+ smoothHashScroll,
+ updateLastChange
+} from './extra';
-var markdown = $("#doc.markdown-body");
-var text = markdown.text();
-var lastMeta = md.meta;
+import { preventXSS } from './render';
+
+const markdown = $("#doc.markdown-body");
+const text = markdown.text();
+const lastMeta = md.meta;
md.meta = {};
-var rendered = md.render(text);
+let rendered = md.render(text);
if (md.meta.type && md.meta.type === 'slide') {
- var slideOptions = {
+ const slideOptions = {
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
};
- var slides = RevealMarkdown.slidify(text, slideOptions);
+ const slides = RevealMarkdown.slidify(text, slideOptions);
markdown.html(slides);
RevealMarkdown.initialize();
// prevent XSS
@@ -46,10 +48,11 @@ if (md.meta.type && md.meta.type === 'slide') {
}
// prevent XSS
rendered = preventXSS(rendered);
- var result = postProcess(rendered);
+ const result = postProcess(rendered);
markdown.html(result.html());
}
$(document.body).show();
+
finishView(markdown);
autoLinkify(markdown);
deduplicatedHeaderId(markdown);
@@ -60,17 +63,18 @@ smoothHashScroll();
createtime = lastchangeui.time.attr('data-createtime');
lastchangetime = lastchangeui.time.attr('data-updatetime');
updateLastChange();
-var url = window.location.pathname;
-$('.ui-edit').attr('href', url + '/edit');
-var toc = $('.ui-toc');
-var tocAffix = $('.ui-affix-toc');
-var tocDropdown = $('.ui-toc-dropdown');
+
+const url = window.location.pathname;
+$('.ui-edit').attr('href', `${url}/edit`);
+const toc = $('.ui-toc');
+const tocAffix = $('.ui-affix-toc');
+const tocDropdown = $('.ui-toc-dropdown');
//toc
-tocDropdown.click(function (e) {
+tocDropdown.click(e => {
e.stopPropagation();
});
-var enoughForAffixToc = true;
+let enoughForAffixToc = true;
function generateScrollspy() {
$(document.body).scrollspy({
@@ -89,18 +93,18 @@ function generateScrollspy() {
function windowResize() {
//toc right
- var paddingRight = parseFloat(markdown.css('padding-right'));
- var right = ($(window).width() - (markdown.offset().left + markdown.outerWidth() - paddingRight));
- toc.css('right', right + 'px');
+ const paddingRight = parseFloat(markdown.css('padding-right'));
+ const right = ($(window).width() - (markdown.offset().left + markdown.outerWidth() - paddingRight));
+ toc.css('right', `${right}px`);
//affix toc left
- var newbool;
- var rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2;
+ let newbool;
+ const rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2;
//for ipad or wider device
if (rightMargin >= 133) {
newbool = true;
- var affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2;
- var left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin;
- tocAffix.css('left', left + 'px');
+ const affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2;
+ const left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin;
+ tocAffix.css('left', `${left}px`);
} else {
newbool = false;
}
@@ -109,10 +113,10 @@ function windowResize() {
generateScrollspy();
}
}
-$(window).resize(function () {
+$(window).resize(() => {
windowResize();
});
-$(document).ready(function () {
+$(document).ready(() => {
windowResize();
generateScrollspy();
setTimeout(scrollToHash, 0);
@@ -120,13 +124,13 @@ $(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
});
-function scrollToTop() {
+export function scrollToTop() {
$('body, html').stop(true, true).animate({
scrollTop: 0
}, 100, "linear");
}
-function scrollToBottom() {
+export function scrollToBottom() {
$('body, html').stop(true, true).animate({
scrollTop: $(document.body)[0].scrollHeight
}, 100, "linear");
@@ -134,8 +138,3 @@ function scrollToBottom() {
window.scrollToTop = scrollToTop;
window.scrollToBottom = scrollToBottom;
-
-module.exports = {
- scrollToBottom: scrollToBottom,
- scrollToTop: scrollToTop
-}
--
cgit v1.2.3
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')
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 = '';
+ const thumbnail_src = `//img.youtube.com/vi/${videoid}/hqdefault.jpg`;
+ const image = ``;
div.append(image);
- var icon = '';
+ const icon = '';
div.append(icon);
return div[0].outerHTML;
}
);
//vimeo
-var vimeoPlugin = new Plugin(
+const vimeoPlugin = new Plugin(
// regexp to match
/{%vimeo\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 icon = '';
+ const icon = '';
div.append(icon);
return div[0].outerHTML;
}
);
//gist
-var gistPlugin = new Plugin(
+const gistPlugin = new Plugin(
// regexp to match
/{%gist\s*([\d\D]*?)\s*%}/,
- // this function will be called when something matches
- function (match, utils) {
- var gistid = match[1];
- var code = '
';
+ (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.2.3
From 71aece74292e9764e6dc20ebe84f211099d6076d Mon Sep 17 00:00:00 2001
From: Yukai Huang
Date: Thu, 5 Jan 2017 18:10:55 +0800
Subject: Convert cover.js to es6
---
public/js/cover.js | 253 +++++++++++++++++++++++++++--------------------------
1 file changed, 127 insertions(+), 126 deletions(-)
(limited to 'public/js')
diff --git a/public/js/cover.js b/public/js/cover.js
index b8886849..ecb385ed 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -3,30 +3,30 @@ require('./locale');
require('../css/cover.css');
require('../css/site.css');
-var common = require('./common');
-var checkIfAuth = common.checkIfAuth;
-var urlpath = common.urlpath;
-var resetCheckAuth = common.resetCheckAuth;
-var getLoginState = common.getLoginState;
-var clearLoginState = common.clearLoginState;
-var loginStateChangeEvent = common.loginStateChangeEvent;
-
-var historyModule = require('./history');
-var parseStorageToHistory = historyModule.parseStorageToHistory;
-var parseHistory = historyModule.parseHistory;
-var getStorageHistory = historyModule.getStorageHistory;
-var getHistory = historyModule.getHistory;
-var saveHistory = historyModule.saveHistory;
-var removeHistory = historyModule.removeHistory;
-var postHistoryToServer = historyModule.postHistoryToServer;
-var deleteServerHistory = historyModule.deleteServerHistory;
-var parseServerToHistory = historyModule.parseServerToHistory;
-var saveStorageHistoryToServer = historyModule.saveStorageHistoryToServer;
-var clearDuplicatedHistory = historyModule.clearDuplicatedHistory;
-
-var saveAs = require('file-saver').saveAs;
-var List = require('list.js');
-var S = require('string');
+import {
+ checkIfAuth,
+ clearLoginState,
+ getLoginState,
+ resetCheckAuth,
+ 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 List from 'list.js';
+import S from 'string';
import Cover from './views/Cover';
import Vue from 'vue';
@@ -36,13 +36,13 @@ new Vue({
render: (h) => h(Cover)
})
-var options = {
+const options = {
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
item: '