summaryrefslogtreecommitdiff
path: root/public/js/lib
diff options
context:
space:
mode:
authorPhilip Molares2021-02-15 09:42:51 +0100
committerPhilip Molares2021-02-15 12:15:14 +0100
commit136d895d155f28c2e75b3af206549acaa2a354ed (patch)
treead80595f5dd94a7ac63bc1481943ae7b356ddb17 /public/js/lib
parentb0a45bdf9c531d93a2462c09d58b2e9e703a0a66 (diff)
Linter: Fix all lint errors
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Diffstat (limited to 'public/js/lib')
-rw-r--r--public/js/lib/appState.js2
-rw-r--r--public/js/lib/common/login.js2
-rw-r--r--public/js/lib/editor/config.js2
-rw-r--r--public/js/lib/editor/index.js123
-rw-r--r--public/js/lib/editor/utils.js46
-rw-r--r--public/js/lib/syncscroll.js22
6 files changed, 100 insertions, 97 deletions
diff --git a/public/js/lib/appState.js b/public/js/lib/appState.js
index 87aaf737..f409908c 100644
--- a/public/js/lib/appState.js
+++ b/public/js/lib/appState.js
@@ -1,6 +1,6 @@
import modeType from './modeType'
-let state = {
+const state = {
syncscroll: true,
currentMode: modeType.view,
nightMode: false
diff --git a/public/js/lib/common/login.js b/public/js/lib/common/login.js
index 3f7a3e4d..88e8f8cf 100644
--- a/public/js/lib/common/login.js
+++ b/public/js/lib/common/login.js
@@ -7,7 +7,7 @@ let checkAuth = false
let profile = null
let lastLoginState = getLoginState()
let lastUserId = getUserId()
-var loginStateChangeEvent = null
+let loginStateChangeEvent = null
export function setloginStateChangeEvent (func) {
loginStateChangeEvent = func
diff --git a/public/js/lib/editor/config.js b/public/js/lib/editor/config.js
index 9508b847..338ef6dc 100644
--- a/public/js/lib/editor/config.js
+++ b/public/js/lib/editor/config.js
@@ -1,4 +1,4 @@
-let config = {
+const config = {
docmaxlength: null
}
diff --git a/public/js/lib/editor/index.js b/public/js/lib/editor/index.js
index d86ebf3c..c84a3725 100644
--- a/public/js/lib/editor/index.js
+++ b/public/js/lib/editor/index.js
@@ -35,30 +35,30 @@ export default class Editor {
},
Enter: 'newlineAndIndentContinueMarkdownList',
Tab: function (cm) {
- var tab = '\t'
+ const tab = '\t'
// contruct x length spaces
- var spaces = Array(parseInt(cm.getOption('indentUnit')) + 1).join(' ')
+ const spaces = Array(parseInt(cm.getOption('indentUnit')) + 1).join(' ')
// auto indent whole line when in list or blockquote
- var cursor = cm.getCursor()
- var line = cm.getLine(cursor.line)
+ const cursor = cm.getCursor()
+ const line = cm.getLine(cursor.line)
// this regex match the following patterns
// 1. blockquote starts with "> " or ">>"
// 2. unorder list starts with *+-
// 3. order list starts with "1." or "1)"
- var regex = /^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))/
+ const regex = /^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))/
- var match
- var multiple = cm.getSelection().split('\n').length > 1 ||
+ let match
+ const multiple = cm.getSelection().split('\n').length > 1 ||
cm.getSelections().length > 1
if (multiple) {
cm.execCommand('defaultTab')
} else if ((match = regex.exec(line)) !== null) {
- var ch = match[1].length
- var pos = {
+ const ch = match[1].length
+ const pos = {
line: cursor.line,
ch: ch
}
@@ -77,8 +77,8 @@ export default class Editor {
},
'Cmd-Left': 'goLineLeftSmart',
'Cmd-Right': 'goLineRight',
- 'Home': 'goLineLeftSmart',
- 'End': 'goLineRight',
+ Home: 'goLineLeftSmart',
+ End: 'goLineRight',
'Ctrl-C': function (cm) {
if (!isMac && cm.getOption('keyMap').substr(0, 3) === 'vim') {
document.execCommand('copy')
@@ -140,27 +140,27 @@ export default class Editor {
}
addToolBar () {
- var inlineAttach = inlineAttachment.editors.codemirror4.attach(this.editor)
+ const inlineAttach = inlineAttachment.editors.codemirror4.attach(this.editor)
this.toolBar = $(toolBarTemplate)
this.toolbarPanel = this.editor.addPanel(this.toolBar[0], {
position: 'top'
})
- var makeBold = $('#makeBold')
- var makeItalic = $('#makeItalic')
- var makeStrike = $('#makeStrike')
- var makeHeader = $('#makeHeader')
- var makeCode = $('#makeCode')
- var makeQuote = $('#makeQuote')
- var makeGenericList = $('#makeGenericList')
- var makeOrderedList = $('#makeOrderedList')
- var makeCheckList = $('#makeCheckList')
- var makeLink = $('#makeLink')
- var makeImage = $('#makeImage')
- var makeTable = $('#makeTable')
- var makeLine = $('#makeLine')
- var makeComment = $('#makeComment')
- var uploadImage = $('#uploadImage')
+ const makeBold = $('#makeBold')
+ const makeItalic = $('#makeItalic')
+ const makeStrike = $('#makeStrike')
+ const makeHeader = $('#makeHeader')
+ const makeCode = $('#makeCode')
+ const makeQuote = $('#makeQuote')
+ const makeGenericList = $('#makeGenericList')
+ const makeOrderedList = $('#makeOrderedList')
+ const makeCheckList = $('#makeCheckList')
+ const makeLink = $('#makeLink')
+ const makeImage = $('#makeImage')
+ const makeTable = $('#makeTable')
+ const makeLine = $('#makeLine')
+ const makeComment = $('#makeComment')
+ const uploadImage = $('#uploadImage')
makeBold.click(() => {
utils.wrapTextWith(this.editor, this.editor, '**')
@@ -223,7 +223,7 @@ export default class Editor {
})
uploadImage.bind('change', function (e) {
- var files = e.target.files || e.dataTransfer.files
+ const files = e.target.files || e.dataTransfer.files
e.dataTransfer = {}
e.dataTransfer.files = files
inlineAttach.onDrop(e)
@@ -256,12 +256,12 @@ export default class Editor {
updateStatusBar () {
if (!this.statusBar) return
- var cursor = this.editor.getCursor()
- var cursorText = 'Line ' + (cursor.line + 1) + ', Columns ' + (cursor.ch + 1)
+ const cursor = this.editor.getCursor()
+ const cursorText = 'Line ' + (cursor.line + 1) + ', Columns ' + (cursor.ch + 1)
this.statusCursor.text(cursorText)
- var fileText = ' — ' + editor.lineCount() + ' Lines'
+ const fileText = ' — ' + editor.lineCount() + ' Lines'
this.statusFile.text(fileText)
- var docLength = editor.getValue().length
+ const docLength = editor.getValue().length
this.statusLength.text('Length ' + docLength)
if (docLength > (config.docmaxlength * 0.95)) {
this.statusLength.css('color', 'red')
@@ -276,9 +276,9 @@ export default class Editor {
}
setIndent () {
- var cookieIndentType = Cookies.get('indent_type')
- var cookieTabSize = parseInt(Cookies.get('tab_size'))
- var cookieSpaceUnits = parseInt(Cookies.get('space_units'))
+ const cookieIndentType = Cookies.get('indent_type')
+ let cookieTabSize = parseInt(Cookies.get('tab_size'))
+ let cookieSpaceUnits = parseInt(Cookies.get('space_units'))
if (cookieIndentType) {
if (cookieIndentType === 'tab') {
this.editor.setOption('indentWithTabs', true)
@@ -296,9 +296,9 @@ export default class Editor {
this.editor.setOption('tabSize', cookieTabSize)
}
- var type = this.statusIndicators.find('.indent-type')
- var widthLabel = this.statusIndicators.find('.indent-width-label')
- var widthInput = this.statusIndicators.find('.indent-width-input')
+ const type = this.statusIndicators.find('.indent-type')
+ const widthLabel = this.statusIndicators.find('.indent-width-label')
+ const widthInput = this.statusIndicators.find('.indent-width-input')
const setType = () => {
if (this.editor.getOption('indentWithTabs')) {
@@ -318,7 +318,7 @@ export default class Editor {
setType()
const setUnit = () => {
- var unit = this.editor.getOption('indentUnit')
+ const unit = this.editor.getOption('indentUnit')
if (this.editor.getOption('indentWithTabs')) {
Cookies.set('tab_size', unit, {
expires: 365,
@@ -364,7 +364,7 @@ export default class Editor {
}
})
widthInput.on('change', () => {
- var val = parseInt(widthInput.val())
+ let val = parseInt(widthInput.val())
if (!val) val = this.editor.getOption('indentUnit')
if (val < 1) val = 1
else if (val > 10) val = 10
@@ -382,18 +382,18 @@ export default class Editor {
}
setKeymap () {
- var cookieKeymap = Cookies.get('keymap')
+ const cookieKeymap = Cookies.get('keymap')
if (cookieKeymap) {
this.editor.setOption('keyMap', cookieKeymap)
}
- var label = this.statusIndicators.find('.ui-keymap-label')
- var sublime = this.statusIndicators.find('.ui-keymap-sublime')
- var emacs = this.statusIndicators.find('.ui-keymap-emacs')
- var vim = this.statusIndicators.find('.ui-keymap-vim')
+ const label = this.statusIndicators.find('.ui-keymap-label')
+ const sublime = this.statusIndicators.find('.ui-keymap-sublime')
+ const emacs = this.statusIndicators.find('.ui-keymap-emacs')
+ const vim = this.statusIndicators.find('.ui-keymap-vim')
const setKeymapLabel = () => {
- var keymap = this.editor.getOption('keyMap')
+ const keymap = this.editor.getOption('keyMap')
Cookies.set('keymap', keymap, {
expires: 365,
sameSite: window.cookiePolicy
@@ -419,15 +419,15 @@ export default class Editor {
}
setTheme () {
- var cookieTheme = Cookies.get('theme')
+ const cookieTheme = Cookies.get('theme')
if (cookieTheme) {
this.editor.setOption('theme', cookieTheme)
}
- var themeToggle = this.statusTheme.find('.ui-theme-toggle')
+ const themeToggle = this.statusTheme.find('.ui-theme-toggle')
const checkTheme = () => {
- var theme = this.editor.getOption('theme')
+ const theme = this.editor.getOption('theme')
if (theme === 'one-dark') {
themeToggle.removeClass('active')
} else {
@@ -436,7 +436,7 @@ export default class Editor {
}
themeToggle.click(() => {
- var theme = this.editor.getOption('theme')
+ let theme = this.editor.getOption('theme')
if (theme === 'one-dark') {
theme = 'default'
} else {
@@ -455,9 +455,9 @@ export default class Editor {
}
setSpellcheck () {
- var cookieSpellcheck = Cookies.get('spellcheck')
+ const cookieSpellcheck = Cookies.get('spellcheck')
if (cookieSpellcheck) {
- var mode = null
+ let mode = null
if (cookieSpellcheck === 'true' || cookieSpellcheck === true) {
mode = 'spell-checker'
} else {
@@ -468,10 +468,10 @@ export default class Editor {
}
}
- var spellcheckToggle = this.statusSpellcheck.find('.ui-spellcheck-toggle')
+ const spellcheckToggle = this.statusSpellcheck.find('.ui-spellcheck-toggle')
const checkSpellcheck = () => {
- var mode = this.editor.getOption('mode')
+ const mode = this.editor.getOption('mode')
if (mode === defaultEditorMode) {
spellcheckToggle.removeClass('active')
} else {
@@ -480,7 +480,7 @@ export default class Editor {
}
spellcheckToggle.click(() => {
- var mode = this.editor.getOption('mode')
+ let mode = this.editor.getOption('mode')
if (mode === defaultEditorMode) {
mode = 'spell-checker'
} else {
@@ -501,7 +501,7 @@ export default class Editor {
// workaround spellcheck might not activate beacuse the ajax loading
if (window.num_loaded < 2) {
- var spellcheckTimer = setInterval(
+ const spellcheckTimer = setInterval(
() => {
if (window.num_loaded >= 2) {
if (this.editor.getOption('mode') === 'spell-checker') {
@@ -516,7 +516,7 @@ export default class Editor {
}
resetEditorKeymapToBrowserKeymap () {
- var keymap = this.editor.getOption('keyMap')
+ const keymap = this.editor.getOption('keyMap')
if (!this.jumpToAddressBarKeymapValue) {
this.jumpToAddressBarKeymapValue = CodeMirror.keyMap[keymap][jumpToAddressBarKeymapName]
delete CodeMirror.keyMap[keymap][jumpToAddressBarKeymapName]
@@ -524,14 +524,15 @@ export default class Editor {
}
restoreOverrideEditorKeymap () {
- var keymap = this.editor.getOption('keyMap')
+ const keymap = this.editor.getOption('keyMap')
if (this.jumpToAddressBarKeymapValue) {
CodeMirror.keyMap[keymap][jumpToAddressBarKeymapName] = this.jumpToAddressBarKeymapValue
this.jumpToAddressBarKeymapValue = null
}
}
+
setOverrideBrowserKeymap () {
- var overrideBrowserKeymap = $(
+ const overrideBrowserKeymap = $(
'.ui-preferences-override-browser-keymap label > input[type="checkbox"]'
)
if (overrideBrowserKeymap.is(':checked')) {
@@ -547,10 +548,10 @@ export default class Editor {
}
setPreferences () {
- var overrideBrowserKeymap = $(
+ const overrideBrowserKeymap = $(
'.ui-preferences-override-browser-keymap label > input[type="checkbox"]'
)
- var cookieOverrideBrowserKeymap = Cookies.get(
+ const cookieOverrideBrowserKeymap = Cookies.get(
'preferences-override-browser-keymap'
)
if (cookieOverrideBrowserKeymap && cookieOverrideBrowserKeymap === 'true') {
diff --git a/public/js/lib/editor/utils.js b/public/js/lib/editor/utils.js
index d87c7e41..70428b28 100644
--- a/public/js/lib/editor/utils.js
+++ b/public/js/lib/editor/utils.js
@@ -3,17 +3,17 @@ export function wrapTextWith (editor, cm, symbol) {
if (!cm.getSelection()) {
return CodeMirror.Pass
} else {
- let ranges = cm.listSelections()
+ const ranges = cm.listSelections()
for (let i = 0; i < ranges.length; i++) {
- let range = ranges[i]
+ const range = ranges[i]
if (!range.empty()) {
const from = range.from()
const to = range.to()
if (symbol !== 'Backspace') {
- let selection = cm.getRange(from, to)
- let anchorIndex = editor.indexFromPos(ranges[i].anchor)
- let headIndex = editor.indexFromPos(ranges[i].head)
+ const selection = cm.getRange(from, to)
+ const anchorIndex = editor.indexFromPos(ranges[i].anchor)
+ const headIndex = editor.indexFromPos(ranges[i].head)
cm.replaceRange(symbol + selection + symbol, from, to, '+input')
if (anchorIndex > headIndex) {
ranges[i].anchor.ch += symbol.length
@@ -24,18 +24,18 @@ export function wrapTextWith (editor, cm, symbol) {
}
cm.setSelections(ranges)
} else {
- let preEndPos = {
+ const preEndPos = {
line: to.line,
ch: to.ch + symbol.length
}
- let preText = cm.getRange(to, preEndPos)
- let preIndex = wrapSymbols.indexOf(preText)
- let postEndPos = {
+ const preText = cm.getRange(to, preEndPos)
+ const preIndex = wrapSymbols.indexOf(preText)
+ const postEndPos = {
line: from.line,
ch: from.ch - symbol.length
}
- let postText = cm.getRange(postEndPos, from)
- let postIndex = wrapSymbols.indexOf(postText)
+ const postText = cm.getRange(postEndPos, from)
+ const postIndex = wrapSymbols.indexOf(postText)
// check if surround symbol are list in array and matched
if (preIndex > -1 && postIndex > -1 && preIndex === postIndex) {
cm.replaceRange('', to, preEndPos, '+delete')
@@ -48,25 +48,25 @@ export function wrapTextWith (editor, cm, symbol) {
}
export function insertText (cm, text, cursorEnd = 0) {
- let cursor = cm.getCursor()
+ const cursor = cm.getCursor()
cm.replaceSelection(text, cursor, cursor)
cm.focus()
cm.setCursor({ line: cursor.line, ch: cursor.ch + cursorEnd })
}
export function insertLink (cm, isImage) {
- let cursor = cm.getCursor()
- let ranges = cm.listSelections()
+ const cursor = cm.getCursor()
+ const ranges = cm.listSelections()
const linkEnd = '](https://)'
const symbol = (isImage) ? '![' : '['
for (let i = 0; i < ranges.length; i++) {
- let range = ranges[i]
+ const range = ranges[i]
if (!range.empty()) {
const from = range.from()
const to = range.to()
- let anchorIndex = editor.indexFromPos(ranges[i].anchor)
- let headIndex = editor.indexFromPos(ranges[i].head)
+ const anchorIndex = editor.indexFromPos(ranges[i].anchor)
+ const headIndex = editor.indexFromPos(ranges[i].head)
let selection = cm.getRange(from, to)
selection = symbol + selection + linkEnd
cm.replaceRange(selection, from, to)
@@ -87,9 +87,9 @@ export function insertLink (cm, isImage) {
}
export function insertHeader (cm) {
- let cursor = cm.getCursor()
- let startOfLine = { line: cursor.line, ch: 0 }
- let startOfLineText = cm.getRange(startOfLine, { line: cursor.line, ch: 1 })
+ const cursor = cm.getCursor()
+ const startOfLine = { line: cursor.line, ch: 0 }
+ const startOfLineText = cm.getRange(startOfLine, { line: cursor.line, ch: 1 })
// See if it is already a header
if (startOfLineText === '#') {
cm.replaceRange('#', startOfLine, startOfLine)
@@ -100,11 +100,11 @@ export function insertHeader (cm) {
}
export function insertOnStartOfLines (cm, symbol) {
- let cursor = cm.getCursor()
- let ranges = cm.listSelections()
+ const cursor = cm.getCursor()
+ const ranges = cm.listSelections()
for (let i = 0; i < ranges.length; i++) {
- let range = ranges[i]
+ const range = ranges[i]
if (!range.empty()) {
const from = range.from()
const to = range.to()
diff --git a/public/js/lib/syncscroll.js b/public/js/lib/syncscroll.js
index d492fbc9..f033d00d 100644
--- a/public/js/lib/syncscroll.js
+++ b/public/js/lib/syncscroll.js
@@ -155,12 +155,12 @@ const buildMap = _.throttle(buildMapInner, buildMapThrottle)
// Optimizations are required only for big texts.
function buildMapInner (callback) {
if (!viewArea || !markdownArea) return
- let i, offset, nonEmptyList, pos, a, b, _lineHeightMap, linesCount, acc, _scrollMap
+ let i, pos, a, b, acc
- offset = viewArea.scrollTop() - viewArea.offset().top
- _scrollMap = []
- nonEmptyList = []
- _lineHeightMap = []
+ const offset = viewArea.scrollTop() - viewArea.offset().top
+ const _scrollMap = []
+ const nonEmptyList = []
+ const _lineHeightMap = []
viewTop = 0
viewBottom = viewArea[0].scrollHeight - viewArea.height()
@@ -181,7 +181,7 @@ function buildMapInner (callback) {
acc += Math.round(h / lineHeight)
}
_lineHeightMap.push(acc)
- linesCount = acc
+ const linesCount = acc
for (i = 0; i < linesCount; i++) {
_scrollMap.push(-1)
@@ -290,11 +290,12 @@ export function syncScrollToEdit (event, preventAnimate) {
posTo += Math.ceil(posToNextDiff)
}
+ let duration = 0
if (preventAnimate) {
editArea.scrollTop(posTo)
} else {
const posDiff = Math.abs(scrollInfo.top - posTo)
- var duration = posDiff / 50
+ duration = posDiff / 50
duration = duration >= 100 ? duration : 100
editArea.stop(true, true).animate({
scrollTop: posTo
@@ -331,11 +332,11 @@ export function syncScrollToView (event, preventAnimate) {
}
if (viewScrolling) return
- let lineNo, posTo
+ let posTo
let topDiffPercent, posToNextDiff
const scrollInfo = editor.getScrollInfo()
const textHeight = editor.defaultTextHeight()
- lineNo = Math.floor(scrollInfo.top / textHeight)
+ const lineNo = Math.floor(scrollInfo.top / textHeight)
// if reach the last line, will start lerp to the bottom
const diffToBottom = (scrollInfo.top + scrollInfo.clientHeight) - (scrollInfo.height - textHeight)
if (scrollInfo.height > scrollInfo.clientHeight && diffToBottom > 0) {
@@ -350,11 +351,12 @@ export function syncScrollToView (event, preventAnimate) {
posTo += Math.floor(posToNextDiff)
}
+ let duration = 0
if (preventAnimate) {
viewArea.scrollTop(posTo)
} else {
const posDiff = Math.abs(viewArea.scrollTop() - posTo)
- var duration = posDiff / 50
+ duration = posDiff / 50
duration = duration >= 100 ? duration : 100
viewArea.stop(true, true).animate({
scrollTop: posTo