2015-05-15 00:58:13 -04:00
|
|
|
var markdown = $(".markdown-body");
|
2015-07-01 12:10:20 -04:00
|
|
|
var text = $('<textarea/>').html(markdown.html()).text();
|
2016-02-11 15:35:25 -05:00
|
|
|
var lastMeta = md.meta;
|
2016-01-12 09:01:42 -05:00
|
|
|
md.meta = {};
|
2016-02-11 04:45:13 -05:00
|
|
|
var rendered = md.render(text);
|
2016-02-11 15:35:25 -05:00
|
|
|
// only render again when meta changed
|
|
|
|
if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) {
|
2016-02-15 20:13:17 -05:00
|
|
|
parseMeta(md, null, markdown, $('#toc'), $('#toc-affix'));
|
2016-02-11 15:35:25 -05:00
|
|
|
rendered = md.render(text);
|
|
|
|
}
|
|
|
|
// prevent XSS
|
2016-02-11 04:45:13 -05:00
|
|
|
rendered = preventXSS(rendered);
|
|
|
|
var result = postProcess(rendered);
|
2015-07-01 12:10:20 -04:00
|
|
|
markdown.html(result.html());
|
|
|
|
$(document.body).show();
|
2015-05-15 00:58:13 -04:00
|
|
|
finishView(markdown);
|
|
|
|
autoLinkify(markdown);
|
2015-09-25 02:27:23 -04:00
|
|
|
deduplicatedHeaderId(markdown);
|
2015-12-20 12:28:54 -05:00
|
|
|
renderTOC(markdown);
|
2015-07-01 12:10:20 -04:00
|
|
|
generateToc('toc');
|
|
|
|
generateToc('toc-affix');
|
|
|
|
smoothHashScroll();
|
2016-04-20 06:03:55 -04:00
|
|
|
createtime = lastchangeui.time.attr('data-createtime');
|
|
|
|
lastchangetime = lastchangeui.time.attr('data-updatetime');
|
2015-07-01 12:10:20 -04:00
|
|
|
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');
|
|
|
|
//toc
|
|
|
|
tocDropdown.click(function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
var enoughForAffixToc = true;
|
|
|
|
|
|
|
|
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
|
|
|
|
var paddingRight = parseFloat(markdown.css('padding-right'));
|
|
|
|
var 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;
|
|
|
|
//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');
|
|
|
|
} else {
|
|
|
|
newbool = false;
|
|
|
|
}
|
|
|
|
if (newbool != enoughForAffixToc) {
|
|
|
|
enoughForAffixToc = newbool;
|
|
|
|
generateScrollspy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$(window).resize(function () {
|
|
|
|
windowResize();
|
|
|
|
});
|
|
|
|
$(document).ready(function () {
|
|
|
|
windowResize();
|
|
|
|
generateScrollspy();
|
2016-01-12 09:01:42 -05:00
|
|
|
//tooltip
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
2015-07-01 12:10:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
function scrollToTop() {
|
2015-09-25 02:08:02 -04:00
|
|
|
$('body, html').stop(true, true).animate({
|
2015-07-01 12:10:20 -04:00
|
|
|
scrollTop: 0
|
|
|
|
}, 100, "linear");
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollToBottom() {
|
2015-09-25 02:08:02 -04:00
|
|
|
$('body, html').stop(true, true).animate({
|
2015-07-01 12:10:20 -04:00
|
|
|
scrollTop: $(document.body)[0].scrollHeight
|
|
|
|
}, 100, "linear");
|
|
|
|
}
|