2016-11-02 03:55:08 +00:00
|
|
|
require('../css/extra.css');
|
|
|
|
require('../css/slide-preview.css');
|
|
|
|
require('../css/site.css');
|
|
|
|
|
2016-11-07 13:27:58 +00:00
|
|
|
require('highlight.js/styles/github-gist.css');
|
|
|
|
|
2017-01-05 08:19:13 +00:00
|
|
|
import {
|
|
|
|
autoLinkify,
|
|
|
|
deduplicatedHeaderId,
|
|
|
|
finishView,
|
|
|
|
generateToc,
|
|
|
|
md,
|
|
|
|
parseMeta,
|
|
|
|
postProcess,
|
|
|
|
renderTOC,
|
|
|
|
scrollToHash,
|
|
|
|
smoothHashScroll,
|
|
|
|
updateLastChange
|
|
|
|
} from './extra';
|
2016-10-08 12:02:30 +00:00
|
|
|
|
2017-01-05 08:19:13 +00:00
|
|
|
import { preventXSS } from './render';
|
|
|
|
|
|
|
|
const markdown = $("#doc.markdown-body");
|
|
|
|
const text = markdown.text();
|
|
|
|
const lastMeta = md.meta;
|
2016-01-12 14:01:42 +00:00
|
|
|
md.meta = {};
|
2017-01-21 04:50:02 +00:00
|
|
|
delete md.metaError;
|
2017-01-05 08:19:13 +00:00
|
|
|
let rendered = md.render(text);
|
2016-07-30 03:07:47 +00:00
|
|
|
if (md.meta.type && md.meta.type === 'slide') {
|
2017-01-05 08:19:13 +00:00
|
|
|
const slideOptions = {
|
2016-07-30 03:07:47 +00:00
|
|
|
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
|
|
|
|
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
|
|
|
|
};
|
2017-01-05 08:19:13 +00:00
|
|
|
const slides = RevealMarkdown.slidify(text, slideOptions);
|
2016-07-30 03:07:47 +00:00
|
|
|
markdown.html(slides);
|
|
|
|
RevealMarkdown.initialize();
|
|
|
|
// prevent XSS
|
|
|
|
markdown.html(preventXSS(markdown.html()));
|
|
|
|
markdown.addClass('slides');
|
|
|
|
} else {
|
|
|
|
if (lastMeta.type && lastMeta.type === 'slide') {
|
|
|
|
refreshView();
|
|
|
|
markdown.removeClass('slides');
|
|
|
|
}
|
|
|
|
// only render again when meta changed
|
|
|
|
if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) {
|
2016-08-15 03:27:32 +00:00
|
|
|
parseMeta(md, null, markdown, $('#ui-toc'), $('#ui-toc-affix'));
|
2016-07-30 03:07:47 +00:00
|
|
|
rendered = md.render(text);
|
|
|
|
}
|
|
|
|
// prevent XSS
|
|
|
|
rendered = preventXSS(rendered);
|
2017-01-05 08:19:13 +00:00
|
|
|
const result = postProcess(rendered);
|
2016-07-30 03:07:47 +00:00
|
|
|
markdown.html(result.html());
|
2016-02-11 20:35:25 +00:00
|
|
|
}
|
2015-07-01 16:10:20 +00:00
|
|
|
$(document.body).show();
|
2017-01-05 08:19:13 +00:00
|
|
|
|
2015-05-15 04:58:13 +00:00
|
|
|
finishView(markdown);
|
|
|
|
autoLinkify(markdown);
|
2015-09-25 06:27:23 +00:00
|
|
|
deduplicatedHeaderId(markdown);
|
2015-12-20 17:28:54 +00:00
|
|
|
renderTOC(markdown);
|
2016-08-15 03:27:32 +00:00
|
|
|
generateToc('ui-toc');
|
|
|
|
generateToc('ui-toc-affix');
|
2015-07-01 16:10:20 +00:00
|
|
|
smoothHashScroll();
|
2016-04-20 10:03:55 +00:00
|
|
|
createtime = lastchangeui.time.attr('data-createtime');
|
|
|
|
lastchangetime = lastchangeui.time.attr('data-updatetime');
|
2015-07-01 16:10:20 +00:00
|
|
|
updateLastChange();
|
2017-01-05 08:19:13 +00:00
|
|
|
|
|
|
|
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');
|
2015-07-01 16:10:20 +00:00
|
|
|
//toc
|
2017-01-05 08:19:13 +00:00
|
|
|
tocDropdown.click(e => {
|
2015-07-01 16:10:20 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2017-01-05 08:19:13 +00:00
|
|
|
let enoughForAffixToc = true;
|
2015-07-01 16:10:20 +00:00
|
|
|
|
|
|
|
function generateScrollspy() {
|
|
|
|
$(document.body).scrollspy({
|
|
|
|
target: ''
|
|
|
|
});
|
|
|
|
$(document.body).scrollspy('refresh');
|
|
|
|
if (enoughForAffixToc) {
|
|
|
|
toc.hide();
|
|
|
|
tocAffix.show();
|
|
|
|
} else {
|
|
|
|
tocAffix.hide();
|
|
|
|
toc.show();
|
|
|
|
}
|
|
|
|
$(document.body).scroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
function windowResize() {
|
|
|
|
//toc right
|
2017-01-05 08:19:13 +00:00
|
|
|
const paddingRight = parseFloat(markdown.css('padding-right'));
|
|
|
|
const right = ($(window).width() - (markdown.offset().left + markdown.outerWidth() - paddingRight));
|
|
|
|
toc.css('right', `${right}px`);
|
2015-07-01 16:10:20 +00:00
|
|
|
//affix toc left
|
2017-01-05 08:19:13 +00:00
|
|
|
let newbool;
|
|
|
|
const rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2;
|
2015-07-01 16:10:20 +00:00
|
|
|
//for ipad or wider device
|
|
|
|
if (rightMargin >= 133) {
|
|
|
|
newbool = true;
|
2017-01-05 08:19:13 +00:00
|
|
|
const affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2;
|
|
|
|
const left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin;
|
|
|
|
tocAffix.css('left', `${left}px`);
|
2015-07-01 16:10:20 +00:00
|
|
|
} else {
|
|
|
|
newbool = false;
|
|
|
|
}
|
|
|
|
if (newbool != enoughForAffixToc) {
|
|
|
|
enoughForAffixToc = newbool;
|
|
|
|
generateScrollspy();
|
|
|
|
}
|
|
|
|
}
|
2017-01-05 08:19:13 +00:00
|
|
|
$(window).resize(() => {
|
2015-07-01 16:10:20 +00:00
|
|
|
windowResize();
|
|
|
|
});
|
2017-01-05 08:19:13 +00:00
|
|
|
$(document).ready(() => {
|
2015-07-01 16:10:20 +00:00
|
|
|
windowResize();
|
|
|
|
generateScrollspy();
|
2016-11-26 11:46:20 +00:00
|
|
|
setTimeout(scrollToHash, 0);
|
2016-01-12 14:01:42 +00:00
|
|
|
//tooltip
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
2015-07-01 16:10:20 +00:00
|
|
|
});
|
|
|
|
|
2017-01-05 08:19:13 +00:00
|
|
|
export function scrollToTop() {
|
2015-09-25 06:08:02 +00:00
|
|
|
$('body, html').stop(true, true).animate({
|
2015-07-01 16:10:20 +00:00
|
|
|
scrollTop: 0
|
|
|
|
}, 100, "linear");
|
|
|
|
}
|
|
|
|
|
2017-01-05 08:19:13 +00:00
|
|
|
export function scrollToBottom() {
|
2015-09-25 06:08:02 +00:00
|
|
|
$('body, html').stop(true, true).animate({
|
2015-07-01 16:10:20 +00:00
|
|
|
scrollTop: $(document.body)[0].scrollHeight
|
|
|
|
}, 100, "linear");
|
2016-10-08 12:02:30 +00:00
|
|
|
}
|
|
|
|
|
2016-10-09 13:08:33 +00:00
|
|
|
window.scrollToTop = scrollToTop;
|
|
|
|
window.scrollToBottom = scrollToBottom;
|