From 8e11c19bed6b99b5476d9d7a6125dcfdd4119064 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Fri, 7 Oct 2016 23:06:10 +0800 Subject: Move out script tag and use js instead --- public/js/app.js | 1 + public/js/index.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 public/js/app.js (limited to 'public/js') diff --git a/public/js/app.js b/public/js/app.js new file mode 100644 index 00000000..fe864504 --- /dev/null +++ b/public/js/app.js @@ -0,0 +1 @@ +require('./index'); diff --git a/public/js/index.js b/public/js/index.js index 03729de4..9590a4e3 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1,3 +1,75 @@ +/* include jquery ui */ +require('jquery-ui/ui/widgets/resizable'); +require('jquery-ui/ui/widgets/tooltip'); +require('jquery-ui/ui/widgets/controlgroup'); +require('jquery-ui/ui/widgets/autocomplete'); + +/* jquery and jquery plugins */ +require('jquery'); +require('jquery-textcomplete'); +require('jquery-mousewheel'); +require('../vendor/jquery-scrollspy'); +require('../vendor/showup/showup'); + +/* bootstrap */ +require('bootstrap'); + +/* code mirror plugins */ +require('codemirror/keymap/vim'); +require('codemirror/keymap/emacs'); +require('codemirror/keymap/sublime'); + +require('../vendor/inlineAttachment/inline-attachment'); +require('../vendor/inlineAttachment/codemirror.inline-attachment'); +require('../vendor/codemirror-spell-checker/spell-checker.min'); + +/* operational transformation */ +require('../vendor/ot/ot.min'); + +/* other vendors plugin */ +require('markdown-it'); +require('markdown-it-abbr'); +require('markdown-it-footnote'); +require('markdown-it-deflist'); +require('markdown-it-mark'); +require('markdown-it-ins'); +require('markdown-it-sub'); +require('markdown-it-sup'); +require('markdown-it-container'); +require('markdown-it-mathjax'); +require('markdown-it-regexp'); +require('markdown-it-imsize'); + +require('gist-embed'); +require('lz-string'); +require('xss'); +require('string'); +require('highlight.js'); +require('prismjs'); +require('prismjs/components/prism-wiki'); +require('js-cookie'); +require('emojify.js'); +require('to-markdown'); + +require('raphael'); +require('js-sequence-diagrams'); + +require('flowchart.js'); +require('viz.js'); +require('pdfobject'); +require('file-saver'); +require('store'); +require('js-url'); +require('visibilityjs'); +require('list.js'); +require('../vendor/md-toc'); +require('randomcolor'); +require('keymaster'); + +var common = require('./common.js'); + +var serverurl = common.serverurl; + var defaultTextHeight = 20; var viewportMargin = 20; var mac = CodeMirror.keyMap["default"] == CodeMirror.keyMap.macDefault; @@ -126,7 +198,7 @@ function wrapTextWith(cm, symbol) { }; var postText = cm.getRange(postEndPos, from); var postIndex = wrapSymbols.indexOf(postText); - // check if surround symbol are list in array and matched + // check if surround symbol are list in array and matched if (preIndex > -1 && postIndex > -1 && preIndex === postIndex) { cm.replaceRange("", to, preEndPos, '+delete'); cm.replaceRange("", postEndPos, from, '+delete'); @@ -1035,7 +1107,7 @@ function checkEditorStyle() { }, stop: function (e) { lastEditorWidth = ui.area.edit.width(); - // workaround that scroll event bindings + // workaround that scroll event bindings preventSyncScrollToView = 2; preventSyncScrollToEdit = true; editor.setOption('viewportMargin', viewportMargin); @@ -1269,12 +1341,12 @@ function changeMode(type) { preventSyncScrollToView = 2; syncScrollToEdit(null, true); } - + if (lastMode == modeType.edit && currentMode == modeType.both) { preventSyncScrollToEdit = 2; syncScrollToView(null, true); } - + if (lastMode == modeType.both && currentMode != modeType.both) { preventSyncScrollToView = false; preventSyncScrollToEdit = false; @@ -1675,7 +1747,7 @@ function parseRevisions(_revisions) { } } function selectRevision(time) { - if (time == revisionTime) return; + if (time == revisionTime) return; $.get(noteurl + '/revision/' + time) .done(function(data) { revision = data; -- cgit v1.2.3 From ebee5a8d05a0282f5f584abc7d1eaa26d9d17ad8 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 8 Oct 2016 19:56:38 +0800 Subject: Use xss in script tag --- public/js/index.js | 1 - 1 file changed, 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 9590a4e3..90a3daf4 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -42,7 +42,6 @@ require('markdown-it-imsize'); require('gist-embed'); require('lz-string'); -require('xss'); require('string'); require('highlight.js'); require('prismjs'); -- cgit v1.2.3 From 0be342c44d5b6287c67922758f076e7897f6c3a8 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 8 Oct 2016 19:58:26 +0800 Subject: Fix mutiple socket.on handling --- public/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 90a3daf4..dff278c9 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2250,7 +2250,7 @@ var socket = io.connect({ var on = socket.on; socket.on = function () { if (!checkLoginStateChanged() && !needRefresh) - on.apply(socket, arguments); + return on.apply(socket, arguments); }; var emit = socket.emit; socket.emit = function () { -- cgit v1.2.3 From 963a435ae1e9248b42b4665acf106dcffa549678 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 8 Oct 2016 20:02:30 +0800 Subject: Resolve dependency module requiring * es5 style module exports * remove script tag require * webpack config ProvidePlugin Note that this commit only fix JavaScript module loading runtime error. --- public/js/extra.js | 77 ++++++++++++++++++++++++++++++++++--------------- public/js/history.js | 16 +++++++++- public/js/index.js | 59 +++++++++++++++++++++++++++++-------- public/js/pretty.js | 19 +++++++++++- public/js/render.js | 6 +++- public/js/syncscroll.js | 39 ++++++++++++++++--------- 6 files changed, 163 insertions(+), 53 deletions(-) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index 77f298f9..c6a0f432 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -224,7 +224,7 @@ function finishView(view) { }); //emojify try { - emojify.run(view[0]); + emojify.run(view[0]); } catch (err) { console.warn(err); } @@ -245,12 +245,12 @@ function finishView(view) { try { var $value = $(value); var $ele = $(value).parent().parent(); - + var sequence = $value; sequence.sequenceDiagram({ theme: 'simple' }); - + $ele.addClass('sequence-diagram'); $value.children().unwrap().unwrap(); var svg = $ele.find('> svg'); @@ -266,7 +266,7 @@ function finishView(view) { try { var $value = $(value); var $ele = $(value).parent().parent(); - + var chart = flowchart.parse($value.text()); $value.html(''); chart.drawSVG(value, { @@ -275,7 +275,7 @@ function finishView(view) { 'font-size': '16px', 'font-family': "'Andale Mono', monospace" }); - + $ele.addClass('flow-chart'); $value.children().unwrap().unwrap(); } catch (err) { @@ -288,10 +288,10 @@ function finishView(view) { try { var $value = $(value); var $ele = $(value).parent().parent(); - + var graphviz = Viz($value.text()); $value.html(graphviz); - + $ele.addClass('graphviz'); $value.children().unwrap().unwrap(); } catch (err) { @@ -304,12 +304,12 @@ function finishView(view) { try { var $value = $(value); var $ele = $(value).parent().parent(); - + var mermaidError = null; mermaid.parseError = function (err, hash) { mermaidError = err; }; - + if (mermaidAPI.parse($value.text())) { $ele.addClass('mermaid'); $ele.html($value.text()); @@ -489,6 +489,8 @@ function exportToRawHTML(view) { saveAs(blob, filename); } +var common = require('./common.js'); +var serverurl = common.serverurl; //extract markdown body to html and compile to template function exportToHTML(view) { var title = renderTitle(ui.area.markdown); @@ -794,7 +796,10 @@ emojify.setConfig({ ignore_emoticons: true }); -var md = window.markdownit('default', { +var markdownit = require('markdown-it'); +var markdownitContainer = require('markdown-it-container'); + +var md = markdownit('default', { html: true, breaks: true, langPrefix: "", @@ -802,25 +807,27 @@ var md = window.markdownit('default', { typographer: true, highlight: highlightRender }); -md.use(window.markdownitAbbr); -md.use(window.markdownitFootnote); -md.use(window.markdownitDeflist); -md.use(window.markdownitMark); -md.use(window.markdownitIns); -md.use(window.markdownitSub); -md.use(window.markdownitSup); -md.use(window.markdownitMathjax); -md.use(window.markdownitImsize); + +md.use(require('markdown-it-abbr')); +md.use(require('markdown-it-footnote')); +md.use(require('markdown-it-deflist')); +md.use(require('markdown-it-mark')); +md.use(require('markdown-it-ins')); +md.use(require('markdown-it-sub')); +md.use(require('markdown-it-sup')); +md.use(require('markdown-it-mathjax')); +md.use(require('markdown-it-imsize')); + 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()); return self.renderToken.apply(self, arguments); } -md.use(window.markdownitContainer, 'success', { render: renderContainer }); -md.use(window.markdownitContainer, 'info', { render: renderContainer }); -md.use(window.markdownitContainer, 'warning', { render: renderContainer }); -md.use(window.markdownitContainer, 'danger', { render: renderContainer }); +md.use(markdownitContainer, 'success', { render: renderContainer }); +md.use(markdownitContainer, 'info', { render: renderContainer }); +md.use(markdownitContainer, 'warning', { render: renderContainer }); +md.use(markdownitContainer, 'danger', { render: renderContainer }); md.renderer.rules.image = function (tokens, idx, options, env, self) { tokens[idx].attrJoin('class', 'raw'); @@ -865,6 +872,9 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) { + '\n'; }; +/* Defined regex markdown it plugins */ +var Plugin = require('markdown-it-regexp'); + //youtube var youtubePlugin = new Plugin( // regexp to match @@ -1011,4 +1021,23 @@ md.use(gistPlugin); md.use(tocPlugin); md.use(slidesharePlugin); md.use(speakerdeckPlugin); -md.use(pdfPlugin); \ No newline at end of file +md.use(pdfPlugin); + +module.exports = { + md: md, + createtime: createtime, + lastchangetime: lastchangetime, + updateLastChange: updateLastChange, + lastchangeui: lastchangeui, + lastchangeuser: lastchangeuser, + postProcess: postProcess, + finishView: finishView, + autoLinkify: autoLinkify, + deduplicatedHeaderId: deduplicatedHeaderId, + renderTOC: renderTOC, + renderTitle: renderTitle, + renderFilename: renderFilename, + generateToc: generateToc, + smoothHashScroll: smoothHashScroll, + scrollToHash: scrollToHash +}; diff --git a/public/js/history.js b/public/js/history.js index 0840580d..fbf71db7 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -1,3 +1,13 @@ +var store = require('store'); + +var common = require('./common'); +var checkIfAuth = common.checkIfAuth; +var urlpath = common.urlpath; + +var extra = require('./extra'); +var renderFilename = extra.renderFilename; +var md = extra.md; + var migrateHistoryFromTempCallback = null; migrateHistoryFromTemp(); @@ -365,4 +375,8 @@ function parseToHistory(list, notehistory, callback) { } } callback(list, notehistory); -} \ No newline at end of file +} + +module.exports = { + writeHistory: writeHistory +} diff --git a/public/js/index.js b/public/js/index.js index dff278c9..3801eea2 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -18,15 +18,14 @@ require('bootstrap'); require('codemirror/keymap/vim'); require('codemirror/keymap/emacs'); require('codemirror/keymap/sublime'); - -require('../vendor/inlineAttachment/inline-attachment'); -require('../vendor/inlineAttachment/codemirror.inline-attachment'); -require('../vendor/codemirror-spell-checker/spell-checker.min'); +require('codemirror/addon/display/panel'); /* operational transformation */ -require('../vendor/ot/ot.min'); +require('ot/lib/socketio-adapter'); +require('ot/lib/codemirror-adapter'); +require('ot/lib/undo-manager'); +require('../vendor/ot/editor-client'); -/* other vendors plugin */ require('markdown-it'); require('markdown-it-abbr'); require('markdown-it-footnote'); @@ -40,14 +39,13 @@ require('markdown-it-mathjax'); require('markdown-it-regexp'); require('markdown-it-imsize'); +/* other vendors plugin */ require('gist-embed'); -require('lz-string'); require('string'); require('highlight.js'); require('prismjs'); require('prismjs/components/prism-wiki'); require('js-cookie'); -require('emojify.js'); require('to-markdown'); require('raphael'); @@ -63,11 +61,48 @@ require('visibilityjs'); require('list.js'); require('../vendor/md-toc'); require('randomcolor'); -require('keymaster'); var common = require('./common.js'); - +var urlpath = common.urlpath; +var debug = common.debug; +var version = common.version; var serverurl = common.serverurl; +var GOOGLE_API_KEY = common.GOOGLE_API_KEY; +var GOOGLE_CLIENT_ID = common.GOOGLE_CLIENT_ID; +var DROPBOX_APP_KEY = common.DROPBOX_APP_KEY; +var noteurl = common.noteurl; + +var checkLoginStateChanged = common.checkLoginStateChanged; + +var syncScroll = require('./syncscroll'); +var setupSyncAreas = syncScroll.setupSyncAreas; +var clearMap = syncScroll.clearMap; +var syncScrollToEdit = syncScroll.syncScrollToEdit; + +var extra = require('./extra'); +var md = extra.md; +var createtime = extra.createtime; +var updateLastChange = extra.updateLastChange; +var postProcess = extra.postProcess; +var finishView = extra.finishView; +var lastchangetime = extra.lastchangetime; +var autoLinkify = extra.autoLinkify; +var generateToc = extra.generateToc; +var smoothHashScroll = extra.smoothHashScroll; +var lastchangeuser = extra.lastchangeuser; +var deduplicatedHeaderId = extra.deduplicatedHeaderId; +var renderTOC = extra.renderTOC; +var renderTitle = extra.renderTitle; +var renderFilename = extra.renderFilename; +var scrollToHash = extra.scrollToHash; + +var history = require('./history'); +var writeHistory = history.writeHistory; + +var pretty = require('./pretty'); + +var renderer = require('./render'); +var preventXSS = renderer.preventXSS; var defaultTextHeight = 20; var viewportMargin = 20; @@ -349,7 +384,7 @@ var supportExtraTags = [ } } ]; -var modeType = { +window.modeType = { edit: { name: "edit" }, @@ -389,7 +424,7 @@ var visibleSM = false; var visibleMD = false; var visibleLG = false; var isTouchDevice = 'ontouchstart' in document.documentElement; -var currentMode = defaultMode; +window.currentMode = defaultMode; var currentStatus = statusType.offline; var lastInfo = { needRestore: false, diff --git a/public/js/pretty.js b/public/js/pretty.js index 0ca7ee18..ebdec2a9 100644 --- a/public/js/pretty.js +++ b/public/js/pretty.js @@ -1,3 +1,16 @@ +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 lastchangeui = extra.lastchangeui; +var updateLastChange = extra.updateLastChange; +var preventXSS = require('./render').preventXSS; + var markdown = $(".markdown-body"); var text = $('').html(markdown.html()).text(); var lastMeta = md.meta; @@ -109,4 +122,8 @@ function scrollToBottom() { $('body, html').stop(true, true).animate({ scrollTop: $(document.body)[0].scrollHeight }, 100, "linear"); -} \ No newline at end of file +} + +module.exports = { + scrollToBottom: scrollToBottom +} diff --git a/public/js/render.js b/public/js/render.js index 6f1a1c19..41b367a3 100644 --- a/public/js/render.js +++ b/public/js/render.js @@ -50,4 +50,8 @@ var filterXSSOptions = { function preventXSS(html) { return filterXSS(html, filterXSSOptions); -} \ No newline at end of file +} + +module.exports = { + preventXSS: preventXSS +} diff --git a/public/js/syncscroll.js b/public/js/syncscroll.js index 96663f77..444cdebd 100644 --- a/public/js/syncscroll.js +++ b/public/js/syncscroll.js @@ -1,5 +1,8 @@ // Inject line numbers for sync scroll. +var extra = require('./extra'); +var md = extra.md; + function addPart(tokens, idx) { if (tokens[idx].map && tokens[idx].level === 0) { var startline = tokens[idx].map[0] + 1; @@ -71,7 +74,7 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) { if (highlighted.indexOf('
scrollInfo.clientHeight && scrollTop >= preLastLinePos) { posTo = preLastLineHeight; topDiffPercent = (scrollTop - preLastLinePos) / (viewBottom - preLastLinePos); @@ -281,7 +286,7 @@ function syncScrollToEdit(event, preventAnimate) { posToNextDiff = textHeight * lineDiff * topDiffPercent; posTo += Math.ceil(posToNextDiff); } - + if (preventAnimate) { editArea.scrollTop(posTo); } else { @@ -292,7 +297,7 @@ function syncScrollToEdit(event, preventAnimate) { scrollTop: posTo }, duration, "linear"); } - + viewScrolling = true; clearTimeout(viewScrollingTimer); viewScrollingTimer = setTimeout(viewScrollingTimeoutInner, duration * 1.5); @@ -322,7 +327,7 @@ function syncScrollToView(event, preventAnimate) { return; } if (viewScrolling) return; - + var lineNo, posTo; var topDiffPercent, posToNextDiff; var scrollInfo = editor.getScrollInfo(); @@ -341,7 +346,7 @@ function syncScrollToView(event, preventAnimate) { posToNextDiff = (scrollMap[lineNo + 1] - posTo) * topDiffPercent; posTo += Math.floor(posToNextDiff); } - + if (preventAnimate) { viewArea.scrollTop(posTo); } else { @@ -352,7 +357,7 @@ function syncScrollToView(event, preventAnimate) { scrollTop: posTo }, duration, "linear"); } - + editScrolling = true; clearTimeout(editScrollingTimer); editScrollingTimer = setTimeout(editScrollingTimeoutInner, duration * 1.5); @@ -360,4 +365,10 @@ function syncScrollToView(event, preventAnimate) { function editScrollingTimeoutInner() { editScrolling = false; -} \ No newline at end of file +} + +module.exports = { + setupSyncAreas: setupSyncAreas, + clearMap: clearMap, + syncScrollToEdit: syncScrollToEdit +}; -- cgit v1.2.3 From 2b678c1f129abde7e20f471018c55626f57cae97 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 8 Oct 2016 23:03:33 +0800 Subject: Make editor variable global --- public/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 3801eea2..d84d0a8d 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -464,7 +464,7 @@ var fileTypes = { //editor settings var textit = document.getElementById("textit"); if (!textit) throw new Error("There was no textit area!"); -var editor = CodeMirror.fromTextArea(textit, { +window.editor = CodeMirror.fromTextArea(textit, { mode: 'gfm', backdrop: 'gfm', keyMap: "sublime", -- cgit v1.2.3 From 8e2b03cfd6d389df454d4baed68837c84e64ae66 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 8 Oct 2016 23:04:19 +0800 Subject: Config bootstrap with webpack --- public/js/history.js | 2 +- public/js/index.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/history.js b/public/js/history.js index fbf71db7..23c7bebd 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -378,5 +378,5 @@ function parseToHistory(list, notehistory, callback) { } module.exports = { - writeHistory: writeHistory + writeHistory: writeHistory } diff --git a/public/js/index.js b/public/js/index.js index d84d0a8d..08f64d46 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -13,6 +13,7 @@ require('../vendor/showup/showup'); /* bootstrap */ require('bootstrap'); +require('bootstrap/dist/css/bootstrap.css'); /* code mirror plugins */ require('codemirror/keymap/vim'); -- cgit v1.2.3 From 845e9342c5b12638abcd6aa5cf96c9ce87762e9f Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 07:54:52 +0800 Subject: Add highlight.js and prism styles --- public/js/index.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 08f64d46..243761e6 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -15,6 +15,9 @@ require('../vendor/showup/showup'); require('bootstrap'); require('bootstrap/dist/css/bootstrap.css'); +require('prismjs/themes/prism.css'); +require('highlight.js/styles/github-gist.css'); + /* code mirror plugins */ require('codemirror/keymap/vim'); require('codemirror/keymap/emacs'); -- cgit v1.2.3 From 7e6b9f776ff18e77425bafaed76ede70fe712189 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 08:15:23 +0800 Subject: Revert customized ot library and fix dependency --- public/js/index.js | 6 ------ 1 file changed, 6 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 243761e6..0b64f667 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -24,12 +24,6 @@ require('codemirror/keymap/emacs'); require('codemirror/keymap/sublime'); require('codemirror/addon/display/panel'); -/* operational transformation */ -require('ot/lib/socketio-adapter'); -require('ot/lib/codemirror-adapter'); -require('ot/lib/undo-manager'); -require('../vendor/ot/editor-client'); - require('markdown-it'); require('markdown-it-abbr'); require('markdown-it-footnote'); -- cgit v1.2.3 From 67d118782de12f851ad38be13fa9f519ba100765 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 08:15:37 +0800 Subject: Fix function export --- public/js/index.js | 1 + public/js/syncscroll.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 0b64f667..376c8ddd 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -76,6 +76,7 @@ var syncScroll = require('./syncscroll'); var setupSyncAreas = syncScroll.setupSyncAreas; var clearMap = syncScroll.clearMap; var syncScrollToEdit = syncScroll.syncScrollToEdit; +var syncScrollToView = syncScroll.syncScrollToView; var extra = require('./extra'); var md = extra.md; diff --git a/public/js/syncscroll.js b/public/js/syncscroll.js index 444cdebd..644022de 100644 --- a/public/js/syncscroll.js +++ b/public/js/syncscroll.js @@ -370,5 +370,6 @@ function editScrollingTimeoutInner() { module.exports = { setupSyncAreas: setupSyncAreas, clearMap: clearMap, - syncScrollToEdit: syncScrollToEdit + syncScrollToEdit: syncScrollToEdit, + syncScrollToView: syncScrollToView }; -- cgit v1.2.3 From 196d546f7e8273b3fdc1bd60c3bf627b2fa1462b Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 10:51:39 +0800 Subject: Fix pdfobject require --- public/js/extra.js | 3 +++ public/js/index.js | 31 ++++++++++++++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index c6a0f432..f449bed1 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -1,3 +1,6 @@ +var hljs = require('highlight.js'); +var PDFObject = require('pdfobject'); + //auto update last change var createtime = null; var lastchangetime = null; diff --git a/public/js/index.js b/public/js/index.js index 376c8ddd..0fba0b21 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -51,7 +51,6 @@ require('js-sequence-diagrams'); require('flowchart.js'); require('viz.js'); -require('pdfobject'); require('file-saver'); require('store'); require('js-url'); @@ -414,18 +413,18 @@ var statusType = { var defaultMode = modeType.view; //global vars -var loaded = false; -var needRefresh = false; -var isDirty = false; -var editShown = false; -var visibleXS = false; -var visibleSM = false; -var visibleMD = false; -var visibleLG = false; -var isTouchDevice = 'ontouchstart' in document.documentElement; +window.loaded = false; +window.needRefresh = false; +window.isDirty = false; +window.editShown = false; +window.visibleXS = false; +window.visibleSM = false; +window.visibleMD = false; +window.visibleLG = false; +window.isTouchDevice = 'ontouchstart' in document.documentElement; window.currentMode = defaultMode; -var currentStatus = statusType.offline; -var lastInfo = { +window.currentStatus = statusType.offline; +window.lastInfo = { needRestore: false, cursor: null, scroll: null, @@ -447,9 +446,9 @@ var lastInfo = { }, history: null }; -var personalInfo = {}; -var onlineUsers = []; -var fileTypes = { +window.personalInfo = {}; +window.onlineUsers = []; +window.fileTypes = { "pl": "perl", "cgi": "perl", "js": "javascript", @@ -2274,6 +2273,8 @@ function havePermission() { } return bool; } +// global module workaround +window.havePermission = havePermission; //socket.io actions var socket = io.connect({ -- cgit v1.2.3 From 3e2905be13551a0cceeb18e72242be891db10db7 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 17:54:51 +0800 Subject: Revert to customized codemirror --- public/js/index.js | 6 ------ 1 file changed, 6 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 0fba0b21..db76b745 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -18,12 +18,6 @@ require('bootstrap/dist/css/bootstrap.css'); require('prismjs/themes/prism.css'); require('highlight.js/styles/github-gist.css'); -/* code mirror plugins */ -require('codemirror/keymap/vim'); -require('codemirror/keymap/emacs'); -require('codemirror/keymap/sublime'); -require('codemirror/addon/display/panel'); - require('markdown-it'); require('markdown-it-abbr'); require('markdown-it-footnote'); -- cgit v1.2.3 From 28858288fbc386350022bc4830775d21af217c11 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 17:55:07 +0800 Subject: Fix more js errors --- public/js/extra.js | 1 + 1 file changed, 1 insertion(+) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index f449bed1..d4a6c5cd 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -1,5 +1,6 @@ var hljs = require('highlight.js'); var PDFObject = require('pdfobject'); +var S = require('string'); //auto update last change var createtime = null; -- cgit v1.2.3 From 5355da09606035d3fcb05cc3bccc13e4ff888a91 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 21:08:33 +0800 Subject: Workaround for circular require --- public/js/pretty.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'public/js') diff --git a/public/js/pretty.js b/public/js/pretty.js index ebdec2a9..6b551c17 100644 --- a/public/js/pretty.js +++ b/public/js/pretty.js @@ -1,4 +1,4 @@ -var extra = require('./extra') +var extra = require('./extra'); var md = extra.md; var finishView = extra.finishView; var autoLinkify = extra.autoLinkify; @@ -124,6 +124,10 @@ function scrollToBottom() { }, 100, "linear"); } +window.scrollToTop = scrollToTop; +window.scrollToBottom = scrollToBottom; + module.exports = { - scrollToBottom: scrollToBottom + scrollToBottom: scrollToBottom, + scrollToTop: scrollToTop } -- cgit v1.2.3 From 53b5cbb89325f4acb239afb188c4bbabe1ea8189 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 21:09:22 +0800 Subject: Finish public note view js loading --- public/js/public.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 public/js/public.js (limited to 'public/js') diff --git a/public/js/public.js b/public/js/public.js new file mode 100644 index 00000000..9a46a437 --- /dev/null +++ b/public/js/public.js @@ -0,0 +1,60 @@ +/* include jquery ui */ +require('jquery-ui/ui/widgets/resizable'); +require('jquery-ui/ui/widgets/tooltip'); +require('jquery-ui/ui/widgets/controlgroup'); +require('jquery-ui/ui/widgets/autocomplete'); + +/* jquery and jquery plugins */ +require('jquery'); +require('jquery-textcomplete'); +require('jquery-mousewheel'); +require('../vendor/jquery-scrollspy'); +require('../vendor/showup/showup'); + +/* bootstrap */ +require('bootstrap'); +require('bootstrap/dist/css/bootstrap.css'); + +require('prismjs/themes/prism.css'); +require('highlight.js/styles/github-gist.css'); + +require('markdown-it'); +require('markdown-it-abbr'); +require('markdown-it-footnote'); +require('markdown-it-deflist'); +require('markdown-it-mark'); +require('markdown-it-ins'); +require('markdown-it-sub'); +require('markdown-it-sup'); +require('markdown-it-container'); +require('markdown-it-mathjax'); +require('markdown-it-regexp'); +require('markdown-it-imsize'); + +/* other vendors plugin */ +require('gist-embed'); +require('string'); +require('highlight.js'); +require('prismjs'); +require('prismjs/components/prism-wiki'); +require('js-cookie'); +require('to-markdown'); + +require('raphael'); +require('js-sequence-diagrams'); + +require('flowchart.js'); +require('viz.js'); +require('file-saver'); +require('store'); +require('js-url'); +require('visibilityjs'); +require('list.js'); +require('../vendor/md-toc'); +require('randomcolor'); + +require('./syncscroll'); +require('./extra'); +require('./history'); +require('./pretty'); +require('./render'); -- cgit v1.2.3 From 8a254ea4f109db99bdc172ba2717997c4d5dd490 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 21:14:18 +0800 Subject: Fix scrollToTop/Buttom in preview workaround --- public/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index db76b745..7be03086 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -71,6 +71,7 @@ var clearMap = syncScroll.clearMap; var syncScrollToEdit = syncScroll.syncScrollToEdit; var syncScrollToView = syncScroll.syncScrollToView; +require('./pretty'); var extra = require('./extra'); var md = extra.md; var createtime = extra.createtime; @@ -91,7 +92,6 @@ var scrollToHash = extra.scrollToHash; var history = require('./history'); var writeHistory = history.writeHistory; -var pretty = require('./pretty'); var renderer = require('./render'); var preventXSS = renderer.preventXSS; -- cgit v1.2.3 From 2ccaf7119162f596fbc6ceb011cbf841575e21d5 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 21:34:40 +0800 Subject: Update common.js.example --- public/js/common.js.example | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/common.js.example b/public/js/common.js.example index 11c32acc..c6325721 100644 --- a/public/js/common.js.example +++ b/public/js/common.js.example @@ -92,4 +92,33 @@ function checkIfAuth(yesCallback, noCallback) { } else { noCallback(); } -} \ No newline at end of file +} + +module.exports = { + domain: domain, + urlpath: urlpath, + debug: debug, + GOOGLE_API_KEY: GOOGLE_API_KEY, + GOOGLE_CLIENT_ID: GOOGLE_CLIENT_ID, + DROPBOX_APP_KEY: DROPBOX_APP_KEY, + port: port, + serverurl: serverurl, + noteid: noteid, + noteurl: noteurl, + version: version, + checkAuth: checkAuth, + profile: profile, + lastLoginState: lastLoginState, + lastUserId: lastUserId, + loginStateChangeEvent: loginStateChangeEvent, + + /* export functions */ + resetCheckAuth: resetCheckAuth, + setLoginState: setLoginState, + checkLoginStateChanged: checkLoginStateChanged, + getLoginState: getLoginState, + getUserId: getUserId, + clearLoginState: clearLoginState, + checkIfAuth: checkIfAuth +}; +} -- cgit v1.2.3 From 8f9afa42d57b26599de935e93b8b3a14d899566c Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 21:35:24 +0800 Subject: Fix history and edit mode change --- public/js/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 7be03086..8a55037b 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -55,6 +55,7 @@ require('randomcolor'); var common = require('./common.js'); var urlpath = common.urlpath; +var noteid = common.noteid; var debug = common.debug; var version = common.version; var serverurl = common.serverurl; @@ -89,9 +90,8 @@ var renderTitle = extra.renderTitle; var renderFilename = extra.renderFilename; var scrollToHash = extra.scrollToHash; -var history = require('./history'); -var writeHistory = history.writeHistory; - +var historyModule = require('./history'); +var writeHistory = historyModule.writeHistory; var renderer = require('./render'); var preventXSS = renderer.preventXSS; -- cgit v1.2.3 From a25889788443556703cf1f9b412b5d6dbf90febd Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 21:35:56 +0800 Subject: Revert some bower assets --- public/js/index.js | 2 +- public/js/public.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 8a55037b..bac2c9d0 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -8,7 +8,7 @@ require('jquery-ui/ui/widgets/autocomplete'); require('jquery'); require('jquery-textcomplete'); require('jquery-mousewheel'); -require('../vendor/jquery-scrollspy'); +require('jquery-scrollspy/jquery-scrollspy'); require('../vendor/showup/showup'); /* bootstrap */ diff --git a/public/js/public.js b/public/js/public.js index 9a46a437..858de389 100644 --- a/public/js/public.js +++ b/public/js/public.js @@ -8,7 +8,7 @@ require('jquery-ui/ui/widgets/autocomplete'); require('jquery'); require('jquery-textcomplete'); require('jquery-mousewheel'); -require('../vendor/jquery-scrollspy'); +require('jquery-scrollspy/jquery-scrollspy'); require('../vendor/showup/showup'); /* bootstrap */ -- cgit v1.2.3 From 70c20aaddaff75c3d0b7eb0fd53da13bb5651387 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sun, 9 Oct 2016 21:47:29 +0800 Subject: Remove redundant entry point --- public/js/app.js | 1 - 1 file changed, 1 deletion(-) delete mode 100644 public/js/app.js (limited to 'public/js') diff --git a/public/js/app.js b/public/js/app.js deleted file mode 100644 index fe864504..00000000 --- a/public/js/app.js +++ /dev/null @@ -1 +0,0 @@ -require('./index'); -- cgit v1.2.3 From e10203b7e9bb407fceee1f176dc8ff36b59a4acd Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Mon, 10 Oct 2016 08:24:58 +0800 Subject: More function expose workaround for reveal-markdown.js --- public/js/extra.js | 2 ++ public/js/render.js | 1 + 2 files changed, 3 insertions(+) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index d4a6c5cd..4ec7e80f 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -442,6 +442,7 @@ function postProcess(code) { } return result; } +window.postProcess = postProcess; function generateCleanHTML(view) { var src = view.clone(); @@ -811,6 +812,7 @@ var md = markdownit('default', { typographer: true, highlight: highlightRender }); +window.md = md; md.use(require('markdown-it-abbr')); md.use(require('markdown-it-footnote')); diff --git a/public/js/render.js b/public/js/render.js index 41b367a3..77778795 100644 --- a/public/js/render.js +++ b/public/js/render.js @@ -51,6 +51,7 @@ var filterXSSOptions = { function preventXSS(html) { return filterXSS(html, filterXSSOptions); } +window.preventXSS = preventXSS; module.exports = { preventXSS: preventXSS -- cgit v1.2.3 From 082178d535fd15a49d7157268c62f297af5a27ff Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Mon, 10 Oct 2016 08:25:35 +0800 Subject: Slide mode is now working --- public/js/slide.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'public/js') diff --git a/public/js/slide.js b/public/js/slide.js index 5b0f9bd0..b5aa868f 100644 --- a/public/js/slide.js +++ b/public/js/slide.js @@ -1,3 +1,76 @@ +require('bootstrap'); +require('bootstrap/js/tooltip'); +require('bootstrap/dist/css/bootstrap.css'); + +require('prismjs/themes/prism.css'); +require('highlight.js/styles/github-gist.css'); + +require('markdown-it'); +require('markdown-it-abbr'); +require('markdown-it-footnote'); +require('markdown-it-deflist'); +require('markdown-it-mark'); +require('markdown-it-ins'); +require('markdown-it-sub'); +require('markdown-it-sup'); +require('markdown-it-container'); +require('markdown-it-mathjax'); +require('markdown-it-regexp'); +require('markdown-it-imsize'); + +/* other vendors plugin */ +require('gist-embed'); +var S = require('string'); +require('highlight.js'); +require('prismjs'); +require('prismjs/components/prism-wiki'); +require('js-cookie'); +require('to-markdown'); + +require('raphael'); +require('js-sequence-diagrams'); + +require('flowchart.js'); +require('viz.js'); +require('file-saver'); +require('store'); +require('js-url'); +require('visibilityjs'); +require('list.js'); +require('../vendor/md-toc'); +require('randomcolor'); + +var commonModule = require('./common'); +var urlpath = commonModule.urlpath; +var noteid = commonModule.noteid; +var debug = commonModule.debug; +var version = commonModule.version; +var serverurl = commonModule.serverurl; +var GOOGLE_API_KEY = commonModule.GOOGLE_API_KEY; +var GOOGLE_CLIENT_ID = commonModule.GOOGLE_CLIENT_ID; +var DROPBOX_APP_KEY = commonModule.DROPBOX_APP_KEY; +var noteurl = commonModule.noteurl; + +var extraModule = require('./extra'); +var md = extraModule.md; +var createtime = extraModule.createtime; +var updateLastChange = extraModule.updateLastChange; +var postProcess = extraModule.postProcess; +var finishView = extraModule.finishView; +var lastchangetime = extraModule.lastchangetime; +var lastchangeui = extraModule.lastchangeui; +var autoLinkify = extraModule.autoLinkify; +var generateToc = extraModule.generateToc; +var smoothHashScroll = extraModule.smoothHashScroll; +var lastchangeuser = extraModule.lastchangeuser; +var deduplicatedHeaderId = extraModule.deduplicatedHeaderId; +var renderTOC = extraModule.renderTOC; +var renderTitle = extraModule.renderTitle; +var renderFilename = extraModule.renderFilename; +var scrollToHash = extraModule.scrollToHash; + +var render = require('./render'); + var body = $(".slides").html(); $(".slides").html(S(body).unescapeHTML().s); -- cgit v1.2.3 From 20f2e27350dba2f77199b434a4c236073f1aae04 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Mon, 10 Oct 2016 10:14:17 +0800 Subject: Cover page is now working --- public/js/cover.js | 22 ++++++++++++++++++---- public/js/history.js | 9 ++++++++- public/js/locale.js | 4 +++- 3 files changed, 29 insertions(+), 6 deletions(-) (limited to 'public/js') diff --git a/public/js/cover.js b/public/js/cover.js index f3533826..d3d3c10b 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -1,3 +1,17 @@ +var common = require('./common'); +var checkIfAuth = common.checkIfAuth; +var urlpath = common.urlpath; +var serverurl = common.serverurl; +var resetCheckAuth = common.resetCheckAuth; + +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 options = { valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'], item: '