summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/config/environment.js2
-rw-r--r--lib/config/hackmdEnvironment.js2
-rw-r--r--lib/config/index.js12
-rw-r--r--lib/config/oldEnvironment.js2
-rw-r--r--lib/letter-avatars.js4
-rw-r--r--lib/logger.js2
-rw-r--r--lib/migrations/20150702001020-update-to-0_3_1.js1
-rw-r--r--lib/migrations/20160112220142-note-add-lastchange.js7
-rw-r--r--lib/migrations/20160420180355-note-add-alias.js1
-rw-r--r--lib/migrations/20160515114000-user-add-tokens.js1
-rw-r--r--lib/migrations/20160607060246-support-revision.js1
-rw-r--r--lib/migrations/20160703062241-support-authorship.js1
-rw-r--r--lib/migrations/20161009040430-support-delete-note.js1
-rw-r--r--lib/migrations/20161201050312-support-email-signin.js2
-rw-r--r--lib/migrations/20171009121200-longtext-for-mysql.js16
-rw-r--r--lib/migrations/20180209120907-longtext-of-authorship.js8
-rw-r--r--lib/migrations/20180306150303-fix-enum.js4
-rw-r--r--lib/models/index.js16
-rw-r--r--lib/response.js22
-rw-r--r--lib/web/auth/dropbox/index.js2
-rw-r--r--lib/web/auth/email/index.js4
-rw-r--r--lib/web/auth/facebook/index.js2
-rw-r--r--lib/web/auth/github/index.js2
-rw-r--r--lib/web/auth/gitlab/index.js2
-rw-r--r--lib/web/auth/google/index.js6
-rw-r--r--lib/web/auth/ldap/index.js4
-rw-r--r--lib/web/auth/mattermost/index.js14
-rw-r--r--lib/web/auth/oauth2/index.js2
-rw-r--r--lib/web/auth/openid/index.js4
-rw-r--r--lib/web/auth/saml/index.js2
-rw-r--r--lib/web/auth/twitter/index.js2
-rw-r--r--lib/web/historyRouter.js2
-rw-r--r--lib/web/imageRouter/imgur.js16
-rw-r--r--lib/web/imageRouter/minio.js2
-rw-r--r--lib/web/imageRouter/s3.js2
-rw-r--r--lib/web/middleware/tooBusy.js1
-rw-r--r--lib/web/noteRouter.js2
-rw-r--r--lib/web/statusRouter.js2
-rw-r--r--lib/web/userRouter.js2
-rw-r--r--package.json2
-rw-r--r--public/js/cover.js100
-rw-r--r--public/js/extra.js436
-rw-r--r--public/js/history.js153
-rw-r--r--public/js/index.js1112
-rw-r--r--public/js/lib/common/login.js32
-rw-r--r--public/js/lib/editor/utils.js14
-rw-r--r--public/js/lib/syncscroll.js4
-rw-r--r--public/js/pretty.js48
-rw-r--r--public/js/render.js2
-rw-r--r--public/js/slide.js10
50 files changed, 1053 insertions, 1040 deletions
diff --git a/lib/config/environment.js b/lib/config/environment.js
index 0a709745..d2350e72 100644
--- a/lib/config/environment.js
+++ b/lib/config/environment.js
@@ -1,6 +1,6 @@
'use strict'
-const {toBooleanConfig, toArrayConfig, toIntegerConfig} = require('./utils')
+const { toBooleanConfig, toArrayConfig, toIntegerConfig } = require('./utils')
module.exports = {
sourceURL: process.env.CMD_SOURCE_URL,
diff --git a/lib/config/hackmdEnvironment.js b/lib/config/hackmdEnvironment.js
index e5ffeb8a..dcfda0bc 100644
--- a/lib/config/hackmdEnvironment.js
+++ b/lib/config/hackmdEnvironment.js
@@ -1,6 +1,6 @@
'use strict'
-const {toBooleanConfig, toArrayConfig, toIntegerConfig} = require('./utils')
+const { toBooleanConfig, toArrayConfig, toIntegerConfig } = require('./utils')
module.exports = {
domain: process.env.HMD_DOMAIN,
diff --git a/lib/config/index.js b/lib/config/index.js
index e102dce9..b6001aa0 100644
--- a/lib/config/index.js
+++ b/lib/config/index.js
@@ -4,11 +4,11 @@
const crypto = require('crypto')
const fs = require('fs')
const path = require('path')
-const {merge} = require('lodash')
+const { merge } = require('lodash')
const deepFreeze = require('deep-freeze')
-const {Environment, Permission} = require('./enum')
+const { Environment, Permission } = require('./enum')
const logger = require('../logger')
-const {getGitCommit, getGitHubURL} = require('./utils')
+const { getGitCommit, getGitHubURL } = require('./utils')
const appRootPath = path.resolve(__dirname, '../../')
const env = process.env.NODE_ENV || Environment.development
@@ -17,7 +17,7 @@ const debugConfig = {
}
// Get version string from package.json
-const {version, repository} = require(path.join(appRootPath, 'package.json'))
+const { version, repository } = require(path.join(appRootPath, 'package.json'))
const commitID = getGitCommit(appRootPath)
const sourceURL = getGitHubURL(repository.url, commitID || version)
@@ -159,8 +159,8 @@ if (Object.keys(process.env).toString().indexOf('HMD_') !== -1) {
if (config.sessionSecret === 'secret') {
logger.warn('Session secret not set. Using random generated one. Please set `sessionSecret` in your config.js file. All users will be logged out.')
config.sessionSecret = crypto.randomBytes(Math.ceil(config.sessionSecretLen / 2)) // generate crypto graphic random number
- .toString('hex') // convert to hexadecimal format
- .slice(0, config.sessionSecretLen) // return required number of characters
+ .toString('hex') // convert to hexadecimal format
+ .slice(0, config.sessionSecretLen) // return required number of characters
}
// Validate upload upload providers
diff --git a/lib/config/oldEnvironment.js b/lib/config/oldEnvironment.js
index a3b13cb9..06047553 100644
--- a/lib/config/oldEnvironment.js
+++ b/lib/config/oldEnvironment.js
@@ -1,6 +1,6 @@
'use strict'
-const {toBooleanConfig} = require('./utils')
+const { toBooleanConfig } = require('./utils')
module.exports = {
debug: toBooleanConfig(process.env.DEBUG),
diff --git a/lib/letter-avatars.js b/lib/letter-avatars.js
index 935cc1bb..6fb1888a 100644
--- a/lib/letter-avatars.js
+++ b/lib/letter-avatars.js
@@ -30,14 +30,14 @@ exports.generateAvatarURL = function (name, email = '', big = true) {
if (typeof email !== 'string') {
email = '' + name + '@example.com'
}
- name=encodeURIComponent(name)
+ name = encodeURIComponent(name)
let hash = crypto.createHash('md5')
hash.update(email.toLowerCase())
let hexDigest = hash.digest('hex')
if (email !== '' && config.allowGravatar) {
- photo = 'https://cdn.libravatar.org/avatar/' + hexDigest;
+ photo = 'https://cdn.libravatar.org/avatar/' + hexDigest
if (big) {
photo += '?s=400'
} else {
diff --git a/lib/logger.js b/lib/logger.js
index 5ef1860a..6d4bf69a 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -1,5 +1,5 @@
'use strict'
-const {createLogger, format, transports} = require('winston')
+const { createLogger, format, transports } = require('winston')
const logger = createLogger({
level: 'debug',
diff --git a/lib/migrations/20150702001020-update-to-0_3_1.js b/lib/migrations/20150702001020-update-to-0_3_1.js
index e1a88661..b941048e 100644
--- a/lib/migrations/20150702001020-update-to-0_3_1.js
+++ b/lib/migrations/20150702001020-update-to-0_3_1.js
@@ -22,6 +22,7 @@ module.exports = {
})
}).catch(function (error) {
if (error.message === 'SQLITE_ERROR: duplicate column name: shortid' || error.message === "ER_DUP_FIELDNAME: Duplicate column name 'shortid'" || error.message === 'column "shortid" of relation "Notes" already exists') {
+ // eslint-disable-next-line no-console
console.log('Migration has already run… ignoring.')
} else {
throw error
diff --git a/lib/migrations/20160112220142-note-add-lastchange.js b/lib/migrations/20160112220142-note-add-lastchange.js
index 87e3ff19..69781cef 100644
--- a/lib/migrations/20160112220142-note-add-lastchange.js
+++ b/lib/migrations/20160112220142-note-add-lastchange.js
@@ -9,6 +9,7 @@ module.exports = {
})
}).catch(function (error) {
if (error.message === 'SQLITE_ERROR: duplicate column name: lastchangeuserId' || error.message === "ER_DUP_FIELDNAME: Duplicate column name 'lastchangeuserId'" || error.message === 'column "lastchangeuserId" of relation "Notes" already exists') {
+ // eslint-disable-next-line no-console
console.log('Migration has already run… ignoring.')
} else {
throw error
@@ -18,8 +19,8 @@ module.exports = {
down: function (queryInterface, Sequelize) {
return queryInterface.removeColumn('Notes', 'lastchangeAt')
- .then(function () {
- return queryInterface.removeColumn('Notes', 'lastchangeuserId')
- })
+ .then(function () {
+ return queryInterface.removeColumn('Notes', 'lastchangeuserId')
+ })
}
}
diff --git a/lib/migrations/20160420180355-note-add-alias.js b/lib/migrations/20160420180355-note-add-alias.js
index 45d53e69..82941a91 100644
--- a/lib/migrations/20160420180355-note-add-alias.js
+++ b/lib/migrations/20160420180355-note-add-alias.js
@@ -9,6 +9,7 @@ module.exports = {
})
}).catch(function (error) {
if (error.message === 'SQLITE_ERROR: duplicate column name: alias' || error.message === "ER_DUP_FIELDNAME: Duplicate column name 'alias'" || error.message === 'column "alias" of relation "Notes" already exists') {
+ // eslint-disable-next-line no-console
console.log('Migration has already run… ignoring.')
} else {
throw error
diff --git a/lib/migrations/20160515114000-user-add-tokens.js b/lib/migrations/20160515114000-user-add-tokens.js
index 435ae9cb..e47ef5a4 100644
--- a/lib/migrations/20160515114000-user-add-tokens.js
+++ b/lib/migrations/20160515114000-user-add-tokens.js
@@ -5,6 +5,7 @@ module.exports = {
return queryInterface.addColumn('Users', 'refreshToken', Sequelize.STRING)
}).catch(function (error) {
if (error.message === 'SQLITE_ERROR: duplicate column name: accessToken' || error.message === "ER_DUP_FIELDNAME: Duplicate column name 'accessToken'" || error.message === 'column "accessToken" of relation "Users" already exists') {
+ // eslint-disable-next-line no-console
console.log('Migration has already run… ignoring.')
} else {
throw error
diff --git a/lib/migrations/20160607060246-support-revision.js b/lib/migrations/20160607060246-support-revision.js
index 547f89b8..b318ea44 100644
--- a/lib/migrations/20160607060246-support-revision.js
+++ b/lib/migrations/20160607060246-support-revision.js
@@ -17,6 +17,7 @@ module.exports = {
})
}).catch(function (error) {
if (error.message === 'SQLITE_ERROR: duplicate column name: savedAt' | error.message === "ER_DUP_FIELDNAME: Duplicate column name 'savedAt'" || error.message === 'column "savedAt" of relation "Notes" already exists') {
+ // eslint-disable-next-line no-console
console.log('Migration has already run… ignoring.')
} else {
throw error
diff --git a/lib/migrations/20160703062241-support-authorship.js b/lib/migrations/20160703062241-support-authorship.js
index f452b1a7..86054f1c 100644
--- a/lib/migrations/20160703062241-support-authorship.js
+++ b/lib/migrations/20160703062241-support-authorship.js
@@ -18,6 +18,7 @@ module.exports = {
})
}).catch(function (error) {
if (error.message === 'SQLITE_ERROR: duplicate column name: authorship' || error.message === "ER_DUP_FIELDNAME: Duplicate column name 'authorship'" || error.message === 'column "authorship" of relation "Notes" already exists') {
+ // eslint-disable-next-line no-console
console.log('Migration has already run… ignoring.')
} else {
throw error
diff --git a/lib/migrations/20161009040430-support-delete-note.js b/lib/migrations/20161009040430-support-delete-note.js
index 56a336ac..b7ee72c3 100644
--- a/lib/migrations/20161009040430-support-delete-note.js
+++ b/lib/migrations/20161009040430-support-delete-note.js
@@ -3,6 +3,7 @@ module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Notes', 'deletedAt', Sequelize.DATE).catch(function (error) {
if (error.message === 'SQLITE_ERROR: duplicate column name: deletedAt' || error.message === "ER_DUP_FIELDNAME: Duplicate column name 'deletedAt'" || error.message === 'column "deletedAt" of relation "Notes" already exists') {
+ // eslint-disable-next-line no-console
console.log('Migration has already run… ignoring.')
} else {
throw error
diff --git a/lib/migrations/20161201050312-support-email-signin.js b/lib/migrations/20161201050312-support-email-signin.js
index 26bc09ea..5c9fbf85 100644
--- a/lib/migrations/20161201050312-support-email-signin.js
+++ b/lib/migrations/20161201050312-support-email-signin.js
@@ -4,6 +4,7 @@ module.exports = {
return queryInterface.addColumn('Users', 'email', Sequelize.TEXT).then(function () {
return queryInterface.addColumn('Users', 'password', Sequelize.TEXT).catch(function (error) {
if (error.message === "ER_DUP_FIELDNAME: Duplicate column name 'password'" || error.message === 'column "password" of relation "Users" already exists') {
+ // eslint-disable-next-line no-console
console.log('Migration has already run… ignoring.')
} else {
throw error
@@ -11,6 +12,7 @@ module.exports = {
})
}).catch(function (error) {
if (error.message === 'SQLITE_ERROR: duplicate column name: email' || error.message === "ER_DUP_FIELDNAME: Duplicate column name 'email'" || error.message === 'column "email" of relation "Users" already exists') {
+ // eslint-disable-next-line no-console
console.log('Migration has already run… ignoring.')
} else {
throw error
diff --git a/lib/migrations/20171009121200-longtext-for-mysql.js b/lib/migrations/20171009121200-longtext-for-mysql.js
index 2a7d0d3a..cb9fc8a5 100644
--- a/lib/migrations/20171009121200-longtext-for-mysql.js
+++ b/lib/migrations/20171009121200-longtext-for-mysql.js
@@ -1,16 +1,16 @@
'use strict'
module.exports = {
up: function (queryInterface, Sequelize) {
- queryInterface.changeColumn('Notes', 'content', {type: Sequelize.TEXT('long')})
- queryInterface.changeColumn('Revisions', 'patch', {type: Sequelize.TEXT('long')})
- queryInterface.changeColumn('Revisions', 'content', {type: Sequelize.TEXT('long')})
- queryInterface.changeColumn('Revisions', 'lastContent', {type: Sequelize.TEXT('long')})
+ queryInterface.changeColumn('Notes', 'content', { type: Sequelize.TEXT('long') })
+ queryInterface.changeColumn('Revisions', 'patch', { type: Sequelize.TEXT('long') })
+ queryInterface.changeColumn('Revisions', 'content', { type: Sequelize.TEXT('long') })
+ queryInterface.changeColumn('Revisions', 'lastContent', { type: Sequelize.TEXT('long') })
},
down: function (queryInterface, Sequelize) {
- queryInterface.changeColumn('Notes', 'content', {type: Sequelize.TEXT})
- queryInterface.changeColumn('Revisions', 'patch', {type: Sequelize.TEXT})
- queryInterface.changeColumn('Revisions', 'content', {type: Sequelize.TEXT})
- queryInterface.changeColumn('Revisions', 'lastContent', {type: Sequelize.TEXT})
+ queryInterface.changeColumn('Notes', 'content', { type: Sequelize.TEXT })
+ queryInterface.changeColumn('Revisions', 'patch', { type: Sequelize.TEXT })
+ queryInterface.changeColumn('Revisions', 'content', { type: Sequelize.TEXT })
+ queryInterface.changeColumn('Revisions', 'lastContent', { type: Sequelize.TEXT })
}
}
diff --git a/lib/migrations/20180209120907-longtext-of-authorship.js b/lib/migrations/20180209120907-longtext-of-authorship.js
index 4cca5444..c5d8a1ef 100644
--- a/lib/migrations/20180209120907-longtext-of-authorship.js
+++ b/lib/migrations/20180209120907-longtext-of-authorship.js
@@ -2,12 +2,12 @@
module.exports = {
up: function (queryInterface, Sequelize) {
- queryInterface.changeColumn('Notes', 'authorship', {type: Sequelize.TEXT('long')})
- queryInterface.changeColumn('Revisions', 'authorship', {type: Sequelize.TEXT('long')})
+ queryInterface.changeColumn('Notes', 'authorship', { type: Sequelize.TEXT('long') })
+ queryInterface.changeColumn('Revisions', 'authorship', { type: Sequelize.TEXT('long') })
},
down: function (queryInterface, Sequelize) {
- queryInterface.changeColumn('Notes', 'authorship', {type: Sequelize.TEXT})
- queryInterface.changeColumn('Revisions', 'authorship', {type: Sequelize.TEXT})
+ queryInterface.changeColumn('Notes', 'authorship', { type: Sequelize.TEXT })
+ queryInterface.changeColumn('Revisions', 'authorship', { type: Sequelize.TEXT })
}
}
diff --git a/lib/migrations/20180306150303-fix-enum.js b/lib/migrations/20180306150303-fix-enum.js
index 0ee58a94..433a9749 100644
--- a/lib/migrations/20180306150303-fix-enum.js
+++ b/lib/migrations/20180306150303-fix-enum.js
@@ -2,10 +2,10 @@
module.exports = {
up: function (queryInterface, Sequelize) {
- queryInterface.changeColumn('Notes', 'permission', {type: Sequelize.ENUM('freely', 'editable', 'limited', 'locked', 'protected', 'private')})
+ queryInterface.changeColumn('Notes', 'permission', { type: Sequelize.ENUM('freely', 'editable', 'limited', 'locked', 'protected', 'private') })
},
down: function (queryInterface, Sequelize) {
- queryInterface.changeColumn('Notes', 'permission', {type: Sequelize.ENUM('freely', 'editable', 'locked', 'private')})
+ queryInterface.changeColumn('Notes', 'permission', { type: Sequelize.ENUM('freely', 'editable', 'locked', 'private') })
}
}
diff --git a/lib/models/index.js b/lib/models/index.js
index ef70475e..0f27f57d 100644
--- a/lib/models/index.js
+++ b/lib/models/index.js
@@ -3,7 +3,7 @@
var fs = require('fs')
var path = require('path')
var Sequelize = require('sequelize')
-const {cloneDeep} = require('lodash')
+const { cloneDeep } = require('lodash')
// core
var config = require('../config')
@@ -39,13 +39,13 @@ sequelize.processData = processData
var db = {}
fs.readdirSync(__dirname)
- .filter(function (file) {
- return (file.indexOf('.') !== 0) && (file !== 'index.js')
- })
- .forEach(function (file) {
- var model = sequelize.import(path.join(__dirname, file))
- db[model.name] = model
- })
+ .filter(function (file) {
+ return (file.indexOf('.') !== 0) && (file !== 'index.js')
+ })
+ .forEach(function (file) {
+ var model = sequelize.import(path.join(__dirname, file))
+ db[model.name] = model
+ })
Object.keys(db).forEach(function (modelName) {
if ('associate' in db[modelName]) {
diff --git a/lib/response.js b/lib/response.js
index 9fc9258c..dd33e42b 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -18,7 +18,7 @@ var utils = require('./utils')
// public
var response = {
errorForbidden: function (res) {
- const {req} = res
+ const { req } = res
if (req.user) {
responseError(res, '403', 'Forbidden', 'oh no.')
} else {
@@ -549,16 +549,16 @@ function gitlabActionProjects (req, res, note) {
ret.accesstoken = user.accessToken
ret.profileid = user.profileid
request(
- config.gitlab.baseURL + '/api/' + config.gitlab.version + '/projects?membership=yes&per_page=100&access_token=' + user.accessToken,
- function (error, httpResponse, body) {
- if (!error && httpResponse.statusCode === 200) {
- ret.projects = JSON.parse(body)
- return res.send(ret)
- } else {
- return res.send(ret)
- }
- }
- )
+ config.gitlab.baseURL + '/api/' + config.gitlab.version + '/projects?membership=yes&per_page=100&access_token=' + user.accessToken,
+ function (error, httpResponse, body) {
+ if (!error && httpResponse.statusCode === 200) {
+ ret.projects = JSON.parse(body)
+ return res.send(ret)
+ } else {
+ return res.send(ret)
+ }
+ }
+ )
}).catch(function (err) {
logger.error('gitlab action projects failed: ' + err)
return response.errorInternalError(res)
diff --git a/lib/web/auth/dropbox/index.js b/lib/web/auth/dropbox/index.js
index c44607da..1cfabd29 100644
--- a/lib/web/auth/dropbox/index.js
+++ b/lib/web/auth/dropbox/index.js
@@ -4,7 +4,7 @@ const Router = require('express').Router
const passport = require('passport')
const DropboxStrategy = require('passport-dropbox-oauth2').Strategy
const config = require('../../../config')
-const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
+const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
let dropboxAuth = module.exports = Router()
diff --git a/lib/web/auth/email/index.js b/lib/web/auth/email/index.js
index daa4a8c5..32e21428 100644
--- a/lib/web/auth/email/index.js
+++ b/lib/web/auth/email/index.js
@@ -7,8 +7,8 @@ const LocalStrategy = require('passport-local').Strategy
const config = require('../../../config')
const models = require('../../../models')
const logger = require('../../../logger')
-const {setReturnToFromReferer} = require('../utils')
-const {urlencodedParser} = require('../../utils')
+const { setReturnToFromReferer } = require('../utils')
+const { urlencodedParser } = require('../../utils')
const response = require('../../../response')
let emailAuth = module.exports = Router()
diff --git a/lib/web/auth/facebook/index.js b/lib/web/auth/facebook/index.js
index b2364989..418ddeee 100644
--- a/lib/web/auth/facebook/index.js
+++ b/lib/web/auth/facebook/index.js
@@ -5,7 +5,7 @@ const passport = require('passport')
const FacebookStrategy = require('passport-facebook').Strategy
const config = require('../../../config')
-const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
+const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
let facebookAuth = module.exports = Router()
diff --git a/lib/web/auth/github/index.js b/lib/web/auth/github/index.js
index ece634ba..afa5fa31 100644
--- a/lib/web/auth/github/index.js
+++ b/lib/web/auth/github/index.js
@@ -5,7 +5,7 @@ const passport = require('passport')
const GithubStrategy = require('passport-github').Strategy
const config = require('../../../config')
const response = require('../../../response')
-const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
+const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
let githubAuth = module.exports = Router()
diff --git a/lib/web/auth/gitlab/index.js b/lib/web/auth/gitlab/index.js
index 38436024..4cebbc10 100644
--- a/lib/web/auth/gitlab/index.js
+++ b/lib/web/auth/gitlab/index.js
@@ -5,7 +5,7 @@ const passport = require('passport')
const GitlabStrategy = require('passport-gitlab2').Strategy
const config = require('../../../config')
const response = require('../../../response')
-const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
+const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
let gitlabAuth = module.exports = Router()
diff --git a/lib/web/auth/google/index.js b/lib/web/auth/google/index.js
index 0a4fd55e..ad9bcd7a 100644
--- a/lib/web/auth/google/index.js
+++ b/lib/web/auth/google/index.js
@@ -4,7 +4,7 @@ const Router = require('express').Router
const passport = require('passport')
var GoogleStrategy = require('passport-google-oauth20').Strategy
const config = require('../../../config')
-const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
+const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
let googleAuth = module.exports = Router()
@@ -12,14 +12,14 @@ passport.use(new GoogleStrategy({
clientID: config.google.clientID,
clientSecret: config.google.clientSecret,
callbackURL: config.serverURL + '/auth/google/callback',
- userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo"
+ userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
}, passportGeneralCallback))
googleAuth.get('/auth/google', function (req, res, next) {
setReturnToFromReferer(req)
passport.authenticate('google', { scope: ['profile'] })(req, res, next)
})
- // google auth callback
+// google auth callback
googleAuth.get('/auth/google/callback',
passport.authenticate('google', {
successReturnToOrRedirect: config.serverURL + '/',
diff --git a/lib/web/auth/ldap/index.js b/lib/web/auth/ldap/index.js
index 8d71c18e..77790db3 100644
--- a/lib/web/auth/ldap/index.js
+++ b/lib/web/auth/ldap/index.js
@@ -6,8 +6,8 @@ const LDAPStrategy = require('passport-ldapauth')
const config = require('../../../config')
const models = require('../../../models')
const logger = require('../../../logger')
-const {setReturnToFromReferer} = require('../utils')
-const {urlencodedParser} = require('../../utils')
+const { setReturnToFromReferer } = require('../utils')
+const { urlencodedParser } = require('../../utils')
const response = require('../../../response')
let ldapAuth = module.exports = Router()
diff --git a/lib/web/auth/mattermost/index.js b/lib/web/auth/mattermost/index.js
index 63a4886f..48d6d297 100644
--- a/lib/web/auth/mattermost/index.js
+++ b/lib/web/auth/mattermost/index.js
@@ -5,7 +5,7 @@ const passport = require('passport')
const Mattermost = require('mattermost')
const OAuthStrategy = require('passport-oauth2').Strategy
const config = require('../../../config')
-const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
+const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const mattermost = new Mattermost.Client()
@@ -24,12 +24,12 @@ mattermostStrategy.userProfile = (accessToken, done) => {
mattermost.token = accessToken
mattermost.useHeaderToken()
mattermost.getMe(
- (data) => {
- done(null, data)
- },
- (err) => {
- done(err)
- }
+ (data) => {
+ done(null, data)
+ },
+ (err) => {
+ done(err)
+ }
)
}
diff --git a/lib/web/auth/oauth2/index.js b/lib/web/auth/oauth2/index.js
index 57ab9b9a..78434271 100644
--- a/lib/web/auth/oauth2/index.js
+++ b/lib/web/auth/oauth2/index.js
@@ -4,7 +4,7 @@ const Router = require('express').Router
const passport = require('passport')
const { Strategy, InternalOAuthError } = require('passport-oauth2')
const config = require('../../../config')
-const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
+const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
let oauth2Auth = module.exports = Router()
diff --git a/lib/web/auth/openid/index.js b/lib/web/auth/openid/index.js
index c45c6d71..8d271a7a 100644
--- a/lib/web/auth/openid/index.js
+++ b/lib/web/auth/openid/index.js
@@ -6,8 +6,8 @@ const OpenIDStrategy = require('@passport-next/passport-openid').Strategy
const config = require('../../../config')
const models = require('../../../models')
const logger = require('../../../logger')
-const {urlencodedParser} = require('../../utils')
-const {setReturnToFromReferer} = require('../utils')
+const { urlencodedParser } = require('../../utils')
+const { setReturnToFromReferer } = require('../utils')
let openIDAuth = module.exports = Router()
diff --git a/lib/web/auth/saml/index.js b/lib/web/auth/saml/index.js
index 3cdb7fe2..2289b010 100644
--- a/lib/web/auth/saml/index.js
+++ b/lib/web/auth/saml/index.js
@@ -6,7 +6,7 @@ const SamlStrategy = require('passport-saml').Strategy
const config = require('../../../config')
const models = require('../../../models')
const logger = require('../../../logger')
-const {urlencodedParser} = require('../../utils')
+const { urlencodedParser } = require('../../utils')
const fs = require('fs')
const intersection = function (array1, array2) { return array1.filter((n) => array2.includes(n)) }
diff --git a/lib/web/auth/twitter/index.js b/lib/web/auth/twitter/index.js
index c1860d93..5aba20ff 100644
--- a/lib/web/auth/twitter/index.js
+++ b/lib/web/auth/twitter/index.js
@@ -5,7 +5,7 @@ const passport = require('passport')
const TwitterStrategy = require('passport-twitter').Strategy
const config = require('../../../config')
-const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
+const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
let twitterAuth = module.exports = Router()
diff --git a/lib/web/historyRouter.js b/lib/web/historyRouter.js
index 1b22c232..fa426bbb 100644
--- a/lib/web/historyRouter.js
+++ b/lib/web/historyRouter.js
@@ -2,7 +2,7 @@
const Router = require('express').Router
-const {urlencodedParser} = require('./utils')
+const { urlencodedParser } = require('./utils')
const history = require('../history')
const historyRouter = module.exports = Router()
diff --git a/lib/web/imageRouter/imgur.js b/lib/web/imageRouter/imgur.js
index 2a20002c..eee349f9 100644
--- a/lib/web/imageRouter/imgur.js
+++ b/lib/web/imageRouter/imgur.js
@@ -17,12 +17,12 @@ exports.uploadImage = function (imagePath, callback) {
imgur.setClientId(config.imgur.clientID)
imgur.uploadFile(imagePath)
- .then(function (json) {
- if (config.debug) {
- logger.info('SERVER uploadimage success: ' + JSON.stringify(json))
- }
- callback(null, json.data.link.replace(/^http:\/\//i, 'https://'))
- }).catch(function (err) {
- callback(new Error(err), null)
- })
+ .then(function (json) {
+ if (config.debug) {
+ logger.info('SERVER uploadimage success: ' + JSON.stringify(json))
+ }
+ callback(null, json.data.link.replace(/^http:\/\//i, 'https://'))
+ }).catch(function (err) {
+ callback(new Error(err), null)
+ })
}
diff --git a/lib/web/imageRouter/minio.js b/lib/web/imageRouter/minio.js
index 1d993a45..fe43f76f 100644
--- a/lib/web/imageRouter/minio.js
+++ b/lib/web/imageRouter/minio.js
@@ -3,7 +3,7 @@ const fs = require('fs')
const path = require('path')
const config = require('../../config')
-const {getImageMimeType} = require('../../utils')
+const { getImageMimeType } = require('../../utils')
const logger = require('../../logger')
const Minio = require('minio')
diff --git a/lib/web/imageRouter/s3.js b/lib/web/imageRouter/s3.js
index 626fe148..b0eca7b5 100644
--- a/lib/web/imageRouter/s3.js
+++ b/lib/web/imageRouter/s3.js
@@ -3,7 +3,7 @@ const fs = require('fs')
const path = require('path')
const config = require('../../config')
-const {getImageMimeType} = require('../../utils')
+const { getImageMimeType } = require('../../utils')
const logger = require('../../logger')
const AWS = require('aws-sdk')
diff --git a/lib/web/middleware/tooBusy.js b/lib/web/middleware/tooBusy.js
index 128a5679..49efbe37 100644
--- a/lib/web/middleware/tooBusy.js
+++ b/lib/web/middleware/tooBusy.js
@@ -2,7 +2,6 @@
const toobusy = require('toobusy-js')
-
const response = require('../../response')
const config = require('../../config')
diff --git a/lib/web/noteRouter.js b/lib/web/noteRouter.js
index 41bf5f73..bac2cf88 100644
--- a/lib/web/noteRouter.js
+++ b/lib/web/noteRouter.js
@@ -4,7 +4,7 @@ const Router = require('express').Router
const response = require('../response')
-const {markdownParser} = require('./utils')
+const { markdownParser } = require('./utils')
const noteRouter = module.exports = Router()
diff --git a/lib/web/statusRouter.js b/lib/web/statusRouter.js
index 2b9cb65f..6f797f84 100644
--- a/lib/web/statusRouter.js
+++ b/lib/web/statusRouter.js
@@ -8,7 +8,7 @@ const config = require('../config')
const models = require('../models')
const logger = require('../logger')
-const {urlencodedParser} = require('./utils')
+const { urlencodedParser } = require('./utils')
const statusRouter = module.exports = Router()
diff --git a/lib/web/userRouter.js b/lib/web/userRouter.js
index ca364422..73b519ec 100644
--- a/lib/web/userRouter.js
+++ b/lib/web/userRouter.js
@@ -8,7 +8,7 @@ const response = require('../response')
const config = require('../config')
const models = require('../models')
const logger = require('../logger')
-const {generateAvatar} = require('../letter-avatars')
+const { generateAvatar } = require('../letter-avatars')
const UserRouter = module.exports = Router()
diff --git a/package.json b/package.json
index 490fe5a0..1518abff 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,7 @@
"license": "AGPL-3.0",
"scripts": {
"test": "npm run-script eslint && npm run-script jsonlint && npm run-script mocha-suite",
- "eslint": "node_modules/.bin/eslint lib public test app.js",
+ "eslint": "node_modules/.bin/eslint --max-warnings 0 lib public test app.js",
"jsonlint": "find . -not -path './node_modules/*' -type f -name '*.json' -o -type f -name '*.json.example' | while read json; do echo $json ; jq . $json; done",
"mocha-suite": "NODE_ENV=test CMD_DB_URL=\"sqlite::memory:\" mocha --exit",
"standard": "echo 'standard is no longer being used, use `npm run eslint` instead!' && exit 1",
diff --git a/public/js/cover.js b/public/js/cover.js
index 79fb3a2a..94748cdc 100644
--- a/public/js/cover.js
+++ b/public/js/cover.js
@@ -1,37 +1,37 @@
/* eslint-env browser, jquery */
/* global moment, serverurl */
-require('./locale')
-
-require('../css/cover.css')
-require('../css/site.css')
-
import {
- checkIfAuth,
- clearLoginState,
- getLoginState,
- resetCheckAuth,
- setloginStateChangeEvent
+ checkIfAuth,
+ clearLoginState,
+ getLoginState,
+ resetCheckAuth,
+ setloginStateChangeEvent
} from './lib/common/login'
import {
- clearDuplicatedHistory,
- deleteServerHistory,
- getHistory,
- getStorageHistory,
- parseHistory,
- parseServerToHistory,
- parseStorageToHistory,
- postHistoryToServer,
- removeHistory,
- saveHistory,
- saveStorageHistoryToServer
+ clearDuplicatedHistory,
+ deleteServerHistory,
+ getHistory,
+ getStorageHistory,
+ parseHistory,
+ parseServerToHistory,
+ parseStorageToHistory,
+ postHistoryToServer,
+ removeHistory,
+ saveHistory,
+ saveStorageHistoryToServer
} from './history'
import { saveAs } from 'file-saver'
import List from 'list.js'
import S from 'string'
+require('./locale')
+
+require('../css/cover.css')
+require('../css/site.css')
+
const options = {
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
item: `<li class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
@@ -67,27 +67,27 @@ pageInit()
function pageInit () {
checkIfAuth(
- data => {
- $('.ui-signin').hide()
- $('.ui-or').hide()
- $('.ui-welcome').show()
- if (data.photo) $('.ui-avatar').prop('src', data.photo).show()
- else $('.ui-avatar').prop('src', '').hide()
- $('.ui-name').html(data.name)
- $('.ui-signout').show()
- $('.ui-history').click()
- parseServerToHistory(historyList, parseHistoryCallback)
- },
- () => {
- $('.ui-signin').show()
- $('.ui-or').show()
- $('.ui-welcome').hide()
- $('.ui-avatar').prop('src', '').hide()
- $('.ui-name').html('')
- $('.ui-signout').hide()
- parseStorageToHistory(historyList, parseHistoryCallback)
- }
- )
+ data => {
+ $('.ui-signin').hide()
+ $('.ui-or').hide()
+ $('.ui-welcome').show()
+ if (data.photo) $('.ui-avatar').prop('src', data.photo).show()
+ else $('.ui-avatar').prop('src', '').hide()
+ $('.ui-name').html(data.name)
+ $('.ui-signout').show()
+ $('.ui-history').click()
+ parseServerToHistory(historyList, parseHistoryCallback)
+ },
+ () => {
+ $('.ui-signin').show()
+ $('.ui-or').show()
+ $('.ui-welcome').hide()
+ $('.ui-avatar').prop('src', '').hide()
+ $('.ui-name').html('')
+ $('.ui-signout').hide()
+ parseStorageToHistory(historyList, parseHistoryCallback)
+ }
+ )
}
$('.masthead-nav li').click(function () {
@@ -132,7 +132,7 @@ function checkHistoryList () {
function parseHistoryCallback (list, notehistory) {
checkHistoryList()
- // sort by pinned then timestamp
+ // sort by pinned then timestamp
list.sort('', {
sortFunction (a, b) {
const notea = a.values()
@@ -152,13 +152,13 @@ function parseHistoryCallback (list, notehistory) {
}
}
})
- // parse filter tags
+ // parse filter tags
const filtertags = []
for (let i = 0, l = list.items.length; i < l; i++) {
const tags = list.items[i]._values.tags
if (tags && tags.length > 0) {
for (let j = 0; j < tags.length; j++) {
- // push info filtertags if not found
+ // push info filtertags if not found
let found = false
if (filtertags.includes(tags[j])) { found = true }
if (!found) { filtertags.push(tags[j]) }
@@ -178,20 +178,20 @@ historyList.on('updated', e => {
const a = itemEl.find('a')
const pin = itemEl.find('.ui-history-pin')
const tagsEl = itemEl.find('.tags')
- // parse link to element a
+ // parse link to element a
a.attr('href', `${serverurl}/${values.id}`)
- // parse pinned
+ // parse pinned
if (values.pinned) {
pin.addClass('active')
} else {
pin.removeClass('active')
}
- // parse tags
+ // parse tags
const tags = values.tags
if (tags && tags.length > 0 && tagsEl.children().length <= 0) {
const labels = []
for (let j = 0; j < tags.length; j++) {
- // push into the item label
+ // push into the item label
labels.push(`<span class='label label-default'>${tags[j]}</span>`)
}
tagsEl.html(labels.join(' '))
@@ -328,7 +328,7 @@ $('.ui-open-history').bind('change', e => {
const reader = new FileReader()
reader.onload = () => {
const notehistory = JSON.parse(reader.result)
- // console.log(notehistory);
+ // console.log(notehistory);
if (!reader.result) return
getHistory(data => {
let mergedata = data.concat(notehistory)
diff --git a/public/js/extra.js b/public/js/extra.js
index 011e2143..4431513d 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -1,6 +1,22 @@
/* eslint-env browser, jquery */
+/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
/* global moment, serverurl */
+import Prism from 'prismjs'
+import hljs from 'highlight.js'
+import PDFObject from 'pdfobject'
+import S from 'string'
+import { saveAs } from 'file-saver'
+import escapeHTML from 'escape-html'
+
+import getUIElements from './lib/editor/ui-elements'
+
+import markdownit from 'markdown-it'
+import markdownitContainer from 'markdown-it-container'
+
+/* Defined regex markdown it plugins */
+import Plugin from 'markdown-it-regexp'
+
require('prismjs/themes/prism.css')
require('prismjs/components/prism-wiki')
require('prismjs/components/prism-haskell')
@@ -10,18 +26,9 @@ require('prismjs/components/prism-jsx')
require('prismjs/components/prism-makefile')
require('prismjs/components/prism-gherkin')
-import Prism from 'prismjs'
-import hljs from 'highlight.js'
-import PDFObject from 'pdfobject'
-import S from 'string'
-import { saveAs } from 'file-saver'
-import escapeHTML from 'escape-html'
-
require('./lib/common/login')
require('../vendor/md-toc')
var Viz = require('viz.js')
-
-import getUIElements from './lib/editor/ui-elements'
const ui = getUIElements()
// auto update last change
@@ -191,7 +198,7 @@ export function parseMeta (md, edit, view, toc, tocAffix) {
dir = meta.dir
breaks = meta.breaks
}
- // text language
+ // text language
if (lang && typeof lang === 'string') {
view.attr('lang', lang)
toc.attr('lang', lang)
@@ -203,7 +210,7 @@ export function parseMeta (md, edit, view, toc, tocAffix) {
tocAffix.removeAttr('lang')
if (edit) { edit.removeAttr('lang', lang) }
}
- // text direction
+ // text direction
if (dir && typeof dir === 'string') {
view.attr('dir', dir)
toc.attr('dir', dir)
@@ -213,7 +220,7 @@ export function parseMeta (md, edit, view, toc, tocAffix) {
toc.removeAttr('dir')
tocAffix.removeAttr('dir')
}
- // breaks
+ // breaks
if (typeof breaks === 'boolean' && !breaks) {
md.options.breaks = false
} else {
@@ -246,7 +253,7 @@ if (typeof window.mermaid !== 'undefined' && window.mermaid) window.mermaid.star
// dynamic event or object binding here
export function finishView (view) {
- // todo list
+ // todo list
const lis = view.find('li.raw').removeClass('raw').sortByDepth().toArray()
for (let li of lis) {
@@ -262,7 +269,7 @@ export function finishView (view) {
if (typeof editor !== 'undefined' && window.havePermission()) { disabled = '' }
if (/^\s*\[[x ]\]\s*/.test(html)) {
li.innerHTML = html.replace(/^\s*\[ \]\s*/, `<input type="checkbox" class="task-list-item-checkbox "${disabled}><label></label>`)
- .replace(/^\s*\[x\]\s*/, `<input type="checkbox" class="task-list-item-checkbox" checked ${disabled}><label></label>`)
+ .replace(/^\s*\[x\]\s*/, `<input type="checkbox" class="task-list-item-checkbox" checked ${disabled}><label></label>`)
if (li.tagName.toLowerCase() !== 'li') {
li.parentElement.setAttribute('class', 'task-list-item')
} else {
@@ -270,42 +277,42 @@ export function finishView (view) {
}
}
if (typeof editor !== 'undefined' && window.havePermission()) { $(li).find('input').change(toggleTodoEvent) }
- // color tag in list will convert it to tag icon with color
+ // color tag in list will convert it to tag icon with color
const tagColor = $(li).closest('ul').find('.color')
tagColor.each((key, value) => {
$(value).addClass('fa fa-tag').css('color', $(value).attr('data-color'))
})
}
- // youtube
+ // youtube
view.find('div.youtube.raw').removeClass('raw')
- .click(function () {
- imgPlayiframe(this, '//www.youtube.com/embed/')
- })
+ .click(function () {
+ imgPlayiframe(this, '//www.youtube.com/embed/')
+ })
// vimeo
view.find('div.vimeo.raw').removeClass('raw')
- .click(function () {
- imgPlayiframe(this, '//player.vimeo.com/video/')
- })
- .each((key, value) => {
- $.ajax({
- type: 'GET',
- url: `//vimeo.com/api/v2/video/${$(value).attr('data-videoid')}.json`,
- jsonp: 'callback',
- dataType: 'jsonp',
- success (data) {
- const thumbnailSrc = data[0].thumbnail_large
- const image = `<img src="${thumbnailSrc}" />`
- $(value).prepend(image)
- if (window.viewAjaxCallback) window.viewAjaxCallback()
- }
- })
- })
+ .click(function () {
+ imgPlayiframe(this, '//player.vimeo.com/video/')
+ })
+ .each((key, value) => {
+ $.ajax({
+ type: 'GET',
+ url: `//vimeo.com/api/v2/video/${$(value).attr('data-videoid')}.json`,
+ jsonp: 'callback',
+ dataType: 'jsonp',
+ success (data) {
+ const thumbnailSrc = data[0].thumbnail_large
+ const image = `<img src="${thumbnailSrc}" />`
+ $(value).prepend(image)
+ if (window.viewAjaxCallback) window.viewAjaxCallback()
+ }
+ })
+ })
// gist
view.find('code[data-gist-id]').each((key, value) => {
if ($(value).children().length === 0) { $(value).gist(window.viewAjaxCallback) }
})
- // sequence diagram
+ // sequence diagram
const sequences = view.find('div.sequence-diagram.raw').removeClass('raw')
sequences.each((key, value) => {
try {
@@ -328,7 +335,7 @@ export function finishView (view) {
console.warn(err)
}
})
- // flowchart
+ // flowchart
const flow = view.find('div.flow-chart.raw').removeClass('raw')
flow.each((key, value) => {
try {
@@ -352,7 +359,7 @@ export function finishView (view) {
console.warn(err)
}
})
- // graphviz
+ // graphviz
var graphvizs = view.find('div.graphviz.raw').removeClass('raw')
graphvizs.each(function (key, value) {
try {
@@ -371,7 +378,7 @@ export function finishView (view) {
console.warn(err)
}
})
- // mermaid
+ // mermaid
const mermaids = view.find('div.mermaid.raw').removeClass('raw')
mermaids.each((key, value) => {
try {
@@ -413,16 +420,16 @@ export function finishView (view) {
console.warn(err)
}
})
- // image href new window(emoji not included)
+ // image href new window(emoji not included)
const images = view.find('img.raw[src]').removeClass('raw')
images.each((key, value) => {
- // if it's already wrapped by link, then ignore
+ // if it's already wrapped by link, then ignore
const $value = $(value)
$value[0].onload = e => {
if (window.viewAjaxCallback) window.viewAjaxCallback()
}
})
- // blockquote
+ // blockquote
const blockquote = view.find('blockquote.raw').removeClass('raw')
const blockquoteP = blockquote.find('p')
blockquoteP.each((key, value) => {
@@ -430,96 +437,96 @@ export function finishView (view) {
html = replaceExtraTags(html)
$(value).html(html)
})
- // color tag in blockquote will change its left border color
+ // color tag in blockquote will change its left border color
const blockquoteColor = blockquote.find('.color')
blockquoteColor.each((key, value) => {
$(value).closest('blockquote').css('border-left-color', $(value).attr('data-color'))
})
- // slideshare
+ // slideshare
view.find('div.slideshare.raw').removeClass('raw')
- .each((key, value) => {
- $.ajax({
- type: 'GET',
- url: `//www.slideshare.net/api/oembed/2?url=http://www.slideshare.net/${$(value).attr('data-slideshareid')}&format=json`,
- jsonp: 'callback',
- dataType: 'jsonp',
- success (data) {
- const $html = $(data.html)
- const iframe = $html.closest('iframe')
- const caption = $html.closest('div')
- const inner = $('<div class="inner"></div>').append(iframe)
- const height = iframe.attr('height')
- const width = iframe.attr('width')
- const ratio = (height / width) * 100
- inner.css('padding-bottom', `${ratio}%`)
- $(value).html(inner).append(caption)
- if (window.viewAjaxCallback) window.viewAjaxCallback()
- }
- })
- })
+ .each((key, value) => {
+ $.ajax({
+ type: 'GET',
+ url: `//www.slideshare.net/api/oembed/2?url=http://www.slideshare.net/${$(value).attr('data-slideshareid')}&format=json`,
+ jsonp: 'callback',
+ dataType: 'jsonp',
+ success (data) {
+ const $html = $(data.html)
+ const iframe = $html.closest('iframe')
+ const caption = $html.closest('div')
+ const inner = $('<div class="inner"></div>').append(iframe)
+ const height = iframe.attr('height')
+ const width = iframe.attr('width')
+ const ratio = (height / width) * 100
+ inner.css('padding-bottom', `${ratio}%`)
+ $(value).html(inner).append(caption)
+ if (window.viewAjaxCallback) window.viewAjaxCallback()
+ }
+ })
+ })
// speakerdeck
view.find('div.speakerdeck.raw').removeClass('raw')
- .each((key, value) => {
- const url = `https://speakerdeck.com/${$(value).attr('data-speakerdeckid')}`
- const inner = $('<a>Speakerdeck</a>')
- inner.attr('href', url)
- inner.attr('rel', 'noopener noreferrer')
- inner.attr('target', '_blank')
- $(value).append(inner)
- })
+ .each((key, value) => {
+ const url = `https://speakerdeck.com/${$(value).attr('data-speakerdeckid')}`
+ const inner = $('<a>Speakerdeck</a>')
+ inner.attr('href', url)
+ inner.attr('rel', 'noopener noreferrer')
+ inner.attr('target', '_blank')
+ $(value).append(inner)
+ })
// pdf
view.find('div.pdf.raw').removeClass('raw')
- .each(function (key, value) {
- const url = $(value).attr('data-pdfurl')
- const inner = $('<div></div>')
- $(this).append(inner)
- PDFObject.embed(url, inner, {
- height: '400px'
- })
- })
+ .each(function (key, value) {
+ const url = $(value).attr('data-pdfurl')
+ const inner = $('<div></div>')
+ $(this).append(inner)
+ PDFObject.embed(url, inner, {
+ height: '400px'
+ })
+ })
// syntax highlighting
view.find('code.raw').removeClass('raw')
- .each((key, value) => {
- const langDiv = $(value)
- if (langDiv.length > 0) {
- const reallang = langDiv[0].className.replace(/hljs|wrap/g, '').trim()
- const codeDiv = langDiv.find('.code')
- let code = ''
- if (codeDiv.length > 0) code = codeDiv.html()
- else code = langDiv.html()
- var result
- if (!reallang) {
- result = {
- value: code
- }
- } else if (reallang === 'haskell' || reallang === 'go' || reallang === 'typescript' || reallang === 'jsx' || reallang === 'gherkin') {
- code = S(code).unescapeHTML().s
- result = {
- value: Prism.highlight(code, Prism.languages[reallang])
- }
- } else if (reallang === 'tiddlywiki' || reallang === 'mediawiki') {
- code = S(code).unescapeHTML().s
- result = {
- value: Prism.highlight(code, Prism.languages.wiki)
- }
- } else if (reallang === 'cmake') {
- code = S(code).unescapeHTML().s
- result = {
- value: Prism.highlight(code, Prism.languages.makefile)
- }
- } else {
- code = S(code).unescapeHTML().s
- const languages = hljs.listLanguages()
- if (!languages.includes(reallang)) {
- result = hljs.highlightAuto(code)
- } else {
- result = hljs.highlight(reallang, code)
- }
- }
- if (codeDiv.length > 0) codeDiv.html(result.value)
- else langDiv.html(result.value)
+ .each((key, value) => {
+ const langDiv = $(value)
+ if (langDiv.length > 0) {
+ const reallang = langDiv[0].className.replace(/hljs|wrap/g, '').trim()
+ const codeDiv = langDiv.find('.code')
+ let code = ''
+ if (codeDiv.length > 0) code = codeDiv.html()
+ else code = langDiv.html()
+ var result
+ if (!reallang) {
+ result = {
+ value: code
}
- })
+ } else if (reallang === 'haskell' || reallang === 'go' || reallang === 'typescript' || reallang === 'jsx' || reallang === 'gherkin') {
+ code = S(code).unescapeHTML().s
+ result = {
+ value: Prism.highlight(code, Prism.languages[reallang])
+ }
+ } else if (reallang === 'tiddlywiki' || reallang === 'mediawiki') {
+ code = S(code).unescapeHTML().s
+ result = {
+ value: Prism.highlight(code, Prism.languages.wiki)
+ }
+ } else if (reallang === 'cmake') {
+ code = S(code).unescapeHTML().s
+ result = {
+ value: Prism.highlight(code, Prism.languages.makefile)
+ }
+ } else {
+ code = S(code).unescapeHTML().s
+ const languages = hljs.listLanguages()
+ if (!languages.includes(reallang)) {
+ result = hljs.highlightAuto(code)
+ } else {
+ result = hljs.highlight(reallang, code)
+ }
+ }
+ if (codeDiv.length > 0) codeDiv.html(result.value)
+ else langDiv.html(result.value)
+ }
+ })
// mathjax
const mathjaxdivs = view.find('span.mathjax.raw').removeClass('raw').toArray()
try {
@@ -533,7 +540,7 @@ export function finishView (view) {
} catch (err) {
console.warn(err)
}
- // render title
+ // render title
document.title = renderTitle(view)
}
@@ -593,23 +600,23 @@ window.removeDOMEvents = removeDOMEvents
function generateCleanHTML (view) {
const src = view.clone()
const eles = src.find('*')
- // remove syncscroll parts
+ // remove syncscroll parts
eles.removeClass('part')
src.find('*[class=""]').removeAttr('class')
eles.removeAttr('data-startline data-endline')
src.find("a[href^='#'][smoothhashscroll]").removeAttr('smoothhashscroll')
- // remove gist content
+ // remove gist content
src.find('code[data-gist-id]').children().remove()
- // disable todo list
+ // disable todo list
src.find('input.task-list-item-checkbox').attr('disabled', '')
- // replace emoji image path
+ // replace emoji image path
src.find('img.emoji').each((key, value) => {
let name = $(value).attr('alt')
name = name.substr(1)
name = name.slice(0, name.length - 1)
$(value).attr('src', `https://cdnjs.cloudflare.com/ajax/libs/emojify.js/1.1.0/images/basic/${name}.png`)
})
- // replace video to iframe
+ // replace video to iframe
src.find('div[data-videoid]').each((key, value) => {
const id = $(value).attr('data-videoid')
const style = $(value).attr('style')
@@ -645,12 +652,12 @@ export function exportToHTML (view) {
const title = renderTitle(ui.area.markdown)
const filename = `${renderFilename(ui.area.markdown)}.html`
const src = generateCleanHTML(view)
- // generate toc
+ // generate toc
const toc = $('#ui-toc').clone()
toc.find('*').removeClass('active').find("a[href^='#'][smoothhashscroll]").removeAttr('smoothhashscroll')
const tocAffix = $('#ui-toc-affix').clone()
tocAffix.find('*').removeClass('active').find("a[href^='#'][smoothhashscroll]").removeAttr('smoothhashscroll')
- // generate html via template
+ // generate html via template
$.get(`${serverurl}/build/html.min.css`, css => {
$.get(`${serverurl}/views/html.hbs`, data => {
const template = window.Handlebars.compile(data)
@@ -665,7 +672,6 @@ export function exportToHTML (view) {
dir: (md && md.meta && md.meta.dir) ? `dir="${md.meta.dir}"` : null
}
const html = template(context)
- // console.log(html);
const blob = new Blob([html], {
type: 'text/html;charset=utf-8'
})
@@ -780,20 +786,20 @@ export function smoothHashScroll () {
const hash = element.hash
if (hash) {
$element.on('click', function (e) {
- // store hash
+ // store hash
const hash = decodeURIComponent(this.hash)
- // escape special characters in jquery selector
+ // escape special characters in jquery selector
const $hash = $(hash.replace(/(:|\.|\[|\]|,)/g, '\\$1'))
- // return if no element been selected
+ // return if no element been selected
if ($hash.length <= 0) return
- // prevent default anchor click behavior
+ // prevent default anchor click behavior
e.preventDefault()
- // animate
+ // animate
$('body, html').stop(true, true).animate({
scrollTop: $hash.offset().top
}, 100, 'linear', () => {
- // when done, add hash to url
- // (default click behaviour)
+ // when done, add hash to url
+ // (default click behaviour)
window.location.hash = hash
})
})
@@ -935,9 +941,6 @@ function highlightRender (code, lang) {
return result.value
}
-import markdownit from 'markdown-it'
-import markdownitContainer from 'markdown-it-container'
-
export let md = markdownit('default', {
html: true,
breaks: true,
@@ -1035,109 +1038,106 @@ md.renderer.rules.fence = (tokens, idx, options, env, self) => {
return `<pre><code${self.renderAttrs(token)}>${highlighted}</code></pre>\n`
}
-/* Defined regex markdown it plugins */
-import Plugin from 'markdown-it-regexp'
-
// youtube
const youtubePlugin = new Plugin(
- // regexp to match
- /{%youtube\s*([\d\D]*?)\s*%}/,
-
- (match, utils) => {
- const videoid = match[1]
- if (!videoid) return
- const div = $('<div class="youtube raw"></div>')
- div.attr('data-videoid', videoid)
- const thumbnailSrc = `//img.youtube.com/vi/${videoid}/hqdefault.jpg`
- const image = `<img src="${thumbnailSrc}" />`
- div.append(image)
- const icon = '<i class="icon fa fa-youtube-play fa-5x"></i>'
- div.append(icon)
- return div[0].outerHTML
- }
+ // regexp to match
+ /{%youtube\s*([\d\D]*?)\s*%}/,
+
+ (match, utils) => {
+ const videoid = match[1]
+ if (!videoid) return
+ const div = $('<div class="youtube raw"></div>')
+ div.attr('data-videoid', videoid)
+ const thumbnailSrc = `//img.youtube.com/vi/${videoid}/hqdefault.jpg`
+ const image = `<img src="${thumbnailSrc}" />`
+ div.append(image)
+ const icon = '<i class="icon fa fa-youtube-play fa-5x"></i>'
+ div.append(icon)
+ return div[0].outerHTML
+ }
)
// vimeo
const vimeoPlugin = new Plugin(
- // regexp to match
- /{%vimeo\s*([\d\D]*?)\s*%}/,
-
- (match, utils) => {
- const videoid = match[1]
- if (!videoid) return
- const div = $('<div class="vimeo raw"></div>')
- div.attr('data-videoid', videoid)
- const icon = '<i class="icon fa fa-vimeo-square fa-5x"></i>'
- div.append(icon)
- return div[0].outerHTML
- }
+ // regexp to match
+ /{%vimeo\s*([\d\D]*?)\s*%}/,
+
+ (match, utils) => {
+ const videoid = match[1]
+ if (!videoid) return
+ const div = $('<div class="vimeo raw"></div>')
+ div.attr('data-videoid', videoid)
+ const icon = '<i class="icon fa fa-vimeo-square fa-5x"></i>'
+ div.append(icon)
+ return div[0].outerHTML
+ }
)
// gist
const gistPlugin = new Plugin(
- // regexp to match
- /{%gist\s*([\d\D]*?)\s*%}/,
+ // regexp to match
+ /{%gist\s*([\d\D]*?)\s*%}/,
- (match, utils) => {
- const gistid = match[1]
- const code = `<code data-gist-id="${gistid}"></code>`
- return code
- }
+ (match, utils) => {
+ const gistid = match[1]
+ const code = `<code data-gist-id="${gistid}"></code>`
+ return code
+ }
)
// TOC
const tocPlugin = new Plugin(
- // regexp to match
- /^\[TOC\]$/i,
+ // regexp to match
+ /^\[TOC\]$/i,
- (match, utils) => '<div class="toc"></div>'
+ (match, utils) => '<div class="toc"></div>'
)
// slideshare
const slidesharePlugin = new Plugin(
- // regexp to match
- /{%slideshare\s*([\d\D]*?)\s*%}/,
-
- (match, utils) => {
- const slideshareid = match[1]
- const div = $('<div class="slideshare raw"></div>')
- div.attr('data-slideshareid', slideshareid)
- return div[0].outerHTML
- }
+ // regexp to match
+ /{%slideshare\s*([\d\D]*?)\s*%}/,
+
+ (match, utils) => {
+ const slideshareid = match[1]
+ const div = $('<div class="slideshare raw"></div>')
+ div.attr('data-slideshareid', slideshareid)
+ return div[0].outerHTML
+ }
)
// speakerdeck
const speakerdeckPlugin = new Plugin(
- // regexp to match
- /{%speakerdeck\s*([\d\D]*?)\s*%}/,
-
- (match, utils) => {
- const speakerdeckid = match[1]
- const div = $('<div class="speakerdeck raw"></div>')
- div.attr('data-speakerdeckid', speakerdeckid)
- return div[0].outerHTML
- }
+ // regexp to match
+ /{%speakerdeck\s*([\d\D]*?)\s*%}/,
+
+ (match, utils) => {
+ const speakerdeckid = match[1]
+ const div = $('<div class="speakerdeck raw"></div>')
+ div.attr('data-speakerdeckid', speakerdeckid)
+ return div[0].outerHTML
+ }
)
// pdf
const pdfPlugin = new Plugin(
- // regexp to match
- /{%pdf\s*([\d\D]*?)\s*%}/,
-
- (match, utils) => {
- const pdfurl = match[1]
- if (!isValidURL(pdfurl)) return match[0]
- const div = $('<div class="pdf raw"></div>')
- div.attr('data-pdfurl', pdfurl)
- return div[0].outerHTML
- }
+ // regexp to match
+ /{%pdf\s*([\d\D]*?)\s*%}/,
+
+ (match, utils) => {
+ const pdfurl = match[1]
+ if (!isValidURL(pdfurl)) return match[0]
+ const div = $('<div class="pdf raw"></div>')
+ div.attr('data-pdfurl', pdfurl)
+ return div[0].outerHTML
+ }
)
const emojijsPlugin = new Plugin(
- // regexp to match emoji shortcodes :something:
- // We generate an universal regex that guaranteed only contains the
- // emojies we have available. This should prevent all false-positives
- new RegExp(':(' + window.emojify.emojiNames.map((item) => { return RegExp.escape(item) }).join('|') + '):', 'i'),
-
- (match, utils) => {
- const emoji = match[1].toLowerCase()
- const div = $(`<img class="emoji" alt=":${emoji}:" src="${serverurl}/build/emojify.js/dist/images/basic/${emoji}.png"></img>`)
- return div[0].outerHTML
- }
+ // regexp to match emoji shortcodes :something:
+ // We generate an universal regex that guaranteed only contains the
+ // emojies we have available. This should prevent all false-positives
+ new RegExp(':(' + window.emojify.emojiNames.map((item) => { return RegExp.escape(item) }).join('|') + '):', 'i'),
+
+ (match, utils) => {
+ const emoji = match[1].toLowerCase()
+ const div = $(`<img class="emoji" alt=":${emoji}:" src="${serverurl}/build/emojify.js/dist/images/basic/${emoji}.png"></img>`)
+ return div[0].outerHTML
+ }
)
// yaml meta, from https://github.com/eugeneware/remarkable-meta
diff --git a/public/js/history.js b/public/js/history.js
index 27b8cd28..e0154185 100644
--- a/public/js/history.js
+++ b/public/js/history.js
@@ -1,4 +1,5 @@
/* eslint-env browser, jquery */
+/* eslint no-console: ["error", { allow: ["warn", "error", "debug"] }] */
/* global serverurl, moment */
import store from 'store'
@@ -12,11 +13,11 @@ import {
} from './utils'
import {
- checkIfAuth
+ checkIfAuth
} from './lib/common/login'
import {
- urlpath
+ urlpath
} from './lib/config'
window.migrateHistoryFromTempCallback = null
@@ -28,40 +29,40 @@ function migrateHistoryFromTemp () {
$.get(`${serverurl}/temp`, {
tempid: url('#tempid')
})
- .done(data => {
- if (data && data.temp) {
- getStorageHistory(olddata => {
- if (!olddata || olddata.length === 0) {
- saveHistoryToStorage(JSON.parse(data.temp))
+ .done(data => {
+ if (data && data.temp) {
+ getStorageHistory(olddata => {
+ if (!olddata || olddata.length === 0) {
+ saveHistoryToStorage(JSON.parse(data.temp))
+ }
+ })
+ }
+ })
+ .always(() => {
+ let hash = location.hash.split('#')[1]
+ hash = hash.split('&')
+ for (let i = 0; i < hash.length; i++) {
+ if (hash[i].indexOf('tempid') === 0) {
+ hash.splice(i, 1)
+ i--
}
- })
- }
- })
- .always(() => {
- let hash = location.hash.split('#')[1]
- hash = hash.split('&')
- for (let i = 0; i < hash.length; i++) {
- if (hash[i].indexOf('tempid') === 0) {
- hash.splice(i, 1)
- i--
}
- }
- hash = hash.join('&')
- location.hash = hash
- if (window.migrateHistoryFromTempCallback) { window.migrateHistoryFromTempCallback() }
- })
+ hash = hash.join('&')
+ location.hash = hash
+ if (window.migrateHistoryFromTempCallback) { window.migrateHistoryFromTempCallback() }
+ })
}
}
export function saveHistory (notehistory) {
checkIfAuth(
- () => {
- saveHistoryToServer(notehistory)
- },
- () => {
- saveHistoryToStorage(notehistory)
- }
- )
+ () => {
+ saveHistoryToServer(notehistory)
+ },
+ () => {
+ saveHistoryToStorage(notehistory)
+ }
+ )
}
function saveHistoryToStorage (notehistory) {
@@ -80,9 +81,9 @@ export function saveStorageHistoryToServer (callback) {
$.post(`${serverurl}/history`, {
history: data
})
- .done(data => {
- callback(data)
- })
+ .done(data => {
+ callback(data)
+ })
}
}
@@ -109,7 +110,7 @@ export function clearDuplicatedHistory (notehistory) {
}
function addHistory (id, text, time, tags, pinned, notehistory) {
- // only add when note id exists
+ // only add when note id exists
if (id) {
notehistory.push({
id,
@@ -135,14 +136,14 @@ export function removeHistory (id, notehistory) {
// used for inner
export function writeHistory (title, tags) {
checkIfAuth(
- () => {
- // no need to do this anymore, this will count from server-side
- // writeHistoryToServer(title, tags);
- },
- () => {
- writeHistoryToStorage(title, tags)
- }
- )
+ () => {
+ // no need to do this anymore, this will count from server-side
+ // writeHistoryToServer(title, tags);
+ },
+ () => {
+ writeHistoryToStorage(title, tags)
+ }
+ )
}
function writeHistoryToStorage (title, tags) {
@@ -163,7 +164,7 @@ if (!Array.isArray) {
}
function renderHistory (title, tags) {
- // console.debug(tags);
+ // console.debug(tags);
const id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1]
return {
id,
@@ -175,7 +176,7 @@ function renderHistory (title, tags) {
function generateHistory (title, tags, notehistory) {
const info = renderHistory(title, tags)
- // keep any pinned data
+ // keep any pinned data
let pinned = false
for (let i = 0; i < notehistory.length; i++) {
if (notehistory[i].id === info.id && notehistory[i].pinned) {
@@ -192,25 +193,25 @@ function generateHistory (title, tags, notehistory) {
// used for outer
export function getHistory (callback) {
checkIfAuth(
- () => {
- getServerHistory(callback)
- },
- () => {
- getStorageHistory(callback)
- }
- )
+ () => {
+ getServerHistory(callback)
+ },
+ () => {
+ getStorageHistory(callback)
+ }
+ )
}
function getServerHistory (callback) {
$.get(`${serverurl}/history`)
- .done(data => {
- if (data.history) {
- callback(data.history)
- }
- })
- .fail((xhr, status, error) => {
- console.error(xhr.responseText)
- })
+ .done(data => {
+ if (data.history) {
+ callback(data.history)
+ }
+ })
+ .fail((xhr, status, error) => {
+ console.error(xhr.responseText)
+ })
}
export function getStorageHistory (callback) {
@@ -225,25 +226,25 @@ export function getStorageHistory (callback) {
export function parseHistory (list, callback) {
checkIfAuth(
- () => {
- parseServerToHistory(list, callback)
- },
- () => {
- parseStorageToHistory(list, callback)
- }
- )
+ () => {
+ parseServerToHistory(list, callback)
+ },
+ () => {
+ parseStorageToHistory(list, callback)
+ }
+ )
}
export function parseServerToHistory (list, callback) {
$.get(`${serverurl}/history`)
- .done(data => {
- if (data.history) {
- parseToHistory(list, data.history, callback)
- }
- })
- .fail((xhr, status, error) => {
- console.error(xhr.responseText)
- })
+ .done(data => {
+ if (data.history) {
+ parseToHistory(list, data.history, callback)
+ }
+ })
+ .fail((xhr, status, error) => {
+ console.error(xhr.responseText)
+ })
}
export function parseStorageToHistory (list, callback) {
@@ -269,15 +270,15 @@ function parseToHistory (list, notehistory, callback) {
} catch (err) {
console.error(err)
}
- // parse time to timestamp and fromNow
+ // parse time to timestamp and fromNow
const timestamp = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'))
notehistory[i].timestamp = timestamp.valueOf()
notehistory[i].fromNow = timestamp.fromNow()
notehistory[i].time = timestamp.format('llll')
- // prevent XSS
+ // prevent XSS
notehistory[i].text = S(notehistory[i].text).escapeHTML().s
notehistory[i].tags = (notehistory[i].tags && notehistory[i].tags.length > 0) ? S(notehistory[i].tags).escapeHTML().s.split(',') : []
- // add to list
+ // add to list
if (notehistory[i].id && list.get('id', notehistory[i].id).length === 0) { list.add(notehistory[i]) }
}
}
diff --git a/public/js/index.js b/public/js/index.js
index d5345a8c..bae24fe5 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -1,16 +1,8 @@
/* eslint-env browser, jquery */
+/* eslint no-console: ["error", { allow: ["warn", "error", "debug"] }] */
/* global CodeMirror, Cookies, moment, Spinner, Idle, serverurl,
key, Dropbox, ot, hex2rgb, Visibility */
-require('../vendor/showup/showup')
-
-require('../css/index.css')
-require('../css/extra.css')
-require('../css/slide-preview.css')
-require('../css/site.css')
-
-require('highlight.js/styles/github-gist.css')
-
import TurndownService from 'turndown'
import { saveAs } from 'file-saver'
@@ -24,55 +16,55 @@ import _ from 'lodash'
import List from 'list.js'
import {
- checkLoginStateChanged,
- setloginStateChangeEvent
+ checkLoginStateChanged,
+ setloginStateChangeEvent
} from './lib/common/login'
import {
- debug,
- DROPBOX_APP_KEY,
- noteid,
- noteurl,
- urlpath,
- version
+ debug,
+ DROPBOX_APP_KEY,
+ noteid,
+ noteurl,
+ urlpath,
+ version
} from './lib/config'
import {
- autoLinkify,
- deduplicatedHeaderId,
- exportToHTML,
- exportToRawHTML,
- removeDOMEvents,
- finishView,
- generateToc,
- isValidURL,
- md,
- parseMeta,
- postProcess,
- renderFilename,
- renderTOC,
- renderTags,
- renderTitle,
- scrollToHash,
- smoothHashScroll,
- updateLastChange,
- updateLastChangeUser,
- updateOwner
+ autoLinkify,
+ deduplicatedHeaderId,
+ exportToHTML,
+ exportToRawHTML,
+ removeDOMEvents,
+ finishView,
+ generateToc,
+ isValidURL,
+ md,
+ parseMeta,
+ postProcess,
+ renderFilename,
+ renderTOC,
+ renderTags,
+ renderTitle,
+ scrollToHash,
+ smoothHashScroll,
+ updateLastChange,
+ updateLastChangeUser,
+ updateOwner
} from './extra'
import {
- clearMap,
- setupSyncAreas,
- syncScrollToEdit,
- syncScrollToView
+ clearMap,
+ setupSyncAreas,
+ syncScrollToEdit,
+ syncScrollToView
} from './lib/syncscroll'
import {
- writeHistory,
- deleteServerHistory,
- getHistory,
- saveHistory,
- removeHistory
+ writeHistory,
+ deleteServerHistory,
+ getHistory,
+ saveHistory,
+ removeHistory
} from './history'
import { preventXSS } from './render'
@@ -83,6 +75,15 @@ import getUIElements from './lib/editor/ui-elements'
import modeType from './lib/modeType'
import appState from './lib/appState'
+require('../vendor/showup/showup')
+
+require('../css/index.css')
+require('../css/extra.css')
+require('../css/slide-preview.css')
+require('../css/site.css')
+
+require('highlight.js/styles/github-gist.css')
+
var defaultTextHeight = 20
var viewportMargin = 20
var defaultEditorMode = 'gfm'
@@ -418,7 +419,7 @@ Visibility.change(function (e, state) {
$(document).ready(function () {
idle.checkAway()
checkResponsive()
- // if in smaller screen, we don't need advanced scrollbar
+ // if in smaller screen, we don't need advanced scrollbar
var scrollbarStyle
if (visibleXS) {
scrollbarStyle = 'native'
@@ -438,12 +439,12 @@ $(document).ready(function () {
if (isTouchDevice) {
/* bind events */
$(document)
- .on('focus', 'textarea, input', function () {
- $body.addClass('fixfixed')
- })
- .on('blur', 'textarea, input', function () {
- $body.removeClass('fixfixed')
- })
+ .on('focus', 'textarea, input', function () {
+ $body.addClass('fixfixed')
+ })
+ .on('blur', 'textarea, input', function () {
+ $body.removeClass('fixfixed')
+ })
}
// Re-enable nightmode
@@ -668,14 +669,14 @@ function checkEditorScrollbarInner () {
}
function checkTocStyle () {
- // toc right
+ // toc right
var paddingRight = parseFloat(ui.area.markdown.css('padding-right'))
var right = ($(window).width() - (ui.area.markdown.offset().left + ui.area.markdown.outerWidth() - paddingRight))
ui.toc.toc.css('right', right + 'px')
- // affix toc left
+ // affix toc left
var newbool
var rightMargin = (ui.area.markdown.parent().outerWidth() - ui.area.markdown.outerWidth()) / 2
- // for ipad or wider device
+ // for ipad or wider device
if (rightMargin >= 133) {
newbool = true
var affixLeftMargin = (ui.toc.affix.outerWidth() - ui.toc.affix.width()) / 2
@@ -762,7 +763,7 @@ function toggleMode () {
var lastMode = null
function changeMode (type) {
- // lock navbar to prevent it hide after changeMode
+ // lock navbar to prevent it hide after changeMode
lockNavbar()
saveInfo()
if (type) {
@@ -820,7 +821,7 @@ function changeMode (type) {
} else {
$(document.body).css('background-color', ui.area.codemirror.css('background-color'))
}
- // check resizable editor style
+ // check resizable editor style
if (appState.currentMode === modeType.both) {
if (lastEditorWidth > 0) {
ui.area.edit.css('width', lastEditorWidth + 'px')
@@ -898,13 +899,13 @@ function showMessageModal (title, header, href, text, success) {
// check if dropbox app key is set and load scripts
if (DROPBOX_APP_KEY) {
$('<script>')
- .attr('type', 'text/javascript')
- .attr('src', 'https://www.dropbox.com/static/api/2/dropins.js')
- .attr('id', 'dropboxjs')
- .attr('data-app-key', DROPBOX_APP_KEY)
- .prop('async', true)
- .prop('defer', true)
- .appendTo('body')
+ .attr('type', 'text/javascript')
+ .attr('src', 'https://www.dropbox.com/static/api/2/dropins.js')
+ .attr('id', 'dropboxjs')
+ .attr('data-app-key', DROPBOX_APP_KEY)
+ .prop('async', true)
+ .prop('defer', true)
+ .appendTo('body')
} else {
ui.toolbar.import.dropbox.hide()
ui.toolbar.export.dropbox.hide()
@@ -964,35 +965,35 @@ ui.toolbar.export.gist.attr('href', noteurl + '/gist')
ui.toolbar.export.snippet.click(function () {
ui.spinner.show()
$.get(serverurl + '/auth/gitlab/callback/' + noteid + '/projects')
- .done(function (data) {
- $('#snippetExportModalAccessToken').val(data.accesstoken)
- $('#snippetExportModalBaseURL').val(data.baseURL)
- $('#snippetExportModalVersion').val(data.version)
- $('#snippetExportModalLoading').hide()
- $('#snippetExportModal').modal('toggle')
- $('#snippetExportModalProjects').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Projects</option>')
- if (data.projects) {
- data.projects.sort(function (a, b) {
- return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0)
- })
- data.projects.forEach(function (project) {
- if (!project.snippets_enabled ||
+ .done(function (data) {
+ $('#snippetExportModalAccessToken').val(data.accesstoken)
+ $('#snippetExportModalBaseURL').val(data.baseURL)
+ $('#snippetExportModalVersion').val(data.version)
+ $('#snippetExportModalLoading').hide()
+ $('#snippetExportModal').modal('toggle')
+ $('#snippetExportModalProjects').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Projects</option>')
+ if (data.projects) {
+ data.projects.sort(function (a, b) {
+ return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0)
+ })
+ data.projects.forEach(function (project) {
+ if (!project.snippets_enabled ||
(project.permissions.project_access === null && project.permissions.group_access === null) ||
(project.permissions.project_access !== null && project.permissions.project_access.access_level < 20)) {
- return
- }
- $('<option>').val(project.id).text(project.path_with_namespace).appendTo('#snippetExportModalProjects')
- })
- $('#snippetExportModalProjects').prop('disabled', false)
+ return
}
- $('#snippetExportModalLoading').hide()
- })
- .fail(function (data) {
- showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Unable to fetch gitlab parameters :(', '', '', false)
- })
- .always(function () {
- ui.spinner.hide()
+ $('<option>').val(project.id).text(project.path_with_namespace).appendTo('#snippetExportModalProjects')
})
+ $('#snippetExportModalProjects').prop('disabled', false)
+ }
+ $('#snippetExportModalLoading').hide()
+ })
+ .fail(function (data) {
+ showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Unable to fetch gitlab parameters :(', '', '', false)
+ })
+ .always(function () {
+ ui.spinner.hide()
+ })
})
// import from dropbox
ui.toolbar.import.dropbox.click(function () {
@@ -1010,43 +1011,43 @@ ui.toolbar.import.dropbox.click(function () {
})
// import from gist
ui.toolbar.import.gist.click(function () {
- // na
+ // na
})
// import from snippet
ui.toolbar.import.snippet.click(function () {
ui.spinner.show()
$.get(serverurl + '/auth/gitlab/callback/' + noteid + '/projects')
- .done(function (data) {
- $('#snippetImportModalAccessToken').val(data.accesstoken)
- $('#snippetImportModalBaseURL').val(data.baseURL)
- $('#snippetImportModalVersion').val(data.version)
- $('#snippetImportModalContent').prop('disabled', false)
- $('#snippetImportModalConfirm').prop('disabled', false)
- $('#snippetImportModalLoading').hide()
- $('#snippetImportModal').modal('toggle')
- $('#snippetImportModalProjects').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Projects</option>')
- if (data.projects) {
- data.projects.sort(function (a, b) {
- return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0)
- })
- data.projects.forEach(function (project) {
- if (!project.snippets_enabled ||
+ .done(function (data) {
+ $('#snippetImportModalAccessToken').val(data.accesstoken)
+ $('#snippetImportModalBaseURL').val(data.baseURL)
+ $('#snippetImportModalVersion').val(data.version)
+ $('#snippetImportModalContent').prop('disabled', false)
+ $('#snippetImportModalConfirm').prop('disabled', false)
+ $('#snippetImportModalLoading').hide()
+ $('#snippetImportModal').modal('toggle')
+ $('#snippetImportModalProjects').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Projects</option>')
+ if (data.projects) {
+ data.projects.sort(function (a, b) {
+ return (a.path_with_namespace < b.path_with_namespace) ? -1 : ((a.path_with_namespace > b.path_with_namespace) ? 1 : 0)
+ })
+ data.projects.forEach(function (project) {
+ if (!project.snippets_enabled ||
(project.permissions.project_access === null && project.permissions.group_access === null) ||
(project.permissions.project_access !== null && project.permissions.project_access.access_level < 20)) {
- return
- }
- $('<option>').val(project.id).text(project.path_with_namespace).appendTo('#snippetImportModalProjects')
- })
- $('#snippetImportModalProjects').prop('disabled', false)
+ return
}
- $('#snippetImportModalLoading').hide()
- })
- .fail(function (data) {
- showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Unable to fetch gitlab parameters :(', '', '', false)
- })
- .always(function () {
- ui.spinner.hide()
+ $('<option>').val(project.id).text(project.path_with_namespace).appendTo('#snippetImportModalProjects')
})
+ $('#snippetImportModalProjects').prop('disabled', false)
+ }
+ $('#snippetImportModalLoading').hide()
+ })
+ .fail(function (data) {
+ showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Unable to fetch gitlab parameters :(', '', '', false)
+ })
+ .always(function () {
+ ui.spinner.hide()
+ })
})
// toc
ui.toc.dropdown.click(function (e) {
@@ -1069,18 +1070,19 @@ var revision = null
var revisionTime = null
ui.modal.revision.on('show.bs.modal', function (e) {
$.get(noteurl + '/revision')
- .done(function (data) {
- parseRevisions(data.revision)
- initRevisionViewer()
- })
- .fail(function (err) {
- if (debug) {
- console.log(err)
- }
- })
- .always(function () {
- // na
- })
+ .done(function (data) {
+ parseRevisions(data.revision)
+ initRevisionViewer()
+ })
+ .fail(function (err) {
+ if (debug) {
+ // eslint-disable-next-line no-console
+ console.debug(err)
+ }
+ })
+ .always(function () {
+ // na
+ })
})
function checkRevisionViewer () {
if (revisionViewer) {
@@ -1123,74 +1125,75 @@ function parseRevisions (_revisions) {
function selectRevision (time) {
if (time === revisionTime) return
$.get(noteurl + '/revision/' + time)
- .done(function (data) {
- revision = data
- revisionTime = time
- var lastScrollInfo = revisionViewer.getScrollInfo()
- revisionList.children().removeClass('active')
- revisionList.find('[data-revision-time="' + time + '"]').addClass('active')
- var content = revision.content
- revisionViewer.setValue(content)
- revisionViewer.scrollTo(null, lastScrollInfo.top)
- revisionInsert = []
- revisionDelete = []
- // mark the text which have been insert or delete
- if (revision.patch.length > 0) {
- var bias = 0
- for (var j = 0; j < revision.patch.length; j++) {
- var patch = revision.patch[j]
- var currIndex = patch.start1 + bias
- for (var i = 0; i < patch.diffs.length; i++) {
- var diff = patch.diffs[i]
- // ignore if diff only contains line breaks
- if ((diff[1].match(/\n/g) || []).length === diff[1].length) continue
- var prePos
- var postPos
- switch (diff[0]) {
- case 0: // retain
- currIndex += diff[1].length
- break
- case 1: // insert
- prePos = revisionViewer.posFromIndex(currIndex)
- postPos = revisionViewer.posFromIndex(currIndex + diff[1].length)
- revisionInsert.push({
- from: prePos,
- to: postPos
- })
- revisionViewer.markText(prePos, postPos, {
- css: 'background-color: rgba(230,255,230,0.7); text-decoration: underline;'
- })
- currIndex += diff[1].length
- break
- case -1: // delete
- prePos = revisionViewer.posFromIndex(currIndex)
- revisionViewer.replaceRange(diff[1], prePos)
- postPos = revisionViewer.posFromIndex(currIndex + diff[1].length)
- revisionDelete.push({
- from: prePos,
- to: postPos
- })
- revisionViewer.markText(prePos, postPos, {
- css: 'background-color: rgba(255,230,230,0.7); text-decoration: line-through;'
- })
- bias += diff[1].length
- currIndex += diff[1].length
- break
- }
- }
+ .done(function (data) {
+ revision = data
+ revisionTime = time
+ var lastScrollInfo = revisionViewer.getScrollInfo()
+ revisionList.children().removeClass('active')
+ revisionList.find('[data-revision-time="' + time + '"]').addClass('active')
+ var content = revision.content
+ revisionViewer.setValue(content)
+ revisionViewer.scrollTo(null, lastScrollInfo.top)
+ revisionInsert = []
+ revisionDelete = []
+ // mark the text which have been insert or delete
+ if (revision.patch.length > 0) {
+ var bias = 0
+ for (var j = 0; j < revision.patch.length; j++) {
+ var patch = revision.patch[j]
+ var currIndex = patch.start1 + bias
+ for (var i = 0; i < patch.diffs.length; i++) {
+ var diff = patch.diffs[i]
+ // ignore if diff only contains line breaks
+ if ((diff[1].match(/\n/g) || []).length === diff[1].length) continue
+ var prePos
+ var postPos
+ switch (diff[0]) {
+ case 0: // retain
+ currIndex += diff[1].length
+ break
+ case 1: // insert
+ prePos = revisionViewer.posFromIndex(currIndex)
+ postPos = revisionViewer.posFromIndex(currIndex + diff[1].length)
+ revisionInsert.push({
+ from: prePos,
+ to: postPos
+ })
+ revisionViewer.markText(prePos, postPos, {
+ css: 'background-color: rgba(230,255,230,0.7); text-decoration: underline;'
+ })
+ currIndex += diff[1].length
+ break
+ case -1: // delete
+ prePos = revisionViewer.posFromIndex(currIndex)
+ revisionViewer.replaceRange(diff[1], prePos)
+ postPos = revisionViewer.posFromIndex(currIndex + diff[1].length)
+ revisionDelete.push({
+ from: prePos,
+ to: postPos
+ })
+ revisionViewer.markText(prePos, postPos, {
+ css: 'background-color: rgba(255,230,230,0.7); text-decoration: line-through;'
+ })
+ bias += diff[1].length
+ currIndex += diff[1].length
+ break
}
}
- revisionInsertAnnotation.update(revisionInsert)
- revisionDeleteAnnotation.update(revisionDelete)
- })
- .fail(function (err) {
- if (debug) {
- console.log(err)
- }
- })
- .always(function () {
- // na
- })
+ }
+ }
+ revisionInsertAnnotation.update(revisionInsert)
+ revisionDeleteAnnotation.update(revisionDelete)
+ })
+ .fail(function (err) {
+ if (debug) {
+ // eslint-disable-next-line no-console
+ console.debug(err)
+ }
+ })
+ .always(function () {
+ // na
+ })
}
function initRevisionViewer () {
if (revisionViewer) return
@@ -1235,22 +1238,23 @@ ui.modal.snippetImportProjects.change(function () {
$('#snippetImportModalLoading').show()
$('#snippetImportModalContent').val('/projects/' + project)
$.get(baseURL + '/api/' + version + '/projects/' + project + '/snippets?access_token=' + accesstoken)
- .done(function (data) {
- $('#snippetImportModalSnippets').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Snippets</option>')
- data.forEach(function (snippet) {
- $('<option>').val(snippet.id).text(snippet.title).appendTo($('#snippetImportModalSnippets'))
- })
- $('#snippetImportModalLoading').hide()
- $('#snippetImportModalSnippets').prop('disabled', false)
- })
- .fail(function (err) {
- if (debug) {
- console.log(err)
- }
- })
- .always(function () {
- // na
- })
+ .done(function (data) {
+ $('#snippetImportModalSnippets').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Snippets</option>')
+ data.forEach(function (snippet) {
+ $('<option>').val(snippet.id).text(snippet.title).appendTo($('#snippetImportModalSnippets'))
+ })
+ $('#snippetImportModalLoading').hide()
+ $('#snippetImportModalSnippets').prop('disabled', false)
+ })
+ .fail(function (err) {
+ if (debug) {
+ // eslint-disable-next-line no-console
+ console.debug(err)
+ }
+ })
+ .always(function () {
+ // na
+ })
})
// snippet snippets
ui.modal.snippetImportSnippets.change(function () {
@@ -1310,8 +1314,8 @@ function generateScrollspy () {
ui.toc.affix.hide()
ui.toc.toc.show()
}
- // $(document.body).scroll();
- // ui.area.view.scroll();
+ // $(document.body).scroll();
+ // ui.area.view.scroll();
}
function updateScrollspy () {
@@ -1321,10 +1325,10 @@ function updateScrollspy () {
headerMap.push($(headers[i]).offset().top - parseInt($(headers[i]).css('margin-top')))
}
applyScrollspyActive($(window).scrollTop(), headerMap, headers,
- $('.scrollspy-body'), 0)
+ $('.scrollspy-body'), 0)
var offset = ui.area.view.scrollTop() - ui.area.view.offset().top
applyScrollspyActive(ui.area.view.scrollTop(), headerMap, headers,
- $('.scrollspy-view'), offset - 10)
+ $('.scrollspy-view'), offset - 10)
}
function applyScrollspyActive (top, headerMap, headers, target, offset) {
@@ -1380,26 +1384,26 @@ $('#gistImportModalConfirm').click(function () {
} else {
ui.spinner.show()
$.get('https://api.github.com/gists/' + url('-1', gisturl))
- .done(function (data) {
- if (data.files) {
- var contents = ''
- Object.keys(data.files).forEach(function (key) {
- contents += key
- contents += '\n---\n'
- contents += data.files[key].content
- contents += '\n\n'
- })
- replaceAll(contents)
- } else {
- showMessageModal('<i class="fa fa-github"></i> Import from Gist', 'Unable to fetch gist files :(', '', '', false)
- }
- })
- .fail(function (data) {
- showMessageModal('<i class="fa fa-github"></i> Import from Gist', 'Not a valid Gist URL :(', '', JSON.stringify(data), false)
- })
- .always(function () {
- ui.spinner.hide()
- })
+ .done(function (data) {
+ if (data.files) {
+ var contents = ''
+ Object.keys(data.files).forEach(function (key) {
+ contents += key
+ contents += '\n---\n'
+ contents += data.files[key].content
+ contents += '\n\n'
+ })
+ replaceAll(contents)
+ } else {
+ showMessageModal('<i class="fa fa-github"></i> Import from Gist', 'Unable to fetch gist files :(', '', '', false)
+ }
+ })
+ .fail(function (data) {
+ showMessageModal('<i class="fa fa-github"></i> Import from Gist', 'Not a valid Gist URL :(', '', JSON.stringify(data), false)
+ })
+ .always(function () {
+ ui.spinner.hide()
+ })
}
}
})
@@ -1423,34 +1427,34 @@ $('#snippetImportModalConfirm').click(function () {
var accessToken = '?access_token=' + $('#snippetImportModalAccessToken').val()
var fullURL = $('#snippetImportModalBaseURL').val() + '/api/' + $('#snippetImportModalVersion').val() + snippeturl
$.get(fullURL + accessToken)
- .done(function (data) {
- var content = '# ' + (data.title || 'Snippet Import')
- var fileInfo = data.file_name.split('.')
- fileInfo[1] = (fileInfo[1]) ? fileInfo[1] : 'md'
- $.get(fullURL + '/raw' + accessToken)
- .done(function (raw) {
- if (raw) {
- content += '\n\n'
- if (fileInfo[1] !== 'md') {
- content += '```' + fileTypes[fileInfo[1]] + '\n'
- }
- content += raw
- if (fileInfo[1] !== 'md') {
- content += '\n```'
- }
- replaceAll(content)
- }
- })
- .fail(function (data) {
- showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Not a valid Snippet URL :(', '', JSON.stringify(data), false)
- })
- .always(function () {
- ui.spinner.hide()
- })
- })
- .fail(function (data) {
- showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Not a valid Snippet URL :(', '', JSON.stringify(data), false)
- })
+ .done(function (data) {
+ var content = '# ' + (data.title || 'Snippet Import')
+ var fileInfo = data.file_name.split('.')
+ fileInfo[1] = (fileInfo[1]) ? fileInfo[1] : 'md'
+ $.get(fullURL + '/raw' + accessToken)
+ .done(function (raw) {
+ if (raw) {
+ content += '\n\n'
+ if (fileInfo[1] !== 'md') {
+ content += '```' + fileTypes[fileInfo[1]] + '\n'
+ }
+ content += raw
+ if (fileInfo[1] !== 'md') {
+ content += '\n```'
+ }
+ replaceAll(content)
+ }
+ })
+ .fail(function (data) {
+ showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Not a valid Snippet URL :(', '', JSON.stringify(data), false)
+ })
+ .always(function () {
+ ui.spinner.hide()
+ })
+ })
+ .fail(function (data) {
+ showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Not a valid Snippet URL :(', '', JSON.stringify(data), false)
+ })
}
})
@@ -1472,14 +1476,14 @@ $('#snippetExportModalConfirm').click(function () {
$('#snippetExportModalLoading').show()
var fullURL = baseURL + '/api/' + version + '/projects/' + $('#snippetExportModalProjects').val() + '/snippets?access_token=' + accesstoken
$.post(fullURL
- , data
- , function (ret) {
- $('#snippetExportModalLoading').hide()
- $('#snippetExportModal').modal('hide')
- var redirect = baseURL + '/' + $("#snippetExportModalProjects option[value='" + $('#snippetExportModalProjects').val() + "']").text() + '/snippets/' + ret.id
- showMessageModal('<i class="fa fa-gitlab"></i> Export to Snippet', 'Export Successful!', redirect, 'View Snippet Here', true)
- }
- )
+ , data
+ , function (ret) {
+ $('#snippetExportModalLoading').hide()
+ $('#snippetExportModal').modal('hide')
+ var redirect = baseURL + '/' + $("#snippetExportModalProjects option[value='" + $('#snippetExportModalProjects').val() + "']").text() + '/snippets/' + ret.id
+ showMessageModal('<i class="fa fa-gitlab"></i> Export to Snippet', 'Export Successful!', redirect, 'View Snippet Here', true)
+ }
+ )
})
function parseToEditor (data) {
@@ -1503,7 +1507,7 @@ function replaceAll (data) {
}
function importFromUrl (url) {
- // console.log(url);
+ // console.debug(url);
if (!url) return
if (!isValidURL(url)) {
showMessageModal('<i class="fa fa-cloud-download"></i> Import from URL', 'Not a valid URL :(', '', '', false)
@@ -1741,7 +1745,7 @@ socket.on('disconnect', function (data) {
}
})
socket.on('reconnect', function (data) {
- // sync back any change in offline
+ // sync back any change in offline
emitUserStatus(true)
cursorActivity(editor)
socket.emit('online users')
@@ -1768,7 +1772,7 @@ var authorship = []
var authorMarks = {} // temp variable
var addTextMarkers = [] // temp variable
function updateInfo (data) {
- // console.log(data);
+ // console.debug(data);
if (data.hasOwnProperty('createtime') && window.createtime !== data.createtime) {
window.createtime = data.createtime
updateLastChange()
@@ -1831,7 +1835,7 @@ var addStyleRule = (function () {
}
}())
function updateAuthorshipInner () {
- // ignore when ot not synced yet
+ // ignore when ot not synced yet
if (havePendingOperation()) return
authorMarks = {}
for (let i = 0; i < authorship.length; i++) {
@@ -1993,7 +1997,7 @@ editorInstance.on('update', function () {
})
})
socket.on('check', function (data) {
- // console.log(data);
+ // console.debug(data);
updateInfo(data)
})
socket.on('permission', function (data) {
@@ -2002,13 +2006,13 @@ socket.on('permission', function (data) {
var permission = null
socket.on('refresh', function (data) {
- // console.log(data);
+ // console.debug(data);
editorInstance.config.docmaxlength = data.docmaxlength
editor.setOption('maxLength', editorInstance.config.docmaxlength)
updateInfo(data)
updatePermission(data.permission)
if (!window.loaded) {
- // auto change mode if no content detected
+ // auto change mode if no content detected
var nocontent = editor.getValue().length <= 0
if (nocontent) {
if (visibleXS) { appState.currentMode = modeType.edit } else { appState.currentMode = modeType.both }
@@ -2147,7 +2151,7 @@ socket.on('cursor focus', function (data) {
}
}
if (data.id !== socket.id) { buildCursor(data) }
- // force show
+ // force show
var cursor = $('div[data-clientid="' + data.id + '"]')
if (cursor.length > 0) {
cursor.stop(true).fadeIn()
@@ -2170,7 +2174,7 @@ socket.on('cursor blur', function (data) {
}
}
if (data.id !== socket.id) { buildCursor(data) }
- // force hide
+ // force hide
var cursor = $('div[data-clientid="' + data.id + '"]')
if (cursor.length > 0) {
cursor.stop(true).fadeOut()
@@ -2194,7 +2198,7 @@ function updateOnlineStatus () {
var _onlineUsers = deduplicateOnlineUsers(onlineUsers)
showStatus(statusType.online, _onlineUsers.length)
var items = onlineUserList.items
- // update or remove current list items
+ // update or remove current list items
for (let i = 0; i < items.length; i++) {
let found = false
let foundindex = null
@@ -2214,7 +2218,7 @@ function updateOnlineStatus () {
shortOnlineUserList.remove('id', id)
}
}
- // add not in list items
+ // add not in list items
for (let i = 0; i < _onlineUsers.length; i++) {
let found = false
for (let j = 0; j < items.length; j++) {
@@ -2228,16 +2232,16 @@ function updateOnlineStatus () {
shortOnlineUserList.add(_onlineUsers[i])
}
}
- // sorting
+ // sorting
sortOnlineUserList(onlineUserList)
sortOnlineUserList(shortOnlineUserList)
- // render list items
+ // render list items
renderUserStatusList(onlineUserList)
renderUserStatusList(shortOnlineUserList)
}
function sortOnlineUserList (list) {
- // sort order by isSelf, login state, idle state, alphabet name, color brightness
+ // sort order by isSelf, login state, idle state, alphabet name, color brightness
list.sort('', {
sortFunction: function (a, b) {
var usera = a.values()
@@ -2273,7 +2277,7 @@ function renderUserStatusList (list) {
var 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
+ // add 1px more to right, make it feel aligned
usericon.css('margin-right', '6px')
$(item.elm).css('border-left', '4px solid ' + item.values().color)
usericon.css('margin-left', '-4px')
@@ -2554,15 +2558,15 @@ editorInstance.on('beforeChange', function (cm, change) {
if (cmClient && !socket.connected) { cmClient.editorAdapter.ignoreNextChange = true }
})
editorInstance.on('cut', function () {
- // na
+ // na
})
editorInstance.on('paste', function () {
- // na
+ // na
})
editorInstance.on('changes', function (editor, changes) {
updateHistory()
var docLength = editor.getValue().length
- // workaround for big documents
+ // workaround for big documents
var newViewportMargin = 20
if (docLength > 20000) {
newViewportMargin = 1
@@ -2747,7 +2751,7 @@ function updateViewInner () {
var slides = window.RevealMarkdown.slidify(editor.getValue(), slideOptions)
ui.area.markdown.html(slides)
window.RevealMarkdown.initialize()
- // prevent XSS
+ // prevent XSS
ui.area.markdown.html(preventXSS(ui.area.markdown.html()))
ui.area.markdown.addClass('slides')
appState.syncscroll = false
@@ -2759,12 +2763,12 @@ function updateViewInner () {
appState.syncscroll = true
checkSyncToggle()
}
- // only render again when meta changed
+ // 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'))
rendered = md.render(value)
}
- // prevent XSS
+ // prevent XSS
rendered = preventXSS(rendered)
var result = postProcess(rendered).children().toArray()
partialUpdate(result, lastResult, ui.area.markdown.children().toArray())
@@ -2784,7 +2788,7 @@ function updateViewInner () {
smoothHashScroll()
isDirty = false
clearMap()
- // buildMap();
+ // buildMap();
updateTitleReminder()
if (postUpdateEvent && typeof postUpdateEvent === 'function') { postUpdateEvent() }
}
@@ -2798,7 +2802,7 @@ function updateHistoryInner () {
}
function updateDataAttrs (src, des) {
- // sync data attr startline and endline
+ // sync data attr startline and endline
for (var i = 0; i < src.length; i++) {
copyAttribute(src[i], des[i], 'data-startline')
copyAttribute(src[i], des[i], 'data-endline')
@@ -2817,8 +2821,8 @@ function partialUpdate (src, tar, des) {
var rawSrc = cloneAndRemoveDataAttr(src[i])
var rawTar = cloneAndRemoveDataAttr(tar[i])
if (rawSrc.outerHTML !== rawTar.outerHTML) {
- // console.log(rawSrc);
- // console.log(rawTar);
+ // console.debug(rawSrc);
+ // console.debug(rawTar);
$(des[i]).replaceWith(src[i])
}
}
@@ -2826,8 +2830,8 @@ function partialUpdate (src, tar, des) {
var 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');
+ // copyAttribute(src[i], des[i], 'data-startline');
+ // copyAttribute(src[i], des[i], 'data-endline');
let rawSrc = cloneAndRemoveDataAttr(src[i])
let rawTar = cloneAndRemoveDataAttr(tar[i])
if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) {
@@ -2835,12 +2839,12 @@ function partialUpdate (src, tar, des) {
break
}
}
- // find diff end position
+ // find diff end position
var srcEnd = 0
var tarEnd = 0
for (let i = 0; i < src.length; i++) {
- // copyAttribute(src[i], des[i], 'data-startline');
- // copyAttribute(src[i], des[i], 'data-endline');
+ // copyAttribute(src[i], des[i], 'data-startline');
+ // copyAttribute(src[i], des[i], 'data-endline');
let rawSrc = cloneAndRemoveDataAttr(src[i])
let rawTar = cloneAndRemoveDataAttr(tar[i])
if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) {
@@ -2848,12 +2852,12 @@ function partialUpdate (src, tar, des) {
break
}
}
- // tar end
+ // tar end
for (let i = 1; i <= tar.length + 1; i++) {
let srcLength = src.length
let tarLength = tar.length
- // copyAttribute(src[srcLength - i], des[srcLength - i], 'data-startline');
- // copyAttribute(src[srcLength - i], des[srcLength - i], 'data-endline');
+ // 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])
if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) {
@@ -2861,12 +2865,12 @@ function partialUpdate (src, tar, des) {
break
}
}
- // src end
+ // src end
for (let i = 1; i <= src.length + 1; i++) {
let srcLength = src.length
let tarLength = tar.length
- // copyAttribute(src[srcLength - i], des[srcLength - i], 'data-startline');
- // copyAttribute(src[srcLength - i], des[srcLength - i], 'data-endline');
+ // 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])
if (!rawSrc || !rawTar || rawSrc.outerHTML !== rawTar.outerHTML) {
@@ -2874,25 +2878,25 @@ function partialUpdate (src, tar, des) {
break
}
}
- // check if tar end overlap tar start
+ // 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 }
}
- if (debug) { console.log('overlap:' + overlap) }
- // show diff content
+ if (debug) { console.debug('overlap:' + overlap) }
+ // show diff content
if (debug) {
- console.log('start:' + start)
- console.log('tarEnd:' + tarEnd)
- console.log('srcEnd:' + srcEnd)
+ console.debug('start:' + start)
+ console.debug('tarEnd:' + tarEnd)
+ console.debug('srcEnd:' + srcEnd)
}
tarEnd += overlap
srcEnd += overlap
var repeatAdd = (start - srcEnd) < (start - tarEnd)
var repeatDiff = Math.abs(srcEnd - tarEnd) - 1
- // push new elements
+ // push new elements
var newElements = []
if (srcEnd >= start) {
for (let j = start; j <= srcEnd; j++) {
@@ -2905,7 +2909,7 @@ function partialUpdate (src, tar, des) {
newElements.push(des[j].outerHTML)
}
}
- // push remove elements
+ // push remove elements
var removeElements = []
if (tarEnd >= start) {
for (let j = start; j <= tarEnd; j++) {
@@ -2918,17 +2922,17 @@ function partialUpdate (src, tar, des) {
removeElements.push(des[j])
}
}
- // add elements
+ // add elements
if (debug) {
- console.log('ADD ELEMENTS')
- console.log(newElements.join('\n'))
+ console.debug('ADD ELEMENTS')
+ console.debug(newElements.join('\n'))
}
if (des[start]) { $(newElements.join('')).insertBefore(des[start]) } else { $(newElements.join('')).insertAfter(des[start - 1]) }
- // remove elements
- if (debug) { console.log('REMOVE ELEMENTS') }
+ // remove elements
+ if (debug) { console.debug('REMOVE ELEMENTS') }
for (let j = 0; j < removeElements.length; j++) {
if (debug) {
- console.log(removeElements[j].outerHTML)
+ console.debug(removeElements[j].outerHTML)
}
if (removeElements[j]) { $(removeElements[j]).remove() }
}
@@ -2962,50 +2966,50 @@ function reverseSortCursorMenu (dropdown) {
var checkCursorMenu = _.throttle(checkCursorMenuInner, cursorMenuThrottle)
function checkCursorMenuInner () {
- // get element
+ // get element
var dropdown = $('.cursor-menu > .dropdown-menu')
- // return if not exists
+ // return if not exists
if (dropdown.length <= 0) return
- // set margin
+ // set margin
var menuRightMargin = 10
var menuBottomMargin = 4
- // 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()
- // get editor size (status bar not count in)
+ // get editor size (status bar not count in)
var editorHeight = ui.area.codemirror.height()
- // get element size
+ // get element size
var width = dropdown.outerWidth()
var height = dropdown.outerHeight()
- // get cursor
+ // get cursor
var cursor = editor.getCursor()
- // set element cursor data
+ // set element cursor data
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
+ // get coord position
var coord = editor.charCoords({
line: cursor.line,
ch: cursor.ch
}, 'windows')
var left = coord.left
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
- // set offset
+ // set offset
var offsetLeft = 0
var offsetTop = defaultTextHeight
- // set up side down
+ // set up side down
window.upSideDown = false
var lastUpSideDown = window.upSideDown = false
- // only do when have width and height
+ // only do when have width and height
if (width > 0 && height > 0) {
- // make element right bound not larger than doc width
+ // make element right bound not larger than doc width
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
+ // 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) {
offsetTop = -(height + menuBottomMargin)
- // reverse sort menu because upSideDown
+ // reverse sort menu because upSideDown
dropdown.html(reverseSortCursorMenu(dropdown))
window.upSideDown = true
}
@@ -3013,18 +3017,18 @@ function checkCursorMenuInner () {
lastUpSideDown = textCompleteDropdown.upSideDown
textCompleteDropdown.upSideDown = window.upSideDown
}
- // make menu scroll top only if upSideDown changed
+ // make menu scroll top only if upSideDown changed
if (window.upSideDown !== lastUpSideDown) { dropdown.scrollTop(dropdown[0].scrollHeight) }
- // set element offset data
+ // set element offset data
dropdown.attr('data-offset-left', offsetLeft)
dropdown.attr('data-offset-top', offsetTop)
- // set position
+ // set position
dropdown[0].style.left = left + offsetLeft + 'px'
dropdown[0].style.top = top + offsetTop + 'px'
}
function checkInIndentCode () {
- // if line starts with tab or four spaces is a code block
+ // 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'))
return isIndentCode
@@ -3043,7 +3047,7 @@ function checkAbove (method) {
text.push(editor.getLine(i))
}
text = text.join('\n') + '\n' + editor.getLine(cursor.line).slice(0, cursor.ch)
- // console.log(text);
+ // console.debug(text);
return method(text)
}
@@ -3055,7 +3059,7 @@ function checkBelow (method) {
text.push(editor.getLine(i))
}
text = editor.getLine(cursor.line).slice(cursor.ch) + '\n' + text.join('\n')
- // console.log(text);
+ // console.debug(text);
return method(text)
}
@@ -3082,7 +3086,7 @@ function checkInContainer () {
}
function checkInContainerSyntax () {
- // if line starts with :::, it's in container syntax
+ // if line starts with :::, it's in container syntax
var line = editor.getLine(editor.getCursor().line)
isInContainerSyntax = (line.substr(0, 3) === ':::')
}
@@ -3098,229 +3102,229 @@ 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 '<img class="emoji" src="' + serverurl + '/build/emojify.js/dist/images/basic/' + value + '.png"></img> ' + 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```'
+ .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)
}
- 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.log(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:::'
+ })
+ $.map(window.emojify.emojiNames, function (emoji) {
+ if (emoji.indexOf(term) !== -1) { // match inside the word
+ list.push(emoji)
}
- 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.log(text);
- if (text === '\n:::') { editor.doc.cm.execCommand('goLineUp') }
- },
- context: function (text) {
- return !isInCode && isInContainer
+ })
+ callback(list)
+ },
+ template: function (value) {
+ return '<img class="emoji" src="' + serverurl + '/build/emojify.js/dist/images/basic/' + value + '.png"></img> ' + 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 }
},
- { // 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
+ 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
},
- { // extra tags for list
- match: /(^[>\s]*[-+*]\s(?:\[[x ]\]|.*))(\[\])(\w*)$/,
- search: function (term, callback) {
- var list = []
+ 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()) }
})
- $.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()) }
- })
- }
- $.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
}
+ $.map(supportReferrals, function (referral) {
+ if (referral.search.indexOf(term) === 0) { list.push(referral.text) }
+ })
+ callback(list)
},
- { // 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
- }
+ replace: function (value) {
+ return '$1' + value
},
- { // 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
- }
+ context: function (text) {
+ return !isInCode
}
- ], {
- appendTo: $('.cursor-menu')
- })
- .on({
- 'textComplete:beforeSearch': function (e) {
- // NA
+ },
+ { // 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
+ }))
},
- 'textComplete:afterSearch': function (e) {
- checkCursorMenu()
+ replace: function (value) {
+ return '$1' + value
},
- 'textComplete:select': function (e, value, strategy) {
- // NA
+ 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
+ }))
},
- 'textComplete:show': function (e) {
- $(this).data('autocompleting', true)
- editor.setOption('extraKeys', {
- 'Up': function () {
- return false
- },
- 'Right': function () {
- editor.doc.cm.execCommand('goCharRight')
- },
- 'Down': function () {
- return false
- },
- 'Left': function () {
- editor.doc.cm.execCommand('goCharLeft')
- },
- 'Enter': function () {
- return false
- },
- 'Backspace': function () {
- editor.doc.cm.execCommand('delCharBefore')
- }
- })
+ replace: function (value) {
+ return '$1' + value
},
- 'textComplete:hide': function (e) {
- $(this).data('autocompleting', false)
- editor.setOption('extraKeys', editorInstance.defaultExtraKeys)
+ context: function (text) {
+ return !isInCode
}
- })
+ }
+ ], {
+ appendTo: $('.cursor-menu')
+ })
+ .on({
+ 'textComplete:beforeSearch': function (e) {
+ // NA
+ },
+ 'textComplete:afterSearch': function (e) {
+ checkCursorMenu()
+ },
+ 'textComplete:select': function (e, value, strategy) {
+ // NA
+ },
+ 'textComplete:show': function (e) {
+ $(this).data('autocompleting', true)
+ editor.setOption('extraKeys', {
+ 'Up': function () {
+ return false
+ },
+ 'Right': function () {
+ editor.doc.cm.execCommand('goCharRight')
+ },
+ 'Down': function () {
+ return false
+ },
+ 'Left': function () {
+ editor.doc.cm.execCommand('goCharLeft')
+ },
+ 'Enter': function () {
+ return false
+ },
+ 'Backspace': function () {
+ editor.doc.cm.execCommand('delCharBefore')
+ }
+ })
+ },
+ 'textComplete:hide': function (e) {
+ $(this).data('autocompleting', false)
+ editor.setOption('extraKeys', editorInstance.defaultExtraKeys)
+ }
+ })
diff --git a/public/js/lib/common/login.js b/public/js/lib/common/login.js
index 18cd377d..28e5b470 100644
--- a/public/js/lib/common/login.js
+++ b/public/js/lib/common/login.js
@@ -60,22 +60,22 @@ export function checkIfAuth (yesCallback, noCallback) {
if (checkLoginStateChanged()) checkAuth = false
if (!checkAuth || typeof cookieLoginState === 'undefined') {
$.get(`${serverurl}/me`)
- .done(data => {
- if (data && data.status === 'ok') {
- profile = data
- yesCallback(profile)
- setLoginState(true, data.id)
- } else {
- noCallback()
- setLoginState(false)
- }
- })
- .fail(() => {
- noCallback()
- })
- .always(() => {
- checkAuth = true
- })
+ .done(data => {
+ if (data && data.status === 'ok') {
+ profile = data
+ yesCallback(profile)
+ setLoginState(true, data.id)
+ } else {
+ noCallback()
+ setLoginState(false)
+ }
+ })
+ .fail(() => {
+ noCallback()
+ })
+ .always(() => {
+ checkAuth = true
+ })
} else if (cookieLoginState) {
yesCallback(profile)
} else {
diff --git a/public/js/lib/editor/utils.js b/public/js/lib/editor/utils.js
index 36e5c121..d87c7e41 100644
--- a/public/js/lib/editor/utils.js
+++ b/public/js/lib/editor/utils.js
@@ -51,7 +51,7 @@ export function insertText (cm, text, cursorEnd = 0) {
let cursor = cm.getCursor()
cm.replaceSelection(text, cursor, cursor)
cm.focus()
- cm.setCursor({line: cursor.line, ch: cursor.ch + cursorEnd})
+ cm.setCursor({ line: cursor.line, ch: cursor.ch + cursorEnd })
}
export function insertLink (cm, isImage) {
@@ -80,7 +80,7 @@ export function insertLink (cm, isImage) {
cm.setSelections(ranges)
} else {
cm.replaceRange(symbol + linkEnd, cursor, cursor)
- cm.setCursor({line: cursor.line, ch: cursor.ch + symbol.length + linkEnd.length})
+ cm.setCursor({ line: cursor.line, ch: cursor.ch + symbol.length + linkEnd.length })
}
}
cm.focus()
@@ -88,8 +88,8 @@ 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})
+ let startOfLine = { line: cursor.line, ch: 0 }
+ let startOfLineText = cm.getRange(startOfLine, { line: cursor.line, ch: 1 })
// See if it is already a header
if (startOfLineText === '#') {
cm.replaceRange('#', startOfLine, startOfLine)
@@ -108,14 +108,14 @@ export function insertOnStartOfLines (cm, symbol) {
if (!range.empty()) {
const from = range.from()
const to = range.to()
- let selection = cm.getRange({line: from.line, ch: 0}, to)
+ let selection = cm.getRange({ line: from.line, ch: 0 }, to)
selection = selection.replace(/\n/g, '\n' + symbol)
selection = symbol + selection
cm.replaceRange(selection, from, to)
} else {
- cm.replaceRange(symbol, {line: cursor.line, ch: 0}, {line: cursor.line, ch: 0})
+ cm.replaceRange(symbol, { line: cursor.line, ch: 0 }, { line: cursor.line, ch: 0 })
}
}
- cm.setCursor({line: cursor.line, ch: cursor.ch + symbol.length})
+ cm.setCursor({ line: cursor.line, ch: cursor.ch + symbol.length })
cm.focus()
}
diff --git a/public/js/lib/syncscroll.js b/public/js/lib/syncscroll.js
index cee317ea..d492fbc9 100644
--- a/public/js/lib/syncscroll.js
+++ b/public/js/lib/syncscroll.js
@@ -188,7 +188,7 @@ function buildMapInner (callback) {
}
nonEmptyList.push(0)
- // make the first line go top
+ // make the first line go top
_scrollMap[0] = viewTop
const parts = markdownArea.find('.part').toArray()
@@ -336,7 +336,7 @@ export function syncScrollToView (event, preventAnimate) {
const scrollInfo = editor.getScrollInfo()
const textHeight = editor.defaultTextHeight()
lineNo = Math.floor(scrollInfo.top / textHeight)
- // if reach the last line, will start lerp to the bottom
+ // 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) {
topDiffPercent = diffToBottom / textHeight
diff --git a/public/js/pretty.js b/public/js/pretty.js
index ff6f9dfd..a5df0a47 100644
--- a/public/js/pretty.js
+++ b/public/js/pretty.js
@@ -1,29 +1,29 @@
/* eslint-env browser, jquery */
/* global refreshView */
+import {
+ autoLinkify,
+ deduplicatedHeaderId,
+ removeDOMEvents,
+ finishView,
+ generateToc,
+ md,
+ parseMeta,
+ postProcess,
+ renderTOC,
+ scrollToHash,
+ smoothHashScroll,
+ updateLastChange
+} from './extra'
+
+import { preventXSS } from './render'
+
require('../css/extra.css')
require('../css/slide-preview.css')
require('../css/site.css')
require('highlight.js/styles/github-gist.css')
-import {
- autoLinkify,
- deduplicatedHeaderId,
- removeDOMEvents,
- finishView,
- generateToc,
- md,
- parseMeta,
- postProcess,
- renderTOC,
- scrollToHash,
- smoothHashScroll,
- updateLastChange
-} from './extra'
-
-import { preventXSS } from './render'
-
const markdown = $('#doc.markdown-body')
const text = markdown.text()
const lastMeta = md.meta
@@ -38,7 +38,7 @@ if (md.meta.type && md.meta.type === 'slide') {
const slides = window.RevealMarkdown.slidify(text, slideOptions)
markdown.html(slides)
window.RevealMarkdown.initialize()
- // prevent XSS
+ // prevent XSS
markdown.html(preventXSS(markdown.html()))
markdown.addClass('slides')
} else {
@@ -46,12 +46,12 @@ if (md.meta.type && md.meta.type === 'slide') {
refreshView()
markdown.removeClass('slides')
}
- // only render again when meta changed
+ // only render again when meta changed
if (JSON.stringify(md.meta) !== JSON.stringify(lastMeta)) {
parseMeta(md, null, markdown, $('#ui-toc'), $('#ui-toc-affix'))
rendered = md.render(text)
}
- // prevent XSS
+ // prevent XSS
rendered = preventXSS(rendered)
const result = postProcess(rendered)
markdown.html(result.html())
@@ -98,14 +98,14 @@ function generateScrollspy () {
}
function windowResize () {
- // toc right
+ // toc right
const paddingRight = parseFloat(markdown.css('padding-right'))
const right = ($(window).width() - (markdown.offset().left + markdown.outerWidth() - paddingRight))
toc.css('right', `${right}px`)
- // affix toc left
+ // affix toc left
let newbool
const rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2
- // for ipad or wider device
+ // for ipad or wider device
if (rightMargin >= 133) {
newbool = true
const affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2
@@ -126,7 +126,7 @@ $(document).ready(() => {
windowResize()
generateScrollspy()
setTimeout(scrollToHash, 0)
- // tooltip
+ // tooltip
$('[data-toggle="tooltip"]').tooltip()
})
diff --git a/public/js/render.js b/public/js/render.js
index 87e5cfdf..d37f38ef 100644
--- a/public/js/render.js
+++ b/public/js/render.js
@@ -44,7 +44,7 @@ var filterXSSOptions = {
onIgnoreTag: function (tag, html, options) {
// allow comment tag
if (tag === '!--') {
- // do not filter its attributes
+ // do not filter its attributes
return html.replace(/<(?!!--)/g, '&lt;').replace(/-->/g, '__HTML_COMMENT_END__').replace(/>/g, '&gt;').replace(/__HTML_COMMENT_END__/g, '-->')
}
},
diff --git a/public/js/slide.js b/public/js/slide.js
index 1eb8dfd4..3a47ac43 100644
--- a/public/js/slide.js
+++ b/public/js/slide.js
@@ -1,12 +1,12 @@
/* eslint-env browser, jquery */
/* global serverurl, Reveal, RevealMarkdown */
-require('../css/extra.css')
-require('../css/site.css')
-
import { preventXSS } from './render'
import { md, updateLastChange, removeDOMEvents, finishView } from './extra'
+require('../css/extra.css')
+require('../css/site.css')
+
const body = preventXSS($('.slides').text())
window.createtime = window.lastchangeui.time.attr('data-createtime')
@@ -17,7 +17,7 @@ $('.ui-edit').attr('href', `${url}/edit`)
$('.ui-print').attr('href', `${url}?print-pdf`)
$(document).ready(() => {
- // tooltip
+ // tooltip
$('[data-toggle="tooltip"]').tooltip()
})
@@ -127,7 +127,7 @@ function renderSlide (event) {
Reveal.addEventListener('ready', event => {
renderSlide(event)
const markdown = $(event.currentSlide)
- // force browser redraw
+ // force browser redraw
setTimeout(() => {
markdown.hide().show(0)
}, 0)