From 3505dcb1c88ea86713e4348331144ef7b648a4d7 Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Fri, 2 Aug 2019 01:03:16 +0800 Subject: [PATCH] refactor: fix lint on public/js/index.js Signed-off-by: BoHong Li --- public/js/index.js | 146 ++++++++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index b27800ec..6d373dab 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -17,7 +17,7 @@ import List from 'list.js' import Idle from '@hackmd/idle-js' -import { Spinner } from 'spin.js'; +import { Spinner } from 'spin.js' import { checkLoginStateChanged, @@ -263,7 +263,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, @@ -289,14 +289,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 @@ -956,8 +956,8 @@ ui.toolbar.export.dropbox.click(function () { var options = { files: [ { - 'url': noteurl + '/download', - 'filename': filename + url: noteurl + '/download', + filename: filename } ], error: function (errorMessage) { @@ -1788,29 +1788,29 @@ var authorMarks = {} // temp variable var addTextMarkers = [] // temp variable function updateInfo (data) { // console.log(data); - if (data.hasOwnProperty('createtime') && window.createtime !== data.createtime) { + if (Object.hasOwnProperty.call(data, 'createtime') && window.createtime !== data.createtime) { window.createtime = data.createtime updateLastChange() } - if (data.hasOwnProperty('updatetime') && window.lastchangetime !== data.updatetime) { + if (Object.hasOwnProperty.call(data, 'updatetime') && window.lastchangetime !== data.updatetime) { window.lastchangetime = data.updatetime updateLastChange() } - if (data.hasOwnProperty('owner') && window.owner !== data.owner) { + if (Object.hasOwnProperty.call(data, 'owner') && window.owner !== data.owner) { window.owner = data.owner window.ownerprofile = data.ownerprofile updateOwner() } - if (data.hasOwnProperty('lastchangeuser') && window.lastchangeuser !== data.lastchangeuser) { + if (Object.hasOwnProperty.call(data, 'lastchangeuser') && window.lastchangeuser !== data.lastchangeuser) { window.lastchangeuser = data.lastchangeuser window.lastchangeuserprofile = data.lastchangeuserprofile updateLastChangeUser() updateOwner() } - if (data.hasOwnProperty('authors') && authors !== data.authors) { + if (Object.hasOwnProperty.call(data, 'authors') && authors !== data.authors) { authors = data.authors } - if (data.hasOwnProperty('authorship') && authorship !== data.authorship) { + if (Object.hasOwnProperty.call(data, 'authorship') && authorship !== data.authorship) { authorship = data.authorship updateAuthorship() } @@ -1855,7 +1855,7 @@ function updateAuthorshipInner () { authorMarks = {} for (let i = 0; i < authorship.length; i++) { var atom = authorship[i] - let author = authors[atom[0]] + const author = authors[atom[0]] if (author) { var prePos = editor.posFromIndex(atom[1]) var preLine = editor.getLine(prePos.line) @@ -1873,7 +1873,7 @@ function updateAuthorshipInner () { if (prePos.ch === preLine.length) { startLine++ } else if (prePos.ch !== 0) { - let mark = initMarkAndCheckGutter(authorMarks[prePos.line], author, atom[3]) + const mark = initMarkAndCheckGutter(authorMarks[prePos.line], author, atom[3]) var _postPos = { line: prePos.line, ch: preLine.length @@ -1890,7 +1890,7 @@ function updateAuthorshipInner () { if (postPos.ch === 0) { endLine-- } else if (postPos.ch !== postLine.length) { - let mark = initMarkAndCheckGutter(authorMarks[postPos.line], author, atom[3]) + const mark = initMarkAndCheckGutter(authorMarks[postPos.line], author, atom[3]) var _prePos = { line: postPos.line, ch: 0 @@ -1910,7 +1910,7 @@ function updateAuthorshipInner () { } } } else { - let mark = initMarkAndCheckGutter(authorMarks[prePos.line], author, atom[3]) + const mark = initMarkAndCheckGutter(authorMarks[prePos.line], author, atom[3]) if (JSON.stringify(prePos) !== JSON.stringify(postPos)) { mark.textmarkers.push({ userid: author.userid, @@ -1923,15 +1923,15 @@ function updateAuthorshipInner () { } addTextMarkers = [] editor.eachLine(iterateLine) - var allTextMarks = editor.getAllMarks() + const allTextMarks = editor.getAllMarks() for (let i = 0; i < allTextMarks.length; i++) { - let _textMarker = allTextMarks[i] - var pos = _textMarker.find() - var found = false + const _textMarker = allTextMarks[i] + const pos = _textMarker.find() + let found = false for (let j = 0; j < addTextMarkers.length; j++) { - let textMarker = addTextMarkers[j] - let author = authors[textMarker.userid] - let className = 'authorship-inline-' + author.color.substr(1) + const textMarker = addTextMarkers[j] + const author = authors[textMarker.userid] + const className = 'authorship-inline-' + author.color.substr(1) var obj = { from: textMarker.pos[0], to: textMarker.pos[1] @@ -1949,12 +1949,12 @@ function updateAuthorshipInner () { } } for (let i = 0; i < addTextMarkers.length; i++) { - let textMarker = addTextMarkers[i] - let author = authors[textMarker.userid] + const textMarker = addTextMarkers[i] + const author = authors[textMarker.userid] const rgbcolor = hex2rgb(author.color) const colorString = `rgba(${rgbcolor.red},${rgbcolor.green},${rgbcolor.blue},0.7)` const styleString = `background-image: linear-gradient(to top, ${colorString} 1px, transparent 1px);` - let className = `authorship-inline-${author.color.substr(1)}` + const className = `authorship-inline-${author.color.substr(1)}` const rule = `.${className} { ${styleString} }` addStyleRule(rule) editor.markText(textMarker.pos[0], textMarker.pos[1], { @@ -1964,11 +1964,11 @@ function updateAuthorshipInner () { } } function iterateLine (line) { - var lineNumber = line.lineNo() - var currMark = authorMarks[lineNumber] - var author = currMark ? authors[currMark.gutter.userid] : null + const lineNumber = line.lineNo() + const currMark = authorMarks[lineNumber] + const author = currMark ? authors[currMark.gutter.userid] : null if (currMark && author) { - let className = 'authorship-gutter-' + author.color.substr(1) + const className = 'authorship-gutter-' + author.color.substr(1) const gutters = line.gutterMarkers if (!gutters || !gutters['authorship-gutters'] || !gutters['authorship-gutters'].className || @@ -1976,7 +1976,7 @@ function iterateLine (line) { const styleString = `border-left: 3px solid ${author.color}; height: ${defaultTextHeight}px; margin-left: 3px;` const rule = `.${className} { ${styleString} }` addStyleRule(rule) - var gutter = $('
', { + const gutter = $('
', { class: 'authorship-gutter ' + className, title: author.name }) @@ -1986,8 +1986,8 @@ function iterateLine (line) { editor.setGutterMarker(line, 'authorship-gutters', null) } if (currMark && currMark.textmarkers.length > 0) { - for (var i = 0; i < currMark.textmarkers.length; i++) { - let textMarker = currMark.textmarkers[i] + for (let i = 0; i < currMark.textmarkers.length; i++) { + const textMarker = currMark.textmarkers[i] if (textMarker.userid !== currMark.gutter.userid) { addTextMarkers.push(textMarker) } @@ -1998,12 +1998,12 @@ editorInstance.on('update', function () { $('.authorship-gutter:not([data-original-title])').tooltip({ container: '.CodeMirror-lines', placement: 'right', - delay: { 'show': 500, 'hide': 100 } + delay: { show: 500, hide: 100 } }) $('.authorship-inline:not([data-original-title])').tooltip({ container: '.CodeMirror-lines', placement: 'bottom', - delay: { 'show': 500, 'hide': 100 } + delay: { show: 500, hide: 100 } }) // clear tooltip which described element has been removed $('[id^="tooltip"]').each(function (index, element) { @@ -2064,7 +2064,7 @@ var cmClient = null var synchronized_ = null function havePendingOperation () { - return !!((cmClient && cmClient.state && cmClient.state.hasOwnProperty('outstanding'))) + return !!((cmClient && cmClient.state && Object.hasOwnProperty.call(cmClient.state, 'outstanding'))) } socket.on('doc', function (obj) { @@ -2224,7 +2224,7 @@ function updateOnlineStatus () { break } } - let id = items[i].values().id + const id = items[i].values().id if (found) { onlineUserList.get('id', id)[0].values(_onlineUsers[foundindex]) shortOnlineUserList.get('id', id)[0].values(_onlineUsers[foundindex]) @@ -2418,19 +2418,19 @@ function buildCursor (user) { break } if ($('div[data-clientid="' + user.id + '"]').length <= 0) { - let cursor = $('') + const cursor = $('') cursor.attr('data-line', user.cursor.line) cursor.attr('data-ch', user.cursor.ch) cursor.attr('data-offset-left', 0) cursor.attr('data-offset-top', 0) - let cursorbar = $('
 
') + const cursorbar = $('
 
') cursorbar[0].style.height = defaultTextHeight + 'px' cursorbar[0].style.borderLeft = '2px solid ' + user.color var icon = '' - let cursortag = $('
' + icon + ' ' + user.name + '
') + const cursortag = $('
' + icon + ' ' + user.name + '
') // cursortag[0].style.background = color; cursortag[0].style.color = user.color @@ -2486,15 +2486,15 @@ function buildCursor (user) { checkCursorTag(coord, cursortag) } else { - let cursor = $('div[data-clientid="' + user.id + '"]') + const cursor = $('div[data-clientid="' + user.id + '"]') cursor.attr('data-line', user.cursor.line) cursor.attr('data-ch', user.cursor.ch) - let cursorbar = cursor.find('.cursorbar') + const cursorbar = cursor.find('.cursorbar') cursorbar[0].style.height = defaultTextHeight + 'px' cursorbar[0].style.borderLeft = '2px solid ' + user.color - let cursortag = cursor.find('.cursortag') + const cursortag = cursor.find('.cursortag') cursortag.find('i').removeClass().addClass('fa').addClass(iconClass) cursortag.find('.name').text(user.name) @@ -2503,8 +2503,8 @@ function buildCursor (user) { cursor[0].style.top = coord.top + 'px' } else { cursor.animate({ - 'left': coord.left, - 'top': coord.top + left: coord.left, + top: coord.top }, { duration: cursorAnimatePeriod, queue: false @@ -2713,8 +2713,8 @@ function restoreInfo () { $(window).scrollLeft(lastInfo.edit.scroll.left) $(window).scrollTop(lastInfo.edit.scroll.top) } else { - let left = lastInfo.edit.scroll.left - let top = lastInfo.edit.scroll.top + const left = lastInfo.edit.scroll.left + const top = lastInfo.edit.scroll.top editor.scrollIntoView() editor.scrollTo(left, top) } @@ -2724,8 +2724,8 @@ function restoreInfo () { $(window).scrollTop(lastInfo.view.scroll.top) break case modeType.both: - let left = lastInfo.edit.scroll.left - let top = lastInfo.edit.scroll.top + const left = lastInfo.edit.scroll.left + const top = lastInfo.edit.scroll.top editor.scrollIntoView() editor.scrollTo(left, top) ui.area.view.scrollLeft(lastInfo.view.scroll.left) @@ -2847,8 +2847,8 @@ function partialUpdate (src, tar, des) { for (let i = 0; i < tar.length; i++) { // copyAttribute(src[i], des[i], 'data-startline'); // copyAttribute(src[i], des[i], 'data-endline'); - let rawSrc = cloneAndRemoveDataAttr(src[i]) - let rawTar = cloneAndRemoveDataAttr(tar[i]) + const rawSrc = cloneAndRemoveDataAttr(src[i]) + const rawTar = cloneAndRemoveDataAttr(tar[i]) if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) { start = i break @@ -2860,8 +2860,8 @@ function partialUpdate (src, tar, des) { for (let i = 0; i < src.length; i++) { // copyAttribute(src[i], des[i], 'data-startline'); // copyAttribute(src[i], des[i], 'data-endline'); - let rawSrc = cloneAndRemoveDataAttr(src[i]) - let rawTar = cloneAndRemoveDataAttr(tar[i]) + const rawSrc = cloneAndRemoveDataAttr(src[i]) + const rawTar = cloneAndRemoveDataAttr(tar[i]) if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) { start = i break @@ -2869,12 +2869,12 @@ function partialUpdate (src, tar, des) { } // tar end for (let i = 1; i <= tar.length + 1; i++) { - let srcLength = src.length - let tarLength = tar.length + const srcLength = src.length + const tarLength = tar.length // copyAttribute(src[srcLength - i], des[srcLength - i], 'data-startline'); // copyAttribute(src[srcLength - i], des[srcLength - i], 'data-endline'); - let rawSrc = cloneAndRemoveDataAttr(src[srcLength - i]) - let rawTar = cloneAndRemoveDataAttr(tar[tarLength - i]) + const rawSrc = cloneAndRemoveDataAttr(src[srcLength - i]) + const rawTar = cloneAndRemoveDataAttr(tar[tarLength - i]) if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) { tarEnd = tar.length - i break @@ -2882,12 +2882,12 @@ function partialUpdate (src, tar, des) { } // src end for (let i = 1; i <= src.length + 1; i++) { - let srcLength = src.length - let tarLength = tar.length + const srcLength = src.length + const tarLength = tar.length // copyAttribute(src[srcLength - i], des[srcLength - i], 'data-startline'); // copyAttribute(src[srcLength - i], des[srcLength - i], 'data-endline'); - let rawSrc = cloneAndRemoveDataAttr(src[srcLength - i]) - let rawTar = cloneAndRemoveDataAttr(tar[tarLength - i]) + const rawSrc = cloneAndRemoveDataAttr(src[srcLength - i]) + const rawTar = cloneAndRemoveDataAttr(tar[tarLength - i]) if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) { srcEnd = src.length - i break @@ -3318,22 +3318,22 @@ $(editor.getInputField()) 'textComplete:show': function (e) { $(this).data('autocompleting', true) editor.setOption('extraKeys', { - 'Up': function () { + Up: function () { return false }, - 'Right': function () { + Right: function () { editor.doc.cm.execCommand('goCharRight') }, - 'Down': function () { + Down: function () { return false }, - 'Left': function () { + Left: function () { editor.doc.cm.execCommand('goCharLeft') }, - 'Enter': function () { + Enter: function () { return false }, - 'Backspace': function () { + Backspace: function () { editor.doc.cm.execCommand('delCharBefore') } })