', {
class: 'authorship-gutter ' + className,
title: author.name
})
@@ -1973,8 +2367,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)
}
@@ -1985,17 +2379,17 @@ 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) {
- var $ele = $(element)
- if ($('[aria-describedby="' + $ele.attr('id') + '"]').length <= 0) $ele.remove()
+ const $ele = $(element)
+ if ($('[aria-describedby="' + $ele.attr('id') + '"]').length <= 0) { $ele.remove() }
})
})
socket.on('check', function (data) {
@@ -2006,7 +2400,7 @@ socket.on('permission', function (data) {
updatePermission(data.permission)
})
-var permission = null
+let permission = null
socket.on('refresh', function (data) {
// console.debug(data);
editorInstance.config.docmaxlength = data.docmaxlength
@@ -2015,13 +2409,17 @@ socket.on('refresh', function (data) {
updatePermission(data.permission)
if (!window.loaded) {
// auto change mode if no content detected
- var nocontent = editor.getValue().length <= 0
+ const nocontent = editor.getValue().length <= 0
if (nocontent) {
- if (visibleXS) { appState.currentMode = modeType.edit } else { appState.currentMode = modeType.both }
+ if (visibleXS) {
+ appState.currentMode = modeType.edit
+ } else {
+ appState.currentMode = modeType.both
+ }
}
// parse mode from url
if (window.location.search.length > 0) {
- var urlMode = modeType[window.location.search.substr(1)]
+ const urlMode = modeType[window.location.search.substr(1)]
if (urlMode) appState.currentMode = urlMode
}
changeMode(appState.currentMode)
@@ -2041,23 +2439,34 @@ socket.on('refresh', function (data) {
scrollToHash()
}, 1)
}
- if (editor.getOption('readOnly')) { editor.setOption('readOnly', false) }
+ if (editor.getOption('readOnly')) {
+ editor.setOption('readOnly', false)
+ }
})
-var EditorClient = ot.EditorClient
-var SocketIOAdapter = ot.SocketIOAdapter
-var CodeMirrorAdapter = ot.CodeMirrorAdapter
-var cmClient = null
-var synchronized_ = null
+const EditorClient = ot.EditorClient
+const SocketIOAdapter = ot.SocketIOAdapter
+const CodeMirrorAdapter = ot.CodeMirrorAdapter
+let cmClient = null
+let synchronized_ = null
function havePendingOperation () {
- return !!((cmClient && cmClient.state && cmClient.state.hasOwnProperty('outstanding')))
+ return !!(
+ cmClient &&
+ cmClient.state &&
+ Object.prototype.hasOwnProperty.call(cmClient, 'outstanding')
+ )
}
socket.on('doc', function (obj) {
- var body = obj.str
- var bodyMismatch = editor.getValue() !== body
- var setDoc = !cmClient || (cmClient && (cmClient.revision === -1 || (cmClient.revision !== obj.revision && !havePendingOperation()))) || obj.force
+ const body = obj.str
+ const bodyMismatch = editor.getValue() !== body
+ const setDoc =
+ !cmClient ||
+ (cmClient &&
+ (cmClient.revision === -1 ||
+ (cmClient.revision !== obj.revision && !havePendingOperation()))) ||
+ obj.force
saveInfo()
if (setDoc && bodyMismatch) {
@@ -2079,8 +2488,10 @@ socket.on('doc', function (obj) {
if (!cmClient) {
cmClient = window.cmClient = new EditorClient(
- obj.revision, obj.clients,
- new SocketIOAdapter(socket), new CodeMirrorAdapter(editor)
+ obj.revision,
+ obj.clients,
+ new SocketIOAdapter(socket),
+ new CodeMirrorAdapter(editor)
)
synchronized_ = cmClient.state
} else if (setDoc) {
@@ -2115,91 +2526,120 @@ socket.on('operation', function () {
})
socket.on('online users', function (data) {
- if (debug) { console.debug(data) }
+ if (debug) {
+ console.debug(data)
+ }
onlineUsers = data.users
updateOnlineStatus()
- $('.CodeMirror-other-cursors').children().each(function (key, value) {
- var found = false
- for (var i = 0; i < data.users.length; i++) {
- var user = data.users[i]
- if ($(this).attr('id') === user.id) { found = true }
+ $('.CodeMirror-other-cursors')
+ .children()
+ .each(function (key, value) {
+ let found = false
+ for (let i = 0; i < data.users.length; i++) {
+ const user = data.users[i]
+ if ($(this).attr('id') === user.id) {
+ found = true
+ }
+ }
+ if (!found) {
+ $(this)
+ .stop(true)
+ .fadeOut('normal', function () {
+ $(this).remove()
+ })
+ }
+ })
+ for (let i = 0; i < data.users.length; i++) {
+ const user = data.users[i]
+ if (user.id !== socket.id) {
+ buildCursor(user)
+ } else {
+ personalInfo = user
}
- if (!found) {
- $(this).stop(true).fadeOut('normal', function () {
- $(this).remove()
- })
- }
- })
- for (var i = 0; i < data.users.length; i++) {
- var user = data.users[i]
- if (user.id !== socket.id) { buildCursor(user) } else { personalInfo = user }
}
})
socket.on('user status', function (data) {
- if (debug) { console.debug(data) }
- for (var i = 0; i < onlineUsers.length; i++) {
+ if (debug) {
+ console.debug(data)
+ }
+ for (let i = 0; i < onlineUsers.length; i++) {
if (onlineUsers[i].id === data.id) {
onlineUsers[i] = data
}
}
updateOnlineStatus()
- if (data.id !== socket.id) { buildCursor(data) }
+ if (data.id !== socket.id) {
+ buildCursor(data)
+ }
})
socket.on('cursor focus', function (data) {
- if (debug) { console.debug(data) }
- for (var i = 0; i < onlineUsers.length; i++) {
+ if (debug) {
+ console.debug(data)
+ }
+ for (let i = 0; i < onlineUsers.length; i++) {
if (onlineUsers[i].id === data.id) {
onlineUsers[i].cursor = data.cursor
}
}
- if (data.id !== socket.id) { buildCursor(data) }
+ if (data.id !== socket.id) {
+ buildCursor(data)
+ }
// force show
- var cursor = $('div[data-clientid="' + data.id + '"]')
+ const cursor = $('div[data-clientid="' + data.id + '"]')
if (cursor.length > 0) {
cursor.stop(true).fadeIn()
}
})
socket.on('cursor activity', function (data) {
- if (debug) { console.debug(data) }
- for (var i = 0; i < onlineUsers.length; i++) {
+ if (debug) {
+ console.debug(data)
+ }
+ for (let i = 0; i < onlineUsers.length; i++) {
if (onlineUsers[i].id === data.id) {
onlineUsers[i].cursor = data.cursor
}
}
- if (data.id !== socket.id) { buildCursor(data) }
+ if (data.id !== socket.id) {
+ buildCursor(data)
+ }
})
socket.on('cursor blur', function (data) {
- if (debug) { console.debug(data) }
- for (var i = 0; i < onlineUsers.length; i++) {
+ if (debug) {
+ console.debug(data)
+ }
+ for (let i = 0; i < onlineUsers.length; i++) {
if (onlineUsers[i].id === data.id) {
onlineUsers[i].cursor = null
}
}
- if (data.id !== socket.id) { buildCursor(data) }
+ if (data.id !== socket.id) {
+ buildCursor(data)
+ }
// force hide
- var cursor = $('div[data-clientid="' + data.id + '"]')
+ const cursor = $('div[data-clientid="' + data.id + '"]')
if (cursor.length > 0) {
cursor.stop(true).fadeOut()
}
})
-var options = {
+const options = {
valueNames: ['id', 'name'],
- item: '
' +
- '' +
- '' +
- '' +
- '' +
- ''
+ item:
+ '
' +
+ '' +
+ '' +
+ '' +
+ '' +
+ ''
}
-var onlineUserList = new List('online-user-list', options)
-var shortOnlineUserList = new List('short-online-user-list', options)
+const onlineUserList = new List('online-user-list', options)
+const shortOnlineUserList = new List('short-online-user-list', options)
function updateOnlineStatus () {
if (!window.loaded || !socket.connected) return
- var _onlineUsers = deduplicateOnlineUsers(onlineUsers)
+ const _onlineUsers = deduplicateOnlineUsers(onlineUsers)
showStatus(statusType.online, _onlineUsers.length)
- var items = onlineUserList.items
+ const items = onlineUserList.items
// update or remove current list items
for (let i = 0; i < items.length; i++) {
let found = false
@@ -2211,7 +2651,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])
@@ -2246,23 +2686,57 @@ function sortOnlineUserList (list) {
// sort order by isSelf, login state, idle state, alphabet name, color brightness
list.sort('', {
sortFunction: function (a, b) {
- var usera = a.values()
- var userb = b.values()
- var useraIsSelf = (usera.id === personalInfo.id || (usera.login && usera.userid === personalInfo.userid))
- var userbIsSelf = (userb.id === personalInfo.id || (userb.login && userb.userid === personalInfo.userid))
+ const usera = a.values()
+ const userb = b.values()
+ const useraIsSelf =
+ usera.id === personalInfo.id ||
+ (usera.login && usera.userid === personalInfo.userid)
+ const userbIsSelf =
+ userb.id === personalInfo.id ||
+ (userb.login && userb.userid === personalInfo.userid)
if (useraIsSelf && !userbIsSelf) {
return -1
} else if (!useraIsSelf && userbIsSelf) {
return 1
} else {
- if (usera.login && !userb.login) { return -1 } else if (!usera.login && userb.login) { return 1 } else {
- if (!usera.idle && userb.idle) { return -1 } else if (usera.idle && !userb.idle) { return 1 } else {
- if (usera.name && userb.name && usera.name.toLowerCase() < userb.name.toLowerCase()) {
+ if (usera.login && !userb.login) {
+ return -1
+ } else if (!usera.login && userb.login) {
+ return 1
+ } else {
+ if (!usera.idle && userb.idle) {
+ return -1
+ } else if (usera.idle && !userb.idle) {
+ return 1
+ } else {
+ if (
+ usera.name &&
+ userb.name &&
+ usera.name.toLowerCase() < userb.name.toLowerCase()
+ ) {
return -1
- } else if (usera.name && userb.name && usera.name.toLowerCase() > userb.name.toLowerCase()) {
+ } else if (
+ usera.name &&
+ userb.name &&
+ usera.name.toLowerCase() > userb.name.toLowerCase()
+ ) {
return 1
} else {
- if (usera.color && userb.color && usera.color.toLowerCase() < userb.color.toLowerCase()) { return -1 } else if (usera.color && userb.color && usera.color.toLowerCase() > userb.color.toLowerCase()) { return 1 } else { return 0 }
+ if (
+ usera.color &&
+ userb.color &&
+ usera.color.toLowerCase() < userb.color.toLowerCase()
+ ) {
+ return -1
+ } else if (
+ usera.color &&
+ userb.color &&
+ usera.color.toLowerCase() > userb.color.toLowerCase()
+ ) {
+ return 1
+ } else {
+ return 0
+ }
}
}
}
@@ -2272,11 +2746,11 @@ function sortOnlineUserList (list) {
}
function renderUserStatusList (list) {
- var items = list.items
- for (var j = 0; j < items.length; j++) {
- var item = items[j]
- var userstatus = $(item.elm).find('.ui-user-status')
- var usericon = $(item.elm).find('.ui-user-icon')
+ const items = list.items
+ for (let j = 0; j < items.length; j++) {
+ const item = items[j]
+ const userstatus = $(item.elm).find('.ui-user-status')
+ const usericon = $(item.elm).find('.ui-user-icon')
if (item.values().login && item.values().photo) {
usericon.css('background-image', 'url(' + item.values().photo + ')')
// add 1px more to right, make it feel aligned
@@ -2286,18 +2760,26 @@ function renderUserStatusList (list) {
} else {
usericon.css('background-color', item.values().color)
}
- userstatus.removeClass('ui-user-status-offline ui-user-status-online ui-user-status-idle')
- if (item.values().idle) { userstatus.addClass('ui-user-status-idle') } else { userstatus.addClass('ui-user-status-online') }
+ userstatus.removeClass(
+ 'ui-user-status-offline ui-user-status-online ui-user-status-idle'
+ )
+ if (item.values().idle) {
+ userstatus.addClass('ui-user-status-idle')
+ } else {
+ userstatus.addClass('ui-user-status-online')
+ }
}
}
function deduplicateOnlineUsers (list) {
- var _onlineUsers = []
- for (var i = 0; i < list.length; i++) {
- var user = $.extend({}, list[i])
- if (!user.userid) { _onlineUsers.push(user) } else {
- var found = false
- for (var j = 0; j < _onlineUsers.length; j++) {
+ const _onlineUsers = []
+ for (let i = 0; i < list.length; i++) {
+ const user = $.extend({}, list[i])
+ if (!user.userid) {
+ _onlineUsers.push(user)
+ } else {
+ let found = false
+ for (let j = 0; j < _onlineUsers.length; j++) {
if (_onlineUsers[j].userid === user.userid) {
// keep self color when login
if (user.id === personalInfo.id) {
@@ -2312,29 +2794,39 @@ function deduplicateOnlineUsers (list) {
break
}
}
- if (!found) { _onlineUsers.push(user) }
+ if (!found) {
+ _onlineUsers.push(user)
+ }
}
}
return _onlineUsers
}
-var userStatusCache = null
+let userStatusCache = null
function emitUserStatus (force) {
if (!window.loaded) return
- var type = null
- if (visibleXS) { type = 'xs' } else if (visibleSM) { type = 'sm' } else if (visibleMD) { type = 'md' } else if (visibleLG) { type = 'lg' }
+ let type = null
+ if (visibleXS) {
+ type = 'xs'
+ } else if (visibleSM) {
+ type = 'sm'
+ } else if (visibleMD) {
+ type = 'md'
+ } else if (visibleLG) {
+ type = 'lg'
+ }
- personalInfo['idle'] = idle.isAway
- personalInfo['type'] = type
+ personalInfo.idle = idle.isAway
+ personalInfo.type = type
- for (var i = 0; i < onlineUsers.length; i++) {
+ for (let i = 0; i < onlineUsers.length; i++) {
if (onlineUsers[i].id === personalInfo.id) {
onlineUsers[i] = personalInfo
}
}
- var userStatus = {
+ const userStatus = {
idle: idle.isAway,
type: type
}
@@ -2348,24 +2840,24 @@ function emitUserStatus (force) {
function checkCursorTag (coord, ele) {
if (!ele) return // return if element not exists
// set margin
- var tagRightMargin = 0
- var tagBottomMargin = 2
+ const tagRightMargin = 0
+ const tagBottomMargin = 2
// use sizer to get the real doc size (won't count status bar and gutters)
- var docWidth = ui.area.codemirrorSizer.width()
+ const docWidth = ui.area.codemirrorSizer.width()
// get editor size (status bar not count in)
- var editorHeight = ui.area.codemirror.height()
+ const editorHeight = ui.area.codemirror.height()
// get element size
- var width = ele.outerWidth()
- var height = ele.outerHeight()
- var padding = (ele.outerWidth() - ele.width()) / 2
+ const width = ele.outerWidth()
+ const height = ele.outerHeight()
+ const padding = (ele.outerWidth() - ele.width()) / 2
// get coord position
- var left = coord.left
- var top = coord.top
+ const left = coord.left
+ const top = coord.top
// get doc top offset (to workaround with viewport)
- var docTopOffset = ui.area.codemirrorSizerInner.position().top
+ const docTopOffset = ui.area.codemirrorSizerInner.position().top
// set offset
- var offsetLeft = -3
- var offsetTop = defaultTextHeight
+ let offsetLeft = -3
+ let offsetTop = defaultTextHeight
// only do when have width and height
if (width > 0 && height > 0) {
// flip x when element right bound larger than doc width
@@ -2374,8 +2866,12 @@ function checkCursorTag (coord, ele) {
}
// flip y when element bottom bound larger than doc height
// and element top position is larger than element height
- if (top + docTopOffset + height + offsetTop + tagBottomMargin > Math.max(editor.doc.height, editorHeight) && top + docTopOffset > height + tagBottomMargin) {
- offsetTop = -(height)
+ if (
+ top + docTopOffset + height + offsetTop + tagBottomMargin >
+ Math.max(editor.doc.height, editorHeight) &&
+ top + docTopOffset > height + tagBottomMargin
+ ) {
+ offsetTop = -height
}
}
// set position
@@ -2386,10 +2882,10 @@ function checkCursorTag (coord, ele) {
function buildCursor (user) {
if (appState.currentMode === modeType.view) return
if (!user.cursor) return
- var coord = editor.charCoords(user.cursor, 'windows')
+ const coord = editor.charCoords(user.cursor, 'windows')
coord.left = coord.left < 4 ? 4 : coord.left
coord.top = coord.top < 0 ? 0 : coord.top
- var iconClass = 'fa-user'
+ let iconClass = 'fa-user'
switch (user.type) {
case 'xs':
iconClass = 'fa-mobile'
@@ -2405,19 +2901,29 @@ 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 = '
'
+ const icon = '
'
- let cursortag = $('
' + icon + ' ' + user.name + '
')
+ const cursortag = $(
+ '
' +
+ icon +
+ ' ' +
+ user.name +
+ '
'
+ )
// cursortag[0].style.background = color;
cursortag[0].style.color = user.color
@@ -2425,28 +2931,43 @@ function buildCursor (user) {
cursortag.delay(2000).fadeOut('fast')
cursor.hover(
function () {
- if (cursor.attr('data-mode') === 'hover') { cursortag.stop(true).fadeIn('fast') }
+ if (cursor.attr('data-mode') === 'hover') {
+ cursortag.stop(true).fadeIn('fast')
+ }
},
function () {
- if (cursor.attr('data-mode') === 'hover') { cursortag.stop(true).fadeOut('fast') }
- })
+ if (cursor.attr('data-mode') === 'hover') {
+ cursortag.stop(true).fadeOut('fast')
+ }
+ }
+ )
- var hideCursorTagDelay = 2000
- var hideCursorTagTimer = null
+ const hideCursorTagDelay = 2000
+ let hideCursorTagTimer = null
- var switchMode = function (ele) {
- if (ele.attr('data-mode') === 'state') { ele.attr('data-mode', 'hover') } else if (ele.attr('data-mode') === 'hover') { ele.attr('data-mode', 'state') }
+ const switchMode = function (ele) {
+ if (ele.attr('data-mode') === 'state') {
+ ele.attr('data-mode', 'hover')
+ } else if (ele.attr('data-mode') === 'hover') {
+ ele.attr('data-mode', 'state')
+ }
}
- var switchTag = function (ele) {
- if (ele.css('display') === 'none') { ele.stop(true).fadeIn('fast') } else { ele.stop(true).fadeOut('fast') }
+ const switchTag = function (ele) {
+ if (ele.css('display') === 'none') {
+ ele.stop(true).fadeIn('fast')
+ } else {
+ ele.stop(true).fadeOut('fast')
+ }
}
- var hideCursorTag = function () {
- if (cursor.attr('data-mode') === 'hover') { cursortag.fadeOut('fast') }
+ const hideCursorTag = function () {
+ if (cursor.attr('data-mode') === 'hover') {
+ cursortag.fadeOut('fast')
+ }
}
cursor.on('touchstart', function (e) {
- var display = cursortag.css('display')
+ const display = cursortag.css('display')
cursortag.stop(true).fadeIn('fast')
clearTimeout(hideCursorTagTimer)
hideCursorTagTimer = setTimeout(hideCursorTag, hideCursorTagDelay)
@@ -2456,7 +2977,9 @@ function buildCursor (user) {
}
})
cursortag.on('mousedown touchstart', function (e) {
- if (cursor.attr('data-mode') === 'state') { switchTag(cursortag) }
+ if (cursor.attr('data-mode') === 'state') {
+ switchTag(cursortag)
+ }
switchMode(cursor)
e.preventDefault()
e.stopPropagation()
@@ -2469,19 +2992,21 @@ function buildCursor (user) {
cursor[0].style.top = coord.top + 'px'
$('.CodeMirror-other-cursors').append(cursor)
- if (!user.idle) { cursor.stop(true).fadeIn() }
+ if (!user.idle) {
+ cursor.stop(true).fadeIn()
+ }
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)
@@ -2489,16 +3014,23 @@ function buildCursor (user) {
cursor[0].style.left = coord.left + 'px'
cursor[0].style.top = coord.top + 'px'
} else {
- cursor.animate({
- 'left': coord.left,
- 'top': coord.top
- }, {
- duration: cursorAnimatePeriod,
- queue: false
- })
+ cursor.animate(
+ {
+ left: coord.left,
+ top: coord.top
+ },
+ {
+ duration: cursorAnimatePeriod,
+ queue: false
+ }
+ )
}
- if (user.idle && cursor.css('display') !== 'none') { cursor.stop(true).fadeOut() } else if (!user.idle && cursor.css('display') === 'none') { cursor.stop(true).fadeIn() }
+ if (user.idle && cursor.css('display') !== 'none') {
+ cursor.stop(true).fadeOut()
+ } else if (!user.idle && cursor.css('display') === 'none') {
+ cursor.stop(true).fadeIn()
+ }
checkCursorTag(coord, cursortag)
}
@@ -2506,18 +3038,23 @@ function buildCursor (user) {
// editor actions
function removeNullByte (cm, change) {
- var str = change.text.join('\n')
+ const str = change.text.join('\n')
// eslint-disable-next-line no-control-regex
if (/\u0000/g.test(str) && change.update) {
- // eslint-disable-next-line no-control-regex
- change.update(change.from, change.to, str.replace(/\u0000/g, '').split('\n'))
+ change.update(
+ change.from,
+ change.to,
+ // eslint-disable-next-line no-control-regex
+ str.replace(/\u0000/g, '').split('\n')
+ )
}
}
function enforceMaxLength (cm, change) {
- var maxLength = cm.getOption('maxLength')
+ const maxLength = cm.getOption('maxLength')
if (maxLength && change.update) {
- var str = change.text.join('\n')
- var delta = str.length - (cm.indexFromPos(change.to) - cm.indexFromPos(change.from))
+ let str = change.text.join('\n')
+ let delta =
+ str.length - (cm.indexFromPos(change.to) - cm.indexFromPos(change.from))
if (delta <= 0) {
return false
}
@@ -2530,14 +3067,16 @@ function enforceMaxLength (cm, change) {
}
return false
}
-var ignoreEmitEvents = ['setValue', 'ignoreHistory']
+const ignoreEmitEvents = ['setValue', 'ignoreHistory']
editorInstance.on('beforeChange', function (cm, change) {
- if (debug) { console.debug(change) }
+ if (debug) {
+ console.debug(change)
+ }
removeNullByte(cm, change)
if (enforceMaxLength(cm, change)) {
$('.limit-modal').modal('show')
}
- var isIgnoreEmitEvent = (ignoreEmitEvents.indexOf(change.origin) !== -1)
+ const isIgnoreEmitEvent = ignoreEmitEvents.indexOf(change.origin) !== -1
if (!isIgnoreEmitEvent) {
if (!havePermission()) {
change.canceled = true
@@ -2557,7 +3096,9 @@ editorInstance.on('beforeChange', function (cm, change) {
updateTitleReminder()
}
}
- if (cmClient && !socket.connected) { cmClient.editorAdapter.ignoreNextChange = true }
+ if (cmClient && !socket.connected) {
+ cmClient.editorAdapter.ignoreNextChange = true
+ }
})
editorInstance.on('cut', function () {
// na
@@ -2567,9 +3108,9 @@ editorInstance.on('paste', function () {
})
editorInstance.on('changes', function (editor, changes) {
updateHistory()
- var docLength = editor.getValue().length
+ const docLength = editor.getValue().length
// workaround for big documents
- var newViewportMargin = 20
+ let newViewportMargin = 20
if (docLength > 20000) {
newViewportMargin = 1
} else if (docLength > 10000) {
@@ -2582,7 +3123,10 @@ editorInstance.on('changes', function (editor, changes) {
windowResize()
}
checkEditorScrollbar()
- if (ui.area.codemirrorScroll[0].scrollHeight > ui.area.view[0].scrollHeight && editorHasFocus()) {
+ if (
+ ui.area.codemirrorScroll[0].scrollHeight > ui.area.view[0].scrollHeight &&
+ editorHasFocus()
+ ) {
postUpdateEvent = function () {
syncScrollToView()
postUpdateEvent = null
@@ -2590,12 +3134,12 @@ editorInstance.on('changes', function (editor, changes) {
}
})
editorInstance.on('focus', function (editor) {
- for (var i = 0; i < onlineUsers.length; i++) {
+ for (let i = 0; i < onlineUsers.length; i++) {
if (onlineUsers[i].id === personalInfo.id) {
onlineUsers[i].cursor = editor.getCursor()
}
}
- personalInfo['cursor'] = editor.getCursor()
+ personalInfo.cursor = editor.getCursor()
socket.emit('cursor focus', editor.getCursor())
})
@@ -2603,12 +3147,12 @@ const cursorActivity = _.debounce(cursorActivityInner, cursorActivityDebounce)
function cursorActivityInner (editor) {
if (editorHasFocus() && !Visibility.hidden()) {
- for (var i = 0; i < onlineUsers.length; i++) {
+ for (let i = 0; i < onlineUsers.length; i++) {
if (onlineUsers[i].id === personalInfo.id) {
onlineUsers[i].cursor = editor.getCursor()
}
}
- personalInfo['cursor'] = editor.getCursor()
+ personalInfo.cursor = editor.getCursor()
socket.emit('cursor activity', editor.getCursor())
}
}
@@ -2632,7 +3176,7 @@ editorInstance.on('beforeSelectionChange', function (doc, selections) {
// borrow from brackets EditorStatusBar.js
if (start.line !== end.line) {
- var lines = end.line - start.line + 1
+ let lines = end.line - start.line + 1
if (end.ch === 0) {
lines--
}
@@ -2650,19 +3194,19 @@ editorInstance.on('beforeSelectionChange', function (doc, selections) {
})
editorInstance.on('blur', function (cm) {
- for (var i = 0; i < onlineUsers.length; i++) {
+ for (let i = 0; i < onlineUsers.length; i++) {
if (onlineUsers[i].id === personalInfo.id) {
onlineUsers[i].cursor = null
}
}
- personalInfo['cursor'] = null
+ personalInfo.cursor = null
socket.emit('cursor blur')
})
function saveInfo () {
- var scrollbarStyle = editor.getOption('scrollbarStyle')
- var left = $(window).scrollLeft()
- var top = $(window).scrollTop()
+ const scrollbarStyle = editor.getOption('scrollbarStyle')
+ const left = $(window).scrollLeft()
+ const top = $(window).scrollTop()
switch (appState.currentMode) {
case modeType.edit:
if (scrollbarStyle === 'native') {
@@ -2688,10 +3232,10 @@ function saveInfo () {
}
function restoreInfo () {
- var scrollbarStyle = editor.getOption('scrollbarStyle')
+ const scrollbarStyle = editor.getOption('scrollbarStyle')
if (lastInfo.needRestore) {
- var line = lastInfo.edit.cursor.line
- var ch = lastInfo.edit.cursor.ch
+ const line = lastInfo.edit.cursor.line
+ const ch = lastInfo.edit.cursor.ch
editor.setCursor(line, ch)
editor.setSelections(lastInfo.edit.selections)
switch (appState.currentMode) {
@@ -2700,8 +3244,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)
}
@@ -2711,10 +3255,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
editor.scrollIntoView()
- editor.scrollTo(left, top)
+ editor.scrollTo(lastInfo.edit.scroll.left, lastInfo.edit.scroll.top)
ui.area.view.scrollLeft(lastInfo.view.scroll.left)
ui.area.view.scrollTop(lastInfo.view.scroll.top)
break
@@ -2731,27 +3273,30 @@ function refreshView () {
updateViewInner()
}
-var updateView = _.debounce(function () {
+const updateView = _.debounce(function () {
editor.operation(updateViewInner)
}, updateViewDebounce)
-var lastResult = null
-var postUpdateEvent = null
+let lastResult = null
+let postUpdateEvent = null
function updateViewInner () {
if (appState.currentMode === modeType.edit || !isDirty) return
- var value = editor.getValue()
- var lastMeta = md.meta
+ const value = editor.getValue()
+ const lastMeta = md.meta
md.meta = {}
delete md.metaError
- var rendered = md.render(value)
+ let rendered = md.render(value)
if (md.meta.type && md.meta.type === 'slide') {
ui.area.view.addClass('black')
- var slideOptions = {
+ const slideOptions = {
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
}
- var slides = window.RevealMarkdown.slidify(editor.getValue(), slideOptions)
+ const slides = window.RevealMarkdown.slidify(
+ editor.getValue(),
+ slideOptions
+ )
ui.area.markdown.html(slides)
window.RevealMarkdown.initialize()
// prevent XSS
@@ -2769,14 +3314,22 @@ function updateViewInner () {
}
// only render again when meta changed
if (JSON.stringify(md.meta) !== JSON.stringify(lastMeta)) {
- parseMeta(md, ui.area.codemirror, ui.area.markdown, $('#ui-toc'), $('#ui-toc-affix'))
+ parseMeta(
+ md,
+ ui.area.codemirror,
+ ui.area.markdown,
+ $('#ui-toc'),
+ $('#ui-toc-affix')
+ )
rendered = md.render(value)
}
// prevent XSS
rendered = preventXSS(rendered)
- var result = postProcess(rendered).children().toArray()
+ const result = postProcess(rendered).children().toArray()
partialUpdate(result, lastResult, ui.area.markdown.children().toArray())
- if (result && lastResult && result.length !== lastResult.length) { updateDataAttrs(result, ui.area.markdown.children().toArray()) }
+ if (result && lastResult && result.length !== lastResult.length) {
+ updateDataAttrs(result, ui.area.markdown.children().toArray())
+ }
lastResult = $(result).clone()
}
removeDOMEvents(ui.area.markdown)
@@ -2794,12 +3347,14 @@ function updateViewInner () {
clearMap()
// buildMap();
updateTitleReminder()
- if (postUpdateEvent && typeof postUpdateEvent === 'function') { postUpdateEvent() }
+ if (postUpdateEvent && typeof postUpdateEvent === 'function') {
+ postUpdateEvent()
+ }
}
-var updateHistoryDebounce = 600
+const updateHistoryDebounce = 600
-var updateHistory = _.debounce(updateHistoryInner, updateHistoryDebounce)
+const updateHistory = _.debounce(updateHistoryInner, updateHistoryDebounce)
function updateHistoryInner () {
writeHistory(renderFilename(ui.area.markdown), renderTags(ui.area.markdown))
@@ -2807,50 +3362,59 @@ function updateHistoryInner () {
function updateDataAttrs (src, des) {
// sync data attr startline and endline
- for (var i = 0; i < src.length; i++) {
+ for (let i = 0; i < src.length; i++) {
copyAttribute(src[i], des[i], 'data-startline')
copyAttribute(src[i], des[i], 'data-endline')
}
}
function partialUpdate (src, tar, des) {
- if (!src || src.length === 0 || !tar || tar.length === 0 || !des || des.length === 0) {
+ if (
+ !src ||
+ src.length === 0 ||
+ !tar ||
+ tar.length === 0 ||
+ !des ||
+ des.length === 0
+ ) {
ui.area.markdown.html(src)
return
}
- if (src.length === tar.length) { // same length
+ if (src.length === tar.length) {
+ // same length
for (let i = 0; i < src.length; i++) {
copyAttribute(src[i], des[i], 'data-startline')
copyAttribute(src[i], des[i], 'data-endline')
- var rawSrc = cloneAndRemoveDataAttr(src[i])
- var rawTar = cloneAndRemoveDataAttr(tar[i])
+ const rawSrc = cloneAndRemoveDataAttr(src[i])
+ const rawTar = cloneAndRemoveDataAttr(tar[i])
if (rawSrc.outerHTML !== rawTar.outerHTML) {
// console.debug(rawSrc);
// console.debug(rawTar);
$(des[i]).replaceWith(src[i])
}
}
- } else { // diff length
- var start = 0
+ } else {
+ // diff length
+ let start = 0
// find diff start position
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
}
}
// find diff end position
- var srcEnd = 0
- var tarEnd = 0
+ let srcEnd = 0
+ let tarEnd = 0
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
@@ -2858,12 +3422,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
@@ -2871,25 +3435,35 @@ 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
}
}
// check if tar end overlap tar start
- var overlap = 0
- for (var i = start; i >= 0; i--) {
- var rawTarStart = cloneAndRemoveDataAttr(tar[i - 1])
- var rawTarEnd = cloneAndRemoveDataAttr(tar[tarEnd + 1 + start - i])
- if (rawTarStart && rawTarEnd && rawTarStart.outerHTML === rawTarEnd.outerHTML) { overlap++ } else { break }
+ let overlap = 0
+ for (let i = start; i >= 0; i--) {
+ const rawTarStart = cloneAndRemoveDataAttr(tar[i - 1])
+ const rawTarEnd = cloneAndRemoveDataAttr(tar[tarEnd + 1 + start - i])
+ if (
+ rawTarStart &&
+ rawTarEnd &&
+ rawTarStart.outerHTML === rawTarEnd.outerHTML
+ ) {
+ overlap++
+ } else {
+ break
+ }
+ }
+ if (debug) {
+ console.debug('overlap:' + overlap)
}
- if (debug) { console.debug('overlap:' + overlap) }
// show diff content
if (debug) {
console.debug('start:' + start)
@@ -2898,10 +3472,10 @@ function partialUpdate (src, tar, des) {
}
tarEnd += overlap
srcEnd += overlap
- var repeatAdd = (start - srcEnd) < (start - tarEnd)
- var repeatDiff = Math.abs(srcEnd - tarEnd) - 1
+ const repeatAdd = start - srcEnd < start - tarEnd
+ const repeatDiff = Math.abs(srcEnd - tarEnd) - 1
// push new elements
- var newElements = []
+ const newElements = []
if (srcEnd >= start) {
for (let j = start; j <= srcEnd; j++) {
if (!src[j]) continue
@@ -2914,7 +3488,7 @@ function partialUpdate (src, tar, des) {
}
}
// push remove elements
- var removeElements = []
+ const removeElements = []
if (tarEnd >= start) {
for (let j = start; j <= tarEnd; j++) {
if (!des[j]) continue
@@ -2931,28 +3505,38 @@ function partialUpdate (src, tar, des) {
console.debug('ADD ELEMENTS')
console.debug(newElements.join('\n'))
}
- if (des[start]) { $(newElements.join('')).insertBefore(des[start]) } else { $(newElements.join('')).insertAfter(des[start - 1]) }
+ if (des[start]) {
+ $(newElements.join('')).insertBefore(des[start])
+ } else {
+ $(newElements.join('')).insertAfter(des[start - 1])
+ }
// remove elements
- if (debug) { console.debug('REMOVE ELEMENTS') }
+ if (debug) {
+ console.debug('REMOVE ELEMENTS')
+ }
for (let j = 0; j < removeElements.length; j++) {
if (debug) {
console.debug(removeElements[j].outerHTML)
}
- if (removeElements[j]) { $(removeElements[j]).remove() }
+ if (removeElements[j]) {
+ $(removeElements[j]).remove()
+ }
}
}
}
function cloneAndRemoveDataAttr (el) {
if (!el) return
- var rawEl = $(el).clone()
+ const rawEl = $(el).clone()
rawEl.removeAttr('data-startline data-endline')
rawEl.find('[data-startline]').removeAttr('data-startline data-endline')
return rawEl[0]
}
function copyAttribute (src, des, attr) {
- if (src && src.getAttribute(attr) && des) { des.setAttribute(attr, src.getAttribute(attr)) }
+ if (src && src.getAttribute(attr) && des) {
+ des.setAttribute(attr, src.getAttribute(attr))
+ }
}
if ($('.cursor-menu').length <= 0) {
@@ -2960,69 +3544,83 @@ if ($('.cursor-menu').length <= 0) {
}
function reverseSortCursorMenu (dropdown) {
- var items = dropdown.find('.textcomplete-item')
+ const items = dropdown.find('.textcomplete-item')
items.sort(function (a, b) {
return $(b).attr('data-index') - $(a).attr('data-index')
})
return items
}
-var checkCursorMenu = _.throttle(checkCursorMenuInner, cursorMenuThrottle)
+const checkCursorMenu = _.throttle(checkCursorMenuInner, cursorMenuThrottle)
function checkCursorMenuInner () {
// get element
- var dropdown = $('.cursor-menu > .dropdown-menu')
+ const dropdown = $('.cursor-menu > .dropdown-menu')
// return if not exists
if (dropdown.length <= 0) return
// set margin
- var menuRightMargin = 10
- var menuBottomMargin = 4
+ const menuRightMargin = 10
+ const menuBottomMargin = 4
// use sizer to get the real doc size (won't count status bar and gutters)
- var docWidth = ui.area.codemirrorSizer.width()
+ const docWidth = ui.area.codemirrorSizer.width()
// get editor size (status bar not count in)
- var editorHeight = ui.area.codemirror.height()
+ const editorHeight = ui.area.codemirror.height()
// get element size
- var width = dropdown.outerWidth()
- var height = dropdown.outerHeight()
+ const width = dropdown.outerWidth()
+ const height = dropdown.outerHeight()
// get cursor
- var cursor = editor.getCursor()
+ const cursor = editor.getCursor()
// set element cursor data
- if (!dropdown.hasClass('CodeMirror-other-cursor')) { dropdown.addClass('CodeMirror-other-cursor') }
+ if (!dropdown.hasClass('CodeMirror-other-cursor')) {
+ dropdown.addClass('CodeMirror-other-cursor')
+ }
dropdown.attr('data-line', cursor.line)
dropdown.attr('data-ch', cursor.ch)
// get coord position
- var coord = editor.charCoords({
- line: cursor.line,
- ch: cursor.ch
- }, 'windows')
- var left = coord.left
- var top = coord.top
+ const coord = editor.charCoords(
+ {
+ line: cursor.line,
+ ch: cursor.ch
+ },
+ 'windows'
+ )
+ const left = coord.left
+ const top = coord.top
// get doc top offset (to workaround with viewport)
- var docTopOffset = ui.area.codemirrorSizerInner.position().top
+ const docTopOffset = ui.area.codemirrorSizerInner.position().top
// set offset
- var offsetLeft = 0
- var offsetTop = defaultTextHeight
+ let offsetLeft = 0
+ let offsetTop = defaultTextHeight
// set up side down
window.upSideDown = false
- var lastUpSideDown = window.upSideDown = false
+ let lastUpSideDown = (window.upSideDown = false)
// only do when have width and height
if (width > 0 && height > 0) {
// make element right bound not larger than doc width
- if (left + width + offsetLeft + menuRightMargin > docWidth) { offsetLeft = -(left + width - docWidth + menuRightMargin) }
+ if (left + width + offsetLeft + menuRightMargin > docWidth) {
+ offsetLeft = -(left + width - docWidth + menuRightMargin)
+ }
// flip y when element bottom bound larger than doc height
// and element top position is larger than element height
- if (top + docTopOffset + height + offsetTop + menuBottomMargin > Math.max(editor.doc.height, editorHeight) && top + docTopOffset > height + menuBottomMargin) {
+ if (
+ top + docTopOffset + height + offsetTop + menuBottomMargin >
+ Math.max(editor.doc.height, editorHeight) &&
+ top + docTopOffset > height + menuBottomMargin
+ ) {
offsetTop = -(height + menuBottomMargin)
// reverse sort menu because upSideDown
dropdown.html(reverseSortCursorMenu(dropdown))
window.upSideDown = true
}
- var textCompleteDropdown = $(editor.getInputField()).data('textComplete').dropdown
+ const textCompleteDropdown = $(editor.getInputField()).data('textComplete')
+ .dropdown
lastUpSideDown = textCompleteDropdown.upSideDown
textCompleteDropdown.upSideDown = window.upSideDown
}
// make menu scroll top only if upSideDown changed
- if (window.upSideDown !== lastUpSideDown) { dropdown.scrollTop(dropdown[0].scrollHeight) }
+ if (window.upSideDown !== lastUpSideDown) {
+ dropdown.scrollTop(dropdown[0].scrollHeight)
+ }
// set element offset data
dropdown.attr('data-offset-left', offsetLeft)
dropdown.attr('data-offset-top', offsetTop)
@@ -3033,33 +3631,37 @@ function checkCursorMenuInner () {
function checkInIndentCode () {
// if line starts with tab or four spaces is a code block
- var line = editor.getLine(editor.getCursor().line)
- var isIndentCode = ((line.substr(0, 4) === ' ') || (line.substr(0, 1) === '\t'))
+ const line = editor.getLine(editor.getCursor().line)
+ const isIndentCode =
+ line.substr(0, 4) === ' ' || line.substr(0, 1) === '\t'
return isIndentCode
}
-var isInCode = false
+let isInCode = false
function checkInCode () {
isInCode = checkAbove(matchInCode) || checkInIndentCode()
}
function checkAbove (method) {
- var cursor = editor.getCursor()
- var text = []
- for (var i = 0; i < cursor.line; i++) { // contain current line
+ const cursor = editor.getCursor()
+ let text = []
+ for (let i = 0; i < cursor.line; i++) {
+ // contain current line
text.push(editor.getLine(i))
}
- text = text.join('\n') + '\n' + editor.getLine(cursor.line).slice(0, cursor.ch)
+ text =
+ text.join('\n') + '\n' + editor.getLine(cursor.line).slice(0, cursor.ch)
// console.debug(text);
return method(text)
}
function checkBelow (method) {
- var cursor = editor.getCursor()
- var count = editor.lineCount()
- var text = []
- for (var i = cursor.line + 1; i < count; i++) { // contain current line
+ const cursor = editor.getCursor()
+ const count = editor.lineCount()
+ let text = []
+ for (let i = cursor.line + 1; i < count; i++) {
+ // contain current line
text.push(editor.getLine(i))
}
text = editor.getLine(cursor.line).slice(cursor.ch) + '\n' + text.join('\n')
@@ -3068,7 +3670,7 @@ function checkBelow (method) {
}
function matchInCode (text) {
- var match
+ let match
match = text.match(/`{3,}/g)
if (match && match.length % 2) {
return true
@@ -3082,8 +3684,8 @@ function matchInCode (text) {
}
}
-var isInContainer = false
-var isInContainerSyntax = false
+let isInContainer = false
+let isInContainerSyntax = false
function checkInContainer () {
isInContainer = checkAbove(matchInContainer) && !checkInIndentCode()
@@ -3091,13 +3693,12 @@ function checkInContainer () {
function checkInContainerSyntax () {
// if line starts with :::, it's in container syntax
- var line = editor.getLine(editor.getCursor().line)
- isInContainerSyntax = (line.substr(0, 3) === ':::')
+ const line = editor.getLine(editor.getCursor().line)
+ isInContainerSyntax = line.substr(0, 3) === ':::'
}
function matchInContainer (text) {
- var match
- match = text.match(/:{3,}/g)
+ const match = text.match(/:{3,}/g)
if (match && match.length % 2) {
return true
} else {
@@ -3106,194 +3707,244 @@ function matchInContainer (text) {
}
$(editor.getInputField())
- .textcomplete([
- { // emoji strategy
- match: /(^|\n|\s)\B:([-+\w]*)$/,
- search: function (term, callback) {
- var line = editor.getLine(editor.getCursor().line)
- term = line.match(this.match)[2]
- var list = []
- $.map(window.emojify.emojiNames, function (emoji) {
- if (emoji.indexOf(term) === 0) { // match at first character
- list.push(emoji)
- }
- })
- $.map(window.emojify.emojiNames, function (emoji) {
- if (emoji.indexOf(term) !== -1) { // match inside the word
- list.push(emoji)
- }
- })
- callback(list)
- },
- template: function (value) {
- return '

' + value
- },
- replace: function (value) {
- return '$1:' + value + ': '
- },
- index: 1,
- context: function (text) {
- checkInCode()
- checkInContainer()
- checkInContainerSyntax()
- return !isInCode && !isInContainerSyntax
- }
- },
- { // Code block language strategy
- langs: supportCodeModes,
- charts: supportCharts,
- match: /(^|\n)```(\w+)$/,
- search: function (term, callback) {
- var line = editor.getLine(editor.getCursor().line)
- term = line.match(this.match)[2]
- var list = []
- $.map(this.langs, function (lang) {
- if (lang.indexOf(term) === 0 && lang !== term) { list.push(lang) }
- })
- $.map(this.charts, function (chart) {
- if (chart.indexOf(term) === 0 && chart !== term) { list.push(chart) }
- })
- callback(list)
- },
- replace: function (lang) {
- var ending = ''
- if (!checkBelow(matchInCode)) {
- ending = '\n\n```'
- }
- if (this.langs.indexOf(lang) !== -1) { return '$1```' + lang + '=' + ending } else if (this.charts.indexOf(lang) !== -1) { return '$1```' + lang + ending }
- },
- done: function () {
- var cursor = editor.getCursor()
- var text = []
- text.push(editor.getLine(cursor.line - 1))
- text.push(editor.getLine(cursor.line))
- text = text.join('\n')
- // console.debug(text);
- if (text === '\n```') { editor.doc.cm.execCommand('goLineUp') }
- },
- context: function (text) {
- return isInCode
- }
- },
- { // Container strategy
- containers: supportContainers,
- match: /(^|\n):::(\s*)(\w*)$/,
- search: function (term, callback) {
- var line = editor.getLine(editor.getCursor().line)
- term = line.match(this.match)[3].trim()
- var list = []
- $.map(this.containers, function (container) {
- if (container.indexOf(term) === 0 && container !== term) { list.push(container) }
- })
- callback(list)
- },
- replace: function (lang) {
- var ending = ''
- if (!checkBelow(matchInContainer)) {
- ending = '\n\n:::'
- }
- if (this.containers.indexOf(lang) !== -1) { return '$1:::$2' + lang + ending }
- },
- done: function () {
- var cursor = editor.getCursor()
- var text = []
- text.push(editor.getLine(cursor.line - 1))
- text.push(editor.getLine(cursor.line))
- text = text.join('\n')
- // console.debug(text);
- if (text === '\n:::') { editor.doc.cm.execCommand('goLineUp') }
- },
- context: function (text) {
- return !isInCode && isInContainer
- }
- },
- { // header
- match: /(?:^|\n)(\s{0,3})(#{1,6}\w*)$/,
- search: function (term, callback) {
- callback($.map(supportHeaders, function (header) {
- return header.search.indexOf(term) === 0 ? header.text : null
- }))
- },
- replace: function (value) {
- return '$1' + value
- },
- context: function (text) {
- return !isInCode
- }
- },
- { // extra tags for list
- match: /(^[>\s]*[-+*]\s(?:\[[x ]\]|.*))(\[\])(\w*)$/,
- search: function (term, callback) {
- var list = []
- $.map(supportExtraTags, function (extratag) {
- if (extratag.search.indexOf(term) === 0) { list.push(extratag.command()) }
- })
- $.map(supportReferrals, function (referral) {
- if (referral.search.indexOf(term) === 0) { list.push(referral.text) }
- })
- callback(list)
- },
- replace: function (value) {
- return '$1' + value
- },
- context: function (text) {
- return !isInCode
- }
- },
- { // extra tags for blockquote
- match: /(?:^|\n|\s)(>.*|\s|)((\^|)\[(\^|)\](\[\]|\(\)|:|)\s*\w*)$/,
- search: function (term, callback) {
- var line = editor.getLine(editor.getCursor().line)
- var quote = line.match(this.match)[1].trim()
- var list = []
- if (quote.indexOf('>') === 0) {
- $.map(supportExtraTags, function (extratag) {
- if (extratag.search.indexOf(term) === 0) { list.push(extratag.command()) }
+ .textcomplete(
+ [
+ {
+ // emoji strategy
+ match: /(^|\n|\s)\B:([-+\w]*)$/,
+ search: function (term, callback) {
+ const line = editor.getLine(editor.getCursor().line)
+ term = line.match(this.match)[2]
+ const list = []
+ $.map(window.emojify.emojiNames, function (emoji) {
+ if (emoji.indexOf(term) === 0) {
+ // match at first character
+ list.push(emoji)
+ }
})
+ $.map(window.emojify.emojiNames, function (emoji) {
+ if (emoji.indexOf(term) !== -1) {
+ // match inside the word
+ list.push(emoji)
+ }
+ })
+ callback(list)
+ },
+ template: function (value) {
+ return (
+ '

' +
+ value
+ )
+ },
+ replace: function (value) {
+ return '$1:' + value + ': '
+ },
+ index: 1,
+ context: function (text) {
+ checkInCode()
+ checkInContainer()
+ checkInContainerSyntax()
+ return !isInCode && !isInContainerSyntax
}
- $.map(supportReferrals, function (referral) {
- if (referral.search.indexOf(term) === 0) { list.push(referral.text) }
- })
- callback(list)
},
- replace: function (value) {
- return '$1' + value
+ {
+ // Code block language strategy
+ langs: supportCodeModes,
+ charts: supportCharts,
+ match: /(^|\n)```(\w+)$/,
+ search: function (term, callback) {
+ const line = editor.getLine(editor.getCursor().line)
+ term = line.match(this.match)[2]
+ const list = []
+ $.map(this.langs, function (lang) {
+ if (lang.indexOf(term) === 0 && lang !== term) {
+ list.push(lang)
+ }
+ })
+ $.map(this.charts, function (chart) {
+ if (chart.indexOf(term) === 0 && chart !== term) {
+ list.push(chart)
+ }
+ })
+ callback(list)
+ },
+ replace: function (lang) {
+ let ending = ''
+ if (!checkBelow(matchInCode)) {
+ ending = '\n\n```'
+ }
+ if (this.langs.indexOf(lang) !== -1) {
+ return '$1```' + lang + '=' + ending
+ } else if (this.charts.indexOf(lang) !== -1) {
+ return '$1```' + lang + ending
+ }
+ },
+ done: function () {
+ const cursor = editor.getCursor()
+ let text = []
+ text.push(editor.getLine(cursor.line - 1))
+ text.push(editor.getLine(cursor.line))
+ text = text.join('\n')
+ // console.debug(text);
+ if (text === '\n```') {
+ editor.doc.cm.execCommand('goLineUp')
+ }
+ },
+ context: function (text) {
+ return isInCode
+ }
},
- context: function (text) {
- return !isInCode
- }
- },
- { // referral
- match: /(^\s*|\n|\s{2})((\[\]|\[\]\[\]|\[\]\(\)|!|!\[\]|!\[\]\[\]|!\[\]\(\))\s*\w*)$/,
- search: function (term, callback) {
- callback($.map(supportReferrals, function (referral) {
- return referral.search.indexOf(term) === 0 ? referral.text : null
- }))
- },
- replace: function (value) {
- return '$1' + value
- },
- context: function (text) {
- return !isInCode
- }
- },
- { // externals
- match: /(^|\n|\s)\{\}(\w*)$/,
- search: function (term, callback) {
- callback($.map(supportExternals, function (external) {
- return external.search.indexOf(term) === 0 ? external.text : null
- }))
- },
- replace: function (value) {
- return '$1' + value
- },
- context: function (text) {
- return !isInCode
+ {
+ // Container strategy
+ containers: supportContainers,
+ match: /(^|\n):::(\s*)(\w*)$/,
+ search: function (term, callback) {
+ const line = editor.getLine(editor.getCursor().line)
+ term = line.match(this.match)[3].trim()
+ const list = []
+ $.map(this.containers, function (container) {
+ if (container.indexOf(term) === 0 && container !== term) {
+ list.push(container)
+ }
+ })
+ callback(list)
+ },
+ replace: function (lang) {
+ let ending = ''
+ if (!checkBelow(matchInContainer)) {
+ ending = '\n\n:::'
+ }
+ if (this.containers.indexOf(lang) !== -1) {
+ return '$1:::$2' + lang + ending
+ }
+ },
+ done: function () {
+ const cursor = editor.getCursor()
+ let text = []
+ text.push(editor.getLine(cursor.line - 1))
+ text.push(editor.getLine(cursor.line))
+ text = text.join('\n')
+ // console.debug(text);
+ if (text === '\n:::') {
+ editor.doc.cm.execCommand('goLineUp')
+ }
+ },
+ context: function (text) {
+ return !isInCode && isInContainer
+ }
+ },
+ {
+ // header
+ match: /(?:^|\n)(\s{0,3})(#{1,6}\w*)$/,
+ search: function (term, callback) {
+ callback(
+ $.map(supportHeaders, function (header) {
+ return header.search.indexOf(term) === 0 ? header.text : null
+ })
+ )
+ },
+ replace: function (value) {
+ return '$1' + value
+ },
+ context: function (text) {
+ return !isInCode
+ }
+ },
+ {
+ // extra tags for list
+ match: /(^[>\s]*[-+*]\s(?:\[[x ]\]|.*))(\[\])(\w*)$/,
+ search: function (term, callback) {
+ const list = []
+ $.map(supportExtraTags, function (extratag) {
+ if (extratag.search.indexOf(term) === 0) {
+ list.push(extratag.command())
+ }
+ })
+ $.map(supportReferrals, function (referral) {
+ if (referral.search.indexOf(term) === 0) {
+ list.push(referral.text)
+ }
+ })
+ callback(list)
+ },
+ replace: function (value) {
+ return '$1' + value
+ },
+ context: function (text) {
+ return !isInCode
+ }
+ },
+ {
+ // extra tags for blockquote
+ match: /(?:^|\n|\s)(>.*|\s|)((\^|)\[(\^|)\](\[\]|\(\)|:|)\s*\w*)$/,
+ search: function (term, callback) {
+ const line = editor.getLine(editor.getCursor().line)
+ const quote = line.match(this.match)[1].trim()
+ const list = []
+ if (quote.indexOf('>') === 0) {
+ $.map(supportExtraTags, function (extratag) {
+ if (extratag.search.indexOf(term) === 0) {
+ list.push(extratag.command())
+ }
+ })
+ }
+ $.map(supportReferrals, function (referral) {
+ if (referral.search.indexOf(term) === 0) {
+ list.push(referral.text)
+ }
+ })
+ callback(list)
+ },
+ replace: function (value) {
+ return '$1' + value
+ },
+ context: function (text) {
+ return !isInCode
+ }
+ },
+ {
+ // referral
+ match: /(^\s*|\n|\s{2})((\[\]|\[\]\[\]|\[\]\(\)|!|!\[\]|!\[\]\[\]|!\[\]\(\))\s*\w*)$/,
+ search: function (term, callback) {
+ callback(
+ $.map(supportReferrals, function (referral) {
+ return referral.search.indexOf(term) === 0 ? referral.text : null
+ })
+ )
+ },
+ replace: function (value) {
+ return '$1' + value
+ },
+ context: function (text) {
+ return !isInCode
+ }
+ },
+ {
+ // externals
+ match: /(^|\n|\s)\{\}(\w*)$/,
+ search: function (term, callback) {
+ callback(
+ $.map(supportExternals, function (external) {
+ return external.search.indexOf(term) === 0 ? external.text : null
+ })
+ )
+ },
+ replace: function (value) {
+ return '$1' + value
+ },
+ context: function (text) {
+ return !isInCode
+ }
}
+ ],
+ {
+ appendTo: $('.cursor-menu')
}
- ], {
- appendTo: $('.cursor-menu')
- })
+ )
.on({
'textComplete:beforeSearch': function (e) {
// NA
@@ -3307,22 +3958,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')
}
})
diff --git a/public/js/lib/appState.js b/public/js/lib/appState.js
index 87aaf7377..f409908ca 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 3f7a3e4d7..88e8f8cfc 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 9508b847d..338ef6dc0 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 d86ebf3cf..c84a37257 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 d87c7e410..70428b28f 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 d492fbc92..f033d00d9 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
diff --git a/public/js/render.js b/public/js/render.js
index ebda29844..af6fb3d4a 100644
--- a/public/js/render.js
+++ b/public/js/render.js
@@ -1,40 +1,40 @@
/* eslint-env browser, jquery */
// allow some attributes
-var filterXSS = require('xss')
+const filterXSS = require('xss')
-var whiteListAttr = ['id', 'class', 'style']
+const whiteListAttr = ['id', 'class', 'style']
window.whiteListAttr = whiteListAttr
// allow link starts with '.', '/' and custom protocol with '://', exclude link starts with javascript://
-var linkRegex = /^(?!javascript:\/\/)([\w|-]+:\/\/)|^([.|/])+/i
+const linkRegex = /^(?!javascript:\/\/)([\w|-]+:\/\/)|^([.|/])+/i
// allow data uri, from https://gist.github.com/bgrins/6194623
-var dataUriRegex = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s]*)\s*$/i
+const dataUriRegex = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s]*)\s*$/i
// custom white list
-var whiteList = filterXSS.whiteList
+const whiteList = filterXSS.whiteList
// allow ol specify start number
-whiteList['ol'] = ['start']
+whiteList.ol = ['start']
// allow li specify value number
-whiteList['li'] = ['value']
+whiteList.li = ['value']
// allow style tag
-whiteList['style'] = []
+whiteList.style = []
// allow kbd tag
-whiteList['kbd'] = []
+whiteList.kbd = []
// allow ifram tag with some safe attributes
-whiteList['iframe'] = ['allowfullscreen', 'name', 'referrerpolicy', 'src', 'width', 'height']
+whiteList.iframe = ['allowfullscreen', 'name', 'referrerpolicy', 'src', 'width', 'height']
// allow summary tag
-whiteList['summary'] = []
+whiteList.summary = []
// allow ruby tag
-whiteList['ruby'] = []
+whiteList.ruby = []
// allow rp tag for ruby
-whiteList['rp'] = []
+whiteList.rp = []
// allow rt tag for ruby
-whiteList['rt'] = []
+whiteList.rt = []
// allow figure tag
-whiteList['figure'] = []
+whiteList.figure = []
// allow figcaption tag
-whiteList['figcaption'] = []
+whiteList.figcaption = []
-var filterXSSOptions = {
+const filterXSSOptions = {
allowCommentTag: true,
whiteList: whiteList,
escapeHtml: function (html) {
diff --git a/public/js/reveal-markdown.js b/public/js/reveal-markdown.js
index c49bb9a24..89cd08871 100644
--- a/public/js/reveal-markdown.js
+++ b/public/js/reveal-markdown.js
@@ -17,28 +17,28 @@ import { md } from './extra'
root.RevealMarkdown.initialize()
}
}(this, function () {
- var DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$'
- var DEFAULT_NOTES_SEPARATOR = '^note:'
- var DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\.element\\s*?(.+?)$'
- var DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\.slide:\\s*?(\\S.+?)$'
+ const DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$'
+ const DEFAULT_NOTES_SEPARATOR = '^note:'
+ const DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\.element\\s*?(.+?)$'
+ const DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\.slide:\\s*?(\\S.+?)$'
- var SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__'
+ const SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__'
/**
* Retrieves the markdown contents of a slide section
* element. Normalizes leading tabs/whitespace.
*/
function getMarkdownFromSlide (section) {
- var template = section.querySelector('script')
+ const template = section.querySelector('script')
// strip leading whitespace so it isn't evaluated as code
- var text = (template || section).textContent
+ let text = (template || section).textContent
// restore script end tags
text = text.replace(new RegExp(SCRIPT_END_PLACEHOLDER, 'g'), '')
- var leadingWs = text.match(/^\n?(\s*)/)[1].length
- var leadingTabs = text.match(/^\n?(\t*)/)[1].length
+ const leadingWs = text.match(/^\n?(\s*)/)[1].length
+ const leadingTabs = text.match(/^\n?(\t*)/)[1].length
if (leadingTabs > 0) {
text = text.replace(new RegExp('\\n?\\t{' + leadingTabs + '}', 'g'), '\n')
@@ -56,12 +56,12 @@ import { md } from './extra'
* to the output markdown slide.
*/
function getForwardedAttributes (section) {
- var attributes = section.attributes
- var result = []
+ const attributes = section.attributes
+ const result = []
- for (var i = 0, len = attributes.length; i < len; i++) {
- var name = attributes[i].name
- var value = attributes[i].value
+ for (let i = 0, len = attributes.length; i < len; i++) {
+ const name = attributes[i].name
+ const value = attributes[i].value
// disregard attributes that are used for markdown loading/parsing
if (/data-(markdown|separator|vertical|notes)/gi.test(name)) continue
@@ -95,7 +95,7 @@ import { md } from './extra'
function createMarkdownSlide (content, options) {
options = getSlidifyOptions(options)
- var notesMatch = content.split(new RegExp(options.notesSeparator, 'mgi'))
+ const notesMatch = content.split(new RegExp(options.notesSeparator, 'mgi'))
if (notesMatch.length === 2) {
content = notesMatch[0] + '
'
@@ -115,15 +115,15 @@ import { md } from './extra'
function slidify (markdown, options) {
options = getSlidifyOptions(options)
- var separatorRegex = new RegExp(options.separator + (options.verticalSeparator ? '|' + options.verticalSeparator : ''), 'mg')
- var horizontalSeparatorRegex = new RegExp(options.separator)
+ const separatorRegex = new RegExp(options.separator + (options.verticalSeparator ? '|' + options.verticalSeparator : ''), 'mg')
+ const horizontalSeparatorRegex = new RegExp(options.separator)
- var matches
- var lastIndex = 0
- var isHorizontal
- var wasHorizontal = true
- var content
- var sectionStack = []
+ let matches
+ let lastIndex = 0
+ let isHorizontal
+ let wasHorizontal = true
+ let content
+ const sectionStack = []
// iterate until all blocks between separators are stacked up
while ((matches = separatorRegex.exec(markdown)) !== null) {
@@ -153,10 +153,10 @@ import { md } from './extra'
// add the remaining slide
(wasHorizontal ? sectionStack : sectionStack[sectionStack.length - 1]).push(markdown.substring(lastIndex))
- var markdownSections = ''
+ let markdownSections = ''
// flatten the hierarchical stack, and insert
tags
- for (var i = 0, len = sectionStack.length; i < len; i++) {
+ for (let i = 0, len = sectionStack.length; i < len; i++) {
// vertical
if (sectionStack[i] instanceof Array) {
markdownSections += ''
@@ -180,17 +180,17 @@ import { md } from './extra'
* handles loading of external markdown.
*/
function processSlides () {
- var sections = document.querySelectorAll('[data-markdown]')
- var section
+ const sections = document.querySelectorAll('[data-markdown]')
+ let section
- for (var i = 0, len = sections.length; i < len; i++) {
+ for (let i = 0, len = sections.length; i < len; i++) {
section = sections[i]
if (section.getAttribute('data-markdown').length) {
- var xhr = new XMLHttpRequest()
- var url = section.getAttribute('data-markdown')
+ const xhr = new XMLHttpRequest()
+ const url = section.getAttribute('data-markdown')
- var datacharset = section.getAttribute('data-charset')
+ const datacharset = section.getAttribute('data-charset')
// see https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute#Notes
if (datacharset !== null && datacharset !== '') {
@@ -247,18 +247,18 @@ import { md } from './extra'
* http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development/7000899#answer-11786277
*/
function addAttributeInElement (node, elementTarget, separator) {
- var mardownClassesInElementsRegex = new RegExp(separator, 'mg')
- var mardownClassRegex = new RegExp('([^"= ]+?)="([^"=]+?)"', 'mg')
- var nodeValue = node.nodeValue
- var matches
- var matchesClass
+ const mardownClassesInElementsRegex = new RegExp(separator, 'mg')
+ const mardownClassRegex = /([^"= ]+?)="([^"=]+?)"/mg
+ let nodeValue = node.nodeValue
+ let matches
+ let matchesClass
if ((matches = mardownClassesInElementsRegex.exec(nodeValue))) {
- var classes = matches[1]
+ const classes = matches[1]
nodeValue = nodeValue.substring(0, matches.index) + nodeValue.substring(mardownClassesInElementsRegex.lastIndex)
node.nodeValue = nodeValue
while ((matchesClass = mardownClassRegex.exec(classes))) {
- var name = matchesClass[1]
- var value = matchesClass[2]
+ const name = matchesClass[1]
+ const value = matchesClass[2]
if (name.substr(0, 5) === 'data-' || window.whiteListAttr.indexOf(name) !== -1) { elementTarget.setAttribute(name, escapeAttrValue(value)) }
}
return true
@@ -272,13 +272,13 @@ import { md } from './extra'
*/
function addAttributes (section, element, previousElement, separatorElementAttributes, separatorSectionAttributes) {
if (element != null && element.childNodes !== undefined && element.childNodes.length > 0) {
- var previousParentElement = element
- for (var i = 0; i < element.childNodes.length; i++) {
- var childElement = element.childNodes[i]
+ let previousParentElement = element
+ for (let i = 0; i < element.childNodes.length; i++) {
+ const childElement = element.childNodes[i]
if (i > 0) {
let j = i - 1
while (j >= 0) {
- var aPreviousChildElement = element.childNodes[j]
+ const aPreviousChildElement = element.childNodes[j]
if (typeof aPreviousChildElement.setAttribute === 'function' && aPreviousChildElement.tagName !== 'BR') {
previousParentElement = aPreviousChildElement
break
@@ -286,7 +286,7 @@ import { md } from './extra'
j = j - 1
}
}
- var parentSection = section
+ let parentSection = section
if (childElement.nodeName === 'section') {
parentSection = childElement
previousParentElement = childElement
@@ -309,21 +309,21 @@ import { md } from './extra'
* DOM to HTML.
*/
function convertSlides () {
- var sections = document.querySelectorAll('[data-markdown]')
+ const sections = document.querySelectorAll('[data-markdown]')
- for (var i = 0, len = sections.length; i < len; i++) {
- var section = sections[i]
+ for (let i = 0, len = sections.length; i < len; i++) {
+ const section = sections[i]
// Only parse the same slide once
if (!section.getAttribute('data-markdown-parsed')) {
section.setAttribute('data-markdown-parsed', true)
- var notes = section.querySelector('aside.notes')
- var markdown = getMarkdownFromSlide(section)
+ const notes = section.querySelector('aside.notes')
+ let markdown = getMarkdownFromSlide(section)
markdown = markdown.replace(/</g, '<').replace(/>/g, '>')
- var rendered = md.render(markdown)
+ let rendered = md.render(markdown)
rendered = preventXSS(rendered)
- var result = window.postProcess(rendered)
+ const result = window.postProcess(rendered)
section.innerHTML = result[0].outerHTML
addAttributes(section, section, null, section.getAttribute('data-element-attributes') ||
section.parentNode.getAttribute('data-element-attributes') ||
diff --git a/public/js/slide.js b/public/js/slide.js
index b8374cbbe..5a28993f8 100644
--- a/public/js/slide.js
+++ b/public/js/slide.js
@@ -26,7 +26,7 @@ function extend () {
for (const source of arguments) {
for (const key in source) {
- if (source.hasOwnProperty(key)) {
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key]
}
}
@@ -36,18 +36,21 @@ function extend () {
}
// Optional libraries used to extend on reveal.js
-const deps = [{
- src: `${serverurl}/build/reveal.js/lib/js/classList.js`,
- condition () {
- return !document.body.classList
+const deps = [
+ {
+ src: `${serverurl}/build/reveal.js/lib/js/classList.js`,
+ condition () {
+ return !document.body.classList
+ }
+ },
+ {
+ src: `${serverurl}/build/reveal.js/plugin/notes/notes.js`,
+ async: true,
+ condition () {
+ return !!document.body.classList
+ }
}
-}, {
- src: `${serverurl}/build/reveal.js/plugin/notes/notes.js`,
- async: true,
- condition () {
- return !!document.body.classList
- }
-}]
+]
const slideOptions = {
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
@@ -73,60 +76,64 @@ const defaultOptions = {
// options from yaml meta
const meta = JSON.parse($('#meta').text())
const metaSlideOptions = !!meta && !!meta.slideOptions ? meta.slideOptions : {}
-var options = {
- autoPlayMedia: metaSlideOptions.autoPlayMedia,
- autoSlide: metaSlideOptions.autoSlide,
- autoSlideStoppable: metaSlideOptions.autoSlideStoppable,
- backgroundTransition: metaSlideOptions.backgroundTransition,
- center: metaSlideOptions.center,
- controls: metaSlideOptions.controls,
- controlsBackArrows: metaSlideOptions.controlsBackArrows,
- controlsLayout: metaSlideOptions.controlsLayout,
- controlsTutorial: metaSlideOptions.controlsTutorial,
- defaultTiming: metaSlideOptions.defaultTiming,
- display: metaSlideOptions.display,
- embedded: metaSlideOptions.embedded,
- fragmentInURL: metaSlideOptions.fragmentInURL,
- fragments: metaSlideOptions.fragments,
- hash: metaSlideOptions.hash,
- height: metaSlideOptions.height,
- help: metaSlideOptions.help,
- hideAddressBar: metaSlideOptions.hideAddressBar,
- hideCursorTime: metaSlideOptions.hideCursorTime,
- hideInactiveCursor: metaSlideOptions.hideInactiveCursor,
- history: metaSlideOptions.history,
- keyboard: metaSlideOptions.keyboard,
- loop: metaSlideOptions.loop,
- margin: metaSlideOptions.margin,
- maxScale: metaSlideOptions.maxScale,
- minScale: metaSlideOptions.minScale,
- minimumTimePerSlide: metaSlideOptions.minimumTimePerSlide,
- mobileViewDistance: metaSlideOptions.mobileViewDistance,
- mouseWheel: metaSlideOptions.mouseWheel,
- navigationMode: metaSlideOptions.navigationMode,
- overview: metaSlideOptions.overview,
- parallaxBackgroundHorizontal: metaSlideOptions.parallaxBackgroundHorizontal,
- parallaxBackgroundImage: metaSlideOptions.parallaxBackgroundImage,
- parallaxBackgroundSize: metaSlideOptions.parallaxBackgroundSize,
- parallaxBackgroundVertical: metaSlideOptions.parallaxBackgroundVertical,
- preloadIframes: metaSlideOptions.preloadIframes,
- previewLinks: metaSlideOptions.previewLinks,
- progress: metaSlideOptions.progress,
- rtl: metaSlideOptions.rtl,
- showNotes: metaSlideOptions.showNotes,
- shuffle: metaSlideOptions.shuffle,
- slideNumber: metaSlideOptions.slideNumber,
- theme: metaSlideOptions.theme,
- totalTime: metaSlideOptions.totalTime,
- touch: metaSlideOptions.touch,
- transition: metaSlideOptions.transition,
- transitionSpeed: metaSlideOptions.transitionSpeed,
- viewDistance: metaSlideOptions.viewDistance,
- width: metaSlideOptions.width
-} || {}
+let options =
+ {
+ autoPlayMedia: metaSlideOptions.autoPlayMedia,
+ autoSlide: metaSlideOptions.autoSlide,
+ autoSlideStoppable: metaSlideOptions.autoSlideStoppable,
+ backgroundTransition: metaSlideOptions.backgroundTransition,
+ center: metaSlideOptions.center,
+ controls: metaSlideOptions.controls,
+ controlsBackArrows: metaSlideOptions.controlsBackArrows,
+ controlsLayout: metaSlideOptions.controlsLayout,
+ controlsTutorial: metaSlideOptions.controlsTutorial,
+ defaultTiming: metaSlideOptions.defaultTiming,
+ display: metaSlideOptions.display,
+ embedded: metaSlideOptions.embedded,
+ fragmentInURL: metaSlideOptions.fragmentInURL,
+ fragments: metaSlideOptions.fragments,
+ hash: metaSlideOptions.hash,
+ height: metaSlideOptions.height,
+ help: metaSlideOptions.help,
+ hideAddressBar: metaSlideOptions.hideAddressBar,
+ hideCursorTime: metaSlideOptions.hideCursorTime,
+ hideInactiveCursor: metaSlideOptions.hideInactiveCursor,
+ history: metaSlideOptions.history,
+ keyboard: metaSlideOptions.keyboard,
+ loop: metaSlideOptions.loop,
+ margin: metaSlideOptions.margin,
+ maxScale: metaSlideOptions.maxScale,
+ minScale: metaSlideOptions.minScale,
+ minimumTimePerSlide: metaSlideOptions.minimumTimePerSlide,
+ mobileViewDistance: metaSlideOptions.mobileViewDistance,
+ mouseWheel: metaSlideOptions.mouseWheel,
+ navigationMode: metaSlideOptions.navigationMode,
+ overview: metaSlideOptions.overview,
+ parallaxBackgroundHorizontal: metaSlideOptions.parallaxBackgroundHorizontal,
+ parallaxBackgroundImage: metaSlideOptions.parallaxBackgroundImage,
+ parallaxBackgroundSize: metaSlideOptions.parallaxBackgroundSize,
+ parallaxBackgroundVertical: metaSlideOptions.parallaxBackgroundVertical,
+ preloadIframes: metaSlideOptions.preloadIframes,
+ previewLinks: metaSlideOptions.previewLinks,
+ progress: metaSlideOptions.progress,
+ rtl: metaSlideOptions.rtl,
+ showNotes: metaSlideOptions.showNotes,
+ shuffle: metaSlideOptions.shuffle,
+ slideNumber: metaSlideOptions.slideNumber,
+ theme: metaSlideOptions.theme,
+ totalTime: metaSlideOptions.totalTime,
+ touch: metaSlideOptions.touch,
+ transition: metaSlideOptions.transition,
+ transitionSpeed: metaSlideOptions.transitionSpeed,
+ viewDistance: metaSlideOptions.viewDistance,
+ width: metaSlideOptions.width
+ } || {}
for (const key in options) {
- if (options.hasOwnProperty(key) && options[key] === undefined) {
+ if (
+ Object.prototype.hasOwnProperty.call(options, key) &&
+ options[key] === undefined
+ ) {
delete options[key]
}
}
@@ -165,14 +172,14 @@ window.viewAjaxCallback = () => {
function renderSlide (event) {
if (window.location.search.match(/print-pdf/gi)) {
const slides = $('.slides')
- let title = document.title
+ const title = document.title
finishView(slides)
document.title = title
Reveal.layout()
} else {
const markdown = $(event.currentSlide)
if (!markdown.attr('data-rendered')) {
- let title = document.title
+ const title = document.title
finishView(markdown)
markdown.attr('data-rendered', 'true')
document.title = title
@@ -181,7 +188,7 @@ function renderSlide (event) {
}
}
-Reveal.addEventListener('ready', event => {
+Reveal.addEventListener('ready', (event) => {
renderSlide(event)
const markdown = $(event.currentSlide)
// force browser redraw
diff --git a/public/js/utils.js b/public/js/utils.js
index 91e7f133f..d42a18e71 100644
--- a/public/js/utils.js
+++ b/public/js/utils.js
@@ -1,9 +1,9 @@
import base64url from 'base64url'
-let uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
+const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
export function checkNoteIdValid (id) {
- let result = id.match(uuidRegex)
+ const result = id.match(uuidRegex)
if (result && result.length === 1) {
return true
} else {
@@ -13,16 +13,16 @@ export function checkNoteIdValid (id) {
export function encodeNoteId (id) {
// remove dashes in UUID and encode in url-safe base64
- let str = id.replace(/-/g, '')
- let hexStr = Buffer.from(str, 'hex')
+ const str = id.replace(/-/g, '')
+ const hexStr = Buffer.from(str, 'hex')
return base64url.encode(hexStr)
}
export function decodeNoteId (encodedId) {
// decode from url-safe base64
- let id = base64url.toBuffer(encodedId).toString('hex')
+ const id = base64url.toBuffer(encodedId).toString('hex')
// add dashes between the UUID string parts
- let idParts = []
+ const idParts = []
idParts.push(id.substr(0, 8))
idParts.push(id.substr(8, 4))
idParts.push(id.substr(12, 4))
diff --git a/test/csp.js b/test/csp.js
index d081cef06..705981566 100644
--- a/test/csp.js
+++ b/test/csp.js
@@ -46,7 +46,7 @@ describe('Content security policies', function () {
// beginnging Tests
it('Disable CDN', function () {
- let testconfig = defaultConfig
+ const testconfig = defaultConfig
testconfig.useCDN = false
mock('../lib/config', testconfig)
csp = mock.reRequire('../lib/csp')
@@ -60,7 +60,7 @@ describe('Content security policies', function () {
})
it('Disable Google Analytics', function () {
- let testconfig = defaultConfig
+ const testconfig = defaultConfig
testconfig.csp.addGoogleAnalytics = false
mock('../lib/config', testconfig)
csp = mock.reRequire('../lib/csp')
@@ -69,7 +69,7 @@ describe('Content security policies', function () {
})
it('Disable Disqus', function () {
- let testconfig = defaultConfig
+ const testconfig = defaultConfig
testconfig.csp.addDisqus = false
mock('../lib/config', testconfig)
csp = mock.reRequire('../lib/csp')
@@ -82,7 +82,7 @@ describe('Content security policies', function () {
})
it('Include dropbox if configured', function () {
- let testconfig = defaultConfig
+ const testconfig = defaultConfig
testconfig.dropbox.appKey = 'hedgedoc'
mock('../lib/config', testconfig)
csp = mock.reRequire('../lib/csp')
@@ -92,7 +92,7 @@ describe('Content security policies', function () {
})
it('Set ReportURI', function () {
- let testconfig = defaultConfig
+ const testconfig = defaultConfig
testconfig.csp.reportURI = 'https://example.com/reportURI'
mock('../lib/config', testconfig)
csp = mock.reRequire('../lib/csp')
@@ -101,7 +101,7 @@ describe('Content security policies', function () {
})
it('Set own directives', function () {
- let testconfig = defaultConfig
+ const testconfig = defaultConfig
mock('../lib/config', defaultConfig)
csp = mock.reRequire('../lib/csp')
const unextendedCSP = csp.computeDirectives()
diff --git a/test/letter-avatars.js b/test/letter-avatars.js
index 8cc32d8b4..0645ef876 100644
--- a/test/letter-avatars.js
+++ b/test/letter-avatars.js
@@ -9,7 +9,7 @@ describe('generateAvatarURL() gravatar enabled', function () {
let avatars
beforeEach(function () {
// Reset config to make sure we don't influence other tests
- let testconfig = {
+ const testconfig = {
allowGravatar: true,
serverURL: 'http://localhost:3000',
port: 3000
@@ -32,7 +32,7 @@ describe('generateAvatarURL() gravatar disabled', function () {
let avatars
beforeEach(function () {
// Reset config to make sure we don't influence other tests
- let testconfig = {
+ const testconfig = {
allowGravatar: false,
serverURL: 'http://localhost:3000',
port: 3000