From 136d895d155f28c2e75b3af206549acaa2a354ed Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Mon, 15 Feb 2021 09:42:51 +0100 Subject: Linter: Fix all lint errors Signed-off-by: Philip Molares --- public/.eslintrc.js | 48 +- public/js/cover.js | 10 +- public/js/extra.js | 74 +- public/js/history.js | 6 +- public/js/index.js | 2171 ++++++++++++++++++++++++++-------------- public/js/lib/appState.js | 2 +- public/js/lib/common/login.js | 2 +- public/js/lib/editor/config.js | 2 +- public/js/lib/editor/index.js | 123 +-- public/js/lib/editor/utils.js | 46 +- public/js/lib/syncscroll.js | 22 +- public/js/render.js | 34 +- public/js/reveal-markdown.js | 102 +- public/js/slide.js | 141 +-- public/js/utils.js | 12 +- 15 files changed, 1731 insertions(+), 1064 deletions(-) (limited to 'public') diff --git a/public/.eslintrc.js b/public/.eslintrc.js index dc37b3cb..77cd2c0d 100644 --- a/public/.eslintrc.js +++ b/public/.eslintrc.js @@ -1,28 +1,28 @@ // this config file is used in concert with the root .eslintrc.js in the root dir. module.exports = { - "env": { - "browser": true + env: { + browser: true }, - "globals": { - "$": false, - "CodeMirror": false, - "Cookies": false, - "moment": false, - "editor": false, - "ui": false, - "Spinner": false, - "modeType": false, - "Idle": false, - "serverurl": false, - "key": false, - "gapi": false, - "Dropbox": false, - "FilePicker": false, - "ot": false, - "MediaUploader": false, - "hex2rgb": false, - "num_loaded": false, - "Visibility": false, - "inlineAttachment": false + globals: { + $: false, + CodeMirror: false, + Cookies: false, + moment: false, + editor: false, + ui: false, + Spinner: false, + modeType: false, + Idle: false, + serverurl: false, + key: false, + gapi: false, + Dropbox: false, + FilePicker: false, + ot: false, + MediaUploader: false, + hex2rgb: false, + num_loaded: false, + Visibility: false, + inlineAttachment: false } -}; +} diff --git a/public/js/cover.js b/public/js/cover.js index ed10afbf..bad92574 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -262,8 +262,8 @@ function updateItemFromNow () { } } -var clearHistory = false -var deleteId = null +let clearHistory = false +let deleteId = null function deleteHistory () { checkIfAuth(() => { @@ -431,9 +431,9 @@ $('.search').keyup(() => { // focus user field after opening login modal $('.signin-modal').on('shown.bs.modal', function () { - let fieldLDAP = $('input[name=username]') - let fieldEmail = $('input[name=email]') - let fieldOpenID = $('input[name=openid_identifier]') + const fieldLDAP = $('input[name=username]') + const fieldEmail = $('input[name=email]') + const fieldOpenID = $('input[name=openid_identifier]') if (fieldLDAP.length === 1) { fieldLDAP.focus() } else if (fieldEmail.length === 1) { diff --git a/public/js/extra.js b/public/js/extra.js index 44db742a..7f06ebda 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -29,7 +29,7 @@ require('prismjs/components/prism-gherkin') require('./lib/common/login') require('./locale') require('../vendor/md-toc') -var Viz = require('viz.js') +const Viz = require('viz.js') const ui = getUIElements() // auto update last change @@ -314,8 +314,9 @@ export function finishView (view) { // sequence diagram const sequences = view.find('div.sequence-diagram.raw').removeClass('raw') sequences.each((key, value) => { + let $value try { - var $value = $(value) + $value = $(value) const $ele = $(value).parent().parent() const sequence = $value @@ -337,15 +338,16 @@ export function finishView (view) { // flowchart const flow = view.find('div.flow-chart.raw').removeClass('raw') flow.each((key, value) => { + let $value try { - var $value = $(value) + $value = $(value) const $ele = $(value).parent().parent() const chart = window.flowchart.parse($value.text()) $value.html('') chart.drawSVG(value, { 'line-width': 2, - 'fill': 'none', + fill: 'none', 'font-size': '16px', 'font-family': "'Andale Mono', monospace" }) @@ -359,13 +361,14 @@ export function finishView (view) { } }) // graphviz - var graphvizs = view.find('div.graphviz.raw').removeClass('raw') + const graphvizs = view.find('div.graphviz.raw').removeClass('raw') graphvizs.each(function (key, value) { + let $value try { - var $value = $(value) - var $ele = $(value).parent().parent() + $value = $(value) + const $ele = $(value).parent().parent() - var graphviz = Viz($value.text()) + const graphviz = Viz($value.text()) if (!graphviz) throw Error('viz.js output empty graph') $value.html(graphviz) @@ -380,8 +383,9 @@ export function finishView (view) { // mermaid const mermaids = view.find('div.mermaid.raw').removeClass('raw') mermaids.each((key, value) => { + let $value try { - var $value = $(value) + $value = $(value) const $ele = $(value).closest('pre') window.mermaid.mermaidAPI.parse($value.text()) @@ -389,7 +393,7 @@ export function finishView (view) { $ele.text($value.text()) window.mermaid.init(undefined, $ele) } catch (err) { - var errormessage = err + let errormessage = err if (err.str) { errormessage = err.str } @@ -402,9 +406,10 @@ export function finishView (view) { // abc.js const abcs = view.find('div.abc.raw').removeClass('raw') abcs.each((key, value) => { + let $value try { - var $value = $(value) - var $ele = $(value).parent().parent() + $value = $(value) + const $ele = $(value).parent().parent() window.ABCJS.renderAbc(value, $value.text()) @@ -493,7 +498,7 @@ export function finishView (view) { let code = '' if (codeDiv.length > 0) code = codeDiv.html() else code = langDiv.html() - var result + let result if (!reallang) { result = { value: code @@ -571,7 +576,7 @@ export function postProcess (code) { } // show yaml meta paring error if (md.metaError) { - var warning = result.find('div#meta-error') + let warning = result.find('div#meta-error') if (warning && warning.length > 0) { warning.text(md.metaError) } else { @@ -583,14 +588,14 @@ export function postProcess (code) { } window.postProcess = postProcess -var domevents = Object.getOwnPropertyNames(document).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(Object.getPrototypeOf(document)))).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(window))).filter(function (i) { +const domevents = Object.getOwnPropertyNames(document).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(Object.getPrototypeOf(document)))).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(window))).filter(function (i) { return !i.indexOf('on') && (document[i] === null || typeof document[i] === 'function') }).filter(function (elem, pos, self) { return self.indexOf(elem) === pos }) export function removeDOMEvents (view) { - for (var i = 0, l = domevents.length; i < l; i++) { + for (let i = 0, l = domevents.length; i < l; i++) { view.find('[' + domevents[i] + ']').removeAttr(domevents[i]) } } @@ -739,13 +744,13 @@ export function generateToc (id) { const target = $(`#${id}`) target.html('') /* eslint-disable no-unused-vars */ - var toc = new window.Toc('doc', { - 'level': 3, - 'top': -1, - 'class': 'toc', - 'ulClass': 'nav', - 'targetId': id, - 'process': getHeaderContent + const toc = new window.Toc('doc', { + level: 3, + top: -1, + class: 'toc', + ulClass: 'nav', + targetId: id, + process: getHeaderContent }) /* eslint-enable no-unused-vars */ if (target.text() === 'undefined') { target.html('') } @@ -858,7 +863,7 @@ const linkifyAnchors = (level, containingElement) => { const headers = containingElement.getElementsByTagName(`h${level}`) for (let i = 0, l = headers.length; i < l; i++) { - let header = headers[i] + const header = headers[i] if (header.getElementsByClassName('anchor').length === 0) { if (typeof header.id === 'undefined' || header.id === '') { header.id = createHeaderId(getHeaderContent(header)) @@ -903,7 +908,7 @@ export function deduplicatedHeaderId (view) { if (window.linkifyHeaderStyle === 'gfm') { // consistent with GitHub, GitLab, Pandoc & co. // all headers contained in the document, in order of appearance - const allHeaders = view.find(`:header`).toArray() + const allHeaders = view.find(':header').toArray() // list of finaly assigned header IDs const headerIds = new Set() for (let j = 0; j < allHeaders.length; j++) { @@ -938,12 +943,12 @@ export function renderTOC (view) { const target = $(`#${id}`) target.html('') /* eslint-disable no-unused-vars */ - let TOC = new window.Toc('doc', { - 'level': 3, - 'top': -1, - 'class': 'toc', - 'targetId': id, - 'process': getHeaderContent + const TOC = new window.Toc('doc', { + level: 3, + top: -1, + class: 'toc', + targetId: id, + process: getHeaderContent }) /* eslint-enable no-unused-vars */ if (target.text() === 'undefined') { target.html('') } @@ -991,7 +996,7 @@ function highlightRender (code, lang) { return result.value } -export let md = markdownit('default', { +export const md = markdownit('default', { html: true, breaks: true, langPrefix: '', @@ -1044,7 +1049,7 @@ md.use(markdownitContainer, 'info', { render: renderContainer }) md.use(markdownitContainer, 'warning', { render: renderContainer }) md.use(markdownitContainer, 'danger', { render: renderContainer }) -let defaultImageRender = md.renderer.rules.image +const defaultImageRender = md.renderer.rules.image md.renderer.rules.image = function (tokens, idx, options, env, self) { tokens[idx].attrJoin('class', 'raw') return defaultImageRender(...arguments) @@ -1203,7 +1208,8 @@ function meta (state, start, end, silent) { if (!get(state, start).match(/^---$/)) return false const data = [] - for (var line = start + 1; line < end; line++) { + let line + for (line = start + 1; line < end; line++) { const str = get(state, line) if (str.match(/^(\.{3}|-{3})$/)) break if (state.tShift[line] < 0) break diff --git a/public/js/history.js b/public/js/history.js index e0154185..b8935eb3 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -147,7 +147,7 @@ export function writeHistory (title, tags) { } function writeHistoryToStorage (title, tags) { - let data = store.get('notehistory') + const data = store.get('notehistory') let notehistory if (data && typeof data === 'string') { notehistory = JSON.parse(data) @@ -220,7 +220,7 @@ export function getStorageHistory (callback) { if (typeof data === 'string') { data = JSON.parse(data) } callback(data) } - // eslint-disable-next-line standard/no-callback-literal + // eslint-disable-next-line node/no-callback-literal callback([]) } @@ -263,7 +263,7 @@ function parseToHistory (list, notehistory, callback) { for (let i = 0; i < notehistory.length; i++) { // migrate LZString encoded id to base64url encoded id try { - let id = LZString.decompressFromBase64(notehistory[i].id) + const id = LZString.decompressFromBase64(notehistory[i].id) if (id && checkNoteIdValid(id)) { notehistory[i].id = encodeNoteId(id) } diff --git a/public/js/index.js b/public/js/index.js index adc95461..03cae1b4 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -85,19 +85,49 @@ require('../css/site.css') require('highlight.js/styles/github-gist.css') -var defaultTextHeight = 20 -var viewportMargin = 20 -var defaultEditorMode = 'gfm' - -var idleTime = 300000 // 5 mins -var updateViewDebounce = 100 -var cursorMenuThrottle = 50 -var cursorActivityDebounce = 50 -var cursorAnimatePeriod = 100 -var supportContainers = ['success', 'info', 'warning', 'danger'] -var supportCodeModes = ['javascript', 'typescript', 'jsx', 'htmlmixed', 'htmlembedded', 'css', 'xml', 'clike', 'clojure', 'ruby', 'python', 'shell', 'php', 'sql', 'haskell', 'coffeescript', 'yaml', 'pug', 'lua', 'cmake', 'nginx', 'perl', 'sass', 'r', 'dockerfile', 'tiddlywiki', 'mediawiki', 'go', 'gherkin'].concat(hljs.listLanguages()) -var supportCharts = ['sequence', 'flow', 'graphviz', 'mermaid', 'abc'] -var supportHeaders = [ +let defaultTextHeight = 20 +let viewportMargin = 20 +const defaultEditorMode = 'gfm' + +const idleTime = 300000 // 5 mins +const updateViewDebounce = 100 +const cursorMenuThrottle = 50 +const cursorActivityDebounce = 50 +const cursorAnimatePeriod = 100 +const supportContainers = ['success', 'info', 'warning', 'danger'] +const supportCodeModes = [ + 'javascript', + 'typescript', + 'jsx', + 'htmlmixed', + 'htmlembedded', + 'css', + 'xml', + 'clike', + 'clojure', + 'ruby', + 'python', + 'shell', + 'php', + 'sql', + 'haskell', + 'coffeescript', + 'yaml', + 'pug', + 'lua', + 'cmake', + 'nginx', + 'perl', + 'sass', + 'r', + 'dockerfile', + 'tiddlywiki', + 'mediawiki', + 'go', + 'gherkin' +].concat(hljs.listLanguages()) +const supportCharts = ['sequence', 'flow', 'graphviz', 'mermaid', 'abc'] +const supportHeaders = [ { text: '# h1', search: '#' @@ -225,7 +255,7 @@ const supportExtraTags = [ text: '[random color tag]', search: '[]', command: function () { - var color = randomColor() + const color = randomColor() return '[color=' + color + ']' } } @@ -259,7 +289,7 @@ let visibleMD = false let visibleLG = false const isTouchDevice = 'ontouchstart' in document.documentElement let currentStatus = statusType.offline -let lastInfo = { +const lastInfo = { needRestore: false, cursor: null, scroll: null, @@ -285,14 +315,14 @@ let lastInfo = { let personalInfo = {} let onlineUsers = [] const fileTypes = { - 'pl': 'perl', - 'cgi': 'perl', - 'js': 'javascript', - 'php': 'php', - 'sh': 'bash', - 'rb': 'ruby', - 'html': 'html', - 'py': 'python' + pl: 'perl', + cgi: 'perl', + js: 'javascript', + php: 'php', + sh: 'bash', + rb: 'ruby', + html: 'html', + py: 'python' } // editor settings @@ -302,7 +332,7 @@ if (!textit) { } const editorInstance = new Editor() -var editor = editorInstance.init(textit) +const editor = editorInstance.init(textit) // FIXME: global referncing in jquery-textcomplete patch window.editor = editor @@ -313,7 +343,7 @@ defaultTextHeight = parseInt($('.CodeMirror').css('line-height')) const ui = getUIElements() // page actions -var opts = { +const opts = { lines: 11, // The number of lines to draw length: 20, // The length of each line width: 2, // The line thickness @@ -333,11 +363,11 @@ var opts = { } /* eslint-disable no-unused-vars */ -var spinner = new Spinner(opts).spin(ui.spinner[0]) +const spinner = new Spinner(opts).spin(ui.spinner[0]) /* eslint-enable no-unused-vars */ // idle -var idle = new Idle({ +const idle = new Idle({ onAway: function () { idle.isAway = true emitUserStatus() @@ -356,7 +386,7 @@ ui.area.codemirror.on('touchstart', function () { idle.onActive() }) -var haveUnreadChanges = false +let haveUnreadChanges = false function setHaveUnreadChanges (bool) { if (!window.loaded) return @@ -379,7 +409,9 @@ function updateTitleReminder () { function setRefreshModal (status) { $('#refreshModal').modal('show') $('#refreshModal').find('.modal-body > div').hide() - $('#refreshModal').find('.' + status).show() + $('#refreshModal') + .find('.' + status) + .show() } function setNeedRefresh () { @@ -395,9 +427,9 @@ setloginStateChangeEvent(function () { }) // visibility -var wasFocus = false +let wasFocus = false Visibility.change(function (e, state) { - var hidden = Visibility.hidden() + const hidden = Visibility.hidden() if (hidden) { if (editorHasFocus()) { wasFocus = true @@ -421,7 +453,7 @@ $(document).ready(function () { idle.checkAway() checkResponsive() // if in smaller screen, we don't need advanced scrollbar - var scrollbarStyle + let scrollbarStyle if (visibleXS) { scrollbarStyle = 'native' } else { @@ -434,7 +466,7 @@ $(document).ready(function () { checkEditorStyle() /* cache dom references */ - var $body = $('body') + const $body = $('body') /* we need this only on touch devices */ if (isTouchDevice) { @@ -463,7 +495,9 @@ $(document).ready(function () { $('[data-toggle="tooltip"]').tooltip() // shortcuts // allow on all tags - key.filter = function (e) { return true } + key.filter = function (e) { + return true + } key('ctrl+alt+e', function (e) { changeMode(modeType.edit) }) @@ -488,13 +522,18 @@ $(window).resize(function () { }) // when page unload $(window).on('unload', function () { -// updateHistoryInner(); + // updateHistoryInner(); }) $(window).on('error', function () { // setNeedRefresh(); }) -setupSyncAreas(ui.area.codemirrorScroll, ui.area.view, ui.area.markdown, editor) +setupSyncAreas( + ui.area.codemirrorScroll, + ui.area.view, + ui.area.markdown, + editor +) function autoSyncscroll () { if (editorHasFocus()) { @@ -504,8 +543,8 @@ function autoSyncscroll () { } } -var windowResizeDebounce = 200 -var windowResize = _.debounce(windowResizeInner, windowResizeDebounce) +const windowResizeDebounce = 200 +const windowResize = _.debounce(windowResizeInner, windowResizeDebounce) function windowResizeInner (callback) { checkLayout() @@ -520,7 +559,9 @@ function windowResizeInner (callback) { clearMap() autoSyncscroll() updateScrollspy() - if (callback && typeof callback === 'function') { callback() } + if (callback && typeof callback === 'function') { + callback() + } }, 1) } else { // force it load all docs at once to prevent scroll knob blink @@ -530,18 +571,22 @@ function windowResizeInner (callback) { autoSyncscroll() editor.setOption('viewportMargin', viewportMargin) // add or update user cursors - for (var i = 0; i < onlineUsers.length; i++) { - if (onlineUsers[i].id !== personalInfo.id) { buildCursor(onlineUsers[i]) } + for (let i = 0; i < onlineUsers.length; i++) { + if (onlineUsers[i].id !== personalInfo.id) { + buildCursor(onlineUsers[i]) + } } updateScrollspy() - if (callback && typeof callback === 'function') { callback() } + if (callback && typeof callback === 'function') { + callback() + } }, 1) } } } function checkLayout () { - var navbarHieght = $('.navbar').outerHeight() + const navbarHieght = $('.navbar').outerHeight() $('body').css('padding-top', navbarHieght + 'px') } @@ -557,22 +602,28 @@ function checkResponsive () { visibleLG = $('.visible-lg').is(':visible') if (visibleXS && appState.currentMode === modeType.both) { - if (editorHasFocus()) { changeMode(modeType.edit) } else { changeMode(modeType.view) } + if (editorHasFocus()) { + changeMode(modeType.edit) + } else { + changeMode(modeType.view) + } } emitUserStatus() } -var lastEditorWidth = 0 -var previousFocusOnEditor = null +let lastEditorWidth = 0 +let previousFocusOnEditor = null function checkEditorStyle () { - var desireHeight = editorInstance.statusBar ? (ui.area.edit.height() - editorInstance.statusBar.outerHeight()) : ui.area.edit.height() + let desireHeight = editorInstance.statusBar + ? ui.area.edit.height() - editorInstance.statusBar.outerHeight() + : ui.area.edit.height() if (editorInstance.toolBar) { desireHeight = desireHeight - editorInstance.toolBar.outerHeight() } // set editor height and min height based on scrollbar style and mode - var scrollbarStyle = editor.getOption('scrollbarStyle') + const scrollbarStyle = editor.getOption('scrollbarStyle') if (scrollbarStyle === 'overlay' || appState.currentMode === modeType.both) { ui.area.codemirrorScroll.css('height', desireHeight + 'px') ui.area.codemirrorScroll.css('min-height', '') @@ -590,9 +641,11 @@ function checkEditorStyle () { maxWidth: $(window).width() * 0.7, minWidth: $(window).width() * 0.2, create: function (e, ui) { - $(this).parent().on('resize', function (e) { - e.stopPropagation() - }) + $(this) + .parent() + .on('resize', function (e) { + e.stopPropagation() + }) }, start: function (e) { editor.setOption('viewportMargin', Infinity) @@ -622,23 +675,31 @@ function checkEditorStyle () { ui.area.resize.handle = $('.ui-resizable-handle') } if (!ui.area.resize.syncToggle.length) { - ui.area.resize.syncToggle = $('') - ui.area.resize.syncToggle.hover(function () { - previousFocusOnEditor = editorHasFocus() - }, function () { - previousFocusOnEditor = null - }) + ui.area.resize.syncToggle = $( + '' + ) + ui.area.resize.syncToggle.hover( + function () { + previousFocusOnEditor = editorHasFocus() + }, + function () { + previousFocusOnEditor = null + } + ) ui.area.resize.syncToggle.click(function () { appState.syncscroll = !appState.syncscroll checkSyncToggle() }) ui.area.resize.handle.append(ui.area.resize.syncToggle) ui.area.resize.syncToggle.hide() - ui.area.resize.handle.hover(function () { - ui.area.resize.syncToggle.stop(true, true).delay(200).fadeIn(100) - }, function () { - ui.area.resize.syncToggle.stop(true, true).delay(300).fadeOut(300) - }) + ui.area.resize.handle.hover( + function () { + ui.area.resize.syncToggle.stop(true, true).delay(200).fadeIn(100) + }, + function () { + ui.area.resize.syncToggle.stop(true, true).delay(300).fadeOut(300) + } + ) } } @@ -651,37 +712,53 @@ function checkSyncToggle () { window.preventSyncScrollToEdit = false syncScrollToEdit() } - ui.area.resize.syncToggle.find('i').removeClass('fa-unlink').addClass('fa-link') + ui.area.resize.syncToggle + .find('i') + .removeClass('fa-unlink') + .addClass('fa-link') } else { - ui.area.resize.syncToggle.find('i').removeClass('fa-link').addClass('fa-unlink') + ui.area.resize.syncToggle + .find('i') + .removeClass('fa-link') + .addClass('fa-unlink') } } -var checkEditorScrollbar = _.debounce(function () { +const checkEditorScrollbar = _.debounce(function () { editor.operation(checkEditorScrollbarInner) }, 50) function checkEditorScrollbarInner () { // workaround simple scroll bar knob // will get wrong position when editor height changed - var scrollInfo = editor.getScrollInfo() + const scrollInfo = editor.getScrollInfo() editor.scrollTo(null, scrollInfo.top - 1) editor.scrollTo(null, scrollInfo.top) } function checkTocStyle () { // toc right - var paddingRight = parseFloat(ui.area.markdown.css('padding-right')) - var right = ($(window).width() - (ui.area.markdown.offset().left + ui.area.markdown.outerWidth() - paddingRight)) + const paddingRight = parseFloat(ui.area.markdown.css('padding-right')) + const right = + $(window).width() - + (ui.area.markdown.offset().left + + ui.area.markdown.outerWidth() - + paddingRight) ui.toc.toc.css('right', right + 'px') // affix toc left - var newbool - var rightMargin = (ui.area.markdown.parent().outerWidth() - ui.area.markdown.outerWidth()) / 2 + let newbool + const rightMargin = + (ui.area.markdown.parent().outerWidth() - ui.area.markdown.outerWidth()) / + 2 // for ipad or wider device if (rightMargin >= 133) { newbool = true - var affixLeftMargin = (ui.toc.affix.outerWidth() - ui.toc.affix.width()) / 2 - var left = ui.area.markdown.offset().left + ui.area.markdown.outerWidth() - affixLeftMargin + const affixLeftMargin = + (ui.toc.affix.outerWidth() - ui.toc.affix.width()) / 2 + const left = + ui.area.markdown.offset().left + + ui.area.markdown.outerWidth() - + affixLeftMargin ui.toc.affix.css('left', left + 'px') ui.toc.affix.css('width', rightMargin + 'px') } else { @@ -708,12 +785,12 @@ function checkTocStyle () { function showStatus (type, num) { currentStatus = type - var shortStatus = ui.toolbar.shortStatus - var status = ui.toolbar.status - var label = $('') - var fa = $('') - var msg = '' - var shortMsg = '' + const shortStatus = ui.toolbar.shortStatus + const status = ui.toolbar.status + const label = $('') + const fa = $('') + let msg = '' + let shortMsg = '' shortStatus.html('') status.html('') @@ -738,7 +815,7 @@ function showStatus (type, num) { } label.append(fa) - var shortLabel = label.clone() + const shortLabel = label.clone() shortLabel.append(' ' + shortMsg) shortStatus.append(shortLabel) @@ -761,7 +838,7 @@ function toggleMode () { } } -var lastMode = null +let lastMode = null function changeMode (type) { // lock navbar to prevent it hide after changeMode @@ -771,8 +848,8 @@ function changeMode (type) { lastMode = appState.currentMode appState.currentMode = type } - var responsiveClass = 'col-lg-6 col-md-6 col-sm-6' - var scrollClass = 'ui-scrollable' + const responsiveClass = 'col-lg-6 col-md-6 col-sm-6' + const scrollClass = 'ui-scrollable' ui.area.codemirror.removeClass(scrollClass) ui.area.edit.removeClass(responsiveClass) ui.area.view.removeClass(scrollClass) @@ -798,11 +875,20 @@ function changeMode (type) { break } // save mode to url - if (history.replaceState && window.loaded) history.replaceState(null, '', serverurl + '/' + noteid + '?' + appState.currentMode.name) + if (history.replaceState && window.loaded) { + history.replaceState( + null, + '', + serverurl + '/' + noteid + '?' + appState.currentMode.name + ) + } if (appState.currentMode === modeType.view) { editor.getInputField().blur() } - if (appState.currentMode === modeType.edit || appState.currentMode === modeType.both) { + if ( + appState.currentMode === modeType.edit || + appState.currentMode === modeType.both + ) { // add and update status bar if (!editorInstance.statusBar) { editorInstance.addStatusBar() @@ -820,7 +906,10 @@ function changeMode (type) { $(document.body).css('background-color', 'white') updateView() } else { - $(document.body).css('background-color', ui.area.codemirror.css('background-color')) + $(document.body).css( + 'background-color', + ui.area.codemirror.css('background-color') + ) } // check resizable editor style if (appState.currentMode === modeType.both) { @@ -864,15 +953,18 @@ function changeMode (type) { ui.toolbar.both.removeClass('active') ui.toolbar.edit.removeClass('active') ui.toolbar.view.removeClass('active') - var modeIcon = ui.toolbar.mode.find('i') + const modeIcon = ui.toolbar.mode.find('i') modeIcon.removeClass('fa-pencil').removeClass('fa-eye') - if (ui.area.edit.is(':visible') && ui.area.view.is(':visible')) { // both + if (ui.area.edit.is(':visible') && ui.area.view.is(':visible')) { + // both ui.toolbar.both.addClass('active') modeIcon.addClass('fa-eye') - } else if (ui.area.edit.is(':visible')) { // edit + } else if (ui.area.edit.is(':visible')) { + // edit ui.toolbar.edit.addClass('active') modeIcon.addClass('fa-eye') - } else if (ui.area.view.is(':visible')) { // view + } else if (ui.area.view.is(':visible')) { + // view ui.toolbar.view.addClass('active') modeIcon.addClass('fa-pencil') } @@ -883,17 +975,27 @@ function lockNavbar () { $('.navbar').addClass('locked') } -var unlockNavbar = _.debounce(function () { +const unlockNavbar = _.debounce(function () { $('.navbar').removeClass('locked') }, 200) function showMessageModal (title, header, href, text, success) { - var modal = $('.message-modal') + const modal = $('.message-modal') modal.find('.modal-title').html(title) modal.find('.modal-body h5').html(header) - if (href) { modal.find('.modal-body a').attr('href', href).text(text) } else { modal.find('.modal-body a').removeAttr('href').text(text) } - modal.find('.modal-footer button').removeClass('btn-default btn-success btn-danger') - if (success) { modal.find('.modal-footer button').addClass('btn-success') } else { modal.find('.modal-footer button').addClass('btn-danger') } + if (href) { + modal.find('.modal-body a').attr('href', href).text(text) + } else { + modal.find('.modal-body a').removeAttr('href').text(text) + } + modal + .find('.modal-footer button') + .removeClass('btn-default btn-success btn-danger') + if (success) { + modal.find('.modal-footer button').addClass('btn-success') + } else { + modal.find('.modal-footer button').addClass('btn-danger') + } modal.modal('show') } @@ -923,9 +1025,9 @@ ui.toolbar.extra.slide.attr('href', noteurl + '/slide') ui.toolbar.download.markdown.click(function (e) { e.preventDefault() e.stopPropagation() - var filename = renderFilename(ui.area.markdown) + '.md' - var markdown = editor.getValue() - var blob = new Blob([markdown], { + const filename = renderFilename(ui.area.markdown) + '.md' + const markdown = editor.getValue() + const blob = new Blob([markdown], { type: 'text/markdown;charset=utf-8' }) saveAs(blob, filename, true) @@ -945,12 +1047,12 @@ ui.toolbar.download.rawhtml.click(function (e) { // export to dropbox ui.toolbar.export.dropbox.click(function (event) { event.preventDefault() - var filename = renderFilename(ui.area.markdown) + '.md' - var options = { + const filename = renderFilename(ui.area.markdown) + '.md' + const options = { files: [ { - 'url': noteurl + '/download', - 'filename': filename + url: noteurl + '/download', + filename: filename } ], error: function (errorMessage) { @@ -971,25 +1073,48 @@ ui.toolbar.export.snippet.click(function () { $('#snippetExportModalVersion').val(data.version) $('#snippetExportModalLoading').hide() $('#snippetExportModal').modal('toggle') - $('#snippetExportModalProjects').find('option').remove().end().append('') + $('#snippetExportModalProjects') + .find('option') + .remove() + .end() + .append( + '' + ) if (data.projects) { data.projects.sort(function (a, b) { - return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0) + return a.path_with_namespace < b.path_with_namespace + ? -1 + : a.path_with_namespace > b.path_with_namespace + ? 1 + : 0 }) data.projects.forEach(function (project) { - if (!project.snippets_enabled || - (project.permissions.project_access === null && project.permissions.group_access === null) || - (project.permissions.project_access !== null && project.permissions.project_access.access_level < 20)) { + if ( + !project.snippets_enabled || + (project.permissions.project_access === null && + project.permissions.group_access === null) || + (project.permissions.project_access !== null && + project.permissions.project_access.access_level < 20) + ) { return } - $('') + $('#snippetImportModalProjects') + .find('option') + .remove() + .end() + .append( + '' + ) if (data.projects) { data.projects.sort(function (a, b) { - return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0) + return a.path_with_namespace < b.path_with_namespace + ? -1 + : a.path_with_namespace > b.path_with_namespace + ? 1 + : 0 }) data.projects.forEach(function (project) { - if (!project.snippets_enabled || - (project.permissions.project_access === null && project.permissions.group_access === null) || - (project.permissions.project_access !== null && project.permissions.project_access.access_level < 20)) { + if ( + !project.snippets_enabled || + (project.permissions.project_access === null && + project.permissions.group_access === null) || + (project.permissions.project_access !== null && + project.permissions.project_access.access_level < 20) + ) { return } - $('') + $('#snippetImportModalSnippets') + .find('option') + .remove() + .end() + .append( + '' + ) data.forEach(function (snippet) { - $('