Skip to content

Commit 3505dcb

Browse files
committed
refactor: fix lint on public/js/index.js
Signed-off-by: BoHong Li <[email protected]>
1 parent 8394ff5 commit 3505dcb

File tree

1 file changed

+73
-73
lines changed

1 file changed

+73
-73
lines changed

public/js/index.js

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import List from 'list.js'
1717

1818
import Idle from '@hackmd/idle-js'
1919

20-
import { Spinner } from 'spin.js';
20+
import { Spinner } from 'spin.js'
2121

2222
import {
2323
checkLoginStateChanged,
@@ -263,7 +263,7 @@ let visibleMD = false
263263
let visibleLG = false
264264
const isTouchDevice = 'ontouchstart' in document.documentElement
265265
let currentStatus = statusType.offline
266-
let lastInfo = {
266+
const lastInfo = {
267267
needRestore: false,
268268
cursor: null,
269269
scroll: null,
@@ -289,14 +289,14 @@ let lastInfo = {
289289
let personalInfo = {}
290290
let onlineUsers = []
291291
const fileTypes = {
292-
'pl': 'perl',
293-
'cgi': 'perl',
294-
'js': 'javascript',
295-
'php': 'php',
296-
'sh': 'bash',
297-
'rb': 'ruby',
298-
'html': 'html',
299-
'py': 'python'
292+
pl: 'perl',
293+
cgi: 'perl',
294+
js: 'javascript',
295+
php: 'php',
296+
sh: 'bash',
297+
rb: 'ruby',
298+
html: 'html',
299+
py: 'python'
300300
}
301301

302302
// editor settings
@@ -956,8 +956,8 @@ ui.toolbar.export.dropbox.click(function () {
956956
var options = {
957957
files: [
958958
{
959-
'url': noteurl + '/download',
960-
'filename': filename
959+
url: noteurl + '/download',
960+
filename: filename
961961
}
962962
],
963963
error: function (errorMessage) {
@@ -1788,29 +1788,29 @@ var authorMarks = {} // temp variable
17881788
var addTextMarkers = [] // temp variable
17891789
function updateInfo (data) {
17901790
// console.log(data);
1791-
if (data.hasOwnProperty('createtime') && window.createtime !== data.createtime) {
1791+
if (Object.hasOwnProperty.call(data, 'createtime') && window.createtime !== data.createtime) {
17921792
window.createtime = data.createtime
17931793
updateLastChange()
17941794
}
1795-
if (data.hasOwnProperty('updatetime') && window.lastchangetime !== data.updatetime) {
1795+
if (Object.hasOwnProperty.call(data, 'updatetime') && window.lastchangetime !== data.updatetime) {
17961796
window.lastchangetime = data.updatetime
17971797
updateLastChange()
17981798
}
1799-
if (data.hasOwnProperty('owner') && window.owner !== data.owner) {
1799+
if (Object.hasOwnProperty.call(data, 'owner') && window.owner !== data.owner) {
18001800
window.owner = data.owner
18011801
window.ownerprofile = data.ownerprofile
18021802
updateOwner()
18031803
}
1804-
if (data.hasOwnProperty('lastchangeuser') && window.lastchangeuser !== data.lastchangeuser) {
1804+
if (Object.hasOwnProperty.call(data, 'lastchangeuser') && window.lastchangeuser !== data.lastchangeuser) {
18051805
window.lastchangeuser = data.lastchangeuser
18061806
window.lastchangeuserprofile = data.lastchangeuserprofile
18071807
updateLastChangeUser()
18081808
updateOwner()
18091809
}
1810-
if (data.hasOwnProperty('authors') && authors !== data.authors) {
1810+
if (Object.hasOwnProperty.call(data, 'authors') && authors !== data.authors) {
18111811
authors = data.authors
18121812
}
1813-
if (data.hasOwnProperty('authorship') && authorship !== data.authorship) {
1813+
if (Object.hasOwnProperty.call(data, 'authorship') && authorship !== data.authorship) {
18141814
authorship = data.authorship
18151815
updateAuthorship()
18161816
}
@@ -1855,7 +1855,7 @@ function updateAuthorshipInner () {
18551855
authorMarks = {}
18561856
for (let i = 0; i < authorship.length; i++) {
18571857
var atom = authorship[i]
1858-
let author = authors[atom[0]]
1858+
const author = authors[atom[0]]
18591859
if (author) {
18601860
var prePos = editor.posFromIndex(atom[1])
18611861
var preLine = editor.getLine(prePos.line)
@@ -1873,7 +1873,7 @@ function updateAuthorshipInner () {
18731873
if (prePos.ch === preLine.length) {
18741874
startLine++
18751875
} else if (prePos.ch !== 0) {
1876-
let mark = initMarkAndCheckGutter(authorMarks[prePos.line], author, atom[3])
1876+
const mark = initMarkAndCheckGutter(authorMarks[prePos.line], author, atom[3])
18771877
var _postPos = {
18781878
line: prePos.line,
18791879
ch: preLine.length
@@ -1890,7 +1890,7 @@ function updateAuthorshipInner () {
18901890
if (postPos.ch === 0) {
18911891
endLine--
18921892
} else if (postPos.ch !== postLine.length) {
1893-
let mark = initMarkAndCheckGutter(authorMarks[postPos.line], author, atom[3])
1893+
const mark = initMarkAndCheckGutter(authorMarks[postPos.line], author, atom[3])
18941894
var _prePos = {
18951895
line: postPos.line,
18961896
ch: 0
@@ -1910,7 +1910,7 @@ function updateAuthorshipInner () {
19101910
}
19111911
}
19121912
} else {
1913-
let mark = initMarkAndCheckGutter(authorMarks[prePos.line], author, atom[3])
1913+
const mark = initMarkAndCheckGutter(authorMarks[prePos.line], author, atom[3])
19141914
if (JSON.stringify(prePos) !== JSON.stringify(postPos)) {
19151915
mark.textmarkers.push({
19161916
userid: author.userid,
@@ -1923,15 +1923,15 @@ function updateAuthorshipInner () {
19231923
}
19241924
addTextMarkers = []
19251925
editor.eachLine(iterateLine)
1926-
var allTextMarks = editor.getAllMarks()
1926+
const allTextMarks = editor.getAllMarks()
19271927
for (let i = 0; i < allTextMarks.length; i++) {
1928-
let _textMarker = allTextMarks[i]
1929-
var pos = _textMarker.find()
1930-
var found = false
1928+
const _textMarker = allTextMarks[i]
1929+
const pos = _textMarker.find()
1930+
let found = false
19311931
for (let j = 0; j < addTextMarkers.length; j++) {
1932-
let textMarker = addTextMarkers[j]
1933-
let author = authors[textMarker.userid]
1934-
let className = 'authorship-inline-' + author.color.substr(1)
1932+
const textMarker = addTextMarkers[j]
1933+
const author = authors[textMarker.userid]
1934+
const className = 'authorship-inline-' + author.color.substr(1)
19351935
var obj = {
19361936
from: textMarker.pos[0],
19371937
to: textMarker.pos[1]
@@ -1949,12 +1949,12 @@ function updateAuthorshipInner () {
19491949
}
19501950
}
19511951
for (let i = 0; i < addTextMarkers.length; i++) {
1952-
let textMarker = addTextMarkers[i]
1953-
let author = authors[textMarker.userid]
1952+
const textMarker = addTextMarkers[i]
1953+
const author = authors[textMarker.userid]
19541954
const rgbcolor = hex2rgb(author.color)
19551955
const colorString = `rgba(${rgbcolor.red},${rgbcolor.green},${rgbcolor.blue},0.7)`
19561956
const styleString = `background-image: linear-gradient(to top, ${colorString} 1px, transparent 1px);`
1957-
let className = `authorship-inline-${author.color.substr(1)}`
1957+
const className = `authorship-inline-${author.color.substr(1)}`
19581958
const rule = `.${className} { ${styleString} }`
19591959
addStyleRule(rule)
19601960
editor.markText(textMarker.pos[0], textMarker.pos[1], {
@@ -1964,19 +1964,19 @@ function updateAuthorshipInner () {
19641964
}
19651965
}
19661966
function iterateLine (line) {
1967-
var lineNumber = line.lineNo()
1968-
var currMark = authorMarks[lineNumber]
1969-
var author = currMark ? authors[currMark.gutter.userid] : null
1967+
const lineNumber = line.lineNo()
1968+
const currMark = authorMarks[lineNumber]
1969+
const author = currMark ? authors[currMark.gutter.userid] : null
19701970
if (currMark && author) {
1971-
let className = 'authorship-gutter-' + author.color.substr(1)
1971+
const className = 'authorship-gutter-' + author.color.substr(1)
19721972
const gutters = line.gutterMarkers
19731973
if (!gutters || !gutters['authorship-gutters'] ||
19741974
!gutters['authorship-gutters'].className ||
19751975
!gutters['authorship-gutters'].className.indexOf(className) < 0) {
19761976
const styleString = `border-left: 3px solid ${author.color}; height: ${defaultTextHeight}px; margin-left: 3px;`
19771977
const rule = `.${className} { ${styleString} }`
19781978
addStyleRule(rule)
1979-
var gutter = $('<div>', {
1979+
const gutter = $('<div>', {
19801980
class: 'authorship-gutter ' + className,
19811981
title: author.name
19821982
})
@@ -1986,8 +1986,8 @@ function iterateLine (line) {
19861986
editor.setGutterMarker(line, 'authorship-gutters', null)
19871987
}
19881988
if (currMark && currMark.textmarkers.length > 0) {
1989-
for (var i = 0; i < currMark.textmarkers.length; i++) {
1990-
let textMarker = currMark.textmarkers[i]
1989+
for (let i = 0; i < currMark.textmarkers.length; i++) {
1990+
const textMarker = currMark.textmarkers[i]
19911991
if (textMarker.userid !== currMark.gutter.userid) {
19921992
addTextMarkers.push(textMarker)
19931993
}
@@ -1998,12 +1998,12 @@ editorInstance.on('update', function () {
19981998
$('.authorship-gutter:not([data-original-title])').tooltip({
19991999
container: '.CodeMirror-lines',
20002000
placement: 'right',
2001-
delay: { 'show': 500, 'hide': 100 }
2001+
delay: { show: 500, hide: 100 }
20022002
})
20032003
$('.authorship-inline:not([data-original-title])').tooltip({
20042004
container: '.CodeMirror-lines',
20052005
placement: 'bottom',
2006-
delay: { 'show': 500, 'hide': 100 }
2006+
delay: { show: 500, hide: 100 }
20072007
})
20082008
// clear tooltip which described element has been removed
20092009
$('[id^="tooltip"]').each(function (index, element) {
@@ -2064,7 +2064,7 @@ var cmClient = null
20642064
var synchronized_ = null
20652065

20662066
function havePendingOperation () {
2067-
return !!((cmClient && cmClient.state && cmClient.state.hasOwnProperty('outstanding')))
2067+
return !!((cmClient && cmClient.state && Object.hasOwnProperty.call(cmClient.state, 'outstanding')))
20682068
}
20692069

20702070
socket.on('doc', function (obj) {
@@ -2224,7 +2224,7 @@ function updateOnlineStatus () {
22242224
break
22252225
}
22262226
}
2227-
let id = items[i].values().id
2227+
const id = items[i].values().id
22282228
if (found) {
22292229
onlineUserList.get('id', id)[0].values(_onlineUsers[foundindex])
22302230
shortOnlineUserList.get('id', id)[0].values(_onlineUsers[foundindex])
@@ -2418,19 +2418,19 @@ function buildCursor (user) {
24182418
break
24192419
}
24202420
if ($('div[data-clientid="' + user.id + '"]').length <= 0) {
2421-
let cursor = $('<div data-clientid="' + user.id + '" class="CodeMirror-other-cursor" style="display:none;"></div>')
2421+
const cursor = $('<div data-clientid="' + user.id + '" class="CodeMirror-other-cursor" style="display:none;"></div>')
24222422
cursor.attr('data-line', user.cursor.line)
24232423
cursor.attr('data-ch', user.cursor.ch)
24242424
cursor.attr('data-offset-left', 0)
24252425
cursor.attr('data-offset-top', 0)
24262426

2427-
let cursorbar = $('<div class="cursorbar">&nbsp;</div>')
2427+
const cursorbar = $('<div class="cursorbar">&nbsp;</div>')
24282428
cursorbar[0].style.height = defaultTextHeight + 'px'
24292429
cursorbar[0].style.borderLeft = '2px solid ' + user.color
24302430

24312431
var icon = '<i class="fa ' + iconClass + '"></i>'
24322432

2433-
let cursortag = $('<div class="cursortag">' + icon + '&nbsp;<span class="name">' + user.name + '</span></div>')
2433+
const cursortag = $('<div class="cursortag">' + icon + '&nbsp;<span class="name">' + user.name + '</span></div>')
24342434
// cursortag[0].style.background = color;
24352435
cursortag[0].style.color = user.color
24362436

@@ -2486,15 +2486,15 @@ function buildCursor (user) {
24862486

24872487
checkCursorTag(coord, cursortag)
24882488
} else {
2489-
let cursor = $('div[data-clientid="' + user.id + '"]')
2489+
const cursor = $('div[data-clientid="' + user.id + '"]')
24902490
cursor.attr('data-line', user.cursor.line)
24912491
cursor.attr('data-ch', user.cursor.ch)
24922492

2493-
let cursorbar = cursor.find('.cursorbar')
2493+
const cursorbar = cursor.find('.cursorbar')
24942494
cursorbar[0].style.height = defaultTextHeight + 'px'
24952495
cursorbar[0].style.borderLeft = '2px solid ' + user.color
24962496

2497-
let cursortag = cursor.find('.cursortag')
2497+
const cursortag = cursor.find('.cursortag')
24982498
cursortag.find('i').removeClass().addClass('fa').addClass(iconClass)
24992499
cursortag.find('.name').text(user.name)
25002500

@@ -2503,8 +2503,8 @@ function buildCursor (user) {
25032503
cursor[0].style.top = coord.top + 'px'
25042504
} else {
25052505
cursor.animate({
2506-
'left': coord.left,
2507-
'top': coord.top
2506+
left: coord.left,
2507+
top: coord.top
25082508
}, {
25092509
duration: cursorAnimatePeriod,
25102510
queue: false
@@ -2713,8 +2713,8 @@ function restoreInfo () {
27132713
$(window).scrollLeft(lastInfo.edit.scroll.left)
27142714
$(window).scrollTop(lastInfo.edit.scroll.top)
27152715
} else {
2716-
let left = lastInfo.edit.scroll.left
2717-
let top = lastInfo.edit.scroll.top
2716+
const left = lastInfo.edit.scroll.left
2717+
const top = lastInfo.edit.scroll.top
27182718
editor.scrollIntoView()
27192719
editor.scrollTo(left, top)
27202720
}
@@ -2724,8 +2724,8 @@ function restoreInfo () {
27242724
$(window).scrollTop(lastInfo.view.scroll.top)
27252725
break
27262726
case modeType.both:
2727-
let left = lastInfo.edit.scroll.left
2728-
let top = lastInfo.edit.scroll.top
2727+
const left = lastInfo.edit.scroll.left
2728+
const top = lastInfo.edit.scroll.top
27292729
editor.scrollIntoView()
27302730
editor.scrollTo(left, top)
27312731
ui.area.view.scrollLeft(lastInfo.view.scroll.left)
@@ -2847,8 +2847,8 @@ function partialUpdate (src, tar, des) {
28472847
for (let i = 0; i < tar.length; i++) {
28482848
// copyAttribute(src[i], des[i], 'data-startline');
28492849
// copyAttribute(src[i], des[i], 'data-endline');
2850-
let rawSrc = cloneAndRemoveDataAttr(src[i])
2851-
let rawTar = cloneAndRemoveDataAttr(tar[i])
2850+
const rawSrc = cloneAndRemoveDataAttr(src[i])
2851+
const rawTar = cloneAndRemoveDataAttr(tar[i])
28522852
if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) {
28532853
start = i
28542854
break
@@ -2860,34 +2860,34 @@ function partialUpdate (src, tar, des) {
28602860
for (let i = 0; i < src.length; i++) {
28612861
// copyAttribute(src[i], des[i], 'data-startline');
28622862
// copyAttribute(src[i], des[i], 'data-endline');
2863-
let rawSrc = cloneAndRemoveDataAttr(src[i])
2864-
let rawTar = cloneAndRemoveDataAttr(tar[i])
2863+
const rawSrc = cloneAndRemoveDataAttr(src[i])
2864+
const rawTar = cloneAndRemoveDataAttr(tar[i])
28652865
if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) {
28662866
start = i
28672867
break
28682868
}
28692869
}
28702870
// tar end
28712871
for (let i = 1; i <= tar.length + 1; i++) {
2872-
let srcLength = src.length
2873-
let tarLength = tar.length
2872+
const srcLength = src.length
2873+
const tarLength = tar.length
28742874
// copyAttribute(src[srcLength - i], des[srcLength - i], 'data-startline');
28752875
// copyAttribute(src[srcLength - i], des[srcLength - i], 'data-endline');
2876-
let rawSrc = cloneAndRemoveDataAttr(src[srcLength - i])
2877-
let rawTar = cloneAndRemoveDataAttr(tar[tarLength - i])
2876+
const rawSrc = cloneAndRemoveDataAttr(src[srcLength - i])
2877+
const rawTar = cloneAndRemoveDataAttr(tar[tarLength - i])
28782878
if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) {
28792879
tarEnd = tar.length - i
28802880
break
28812881
}
28822882
}
28832883
// src end
28842884
for (let i = 1; i <= src.length + 1; i++) {
2885-
let srcLength = src.length
2886-
let tarLength = tar.length
2885+
const srcLength = src.length
2886+
const tarLength = tar.length
28872887
// copyAttribute(src[srcLength - i], des[srcLength - i], 'data-startline');
28882888
// copyAttribute(src[srcLength - i], des[srcLength - i], 'data-endline');
2889-
let rawSrc = cloneAndRemoveDataAttr(src[srcLength - i])
2890-
let rawTar = cloneAndRemoveDataAttr(tar[tarLength - i])
2889+
const rawSrc = cloneAndRemoveDataAttr(src[srcLength - i])
2890+
const rawTar = cloneAndRemoveDataAttr(tar[tarLength - i])
28912891
if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) {
28922892
srcEnd = src.length - i
28932893
break
@@ -3318,22 +3318,22 @@ $(editor.getInputField())
33183318
'textComplete:show': function (e) {
33193319
$(this).data('autocompleting', true)
33203320
editor.setOption('extraKeys', {
3321-
'Up': function () {
3321+
Up: function () {
33223322
return false
33233323
},
3324-
'Right': function () {
3324+
Right: function () {
33253325
editor.doc.cm.execCommand('goCharRight')
33263326
},
3327-
'Down': function () {
3327+
Down: function () {
33283328
return false
33293329
},
3330-
'Left': function () {
3330+
Left: function () {
33313331
editor.doc.cm.execCommand('goCharLeft')
33323332
},
3333-
'Enter': function () {
3333+
Enter: function () {
33343334
return false
33353335
},
3336-
'Backspace': function () {
3336+
Backspace: function () {
33373337
editor.doc.cm.execCommand('delCharBefore')
33383338
}
33393339
})

0 commit comments

Comments
 (0)