summaryrefslogtreecommitdiff
path: root/public/js/index.js
diff options
context:
space:
mode:
authorYukai Huang2017-03-28 17:16:32 +0800
committerYukai Huang2017-03-28 17:16:32 +0800
commitf5b95c5d3692169b48daff3c6f3538f53dd62380 (patch)
tree93259a74d9c88d53a54dcd04c29f441bfad440eb /public/js/index.js
parentdf743ab902e1427b12842ff9542ce9189c37f2b6 (diff)
Move updateStatusBar method into editor class
Diffstat (limited to 'public/js/index.js')
-rw-r--r--public/js/index.js34
1 files changed, 7 insertions, 27 deletions
diff --git a/public/js/index.js b/public/js/index.js
index 82f647df..d51ecb54 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -79,6 +79,7 @@ var renderer = require('./render')
var preventXSS = renderer.preventXSS
import Editor from './lib/editor'
+import EditorConfig from './lib/editor/config'
import getUIElements from './lib/editor/ui-elements'
@@ -320,27 +321,6 @@ window.editor = editor
var inlineAttach = inlineAttachment.editors.codemirror4.attach(editor)
defaultTextHeight = parseInt($('.CodeMirror').css('line-height'))
-function updateStatusBar () {
- if (!editorInstance.statusBar) return
- var cursor = editor.getCursor()
- var cursorText = 'Line ' + (cursor.line + 1) + ', Columns ' + (cursor.ch + 1)
- editorInstance.statusCursor.text(cursorText)
- var fileText = ' — ' + editor.lineCount() + ' Lines'
- editorInstance.statusFile.text(fileText)
- var docLength = editor.getValue().length
- editorInstance.statusLength.text('Length ' + docLength)
- if (docLength > (docmaxlength * 0.95)) {
- editorInstance.statusLength.css('color', 'red')
- editorInstance.statusLength.attr('title', 'Your almost reach note max length limit.')
- } else if (docLength > (docmaxlength * 0.8)) {
- editorInstance.statusLength.css('color', 'orange')
- editorInstance.statusLength.attr('title', 'You nearly fill the note, consider to make more pieces.')
- } else {
- editorInstance.statusLength.css('color', 'white')
- editorInstance.statusLength.attr('title', 'You could write up to ' + docmaxlength + ' characters in this note.')
- }
-}
-
// initalize ui reference
const ui = getUIElements()
// FIXME: fix global ui element expose
@@ -830,7 +810,7 @@ function changeMode (type) {
// add and update status bar
if (!editorInstance.statusBar) {
editorInstance.addStatusBar()
- updateStatusBar()
+ editorInstance.updateStatusBar()
}
// work around foldGutter might not init properly
editor.setOption('foldGutter', false)
@@ -2105,12 +2085,12 @@ socket.on('check', function (data) {
socket.on('permission', function (data) {
updatePermission(data.permission)
})
-var docmaxlength = null
+
var permission = null
socket.on('refresh', function (data) {
// console.log(data);
- docmaxlength = data.docmaxlength
- editor.setOption('maxLength', docmaxlength)
+ EditorConfig.docmaxlength = data.docmaxlength
+ editor.setOption('maxLength', EditorConfig.docmaxlength)
updateInfo(data)
updatePermission(data.permission)
if (!window.loaded) {
@@ -2714,10 +2694,10 @@ function cursorActivityInner (editor) {
}
}
-editorInstance.on('cursorActivity', updateStatusBar)
+editorInstance.on('cursorActivity', editorInstance.updateStatusBar)
editorInstance.on('cursorActivity', cursorActivity)
-editorInstance.on('beforeSelectionChange', updateStatusBar)
+editorInstance.on('beforeSelectionChange', editorInstance.updateStatusBar)
editorInstance.on('beforeSelectionChange', function (doc, selections) {
// check selection and whether the statusbar has added
if (selections && editorInstance.statusSelection) {