summaryrefslogtreecommitdiff
path: root/public/js/pretty.js
diff options
context:
space:
mode:
authorBoHong Li2017-03-13 02:09:52 +0800
committerBoHong Li2017-03-13 02:09:52 +0800
commitbefa89be8b69ed1b951099828c5dbc7e550d4c68 (patch)
tree835b840c390029c596756a59abc919bf17d14b54 /public/js/pretty.js
parent747da6772d339329ed130f5a0dbc896be5391ef8 (diff)
parent5bc642d02e8955b200bb21cf30e863fdf0c53765 (diff)
Merge branch 'use_javascript_standard_style'
Introduce JavaScript Standard Style Signed-off-by: BoHong Li <a60814billy@gmail.com>
Diffstat (limited to 'public/js/pretty.js')
-rw-r--r--public/js/pretty.js211
1 files changed, 107 insertions, 104 deletions
diff --git a/public/js/pretty.js b/public/js/pretty.js
index 18d0dc0d..718941a8 100644
--- a/public/js/pretty.js
+++ b/public/js/pretty.js
@@ -1,8 +1,11 @@
-require('../css/extra.css');
-require('../css/slide-preview.css');
-require('../css/site.css');
+/* eslint-env browser, jquery */
+/* global refreshView */
-require('highlight.js/styles/github-gist.css');
+require('../css/extra.css')
+require('../css/slide-preview.css')
+require('../css/site.css')
+
+require('highlight.js/styles/github-gist.css')
import {
autoLinkify,
@@ -16,126 +19,126 @@ import {
scrollToHash,
smoothHashScroll,
updateLastChange
-} from './extra';
+} from './extra'
-import { preventXSS } from './render';
+import { preventXSS } from './render'
-const markdown = $("#doc.markdown-body");
-const text = markdown.text();
-const lastMeta = md.meta;
-md.meta = {};
-delete md.metaError;
-let rendered = md.render(text);
+const markdown = $('#doc.markdown-body')
+const text = markdown.text()
+const lastMeta = md.meta
+md.meta = {}
+delete md.metaError
+let rendered = md.render(text)
if (md.meta.type && md.meta.type === 'slide') {
- const slideOptions = {
- separator: '^(\r\n?|\n)---(\r\n?|\n)$',
- verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
- };
- const slides = RevealMarkdown.slidify(text, slideOptions);
- markdown.html(slides);
- RevealMarkdown.initialize();
+ const slideOptions = {
+ separator: '^(\r\n?|\n)---(\r\n?|\n)$',
+ verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
+ }
+ const slides = window.RevealMarkdown.slidify(text, slideOptions)
+ markdown.html(slides)
+ window.RevealMarkdown.initialize()
// prevent XSS
- markdown.html(preventXSS(markdown.html()));
- markdown.addClass('slides');
+ markdown.html(preventXSS(markdown.html()))
+ markdown.addClass('slides')
} else {
- if (lastMeta.type && lastMeta.type === 'slide') {
- refreshView();
- markdown.removeClass('slides');
- }
+ if (lastMeta.type && lastMeta.type === 'slide') {
+ refreshView()
+ markdown.removeClass('slides')
+ }
// only render again when meta changed
- if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) {
- parseMeta(md, null, markdown, $('#ui-toc'), $('#ui-toc-affix'));
- rendered = md.render(text);
- }
+ if (JSON.stringify(md.meta) !== JSON.stringify(lastMeta)) {
+ parseMeta(md, null, markdown, $('#ui-toc'), $('#ui-toc-affix'))
+ rendered = md.render(text)
+ }
// prevent XSS
- rendered = preventXSS(rendered);
- const result = postProcess(rendered);
- markdown.html(result.html());
+ rendered = preventXSS(rendered)
+ const result = postProcess(rendered)
+ markdown.html(result.html())
}
-$(document.body).show();
+$(document.body).show()
-finishView(markdown);
-autoLinkify(markdown);
-deduplicatedHeaderId(markdown);
-renderTOC(markdown);
-generateToc('ui-toc');
-generateToc('ui-toc-affix');
-smoothHashScroll();
-createtime = lastchangeui.time.attr('data-createtime');
-lastchangetime = lastchangeui.time.attr('data-updatetime');
-updateLastChange();
+finishView(markdown)
+autoLinkify(markdown)
+deduplicatedHeaderId(markdown)
+renderTOC(markdown)
+generateToc('ui-toc')
+generateToc('ui-toc-affix')
+smoothHashScroll()
+window.createtime = window.lastchangeui.time.attr('data-createtime')
+window.lastchangetime = window.lastchangeui.time.attr('data-updatetime')
+updateLastChange()
-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
+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(e => {
- e.stopPropagation();
-});
+ e.stopPropagation()
+})
-let enoughForAffixToc = true;
+let 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 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
- 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
- let newbool;
- const rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2;
- //for ipad or wider device
- if (rightMargin >= 133) {
- newbool = true;
- const affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2;
- const left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin;
- tocAffix.css('left', `${left}px`);
- } else {
- newbool = false;
- }
- if (newbool != enoughForAffixToc) {
- enoughForAffixToc = newbool;
- generateScrollspy();
- }
+function windowResize () {
+ // toc right
+ 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
+ let newbool
+ const rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2
+ // for ipad or wider device
+ if (rightMargin >= 133) {
+ newbool = true
+ const affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2
+ const left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin
+ tocAffix.css('left', `${left}px`)
+ } else {
+ newbool = false
+ }
+ if (newbool !== enoughForAffixToc) {
+ enoughForAffixToc = newbool
+ generateScrollspy()
+ }
}
$(window).resize(() => {
- windowResize();
-});
+ windowResize()
+})
$(document).ready(() => {
- windowResize();
- generateScrollspy();
- setTimeout(scrollToHash, 0);
- //tooltip
- $('[data-toggle="tooltip"]').tooltip();
-});
+ windowResize()
+ generateScrollspy()
+ setTimeout(scrollToHash, 0)
+ // tooltip
+ $('[data-toggle="tooltip"]').tooltip()
+})
-export function scrollToTop() {
- $('body, html').stop(true, true).animate({
- scrollTop: 0
- }, 100, "linear");
+export function scrollToTop () {
+ $('body, html').stop(true, true).animate({
+ scrollTop: 0
+ }, 100, 'linear')
}
-export function scrollToBottom() {
- $('body, html').stop(true, true).animate({
- scrollTop: $(document.body)[0].scrollHeight
- }, 100, "linear");
+export function scrollToBottom () {
+ $('body, html').stop(true, true).animate({
+ scrollTop: $(document.body)[0].scrollHeight
+ }, 100, 'linear')
}
-window.scrollToTop = scrollToTop;
-window.scrollToBottom = scrollToBottom;
+window.scrollToTop = scrollToTop
+window.scrollToBottom = scrollToBottom