Fix front-end index.js code styles

This commit is contained in:
Wu Cheng-Han 2017-03-22 17:48:26 +08:00
parent 802ed406e6
commit cac618eca8

View file

@ -333,7 +333,7 @@ function updateStatusBar () {
var end = head.line >= anchor.line ? head : anchor var end = head.line >= anchor.line ? head : anchor
var selectionText = ' — Selected ' var selectionText = ' — Selected '
var selectionCharCount = Math.abs(head.ch - anchor.ch) var selectionCharCount = Math.abs(head.ch - anchor.ch)
// borrow from brackets EditorStatusBar.js // borrow from brackets EditorStatusBar.js
if (start.line !== end.line) { if (start.line !== end.line) {
var lines = end.line - start.line + 1 var lines = end.line - start.line + 1
if (end.ch === 0) { if (end.ch === 0) {
@ -649,7 +649,7 @@ function checkEditorStyle () {
}, },
stop: function (e) { stop: function (e) {
lastEditorWidth = ui.area.edit.width() lastEditorWidth = ui.area.edit.width()
// workaround that scroll event bindings // workaround that scroll event bindings
window.preventSyncScrollToView = 2 window.preventSyncScrollToView = 2
window.preventSyncScrollToEdit = true window.preventSyncScrollToEdit = true
editor.setOption('viewportMargin', viewportMargin) editor.setOption('viewportMargin', viewportMargin)
@ -843,19 +843,19 @@ function changeMode (type) {
ui.area.view.show() ui.area.view.show()
break break
} }
// save mode to url // save mode to url
if (history.replaceState && window.loaded) history.replaceState(null, '', serverurl + '/' + noteid + '?' + window.currentMode.name) if (history.replaceState && window.loaded) history.replaceState(null, '', serverurl + '/' + noteid + '?' + window.currentMode.name)
if (window.currentMode === modeType.view) { if (window.currentMode === modeType.view) {
editor.getInputField().blur() editor.getInputField().blur()
} }
if (window.currentMode === modeType.edit || window.currentMode === modeType.both) { if (window.currentMode === modeType.edit || window.currentMode === modeType.both) {
ui.toolbar.uploadImage.fadeIn() ui.toolbar.uploadImage.fadeIn()
// add and update status bar // add and update status bar
if (!editorInstance.statusBar) { if (!editorInstance.statusBar) {
editorInstance.addStatusBar() editorInstance.addStatusBar()
updateStatusBar() updateStatusBar()
} }
// work around foldGutter might not init properly // work around foldGutter might not init properly
editor.setOption('foldGutter', false) editor.setOption('foldGutter', false)
editor.setOption('foldGutter', true) editor.setOption('foldGutter', true)
} else { } else {
@ -1298,7 +1298,7 @@ function selectRevision (time) {
var currIndex = patch.start1 + bias var currIndex = patch.start1 + bias
for (var i = 0; i < patch.diffs.length; i++) { for (var i = 0; i < patch.diffs.length; i++) {
var diff = patch.diffs[i] var diff = patch.diffs[i]
// ignore if diff only contains line breaks // ignore if diff only contains line breaks
if ((diff[1].match(/\n/g) || []).length === diff[1].length) continue if ((diff[1].match(/\n/g) || []).length === diff[1].length) continue
var prePos var prePos
var postPos var postPos
@ -1987,7 +1987,10 @@ function updateAuthorshipInner () {
ch: preLine.length ch: preLine.length
} }
if (JSON.stringify(prePos) !== JSON.stringify(_postPos)) { if (JSON.stringify(prePos) !== JSON.stringify(_postPos)) {
mark.textmarkers.push({ userid: author.userid, pos: [prePos, _postPos] }) mark.textmarkers.push({
userid: author.userid,
pos: [prePos, _postPos]
})
startLine++ startLine++
} }
authorMarks[prePos.line] = mark authorMarks[prePos.line] = mark
@ -2001,7 +2004,10 @@ function updateAuthorshipInner () {
ch: 0 ch: 0
} }
if (JSON.stringify(_prePos) !== JSON.stringify(postPos)) { if (JSON.stringify(_prePos) !== JSON.stringify(postPos)) {
mark.textmarkers.push({ userid: author.userid, pos: [_prePos, postPos] }) mark.textmarkers.push({
userid: author.userid,
pos: [_prePos, postPos]
})
endLine-- endLine--
} }
authorMarks[postPos.line] = mark authorMarks[postPos.line] = mark
@ -2374,7 +2380,11 @@ function sortOnlineUserList (list) {
if (!usera.idle && userb.idle) { return -1 } else if (usera.idle && !userb.idle) { 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.name && userb.name && usera.name.toLowerCase() < userb.name.toLowerCase()) {
return -1 return -1
} 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 } } } 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 }
}
} }
} }
} }
@ -2410,11 +2420,11 @@ function deduplicateOnlineUsers (list) {
var found = false var found = false
for (var j = 0; j < _onlineUsers.length; j++) { for (var j = 0; j < _onlineUsers.length; j++) {
if (_onlineUsers[j].userid === user.userid) { if (_onlineUsers[j].userid === user.userid) {
// keep self color when login // keep self color when login
if (user.id === window.personalInfo.id) { if (user.id === window.personalInfo.id) {
_onlineUsers[j].color = user.color _onlineUsers[j].color = user.color
} }
// keep idle state if any of self client not idle // keep idle state if any of self client not idle
if (!user.idle) { if (!user.idle) {
_onlineUsers[j].idle = user.idle _onlineUsers[j].idle = user.idle
_onlineUsers[j].color = user.color _onlineUsers[j].color = user.color
@ -2458,38 +2468,38 @@ function emitUserStatus (force) {
function checkCursorTag (coord, ele) { function checkCursorTag (coord, ele) {
if (!ele) return // return if element not exists if (!ele) return // return if element not exists
// set margin // set margin
var tagRightMargin = 0 var tagRightMargin = 0
var tagBottomMargin = 2 var tagBottomMargin = 2
// use sizer to get the real doc size (won't count status bar and gutters) // use sizer to get the real doc size (won't count status bar and gutters)
var docWidth = ui.area.codemirrorSizer.width() var docWidth = ui.area.codemirrorSizer.width()
// get editor size (status bar not count in) // get editor size (status bar not count in)
var editorHeight = ui.area.codemirror.height() var editorHeight = ui.area.codemirror.height()
// get element size // get element size
var width = ele.outerWidth() var width = ele.outerWidth()
var height = ele.outerHeight() var height = ele.outerHeight()
var padding = (ele.outerWidth() - ele.width()) / 2 var padding = (ele.outerWidth() - ele.width()) / 2
// get coord position // get coord position
var left = coord.left var left = coord.left
var top = coord.top var top = coord.top
// get doc top offset (to workaround with viewport) // get doc top offset (to workaround with viewport)
var docTopOffset = ui.area.codemirrorSizerInner.position().top var docTopOffset = ui.area.codemirrorSizerInner.position().top
// set offset // set offset
var offsetLeft = -3 var offsetLeft = -3
var offsetTop = defaultTextHeight var offsetTop = defaultTextHeight
// only do when have width and height // only do when have width and height
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
// flip x when element right bound larger than doc width // flip x when element right bound larger than doc width
if (left + width + offsetLeft + tagRightMargin > docWidth) { if (left + width + offsetLeft + tagRightMargin > docWidth) {
offsetLeft = -(width + tagRightMargin) + padding + offsetLeft offsetLeft = -(width + tagRightMargin) + padding + offsetLeft
} }
// flip y when element bottom bound larger than doc height // flip y when element bottom bound larger than doc height
// and element top position is larger than element 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) { if (top + docTopOffset + height + offsetTop + tagBottomMargin > Math.max(editor.doc.height, editorHeight) && top + docTopOffset > height + tagBottomMargin) {
offsetTop = -(height) offsetTop = -(height)
} }
} }
// set position // set position
ele[0].style.left = offsetLeft + 'px' ele[0].style.left = offsetLeft + 'px'
ele[0].style.top = offsetTop + 'px' ele[0].style.top = offsetTop + 'px'
} }
@ -2532,7 +2542,7 @@ function buildCursor (user) {
var icon = '<i class="fa ' + iconClass + '"></i>' var icon = '<i class="fa ' + iconClass + '"></i>'
let cursortag = $('<div class="cursortag">' + icon + '&nbsp;<span class="name">' + user.name + '</span></div>') let cursortag = $('<div class="cursortag">' + icon + '&nbsp;<span class="name">' + user.name + '</span></div>')
// cursortag[0].style.background = color; // cursortag[0].style.background = color;
cursortag[0].style.color = user.color cursortag[0].style.color = user.color
cursor.attr('data-mode', 'hover') cursor.attr('data-mode', 'hover')