Merge branch 'use_javascript_standard_style'
Introduce JavaScript Standard Style Signed-off-by: BoHong Li <a60814billy@gmail.com>
This commit is contained in:
commit
befa89be8b
40 changed files with 10529 additions and 10834 deletions
360
lib/auth.js
360
lib/auth.js
|
@ -1,190 +1,192 @@
|
||||||
//auth
|
// auth
|
||||||
//external modules
|
// external modules
|
||||||
var passport = require('passport');
|
var passport = require('passport')
|
||||||
var FacebookStrategy = require('passport-facebook').Strategy;
|
var FacebookStrategy = require('passport-facebook').Strategy
|
||||||
var TwitterStrategy = require('passport-twitter').Strategy;
|
var TwitterStrategy = require('passport-twitter').Strategy
|
||||||
var GithubStrategy = require('passport-github').Strategy;
|
var GithubStrategy = require('passport-github').Strategy
|
||||||
var GitlabStrategy = require('passport-gitlab2').Strategy;
|
var GitlabStrategy = require('passport-gitlab2').Strategy
|
||||||
var DropboxStrategy = require('passport-dropbox-oauth2').Strategy;
|
var DropboxStrategy = require('passport-dropbox-oauth2').Strategy
|
||||||
var GoogleStrategy = require('passport-google-oauth20').Strategy;
|
var GoogleStrategy = require('passport-google-oauth20').Strategy
|
||||||
var LdapStrategy = require('passport-ldapauth');
|
var LdapStrategy = require('passport-ldapauth')
|
||||||
var LocalStrategy = require('passport-local').Strategy;
|
var LocalStrategy = require('passport-local').Strategy
|
||||||
var validator = require('validator');
|
var validator = require('validator')
|
||||||
|
|
||||||
//core
|
// core
|
||||||
var config = require('./config.js');
|
var config = require('./config.js')
|
||||||
var logger = require("./logger.js");
|
var logger = require('./logger.js')
|
||||||
var models = require("./models");
|
var models = require('./models')
|
||||||
|
|
||||||
function callback(accessToken, refreshToken, profile, done) {
|
function callback (accessToken, refreshToken, profile, done) {
|
||||||
//logger.info(profile.displayName || profile.username);
|
// logger.info(profile.displayName || profile.username);
|
||||||
var stringifiedProfile = JSON.stringify(profile);
|
var stringifiedProfile = JSON.stringify(profile)
|
||||||
models.User.findOrCreate({
|
models.User.findOrCreate({
|
||||||
|
where: {
|
||||||
|
profileid: profile.id.toString()
|
||||||
|
},
|
||||||
|
defaults: {
|
||||||
|
profile: stringifiedProfile,
|
||||||
|
accessToken: accessToken,
|
||||||
|
refreshToken: refreshToken
|
||||||
|
}
|
||||||
|
}).spread(function (user, created) {
|
||||||
|
if (user) {
|
||||||
|
var needSave = false
|
||||||
|
if (user.profile !== stringifiedProfile) {
|
||||||
|
user.profile = stringifiedProfile
|
||||||
|
needSave = true
|
||||||
|
}
|
||||||
|
if (user.accessToken !== accessToken) {
|
||||||
|
user.accessToken = accessToken
|
||||||
|
needSave = true
|
||||||
|
}
|
||||||
|
if (user.refreshToken !== refreshToken) {
|
||||||
|
user.refreshToken = refreshToken
|
||||||
|
needSave = true
|
||||||
|
}
|
||||||
|
if (needSave) {
|
||||||
|
user.save().then(function () {
|
||||||
|
if (config.debug) { logger.info('user login: ' + user.id) }
|
||||||
|
return done(null, user)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (config.debug) { logger.info('user login: ' + user.id) }
|
||||||
|
return done(null, user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).catch(function (err) {
|
||||||
|
logger.error('auth callback failed: ' + err)
|
||||||
|
return done(err, null)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerAuthMethod () {
|
||||||
|
// facebook
|
||||||
|
if (config.facebook) {
|
||||||
|
passport.use(new FacebookStrategy({
|
||||||
|
clientID: config.facebook.clientID,
|
||||||
|
clientSecret: config.facebook.clientSecret,
|
||||||
|
callbackURL: config.serverurl + '/auth/facebook/callback'
|
||||||
|
}, callback))
|
||||||
|
}
|
||||||
|
// twitter
|
||||||
|
if (config.twitter) {
|
||||||
|
passport.use(new TwitterStrategy({
|
||||||
|
consumerKey: config.twitter.consumerKey,
|
||||||
|
consumerSecret: config.twitter.consumerSecret,
|
||||||
|
callbackURL: config.serverurl + '/auth/twitter/callback'
|
||||||
|
}, callback))
|
||||||
|
}
|
||||||
|
// github
|
||||||
|
if (config.github) {
|
||||||
|
passport.use(new GithubStrategy({
|
||||||
|
clientID: config.github.clientID,
|
||||||
|
clientSecret: config.github.clientSecret,
|
||||||
|
callbackURL: config.serverurl + '/auth/github/callback'
|
||||||
|
}, callback))
|
||||||
|
}
|
||||||
|
// gitlab
|
||||||
|
if (config.gitlab) {
|
||||||
|
passport.use(new GitlabStrategy({
|
||||||
|
baseURL: config.gitlab.baseURL,
|
||||||
|
clientID: config.gitlab.clientID,
|
||||||
|
clientSecret: config.gitlab.clientSecret,
|
||||||
|
callbackURL: config.serverurl + '/auth/gitlab/callback'
|
||||||
|
}, callback))
|
||||||
|
}
|
||||||
|
// dropbox
|
||||||
|
if (config.dropbox) {
|
||||||
|
passport.use(new DropboxStrategy({
|
||||||
|
apiVersion: '2',
|
||||||
|
clientID: config.dropbox.clientID,
|
||||||
|
clientSecret: config.dropbox.clientSecret,
|
||||||
|
callbackURL: config.serverurl + '/auth/dropbox/callback'
|
||||||
|
}, callback))
|
||||||
|
}
|
||||||
|
// google
|
||||||
|
if (config.google) {
|
||||||
|
passport.use(new GoogleStrategy({
|
||||||
|
clientID: config.google.clientID,
|
||||||
|
clientSecret: config.google.clientSecret,
|
||||||
|
callbackURL: config.serverurl + '/auth/google/callback'
|
||||||
|
}, callback))
|
||||||
|
}
|
||||||
|
// ldap
|
||||||
|
if (config.ldap) {
|
||||||
|
passport.use(new LdapStrategy({
|
||||||
|
server: {
|
||||||
|
url: config.ldap.url || null,
|
||||||
|
bindDn: config.ldap.bindDn || null,
|
||||||
|
bindCredentials: config.ldap.bindCredentials || null,
|
||||||
|
searchBase: config.ldap.searchBase || null,
|
||||||
|
searchFilter: config.ldap.searchFilter || null,
|
||||||
|
searchAttributes: config.ldap.searchAttributes || null,
|
||||||
|
tlsOptions: config.ldap.tlsOptions || null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (user, done) {
|
||||||
|
var profile = {
|
||||||
|
id: 'LDAP-' + user.uidNumber,
|
||||||
|
username: user.uid,
|
||||||
|
displayName: user.displayName,
|
||||||
|
emails: user.mail ? [user.mail] : [],
|
||||||
|
avatarUrl: null,
|
||||||
|
profileUrl: null,
|
||||||
|
provider: 'ldap'
|
||||||
|
}
|
||||||
|
var stringifiedProfile = JSON.stringify(profile)
|
||||||
|
models.User.findOrCreate({
|
||||||
where: {
|
where: {
|
||||||
profileid: profile.id.toString()
|
profileid: profile.id.toString()
|
||||||
},
|
},
|
||||||
defaults: {
|
defaults: {
|
||||||
profile: stringifiedProfile,
|
profile: stringifiedProfile
|
||||||
accessToken: accessToken,
|
|
||||||
refreshToken: refreshToken
|
|
||||||
}
|
}
|
||||||
}).spread(function (user, created) {
|
}).spread(function (user, created) {
|
||||||
if (user) {
|
if (user) {
|
||||||
var needSave = false;
|
var needSave = false
|
||||||
if (user.profile != stringifiedProfile) {
|
if (user.profile !== stringifiedProfile) {
|
||||||
user.profile = stringifiedProfile;
|
user.profile = stringifiedProfile
|
||||||
needSave = true;
|
needSave = true
|
||||||
}
|
}
|
||||||
if (user.accessToken != accessToken) {
|
if (needSave) {
|
||||||
user.accessToken = accessToken;
|
user.save().then(function () {
|
||||||
needSave = true;
|
if (config.debug) { logger.info('user login: ' + user.id) }
|
||||||
}
|
return done(null, user)
|
||||||
if (user.refreshToken != refreshToken) {
|
})
|
||||||
user.refreshToken = refreshToken;
|
} else {
|
||||||
needSave = true;
|
if (config.debug) { logger.info('user login: ' + user.id) }
|
||||||
}
|
return done(null, user)
|
||||||
if (needSave) {
|
}
|
||||||
user.save().then(function () {
|
|
||||||
if (config.debug)
|
|
||||||
logger.info('user login: ' + user.id);
|
|
||||||
return done(null, user);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (config.debug)
|
|
||||||
logger.info('user login: ' + user.id);
|
|
||||||
return done(null, user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
logger.error('auth callback failed: ' + err);
|
logger.error('ldap auth failed: ' + err)
|
||||||
return done(err, null);
|
return done(err, null)
|
||||||
});
|
})
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
// email
|
||||||
|
if (config.email) {
|
||||||
|
passport.use(new LocalStrategy({
|
||||||
|
usernameField: 'email'
|
||||||
|
},
|
||||||
|
function (email, password, done) {
|
||||||
|
if (!validator.isEmail(email)) return done(null, false)
|
||||||
|
models.User.findOne({
|
||||||
|
where: {
|
||||||
|
email: email
|
||||||
|
}
|
||||||
|
}).then(function (user) {
|
||||||
|
if (!user) return done(null, false)
|
||||||
|
if (!user.verifyPassword(password)) return done(null, false)
|
||||||
|
return done(null, user)
|
||||||
|
}).catch(function (err) {
|
||||||
|
logger.error(err)
|
||||||
|
return done(err)
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//facebook
|
module.exports = {
|
||||||
if (config.facebook) {
|
registerAuthMethod: registerAuthMethod
|
||||||
module.exports = passport.use(new FacebookStrategy({
|
|
||||||
clientID: config.facebook.clientID,
|
|
||||||
clientSecret: config.facebook.clientSecret,
|
|
||||||
callbackURL: config.serverurl + '/auth/facebook/callback'
|
|
||||||
}, callback));
|
|
||||||
}
|
|
||||||
//twitter
|
|
||||||
if (config.twitter) {
|
|
||||||
passport.use(new TwitterStrategy({
|
|
||||||
consumerKey: config.twitter.consumerKey,
|
|
||||||
consumerSecret: config.twitter.consumerSecret,
|
|
||||||
callbackURL: config.serverurl + '/auth/twitter/callback'
|
|
||||||
}, callback));
|
|
||||||
}
|
|
||||||
//github
|
|
||||||
if (config.github) {
|
|
||||||
passport.use(new GithubStrategy({
|
|
||||||
clientID: config.github.clientID,
|
|
||||||
clientSecret: config.github.clientSecret,
|
|
||||||
callbackURL: config.serverurl + '/auth/github/callback'
|
|
||||||
}, callback));
|
|
||||||
}
|
|
||||||
//gitlab
|
|
||||||
if (config.gitlab) {
|
|
||||||
passport.use(new GitlabStrategy({
|
|
||||||
baseURL: config.gitlab.baseURL,
|
|
||||||
clientID: config.gitlab.clientID,
|
|
||||||
clientSecret: config.gitlab.clientSecret,
|
|
||||||
callbackURL: config.serverurl + '/auth/gitlab/callback'
|
|
||||||
}, callback));
|
|
||||||
}
|
|
||||||
//dropbox
|
|
||||||
if (config.dropbox) {
|
|
||||||
passport.use(new DropboxStrategy({
|
|
||||||
apiVersion: '2',
|
|
||||||
clientID: config.dropbox.clientID,
|
|
||||||
clientSecret: config.dropbox.clientSecret,
|
|
||||||
callbackURL: config.serverurl + '/auth/dropbox/callback'
|
|
||||||
}, callback));
|
|
||||||
}
|
|
||||||
//google
|
|
||||||
if (config.google) {
|
|
||||||
passport.use(new GoogleStrategy({
|
|
||||||
clientID: config.google.clientID,
|
|
||||||
clientSecret: config.google.clientSecret,
|
|
||||||
callbackURL: config.serverurl + '/auth/google/callback'
|
|
||||||
}, callback));
|
|
||||||
}
|
|
||||||
// ldap
|
|
||||||
if (config.ldap) {
|
|
||||||
passport.use(new LdapStrategy({
|
|
||||||
server: {
|
|
||||||
url: config.ldap.url || null,
|
|
||||||
bindDn: config.ldap.bindDn || null,
|
|
||||||
bindCredentials: config.ldap.bindCredentials || null,
|
|
||||||
searchBase: config.ldap.searchBase || null,
|
|
||||||
searchFilter: config.ldap.searchFilter || null,
|
|
||||||
searchAttributes: config.ldap.searchAttributes || null,
|
|
||||||
tlsOptions: config.ldap.tlsOptions || null
|
|
||||||
},
|
|
||||||
},
|
|
||||||
function(user, done) {
|
|
||||||
var profile = {
|
|
||||||
id: 'LDAP-' + user.uidNumber,
|
|
||||||
username: user.uid,
|
|
||||||
displayName: user.displayName,
|
|
||||||
emails: user.mail ? [user.mail] : [],
|
|
||||||
avatarUrl: null,
|
|
||||||
profileUrl: null,
|
|
||||||
provider: 'ldap',
|
|
||||||
}
|
|
||||||
var stringifiedProfile = JSON.stringify(profile);
|
|
||||||
models.User.findOrCreate({
|
|
||||||
where: {
|
|
||||||
profileid: profile.id.toString()
|
|
||||||
},
|
|
||||||
defaults: {
|
|
||||||
profile: stringifiedProfile,
|
|
||||||
}
|
|
||||||
}).spread(function (user, created) {
|
|
||||||
if (user) {
|
|
||||||
var needSave = false;
|
|
||||||
if (user.profile != stringifiedProfile) {
|
|
||||||
user.profile = stringifiedProfile;
|
|
||||||
needSave = true;
|
|
||||||
}
|
|
||||||
if (needSave) {
|
|
||||||
user.save().then(function () {
|
|
||||||
if (config.debug)
|
|
||||||
logger.info('user login: ' + user.id);
|
|
||||||
return done(null, user);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (config.debug)
|
|
||||||
logger.info('user login: ' + user.id);
|
|
||||||
return done(null, user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).catch(function (err) {
|
|
||||||
logger.error('ldap auth failed: ' + err);
|
|
||||||
return done(err, null);
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
// email
|
|
||||||
if (config.email) {
|
|
||||||
passport.use(new LocalStrategy({
|
|
||||||
usernameField: 'email'
|
|
||||||
},
|
|
||||||
function(email, password, done) {
|
|
||||||
if (!validator.isEmail(email)) return done(null, false);
|
|
||||||
models.User.findOne({
|
|
||||||
where: {
|
|
||||||
email: email
|
|
||||||
}
|
|
||||||
}).then(function (user) {
|
|
||||||
if (!user) return done(null, false);
|
|
||||||
if (!user.verifyPassword(password)) return done(null, false);
|
|
||||||
return done(null, user);
|
|
||||||
}).catch(function (err) {
|
|
||||||
logger.error(err);
|
|
||||||
return done(err);
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
330
lib/config.js
330
lib/config.js
|
@ -1,118 +1,117 @@
|
||||||
// external modules
|
// external modules
|
||||||
var fs = require('fs');
|
var fs = require('fs')
|
||||||
var path = require('path');
|
var path = require('path')
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
// configs
|
// configs
|
||||||
var env = process.env.NODE_ENV || 'development';
|
var env = process.env.NODE_ENV || 'development'
|
||||||
var config = require(path.join(__dirname, '..', 'config.json'))[env];
|
var config = require(path.join(__dirname, '..', 'config.json'))[env]
|
||||||
var debug = process.env.DEBUG ? (process.env.DEBUG === 'true') : ((typeof config.debug === 'boolean') ? config.debug : (env === 'development'));
|
var debug = process.env.DEBUG ? (process.env.DEBUG === 'true') : ((typeof config.debug === 'boolean') ? config.debug : (env === 'development'))
|
||||||
|
|
||||||
// Create function that reads docker secrets but fails fast in case of a non docker environment
|
// Create function that reads docker secrets but fails fast in case of a non docker environment
|
||||||
var handleDockerSecret = fs.existsSync('/run/secrets/') ? function(secret) {
|
var handleDockerSecret = fs.existsSync('/run/secrets/') ? function (secret) {
|
||||||
return fs.existsSync('/run/secrets/' + secret) ? fs.readFileSync('/run/secrets/' + secret) : null;
|
return fs.existsSync('/run/secrets/' + secret) ? fs.readFileSync('/run/secrets/' + secret) : null
|
||||||
} : function() {
|
} : function () {
|
||||||
return null
|
return null
|
||||||
};
|
}
|
||||||
|
|
||||||
// url
|
// url
|
||||||
var domain = process.env.DOMAIN || process.env.HMD_DOMAIN || config.domain || '';
|
var domain = process.env.DOMAIN || process.env.HMD_DOMAIN || config.domain || ''
|
||||||
var urlpath = process.env.URL_PATH || process.env.HMD_URL_PATH || config.urlpath || '';
|
var urlpath = process.env.URL_PATH || process.env.HMD_URL_PATH || config.urlpath || ''
|
||||||
var port = process.env.PORT || process.env.HMD_PORT || config.port || 3000;
|
var port = process.env.PORT || process.env.HMD_PORT || config.port || 3000
|
||||||
var alloworigin = process.env.HMD_ALLOW_ORIGIN ? process.env.HMD_ALLOW_ORIGIN.split(',') : (config.alloworigin || ['localhost']);
|
var alloworigin = process.env.HMD_ALLOW_ORIGIN ? process.env.HMD_ALLOW_ORIGIN.split(',') : (config.alloworigin || ['localhost'])
|
||||||
|
|
||||||
var usessl = !!config.usessl;
|
var usessl = !!config.usessl
|
||||||
var protocolusessl = (usessl === true && typeof process.env.HMD_PROTOCOL_USESSL === 'undefined' && typeof config.protocolusessl === 'undefined')
|
var protocolusessl = (usessl === true && typeof process.env.HMD_PROTOCOL_USESSL === 'undefined' && typeof config.protocolusessl === 'undefined')
|
||||||
? true : (process.env.HMD_PROTOCOL_USESSL ? (process.env.HMD_PROTOCOL_USESSL === 'true') : !!config.protocolusessl);
|
? true : (process.env.HMD_PROTOCOL_USESSL ? (process.env.HMD_PROTOCOL_USESSL === 'true') : !!config.protocolusessl)
|
||||||
var urladdport = process.env.HMD_URL_ADDPORT ? (process.env.HMD_URL_ADDPORT === 'true') : !!config.urladdport;
|
var urladdport = process.env.HMD_URL_ADDPORT ? (process.env.HMD_URL_ADDPORT === 'true') : !!config.urladdport
|
||||||
|
|
||||||
var usecdn = process.env.HMD_USECDN ? (process.env.HMD_USECDN === 'true') : ((typeof config.usecdn === 'boolean') ? config.usecdn : true);
|
var usecdn = process.env.HMD_USECDN ? (process.env.HMD_USECDN === 'true') : ((typeof config.usecdn === 'boolean') ? config.usecdn : true)
|
||||||
|
|
||||||
var allowanonymous = process.env.HMD_ALLOW_ANONYMOUS ? (process.env.HMD_ALLOW_ANONYMOUS === 'true') : ((typeof config.allowanonymous === 'boolean') ? config.allowanonymous : true);
|
var allowanonymous = process.env.HMD_ALLOW_ANONYMOUS ? (process.env.HMD_ALLOW_ANONYMOUS === 'true') : ((typeof config.allowanonymous === 'boolean') ? config.allowanonymous : true)
|
||||||
|
|
||||||
var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl;
|
var allowfreeurl = process.env.HMD_ALLOW_FREEURL ? (process.env.HMD_ALLOW_FREEURL === 'true') : !!config.allowfreeurl
|
||||||
|
|
||||||
var permissions = ['editable', 'limited', 'locked', 'protected', 'private'];
|
var permissions = ['editable', 'limited', 'locked', 'protected', 'private']
|
||||||
if (allowanonymous) {
|
if (allowanonymous) {
|
||||||
permissions.unshift('freely');
|
permissions.unshift('freely')
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultpermission = process.env.HMD_DEFAULT_PERMISSION || config.defaultpermission;
|
var defaultpermission = process.env.HMD_DEFAULT_PERMISSION || config.defaultpermission
|
||||||
defaultpermission = permissions.indexOf(defaultpermission) != -1 ? defaultpermission : 'editable';
|
defaultpermission = permissions.indexOf(defaultpermission) !== -1 ? defaultpermission : 'editable'
|
||||||
|
|
||||||
// db
|
// db
|
||||||
var dburl = process.env.HMD_DB_URL || process.env.DATABASE_URL || config.dburl;
|
var dburl = process.env.HMD_DB_URL || process.env.DATABASE_URL || config.dburl
|
||||||
var db = config.db || {};
|
var db = config.db || {}
|
||||||
|
|
||||||
// ssl path
|
// ssl path
|
||||||
var sslkeypath = (fs.existsSync('/run/secrets/key.pem') ? '/run/secrets/key.pem' : null) || config.sslkeypath || '';
|
var sslkeypath = (fs.existsSync('/run/secrets/key.pem') ? '/run/secrets/key.pem' : null) || config.sslkeypath || ''
|
||||||
var sslcertpath = (fs.existsSync('/run/secrets/cert.pem') ? '/run/secrets/cert.pem' : null) || config.sslcertpath || '';
|
var sslcertpath = (fs.existsSync('/run/secrets/cert.pem') ? '/run/secrets/cert.pem' : null) || config.sslcertpath || ''
|
||||||
var sslcapath = (fs.existsSync('/run/secrets/ca.pem') ? '/run/secrets/ca.pem' : null) || config.sslcapath || '';
|
var sslcapath = (fs.existsSync('/run/secrets/ca.pem') ? '/run/secrets/ca.pem' : null) || config.sslcapath || ''
|
||||||
var dhparampath = (fs.existsSync('/run/secrets/dhparam.pem') ? '/run/secrets/dhparam.pem' : null) || config.dhparampath || '';
|
var dhparampath = (fs.existsSync('/run/secrets/dhparam.pem') ? '/run/secrets/dhparam.pem' : null) || config.dhparampath || ''
|
||||||
|
|
||||||
// other path
|
// other path
|
||||||
var tmppath = config.tmppath || './tmp';
|
var tmppath = config.tmppath || './tmp'
|
||||||
var defaultnotepath = config.defaultnotepath || './public/default.md';
|
var defaultnotepath = config.defaultnotepath || './public/default.md'
|
||||||
var docspath = config.docspath || './public/docs';
|
var docspath = config.docspath || './public/docs'
|
||||||
var indexpath = config.indexpath || './public/views/index.ejs';
|
var indexpath = config.indexpath || './public/views/index.ejs'
|
||||||
var hackmdpath = config.hackmdpath || './public/views/hackmd.ejs';
|
var hackmdpath = config.hackmdpath || './public/views/hackmd.ejs'
|
||||||
var errorpath = config.errorpath || './public/views/error.ejs';
|
var errorpath = config.errorpath || './public/views/error.ejs'
|
||||||
var prettypath = config.prettypath || './public/views/pretty.ejs';
|
var prettypath = config.prettypath || './public/views/pretty.ejs'
|
||||||
var slidepath = config.slidepath || './public/views/slide.ejs';
|
var slidepath = config.slidepath || './public/views/slide.ejs'
|
||||||
|
|
||||||
// session
|
// session
|
||||||
var sessionname = config.sessionname || 'connect.sid';
|
var sessionname = config.sessionname || 'connect.sid'
|
||||||
var sessionsecret = handleDockerSecret('sessionsecret') || config.sessionsecret || 'secret';
|
var sessionsecret = handleDockerSecret('sessionsecret') || config.sessionsecret || 'secret'
|
||||||
var sessionlife = config.sessionlife || 14 * 24 * 60 * 60 * 1000; //14 days
|
var sessionlife = config.sessionlife || 14 * 24 * 60 * 60 * 1000 // 14 days
|
||||||
|
|
||||||
// static files
|
// static files
|
||||||
var staticcachetime = config.staticcachetime || 1 * 24 * 60 * 60 * 1000; // 1 day
|
var staticcachetime = config.staticcachetime || 1 * 24 * 60 * 60 * 1000 // 1 day
|
||||||
|
|
||||||
// socket.io
|
// socket.io
|
||||||
var heartbeatinterval = config.heartbeatinterval || 5000;
|
var heartbeatinterval = config.heartbeatinterval || 5000
|
||||||
var heartbeattimeout = config.heartbeattimeout || 10000;
|
var heartbeattimeout = config.heartbeattimeout || 10000
|
||||||
|
|
||||||
// document
|
// document
|
||||||
var documentmaxlength = config.documentmaxlength || 100000;
|
var documentmaxlength = config.documentmaxlength || 100000
|
||||||
|
|
||||||
// image upload setting, available options are imgur/s3/filesystem
|
// image upload setting, available options are imgur/s3/filesystem
|
||||||
var imageUploadType = process.env.HMD_IMAGE_UPLOAD_TYPE || config.imageUploadType || 'imgur';
|
var imageUploadType = process.env.HMD_IMAGE_UPLOAD_TYPE || config.imageUploadType || 'imgur'
|
||||||
|
|
||||||
config.s3 = config.s3 || {};
|
config.s3 = config.s3 || {}
|
||||||
var s3 = {
|
var s3 = {
|
||||||
accessKeyId: handleDockerSecret('s3_acccessKeyId') || process.env.HMD_S3_ACCESS_KEY_ID || config.s3.accessKeyId,
|
accessKeyId: handleDockerSecret('s3_acccessKeyId') || process.env.HMD_S3_ACCESS_KEY_ID || config.s3.accessKeyId,
|
||||||
secretAccessKey: handleDockerSecret('s3_secretAccessKey') || process.env.HMD_S3_SECRET_ACCESS_KEY || config.s3.secretAccessKey,
|
secretAccessKey: handleDockerSecret('s3_secretAccessKey') || process.env.HMD_S3_SECRET_ACCESS_KEY || config.s3.secretAccessKey,
|
||||||
region: process.env.HMD_S3_REGION || config.s3.region
|
region: process.env.HMD_S3_REGION || config.s3.region
|
||||||
}
|
}
|
||||||
var s3bucket = process.env.HMD_S3_BUCKET || config.s3.bucket;
|
var s3bucket = process.env.HMD_S3_BUCKET || config.s3.bucket
|
||||||
|
|
||||||
// auth
|
// auth
|
||||||
var facebook = (process.env.HMD_FACEBOOK_CLIENTID && process.env.HMD_FACEBOOK_CLIENTSECRET || fs.existsSync('/run/secrets/facebook_clientID') && fs.existsSync('/run/secrets/facebook_clientSecret')) ? {
|
var facebook = ((process.env.HMD_FACEBOOK_CLIENTID && process.env.HMD_FACEBOOK_CLIENTSECRET) || (fs.existsSync('/run/secrets/facebook_clientID') && fs.existsSync('/run/secrets/facebook_clientSecret'))) ? {
|
||||||
clientID: handleDockerSecret('facebook_clientID') || process.env.HMD_FACEBOOK_CLIENTID,
|
clientID: handleDockerSecret('facebook_clientID') || process.env.HMD_FACEBOOK_CLIENTID,
|
||||||
clientSecret: handleDockerSecret('facebook_clientSecret') || process.env.HMD_FACEBOOK_CLIENTSECRET
|
clientSecret: handleDockerSecret('facebook_clientSecret') || process.env.HMD_FACEBOOK_CLIENTSECRET
|
||||||
} : config.facebook || false;
|
} : config.facebook || false
|
||||||
var twitter = (process.env.HMD_TWITTER_CONSUMERKEY && process.env.HMD_TWITTER_CONSUMERSECRET || fs.existsSync('/run/secrets/twitter_consumerKey') && fs.existsSync('/run/secrets/twitter_consumerSecret')) ? {
|
var twitter = ((process.env.HMD_TWITTER_CONSUMERKEY && process.env.HMD_TWITTER_CONSUMERSECRET) || (fs.existsSync('/run/secrets/twitter_consumerKey') && fs.existsSync('/run/secrets/twitter_consumerSecret'))) ? {
|
||||||
consumerKey: handleDockerSecret('twitter_consumerKey') || process.env.HMD_TWITTER_CONSUMERKEY,
|
consumerKey: handleDockerSecret('twitter_consumerKey') || process.env.HMD_TWITTER_CONSUMERKEY,
|
||||||
consumerSecret: handleDockerSecret('twitter_consumerSecret') || process.env.HMD_TWITTER_CONSUMERSECRET
|
consumerSecret: handleDockerSecret('twitter_consumerSecret') || process.env.HMD_TWITTER_CONSUMERSECRET
|
||||||
} : config.twitter || false;
|
} : config.twitter || false
|
||||||
var github = (process.env.HMD_GITHUB_CLIENTID && process.env.HMD_GITHUB_CLIENTSECRET || fs.existsSync('/run/secrets/github_clientID') && fs.existsSync('/run/secrets/github_clientSecret')) ? {
|
var github = ((process.env.HMD_GITHUB_CLIENTID && process.env.HMD_GITHUB_CLIENTSECRET) || (fs.existsSync('/run/secrets/github_clientID') && fs.existsSync('/run/secrets/github_clientSecret'))) ? {
|
||||||
clientID: handleDockerSecret('github_clientID') || process.env.HMD_GITHUB_CLIENTID,
|
clientID: handleDockerSecret('github_clientID') || process.env.HMD_GITHUB_CLIENTID,
|
||||||
clientSecret: handleDockerSecret('github_clientSecret') || process.env.HMD_GITHUB_CLIENTSECRET
|
clientSecret: handleDockerSecret('github_clientSecret') || process.env.HMD_GITHUB_CLIENTSECRET
|
||||||
} : config.github || false;
|
} : config.github || false
|
||||||
var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSECRET || fs.existsSync('/run/secrets/gitlab_clientID') && fs.existsSync('/run/secrets/gitlab_clientSecret')) ? {
|
var gitlab = ((process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSECRET) || (fs.existsSync('/run/secrets/gitlab_clientID') && fs.existsSync('/run/secrets/gitlab_clientSecret'))) ? {
|
||||||
baseURL: process.env.HMD_GITLAB_BASEURL,
|
baseURL: process.env.HMD_GITLAB_BASEURL,
|
||||||
clientID: handleDockerSecret('gitlab_clientID') || process.env.HMD_GITLAB_CLIENTID,
|
clientID: handleDockerSecret('gitlab_clientID') || process.env.HMD_GITLAB_CLIENTID,
|
||||||
clientSecret: handleDockerSecret('gitlab_clientSecret') || process.env.HMD_GITLAB_CLIENTSECRET
|
clientSecret: handleDockerSecret('gitlab_clientSecret') || process.env.HMD_GITLAB_CLIENTSECRET
|
||||||
} : config.gitlab || false;
|
} : config.gitlab || false
|
||||||
var dropbox = ((process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) || (fs.existsSync('/run/secrets/dropbox_clientID') && fs.existsSync('/run/secrets/dropbox_clientSecret'))) ? {
|
var dropbox = ((process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) || (fs.existsSync('/run/secrets/dropbox_clientID') && fs.existsSync('/run/secrets/dropbox_clientSecret'))) ? {
|
||||||
clientID: handleDockerSecret('dropbox_clientID') || process.env.HMD_DROPBOX_CLIENTID,
|
clientID: handleDockerSecret('dropbox_clientID') || process.env.HMD_DROPBOX_CLIENTID,
|
||||||
clientSecret: handleDockerSecret('dropbox_clientSecret') || process.env.HMD_DROPBOX_CLIENTSECRET
|
clientSecret: handleDockerSecret('dropbox_clientSecret') || process.env.HMD_DROPBOX_CLIENTSECRET
|
||||||
} : (config.dropbox && config.dropbox.clientID && config.dropbox.clientSecret && config.dropbox) || false;
|
} : (config.dropbox && config.dropbox.clientID && config.dropbox.clientSecret && config.dropbox) || false
|
||||||
var google = ((process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET)
|
var google = ((process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ||
|
||||||
|| (fs.existsSync('/run/secrets/google_clientID') && fs.existsSync('/run/secrets/google_clientSecret'))) ? {
|
(fs.existsSync('/run/secrets/google_clientID') && fs.existsSync('/run/secrets/google_clientSecret'))) ? {
|
||||||
clientID: handleDockerSecret('google_clientID') || process.env.HMD_GOOGLE_CLIENTID,
|
clientID: handleDockerSecret('google_clientID') || process.env.HMD_GOOGLE_CLIENTID,
|
||||||
clientSecret: handleDockerSecret('google_clientSecret') || process.env.HMD_GOOGLE_CLIENTSECRET
|
clientSecret: handleDockerSecret('google_clientSecret') || process.env.HMD_GOOGLE_CLIENTSECRET
|
||||||
} : (config.google && config.google.clientID && config.google.clientSecret && config.google) || false;
|
} : (config.google && config.google.clientID && config.google.clientSecret && config.google) || false
|
||||||
var ldap = config.ldap || ((
|
var ldap = config.ldap || ((
|
||||||
process.env.HMD_LDAP_URL ||
|
process.env.HMD_LDAP_URL ||
|
||||||
process.env.HMD_LDAP_BINDDN ||
|
process.env.HMD_LDAP_BINDDN ||
|
||||||
|
@ -123,106 +122,97 @@ var ldap = config.ldap || ((
|
||||||
process.env.HMD_LDAP_SEARCHATTRIBUTES ||
|
process.env.HMD_LDAP_SEARCHATTRIBUTES ||
|
||||||
process.env.HMD_LDAP_TLS_CA ||
|
process.env.HMD_LDAP_TLS_CA ||
|
||||||
process.env.HMD_LDAP_PROVIDERNAME
|
process.env.HMD_LDAP_PROVIDERNAME
|
||||||
) ? {} : false);
|
) ? {} : false)
|
||||||
if (process.env.HMD_LDAP_URL)
|
if (process.env.HMD_LDAP_URL) { ldap.url = process.env.HMD_LDAP_URL }
|
||||||
ldap.url = process.env.HMD_LDAP_URL;
|
if (process.env.HMD_LDAP_BINDDN) { ldap.bindDn = process.env.HMD_LDAP_BINDDN }
|
||||||
if (process.env.HMD_LDAP_BINDDN)
|
if (process.env.HMD_LDAP_BINDCREDENTIALS) { ldap.bindCredentials = process.env.HMD_LDAP_BINDCREDENTIALS }
|
||||||
ldap.bindDn = process.env.HMD_LDAP_BINDDN;
|
if (process.env.HMD_LDAP_TOKENSECRET) { ldap.tokenSecret = process.env.HMD_LDAP_TOKENSECRET }
|
||||||
if (process.env.HMD_LDAP_BINDCREDENTIALS)
|
if (process.env.HMD_LDAP_SEARCHBASE) { ldap.searchBase = process.env.HMD_LDAP_SEARCHBASE }
|
||||||
ldap.bindCredentials = process.env.HMD_LDAP_BINDCREDENTIALS;
|
if (process.env.HMD_LDAP_SEARCHFILTER) { ldap.searchFilter = process.env.HMD_LDAP_SEARCHFILTER }
|
||||||
if (process.env.HMD_LDAP_TOKENSECRET)
|
if (process.env.HMD_LDAP_SEARCHATTRIBUTES) { ldap.searchAttributes = process.env.HMD_LDAP_SEARCHATTRIBUTES }
|
||||||
ldap.tokenSecret = process.env.HMD_LDAP_TOKENSECRET;
|
|
||||||
if (process.env.HMD_LDAP_SEARCHBASE)
|
|
||||||
ldap.searchBase = process.env.HMD_LDAP_SEARCHBASE;
|
|
||||||
if (process.env.HMD_LDAP_SEARCHFILTER)
|
|
||||||
ldap.searchFilter = process.env.HMD_LDAP_SEARCHFILTER;
|
|
||||||
if (process.env.HMD_LDAP_SEARCHATTRIBUTES)
|
|
||||||
ldap.searchAttributes = process.env.HMD_LDAP_SEARCHATTRIBUTES;
|
|
||||||
if (process.env.HMD_LDAP_TLS_CA) {
|
if (process.env.HMD_LDAP_TLS_CA) {
|
||||||
var ca = {
|
var ca = {
|
||||||
ca: process.env.HMD_LDAP_TLS_CA.split(',')
|
ca: process.env.HMD_LDAP_TLS_CA.split(',')
|
||||||
}
|
}
|
||||||
ldap.tlsOptions = ldap.tlsOptions ? Object.assign(ldap.tlsOptions, ca) : ca;
|
ldap.tlsOptions = ldap.tlsOptions ? Object.assign(ldap.tlsOptions, ca) : ca
|
||||||
if (Array.isArray(ldap.tlsOptions.ca) && ldap.tlsOptions.ca.length > 0) {
|
if (Array.isArray(ldap.tlsOptions.ca) && ldap.tlsOptions.ca.length > 0) {
|
||||||
var i, len, results;
|
var i, len, results
|
||||||
results = [];
|
results = []
|
||||||
for (i = 0, len = ldap.tlsOptions.ca.length; i < len; i++) {
|
for (i = 0, len = ldap.tlsOptions.ca.length; i < len; i++) {
|
||||||
results.push(fs.readFileSync(ldap.tlsOptions.ca[i], 'utf8'));
|
results.push(fs.readFileSync(ldap.tlsOptions.ca[i], 'utf8'))
|
||||||
}
|
|
||||||
ldap.tlsOptions.ca = results;
|
|
||||||
}
|
}
|
||||||
|
ldap.tlsOptions.ca = results
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (process.env.HMD_LDAP_PROVIDERNAME) {
|
if (process.env.HMD_LDAP_PROVIDERNAME) {
|
||||||
ldap.providerName = process.env.HMD_LDAP_PROVIDERNAME;
|
ldap.providerName = process.env.HMD_LDAP_PROVIDERNAME
|
||||||
}
|
}
|
||||||
var imgur = handleDockerSecret('imgur_clientid') || process.env.HMD_IMGUR_CLIENTID || config.imgur || false;
|
var imgur = handleDockerSecret('imgur_clientid') || process.env.HMD_IMGUR_CLIENTID || config.imgur || false
|
||||||
var email = process.env.HMD_EMAIL ? (process.env.HMD_EMAIL === 'true') : !!config.email;
|
var email = process.env.HMD_EMAIL ? (process.env.HMD_EMAIL === 'true') : !!config.email
|
||||||
var allowemailregister = process.env.HMD_ALLOW_EMAIL_REGISTER ? (process.env.HMD_ALLOW_EMAIL_REGISTER === 'true') : ((typeof config.allowemailregister === 'boolean') ? config.allowemailregister : true);
|
var allowemailregister = process.env.HMD_ALLOW_EMAIL_REGISTER ? (process.env.HMD_ALLOW_EMAIL_REGISTER === 'true') : ((typeof config.allowemailregister === 'boolean') ? config.allowemailregister : true)
|
||||||
|
|
||||||
function getserverurl() {
|
function getserverurl () {
|
||||||
var url = '';
|
var url = ''
|
||||||
if (domain) {
|
if (domain) {
|
||||||
var protocol = protocolusessl ? 'https://' : 'http://';
|
var protocol = protocolusessl ? 'https://' : 'http://'
|
||||||
url = protocol + domain;
|
url = protocol + domain
|
||||||
if (urladdport && ((usessl && port != 443) || (!usessl && port != 80)))
|
if (urladdport && ((usessl && port !== 443) || (!usessl && port !== 80))) { url += ':' + port }
|
||||||
url += ':' + port;
|
}
|
||||||
}
|
if (urlpath) { url += '/' + urlpath }
|
||||||
if (urlpath)
|
return url
|
||||||
url += '/' + urlpath;
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var version = '0.5.0';
|
var version = '0.5.0'
|
||||||
var minimumCompatibleVersion = '0.5.0';
|
var minimumCompatibleVersion = '0.5.0'
|
||||||
var maintenance = true;
|
var maintenance = true
|
||||||
var cwd = path.join(__dirname, '..');
|
var cwd = path.join(__dirname, '..')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
version: version,
|
version: version,
|
||||||
minimumCompatibleVersion: minimumCompatibleVersion,
|
minimumCompatibleVersion: minimumCompatibleVersion,
|
||||||
maintenance: maintenance,
|
maintenance: maintenance,
|
||||||
debug: debug,
|
debug: debug,
|
||||||
urlpath: urlpath,
|
urlpath: urlpath,
|
||||||
port: port,
|
port: port,
|
||||||
alloworigin: alloworigin,
|
alloworigin: alloworigin,
|
||||||
usessl: usessl,
|
usessl: usessl,
|
||||||
serverurl: getserverurl(),
|
serverurl: getserverurl(),
|
||||||
usecdn: usecdn,
|
usecdn: usecdn,
|
||||||
allowanonymous: allowanonymous,
|
allowanonymous: allowanonymous,
|
||||||
allowfreeurl: allowfreeurl,
|
allowfreeurl: allowfreeurl,
|
||||||
defaultpermission: defaultpermission,
|
defaultpermission: defaultpermission,
|
||||||
dburl: dburl,
|
dburl: dburl,
|
||||||
db: db,
|
db: db,
|
||||||
sslkeypath: path.join(cwd, sslkeypath),
|
sslkeypath: path.join(cwd, sslkeypath),
|
||||||
sslcertpath: path.join(cwd, sslcertpath),
|
sslcertpath: path.join(cwd, sslcertpath),
|
||||||
sslcapath: path.join(cwd, sslcapath),
|
sslcapath: path.join(cwd, sslcapath),
|
||||||
dhparampath: path.join(cwd, dhparampath),
|
dhparampath: path.join(cwd, dhparampath),
|
||||||
tmppath: path.join(cwd, tmppath),
|
tmppath: path.join(cwd, tmppath),
|
||||||
defaultnotepath: path.join(cwd, defaultnotepath),
|
defaultnotepath: path.join(cwd, defaultnotepath),
|
||||||
docspath: path.join(cwd, docspath),
|
docspath: path.join(cwd, docspath),
|
||||||
indexpath: path.join(cwd, indexpath),
|
indexpath: path.join(cwd, indexpath),
|
||||||
hackmdpath: path.join(cwd, hackmdpath),
|
hackmdpath: path.join(cwd, hackmdpath),
|
||||||
errorpath: path.join(cwd, errorpath),
|
errorpath: path.join(cwd, errorpath),
|
||||||
prettypath: path.join(cwd, prettypath),
|
prettypath: path.join(cwd, prettypath),
|
||||||
slidepath: path.join(cwd, slidepath),
|
slidepath: path.join(cwd, slidepath),
|
||||||
sessionname: sessionname,
|
sessionname: sessionname,
|
||||||
sessionsecret: sessionsecret,
|
sessionsecret: sessionsecret,
|
||||||
sessionlife: sessionlife,
|
sessionlife: sessionlife,
|
||||||
staticcachetime: staticcachetime,
|
staticcachetime: staticcachetime,
|
||||||
heartbeatinterval: heartbeatinterval,
|
heartbeatinterval: heartbeatinterval,
|
||||||
heartbeattimeout: heartbeattimeout,
|
heartbeattimeout: heartbeattimeout,
|
||||||
documentmaxlength: documentmaxlength,
|
documentmaxlength: documentmaxlength,
|
||||||
facebook: facebook,
|
facebook: facebook,
|
||||||
twitter: twitter,
|
twitter: twitter,
|
||||||
github: github,
|
github: github,
|
||||||
gitlab: gitlab,
|
gitlab: gitlab,
|
||||||
dropbox: dropbox,
|
dropbox: dropbox,
|
||||||
google: google,
|
google: google,
|
||||||
ldap: ldap,
|
ldap: ldap,
|
||||||
imgur: imgur,
|
imgur: imgur,
|
||||||
email: email,
|
email: email,
|
||||||
allowemailregister: allowemailregister,
|
allowemailregister: allowemailregister,
|
||||||
imageUploadType: imageUploadType,
|
imageUploadType: imageUploadType,
|
||||||
s3: s3,
|
s3: s3,
|
||||||
s3bucket: s3bucket
|
s3bucket: s3bucket
|
||||||
};
|
}
|
||||||
|
|
309
lib/history.js
309
lib/history.js
|
@ -1,172 +1,175 @@
|
||||||
//history
|
// history
|
||||||
//external modules
|
// external modules
|
||||||
var async = require('async');
|
|
||||||
|
|
||||||
//core
|
// core
|
||||||
var config = require("./config.js");
|
var config = require('./config.js')
|
||||||
var logger = require("./logger.js");
|
var logger = require('./logger.js')
|
||||||
var response = require("./response.js");
|
var response = require('./response.js')
|
||||||
var models = require("./models");
|
var models = require('./models')
|
||||||
|
|
||||||
//public
|
// public
|
||||||
var History = {
|
var History = {
|
||||||
historyGet: historyGet,
|
historyGet: historyGet,
|
||||||
historyPost: historyPost,
|
historyPost: historyPost,
|
||||||
historyDelete: historyDelete,
|
historyDelete: historyDelete,
|
||||||
updateHistory: updateHistory
|
updateHistory: updateHistory
|
||||||
};
|
|
||||||
|
|
||||||
function getHistory(userid, callback) {
|
|
||||||
models.User.findOne({
|
|
||||||
where: {
|
|
||||||
id: userid
|
|
||||||
}
|
|
||||||
}).then(function (user) {
|
|
||||||
if (!user)
|
|
||||||
return callback(null, null);
|
|
||||||
var history = {};
|
|
||||||
if (user.history)
|
|
||||||
history = parseHistoryToObject(JSON.parse(user.history));
|
|
||||||
if (config.debug)
|
|
||||||
logger.info('read history success: ' + user.id);
|
|
||||||
return callback(null, history);
|
|
||||||
}).catch(function (err) {
|
|
||||||
logger.error('read history failed: ' + err);
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setHistory(userid, history, callback) {
|
function getHistory (userid, callback) {
|
||||||
models.User.update({
|
models.User.findOne({
|
||||||
history: JSON.stringify(parseHistoryToArray(history))
|
where: {
|
||||||
}, {
|
id: userid
|
||||||
where: {
|
|
||||||
id: userid
|
|
||||||
}
|
|
||||||
}).then(function (count) {
|
|
||||||
return callback(null, count);
|
|
||||||
}).catch(function (err) {
|
|
||||||
logger.error('set history failed: ' + err);
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateHistory(userid, noteId, document, time) {
|
|
||||||
if (userid && noteId && typeof document !== 'undefined') {
|
|
||||||
getHistory(userid, function (err, history) {
|
|
||||||
if (err || !history) return;
|
|
||||||
if (!history[noteId]) {
|
|
||||||
history[noteId] = {};
|
|
||||||
}
|
|
||||||
var noteHistory = history[noteId];
|
|
||||||
var noteInfo = models.Note.parseNoteInfo(document);
|
|
||||||
noteHistory.id = noteId;
|
|
||||||
noteHistory.text = noteInfo.title;
|
|
||||||
noteHistory.time = time || Date.now();
|
|
||||||
noteHistory.tags = noteInfo.tags;
|
|
||||||
setHistory(userid, history, function (err, count) {
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}).then(function (user) {
|
||||||
|
if (!user) {
|
||||||
function parseHistoryToArray(history) {
|
return callback(null, null)
|
||||||
var _history = [];
|
|
||||||
Object.keys(history).forEach(function (key) {
|
|
||||||
var item = history[key];
|
|
||||||
_history.push(item);
|
|
||||||
});
|
|
||||||
return _history;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseHistoryToObject(history) {
|
|
||||||
var _history = {};
|
|
||||||
for (var i = 0, l = history.length; i < l; i++) {
|
|
||||||
var item = history[i];
|
|
||||||
_history[item.id] = item;
|
|
||||||
}
|
}
|
||||||
return _history;
|
var history = {}
|
||||||
|
if (user.history) {
|
||||||
|
history = parseHistoryToObject(JSON.parse(user.history))
|
||||||
|
}
|
||||||
|
if (config.debug) {
|
||||||
|
logger.info('read history success: ' + user.id)
|
||||||
|
}
|
||||||
|
return callback(null, history)
|
||||||
|
}).catch(function (err) {
|
||||||
|
logger.error('read history failed: ' + err)
|
||||||
|
return callback(err, null)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function historyGet(req, res) {
|
function setHistory (userid, history, callback) {
|
||||||
if (req.isAuthenticated()) {
|
models.User.update({
|
||||||
getHistory(req.user.id, function (err, history) {
|
history: JSON.stringify(parseHistoryToArray(history))
|
||||||
if (err) return response.errorInternalError(res);
|
}, {
|
||||||
if (!history) return response.errorNotFound(res);
|
where: {
|
||||||
res.send({
|
id: userid
|
||||||
history: parseHistoryToArray(history)
|
}
|
||||||
});
|
}).then(function (count) {
|
||||||
});
|
return callback(null, count)
|
||||||
|
}).catch(function (err) {
|
||||||
|
logger.error('set history failed: ' + err)
|
||||||
|
return callback(err, null)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateHistory (userid, noteId, document, time) {
|
||||||
|
if (userid && noteId && typeof document !== 'undefined') {
|
||||||
|
getHistory(userid, function (err, history) {
|
||||||
|
if (err || !history) return
|
||||||
|
if (!history[noteId]) {
|
||||||
|
history[noteId] = {}
|
||||||
|
}
|
||||||
|
var noteHistory = history[noteId]
|
||||||
|
var noteInfo = models.Note.parseNoteInfo(document)
|
||||||
|
noteHistory.id = noteId
|
||||||
|
noteHistory.text = noteInfo.title
|
||||||
|
noteHistory.time = time || Date.now()
|
||||||
|
noteHistory.tags = noteInfo.tags
|
||||||
|
setHistory(userid, history, function (err, count) {
|
||||||
|
if (err) {
|
||||||
|
logger.log(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseHistoryToArray (history) {
|
||||||
|
var _history = []
|
||||||
|
Object.keys(history).forEach(function (key) {
|
||||||
|
var item = history[key]
|
||||||
|
_history.push(item)
|
||||||
|
})
|
||||||
|
return _history
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseHistoryToObject (history) {
|
||||||
|
var _history = {}
|
||||||
|
for (var i = 0, l = history.length; i < l; i++) {
|
||||||
|
var item = history[i]
|
||||||
|
_history[item.id] = item
|
||||||
|
}
|
||||||
|
return _history
|
||||||
|
}
|
||||||
|
|
||||||
|
function historyGet (req, res) {
|
||||||
|
if (req.isAuthenticated()) {
|
||||||
|
getHistory(req.user.id, function (err, history) {
|
||||||
|
if (err) return response.errorInternalError(res)
|
||||||
|
if (!history) return response.errorNotFound(res)
|
||||||
|
res.send({
|
||||||
|
history: parseHistoryToArray(history)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return response.errorForbidden(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function historyPost (req, res) {
|
||||||
|
if (req.isAuthenticated()) {
|
||||||
|
var noteId = req.params.noteId
|
||||||
|
if (!noteId) {
|
||||||
|
if (typeof req.body['history'] === 'undefined') return response.errorBadRequest(res)
|
||||||
|
if (config.debug) { logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history) }
|
||||||
|
try {
|
||||||
|
var history = JSON.parse(req.body.history)
|
||||||
|
} catch (err) {
|
||||||
|
return response.errorBadRequest(res)
|
||||||
|
}
|
||||||
|
if (Array.isArray(history)) {
|
||||||
|
setHistory(req.user.id, history, function (err, count) {
|
||||||
|
if (err) return response.errorInternalError(res)
|
||||||
|
res.end()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return response.errorBadRequest(res)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return response.errorForbidden(res);
|
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(res)
|
||||||
}
|
getHistory(req.user.id, function (err, history) {
|
||||||
}
|
if (err) return response.errorInternalError(res)
|
||||||
|
if (!history) return response.errorNotFound(res)
|
||||||
function historyPost(req, res) {
|
if (!history[noteId]) return response.errorNotFound(res)
|
||||||
if (req.isAuthenticated()) {
|
if (req.body.pinned === 'true' || req.body.pinned === 'false') {
|
||||||
var noteId = req.params.noteId;
|
history[noteId].pinned = (req.body.pinned === 'true')
|
||||||
if (!noteId) {
|
setHistory(req.user.id, history, function (err, count) {
|
||||||
if (typeof req.body['history'] === 'undefined') return response.errorBadRequest(res);
|
if (err) return response.errorInternalError(res)
|
||||||
if (config.debug)
|
res.end()
|
||||||
logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history);
|
})
|
||||||
try {
|
|
||||||
var history = JSON.parse(req.body.history);
|
|
||||||
} catch (err) {
|
|
||||||
return response.errorBadRequest(res);
|
|
||||||
}
|
|
||||||
if (Array.isArray(history)) {
|
|
||||||
setHistory(req.user.id, history, function (err, count) {
|
|
||||||
if (err) return response.errorInternalError(res);
|
|
||||||
res.end();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return response.errorBadRequest(res);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(res);
|
return response.errorBadRequest(res)
|
||||||
getHistory(req.user.id, function (err, history) {
|
|
||||||
if (err) return response.errorInternalError(res);
|
|
||||||
if (!history) return response.errorNotFound(res);
|
|
||||||
if (!history[noteId]) return response.errorNotFound(res);
|
|
||||||
if (req.body.pinned === 'true' || req.body.pinned === 'false') {
|
|
||||||
history[noteId].pinned = (req.body.pinned === 'true');
|
|
||||||
setHistory(req.user.id, history, function (err, count) {
|
|
||||||
if (err) return response.errorInternalError(res);
|
|
||||||
res.end();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return response.errorBadRequest(res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
})
|
||||||
return response.errorForbidden(res);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return response.errorForbidden(res)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function historyDelete(req, res) {
|
function historyDelete (req, res) {
|
||||||
if (req.isAuthenticated()) {
|
if (req.isAuthenticated()) {
|
||||||
var noteId = req.params.noteId;
|
var noteId = req.params.noteId
|
||||||
if (!noteId) {
|
if (!noteId) {
|
||||||
setHistory(req.user.id, [], function (err, count) {
|
setHistory(req.user.id, [], function (err, count) {
|
||||||
if (err) return response.errorInternalError(res);
|
if (err) return response.errorInternalError(res)
|
||||||
res.end();
|
res.end()
|
||||||
});
|
})
|
||||||
} else {
|
|
||||||
getHistory(req.user.id, function (err, history) {
|
|
||||||
if (err) return response.errorInternalError(res);
|
|
||||||
if (!history) return response.errorNotFound(res);
|
|
||||||
delete history[noteId];
|
|
||||||
setHistory(req.user.id, history, function (err, count) {
|
|
||||||
if (err) return response.errorInternalError(res);
|
|
||||||
res.end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return response.errorForbidden(res);
|
getHistory(req.user.id, function (err, history) {
|
||||||
|
if (err) return response.errorInternalError(res)
|
||||||
|
if (!history) return response.errorNotFound(res)
|
||||||
|
delete history[noteId]
|
||||||
|
setHistory(req.user.id, history, function (err, count) {
|
||||||
|
if (err) return response.errorInternalError(res)
|
||||||
|
res.end()
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return response.errorForbidden(res)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = History;
|
module.exports = History
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// external modules
|
// external modules
|
||||||
var randomcolor = require('randomcolor');
|
var randomcolor = require('randomcolor')
|
||||||
|
|
||||||
// core
|
// core
|
||||||
module.exports = function(name) {
|
module.exports = function (name) {
|
||||||
var color = randomcolor({
|
var color = randomcolor({
|
||||||
seed: name,
|
seed: name,
|
||||||
luminosity: 'dark'
|
luminosity: 'dark'
|
||||||
});
|
})
|
||||||
var letter = name.substring(0, 1).toUpperCase();
|
var letter = name.substring(0, 1).toUpperCase()
|
||||||
|
|
||||||
var svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>';
|
var svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
|
||||||
svg += '<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="96" width="96" version="1.1" viewBox="0 0 96 96">';
|
svg += '<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="96" width="96" version="1.1" viewBox="0 0 96 96">'
|
||||||
svg += '<g>';
|
svg += '<g>'
|
||||||
svg += '<rect width="96" height="96" fill="' + color + '" />';
|
svg += '<rect width="96" height="96" fill="' + color + '" />'
|
||||||
svg += '<text font-size="64px" font-family="sans-serif" text-anchor="middle" fill="#ffffff">';
|
svg += '<text font-size="64px" font-family="sans-serif" text-anchor="middle" fill="#ffffff">'
|
||||||
svg += '<tspan x="48" y="72" stroke-width=".26458px" fill="#ffffff">' + letter + '</tspan>';
|
svg += '<tspan x="48" y="72" stroke-width=".26458px" fill="#ffffff">' + letter + '</tspan>'
|
||||||
svg += '</text>';
|
svg += '</text>'
|
||||||
svg += '</g>';
|
svg += '</g>'
|
||||||
svg += '</svg>';
|
svg += '</svg>'
|
||||||
|
|
||||||
return 'data:image/svg+xml;base64,' + new Buffer(svg).toString('base64');
|
return 'data:image/svg+xml;base64,' + new Buffer(svg).toString('base64')
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
var winston = require('winston');
|
var winston = require('winston')
|
||||||
winston.emitErrs = true;
|
winston.emitErrs = true
|
||||||
|
|
||||||
var logger = new winston.Logger({
|
var logger = new winston.Logger({
|
||||||
transports: [
|
transports: [
|
||||||
new winston.transports.Console({
|
new winston.transports.Console({
|
||||||
level: 'debug',
|
level: 'debug',
|
||||||
handleExceptions: true,
|
handleExceptions: true,
|
||||||
json: false,
|
json: false,
|
||||||
colorize: true,
|
colorize: true,
|
||||||
timestamp: true
|
timestamp: true
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
exitOnError: false
|
exitOnError: false
|
||||||
});
|
})
|
||||||
|
|
||||||
module.exports = logger;
|
module.exports = logger
|
||||||
module.exports.stream = {
|
module.exports.stream = {
|
||||||
write: function(message, encoding){
|
write: function (message, encoding) {
|
||||||
logger.info(message);
|
logger.info(message)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function (queryInterface, Sequelize) {
|
up: function (queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('Users', 'accessToken', Sequelize.STRING);
|
queryInterface.addColumn('Users', 'accessToken', Sequelize.STRING)
|
||||||
queryInterface.addColumn('Users', 'refreshToken', Sequelize.STRING);
|
queryInterface.addColumn('Users', 'refreshToken', Sequelize.STRING)
|
||||||
return;
|
},
|
||||||
},
|
|
||||||
|
|
||||||
down: function (queryInterface, Sequelize) {
|
down: function (queryInterface, Sequelize) {
|
||||||
queryInterface.removeColumn('Users', 'accessToken');
|
queryInterface.removeColumn('Users', 'accessToken')
|
||||||
queryInterface.removeColumn('Users', 'refreshToken');
|
queryInterface.removeColumn('Users', 'refreshToken')
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function (queryInterface, Sequelize) {
|
up: function (queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('Notes', 'savedAt', Sequelize.DATE);
|
queryInterface.addColumn('Notes', 'savedAt', Sequelize.DATE)
|
||||||
queryInterface.createTable('Revisions', {
|
queryInterface.createTable('Revisions', {
|
||||||
id: {
|
id: {
|
||||||
type: Sequelize.UUID,
|
type: Sequelize.UUID,
|
||||||
|
@ -15,13 +13,11 @@ module.exports = {
|
||||||
length: Sequelize.INTEGER,
|
length: Sequelize.INTEGER,
|
||||||
createdAt: Sequelize.DATE,
|
createdAt: Sequelize.DATE,
|
||||||
updatedAt: Sequelize.DATE
|
updatedAt: Sequelize.DATE
|
||||||
});
|
})
|
||||||
return;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
down: function (queryInterface, Sequelize) {
|
down: function (queryInterface, Sequelize) {
|
||||||
queryInterface.dropTable('Revisions');
|
queryInterface.dropTable('Revisions')
|
||||||
queryInterface.removeColumn('Notes', 'savedAt');
|
queryInterface.removeColumn('Notes', 'savedAt')
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function (queryInterface, Sequelize) {
|
up: function (queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('Notes', 'authorship', Sequelize.TEXT);
|
queryInterface.addColumn('Notes', 'authorship', Sequelize.TEXT)
|
||||||
queryInterface.addColumn('Revisions', 'authorship', Sequelize.TEXT);
|
queryInterface.addColumn('Revisions', 'authorship', Sequelize.TEXT)
|
||||||
queryInterface.createTable('Authors', {
|
queryInterface.createTable('Authors', {
|
||||||
id: {
|
id: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
|
@ -15,14 +13,12 @@ module.exports = {
|
||||||
userId: Sequelize.UUID,
|
userId: Sequelize.UUID,
|
||||||
createdAt: Sequelize.DATE,
|
createdAt: Sequelize.DATE,
|
||||||
updatedAt: Sequelize.DATE
|
updatedAt: Sequelize.DATE
|
||||||
});
|
})
|
||||||
return;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
down: function (queryInterface, Sequelize) {
|
down: function (queryInterface, Sequelize) {
|
||||||
queryInterface.dropTable('Authors');
|
queryInterface.dropTable('Authors')
|
||||||
queryInterface.removeColumn('Revisions', 'authorship');
|
queryInterface.removeColumn('Revisions', 'authorship')
|
||||||
queryInterface.removeColumn('Notes', 'authorship');
|
queryInterface.removeColumn('Notes', 'authorship')
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function (queryInterface, Sequelize) {
|
up: function (queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('Notes', 'deletedAt', Sequelize.DATE);
|
queryInterface.addColumn('Notes', 'deletedAt', Sequelize.DATE)
|
||||||
},
|
},
|
||||||
|
|
||||||
down: function (queryInterface, Sequelize) {
|
down: function (queryInterface, Sequelize) {
|
||||||
queryInterface.removeColumn('Notes', 'deletedAt');
|
queryInterface.removeColumn('Notes', 'deletedAt')
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function (queryInterface, Sequelize) {
|
up: function (queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('Users', 'email', Sequelize.TEXT);
|
queryInterface.addColumn('Users', 'email', Sequelize.TEXT)
|
||||||
queryInterface.addColumn('Users', 'password', Sequelize.TEXT);
|
queryInterface.addColumn('Users', 'password', Sequelize.TEXT)
|
||||||
},
|
},
|
||||||
|
|
||||||
down: function (queryInterface, Sequelize) {
|
down: function (queryInterface, Sequelize) {
|
||||||
queryInterface.removeColumn('Users', 'email');
|
queryInterface.removeColumn('Users', 'email')
|
||||||
queryInterface.removeColumn('Users', 'password');
|
queryInterface.removeColumn('Users', 'password')
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,43 +1,37 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// external modules
|
// external modules
|
||||||
var Sequelize = require("sequelize");
|
var Sequelize = require('sequelize')
|
||||||
|
|
||||||
// core
|
|
||||||
var logger = require("../logger.js");
|
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function (sequelize, DataTypes) {
|
||||||
var Author = sequelize.define("Author", {
|
var Author = sequelize.define('Author', {
|
||||||
id: {
|
id: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
autoIncrement: true
|
autoIncrement: true
|
||||||
},
|
},
|
||||||
color: {
|
color: {
|
||||||
type: DataTypes.STRING
|
type: DataTypes.STRING
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['noteId', 'userId']
|
fields: ['noteId', 'userId']
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
associate: function (models) {
|
associate: function (models) {
|
||||||
Author.belongsTo(models.Note, {
|
Author.belongsTo(models.Note, {
|
||||||
foreignKey: "noteId",
|
foreignKey: 'noteId',
|
||||||
as: "note",
|
as: 'note',
|
||||||
constraints: false
|
constraints: false
|
||||||
});
|
})
|
||||||
Author.belongsTo(models.User, {
|
Author.belongsTo(models.User, {
|
||||||
foreignKey: "userId",
|
foreignKey: 'userId',
|
||||||
as: "user",
|
as: 'user',
|
||||||
constraints: false
|
constraints: false
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
return Author
|
||||||
return Author;
|
}
|
||||||
};
|
|
||||||
|
|
|
@ -1,57 +1,55 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// external modules
|
// external modules
|
||||||
var fs = require("fs");
|
var fs = require('fs')
|
||||||
var path = require("path");
|
var path = require('path')
|
||||||
var Sequelize = require("sequelize");
|
var Sequelize = require('sequelize')
|
||||||
|
|
||||||
// core
|
// core
|
||||||
var config = require('../config.js');
|
var config = require('../config.js')
|
||||||
var logger = require("../logger.js");
|
var logger = require('../logger.js')
|
||||||
|
|
||||||
var dbconfig = config.db;
|
var dbconfig = config.db
|
||||||
dbconfig.logging = config.debug ? logger.info : false;
|
dbconfig.logging = config.debug ? logger.info : false
|
||||||
|
|
||||||
var sequelize = null;
|
var sequelize = null
|
||||||
|
|
||||||
// Heroku specific
|
// Heroku specific
|
||||||
if (config.dburl)
|
if (config.dburl) {
|
||||||
sequelize = new Sequelize(config.dburl, dbconfig);
|
sequelize = new Sequelize(config.dburl, dbconfig)
|
||||||
else
|
} else {
|
||||||
sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig);
|
sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig)
|
||||||
|
}
|
||||||
|
|
||||||
// [Postgres] Handling NULL bytes
|
// [Postgres] Handling NULL bytes
|
||||||
// https://github.com/sequelize/sequelize/issues/6485
|
// https://github.com/sequelize/sequelize/issues/6485
|
||||||
function stripNullByte(value) {
|
function stripNullByte (value) {
|
||||||
return value ? value.replace(/\u0000/g, "") : value;
|
return value ? value.replace(/\u0000/g, '') : value
|
||||||
}
|
}
|
||||||
sequelize.stripNullByte = stripNullByte;
|
sequelize.stripNullByte = stripNullByte
|
||||||
|
|
||||||
function processData(data, _default, process) {
|
function processData (data, _default, process) {
|
||||||
if (data === undefined) return data;
|
if (data === undefined) return data
|
||||||
else return data === null ? _default : (process ? process(data) : data);
|
else return data === null ? _default : (process ? process(data) : data)
|
||||||
}
|
}
|
||||||
sequelize.processData = processData;
|
sequelize.processData = processData
|
||||||
|
|
||||||
var db = {};
|
var db = {}
|
||||||
|
|
||||||
fs
|
fs.readdirSync(__dirname)
|
||||||
.readdirSync(__dirname)
|
|
||||||
.filter(function (file) {
|
.filter(function (file) {
|
||||||
return (file.indexOf(".") !== 0) && (file !== "index.js");
|
return (file.indexOf('.') !== 0) && (file !== 'index.js')
|
||||||
})
|
})
|
||||||
.forEach(function (file) {
|
.forEach(function (file) {
|
||||||
var model = sequelize.import(path.join(__dirname, file));
|
var model = sequelize.import(path.join(__dirname, file))
|
||||||
db[model.name] = model;
|
db[model.name] = model
|
||||||
});
|
})
|
||||||
|
|
||||||
Object.keys(db).forEach(function (modelName) {
|
Object.keys(db).forEach(function (modelName) {
|
||||||
if ("associate" in db[modelName]) {
|
if ('associate' in db[modelName]) {
|
||||||
db[modelName].associate(db);
|
db[modelName].associate(db)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
db.sequelize = sequelize;
|
db.sequelize = sequelize
|
||||||
db.Sequelize = Sequelize;
|
db.Sequelize = Sequelize
|
||||||
|
|
||||||
module.exports = db;
|
module.exports = db
|
||||||
|
|
1021
lib/models/note.js
1021
lib/models/note.js
File diff suppressed because it is too large
Load diff
|
@ -1,306 +1,306 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// external modules
|
// external modules
|
||||||
var Sequelize = require("sequelize");
|
var Sequelize = require('sequelize')
|
||||||
var async = require('async');
|
var async = require('async')
|
||||||
var moment = require('moment');
|
var moment = require('moment')
|
||||||
var childProcess = require('child_process');
|
var childProcess = require('child_process')
|
||||||
var shortId = require('shortid');
|
var shortId = require('shortid')
|
||||||
|
|
||||||
// core
|
// core
|
||||||
var config = require("../config.js");
|
var config = require('../config.js')
|
||||||
var logger = require("../logger.js");
|
var logger = require('../logger.js')
|
||||||
|
|
||||||
var dmpWorker = createDmpWorker();
|
var dmpWorker = createDmpWorker()
|
||||||
var dmpCallbackCache = {};
|
var dmpCallbackCache = {}
|
||||||
|
|
||||||
function createDmpWorker() {
|
function createDmpWorker () {
|
||||||
var worker = childProcess.fork("./lib/workers/dmpWorker.js", {
|
var worker = childProcess.fork('./lib/workers/dmpWorker.js', {
|
||||||
stdio: 'ignore'
|
stdio: 'ignore'
|
||||||
});
|
})
|
||||||
if (config.debug) logger.info('dmp worker process started');
|
if (config.debug) logger.info('dmp worker process started')
|
||||||
worker.on('message', function (data) {
|
worker.on('message', function (data) {
|
||||||
if (!data || !data.msg || !data.cacheKey) {
|
if (!data || !data.msg || !data.cacheKey) {
|
||||||
return logger.error('dmp worker error: not enough data on message');
|
return logger.error('dmp worker error: not enough data on message')
|
||||||
}
|
}
|
||||||
var cacheKey = data.cacheKey;
|
var cacheKey = data.cacheKey
|
||||||
switch(data.msg) {
|
switch (data.msg) {
|
||||||
case 'error':
|
case 'error':
|
||||||
dmpCallbackCache[cacheKey](data.error, null);
|
dmpCallbackCache[cacheKey](data.error, null)
|
||||||
break;
|
break
|
||||||
case 'check':
|
case 'check':
|
||||||
dmpCallbackCache[cacheKey](null, data.result);
|
dmpCallbackCache[cacheKey](null, data.result)
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
delete dmpCallbackCache[cacheKey];
|
delete dmpCallbackCache[cacheKey]
|
||||||
});
|
})
|
||||||
worker.on('close', function (code) {
|
worker.on('close', function (code) {
|
||||||
dmpWorker = null;
|
dmpWorker = null
|
||||||
if (config.debug) logger.info('dmp worker process exited with code ' + code);
|
if (config.debug) logger.info('dmp worker process exited with code ' + code)
|
||||||
});
|
})
|
||||||
return worker;
|
return worker
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendDmpWorker(data, callback) {
|
function sendDmpWorker (data, callback) {
|
||||||
if (!dmpWorker) dmpWorker = createDmpWorker();
|
if (!dmpWorker) dmpWorker = createDmpWorker()
|
||||||
var cacheKey = Date.now() + '_' + shortId.generate();
|
var cacheKey = Date.now() + '_' + shortId.generate()
|
||||||
dmpCallbackCache[cacheKey] = callback;
|
dmpCallbackCache[cacheKey] = callback
|
||||||
data = Object.assign(data, {
|
data = Object.assign(data, {
|
||||||
cacheKey: cacheKey
|
cacheKey: cacheKey
|
||||||
});
|
})
|
||||||
dmpWorker.send(data);
|
dmpWorker.send(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function (sequelize, DataTypes) {
|
||||||
var Revision = sequelize.define("Revision", {
|
var Revision = sequelize.define('Revision', {
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
defaultValue: Sequelize.UUIDV4
|
defaultValue: Sequelize.UUIDV4
|
||||||
},
|
},
|
||||||
patch: {
|
patch: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
get: function () {
|
get: function () {
|
||||||
return sequelize.processData(this.getDataValue('patch'), "");
|
return sequelize.processData(this.getDataValue('patch'), '')
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setDataValue('patch', sequelize.stripNullByte(value))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
lastContent: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
get: function () {
|
||||||
|
return sequelize.processData(this.getDataValue('lastContent'), '')
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setDataValue('lastContent', sequelize.stripNullByte(value))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
get: function () {
|
||||||
|
return sequelize.processData(this.getDataValue('content'), '')
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setDataValue('content', sequelize.stripNullByte(value))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
length: {
|
||||||
|
type: DataTypes.INTEGER
|
||||||
|
},
|
||||||
|
authorship: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
get: function () {
|
||||||
|
return sequelize.processData(this.getDataValue('authorship'), [], JSON.parse)
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setDataValue('authorship', value ? JSON.stringify(value) : value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
classMethods: {
|
||||||
|
associate: function (models) {
|
||||||
|
Revision.belongsTo(models.Note, {
|
||||||
|
foreignKey: 'noteId',
|
||||||
|
as: 'note',
|
||||||
|
constraints: false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getNoteRevisions: function (note, callback) {
|
||||||
|
Revision.findAll({
|
||||||
|
where: {
|
||||||
|
noteId: note.id
|
||||||
|
},
|
||||||
|
order: '"createdAt" DESC'
|
||||||
|
}).then(function (revisions) {
|
||||||
|
var data = []
|
||||||
|
for (var i = 0, l = revisions.length; i < l; i++) {
|
||||||
|
var revision = revisions[i]
|
||||||
|
data.push({
|
||||||
|
time: moment(revision.createdAt).valueOf(),
|
||||||
|
length: revision.length
|
||||||
|
})
|
||||||
|
}
|
||||||
|
callback(null, data)
|
||||||
|
}).catch(function (err) {
|
||||||
|
callback(err, null)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getPatchedNoteRevisionByTime: function (note, time, callback) {
|
||||||
|
// find all revisions to prepare for all possible calculation
|
||||||
|
Revision.findAll({
|
||||||
|
where: {
|
||||||
|
noteId: note.id
|
||||||
|
},
|
||||||
|
order: '"createdAt" DESC'
|
||||||
|
}).then(function (revisions) {
|
||||||
|
if (revisions.length <= 0) return callback(null, null)
|
||||||
|
// measure target revision position
|
||||||
|
Revision.count({
|
||||||
|
where: {
|
||||||
|
noteId: note.id,
|
||||||
|
createdAt: {
|
||||||
|
$gte: time
|
||||||
|
}
|
||||||
},
|
},
|
||||||
set: function (value) {
|
order: '"createdAt" DESC'
|
||||||
this.setDataValue('patch', sequelize.stripNullByte(value));
|
}).then(function (count) {
|
||||||
}
|
if (count <= 0) return callback(null, null)
|
||||||
},
|
sendDmpWorker({
|
||||||
lastContent: {
|
msg: 'get revision',
|
||||||
type: DataTypes.TEXT,
|
revisions: revisions,
|
||||||
get: function () {
|
count: count
|
||||||
return sequelize.processData(this.getDataValue('lastContent'), "");
|
}, callback)
|
||||||
},
|
}).catch(function (err) {
|
||||||
set: function (value) {
|
return callback(err, null)
|
||||||
this.setDataValue('lastContent', sequelize.stripNullByte(value));
|
})
|
||||||
}
|
}).catch(function (err) {
|
||||||
},
|
return callback(err, null)
|
||||||
content: {
|
})
|
||||||
type: DataTypes.TEXT,
|
},
|
||||||
get: function () {
|
checkAllNotesRevision: function (callback) {
|
||||||
return sequelize.processData(this.getDataValue('content'), "");
|
Revision.saveAllNotesRevision(function (err, notes) {
|
||||||
},
|
if (err) return callback(err, null)
|
||||||
set: function (value) {
|
if (!notes || notes.length <= 0) {
|
||||||
this.setDataValue('content', sequelize.stripNullByte(value));
|
return callback(null, notes)
|
||||||
}
|
} else {
|
||||||
},
|
Revision.checkAllNotesRevision(callback)
|
||||||
length: {
|
}
|
||||||
type: DataTypes.INTEGER
|
})
|
||||||
},
|
},
|
||||||
authorship: {
|
saveAllNotesRevision: function (callback) {
|
||||||
type: DataTypes.TEXT,
|
sequelize.models.Note.findAll({
|
||||||
get: function () {
|
// query all notes that need to save for revision
|
||||||
return sequelize.processData(this.getDataValue('authorship'), [], JSON.parse);
|
where: {
|
||||||
},
|
$and: [
|
||||||
set: function (value) {
|
{
|
||||||
this.setDataValue('authorship', value ? JSON.stringify(value) : value);
|
lastchangeAt: {
|
||||||
}
|
$or: {
|
||||||
}
|
$eq: null,
|
||||||
}, {
|
$and: {
|
||||||
classMethods: {
|
$ne: null,
|
||||||
associate: function (models) {
|
$gt: sequelize.col('createdAt')
|
||||||
Revision.belongsTo(models.Note, {
|
|
||||||
foreignKey: "noteId",
|
|
||||||
as: "note",
|
|
||||||
constraints: false
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getNoteRevisions: function (note, callback) {
|
|
||||||
Revision.findAll({
|
|
||||||
where: {
|
|
||||||
noteId: note.id
|
|
||||||
},
|
|
||||||
order: '"createdAt" DESC'
|
|
||||||
}).then(function (revisions) {
|
|
||||||
var data = [];
|
|
||||||
for (var i = 0, l = revisions.length; i < l; i++) {
|
|
||||||
var revision = revisions[i];
|
|
||||||
data.push({
|
|
||||||
time: moment(revision.createdAt).valueOf(),
|
|
||||||
length: revision.length
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
callback(null, data);
|
}
|
||||||
}).catch(function (err) {
|
}
|
||||||
callback(err, null);
|
},
|
||||||
});
|
{
|
||||||
},
|
savedAt: {
|
||||||
getPatchedNoteRevisionByTime: function (note, time, callback) {
|
$or: {
|
||||||
// find all revisions to prepare for all possible calculation
|
$eq: null,
|
||||||
Revision.findAll({
|
$lt: sequelize.col('lastchangeAt')
|
||||||
where: {
|
}
|
||||||
noteId: note.id
|
}
|
||||||
},
|
}
|
||||||
order: '"createdAt" DESC'
|
]
|
||||||
}).then(function (revisions) {
|
}
|
||||||
if (revisions.length <= 0) return callback(null, null);
|
}).then(function (notes) {
|
||||||
// measure target revision position
|
if (notes.length <= 0) return callback(null, notes)
|
||||||
Revision.count({
|
var savedNotes = []
|
||||||
where: {
|
async.each(notes, function (note, _callback) {
|
||||||
noteId: note.id,
|
// revision saving policy: note not been modified for 5 mins or not save for 10 mins
|
||||||
createdAt: {
|
if (note.lastchangeAt && note.savedAt) {
|
||||||
$gte: time
|
var lastchangeAt = moment(note.lastchangeAt)
|
||||||
}
|
var savedAt = moment(note.savedAt)
|
||||||
},
|
if (moment().isAfter(lastchangeAt.add(5, 'minutes'))) {
|
||||||
order: '"createdAt" DESC'
|
savedNotes.push(note)
|
||||||
}).then(function (count) {
|
Revision.saveNoteRevision(note, _callback)
|
||||||
if (count <= 0) return callback(null, null);
|
} else if (lastchangeAt.isAfter(savedAt.add(10, 'minutes'))) {
|
||||||
sendDmpWorker({
|
savedNotes.push(note)
|
||||||
msg: 'get revision',
|
Revision.saveNoteRevision(note, _callback)
|
||||||
revisions: revisions,
|
} else {
|
||||||
count: count
|
return _callback(null, null)
|
||||||
}, callback);
|
}
|
||||||
}).catch(function (err) {
|
} else {
|
||||||
return callback(err, null);
|
savedNotes.push(note)
|
||||||
});
|
Revision.saveNoteRevision(note, _callback)
|
||||||
}).catch(function (err) {
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
checkAllNotesRevision: function (callback) {
|
|
||||||
Revision.saveAllNotesRevision(function (err, notes) {
|
|
||||||
if (err) return callback(err, null);
|
|
||||||
if (!notes || notes.length <= 0) {
|
|
||||||
return callback(null, notes);
|
|
||||||
} else {
|
|
||||||
Revision.checkAllNotesRevision(callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
saveAllNotesRevision: function (callback) {
|
|
||||||
sequelize.models.Note.findAll({
|
|
||||||
// query all notes that need to save for revision
|
|
||||||
where: {
|
|
||||||
$and: [
|
|
||||||
{
|
|
||||||
lastchangeAt: {
|
|
||||||
$or: {
|
|
||||||
$eq: null,
|
|
||||||
$and: {
|
|
||||||
$ne: null,
|
|
||||||
$gt: sequelize.col('createdAt')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
savedAt: {
|
|
||||||
$or: {
|
|
||||||
$eq: null,
|
|
||||||
$lt: sequelize.col('lastchangeAt')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}).then(function (notes) {
|
|
||||||
if (notes.length <= 0) return callback(null, notes);
|
|
||||||
var savedNotes = [];
|
|
||||||
async.each(notes, function (note, _callback) {
|
|
||||||
// revision saving policy: note not been modified for 5 mins or not save for 10 mins
|
|
||||||
if (note.lastchangeAt && note.savedAt) {
|
|
||||||
var lastchangeAt = moment(note.lastchangeAt);
|
|
||||||
var savedAt = moment(note.savedAt);
|
|
||||||
if (moment().isAfter(lastchangeAt.add(5, 'minutes'))) {
|
|
||||||
savedNotes.push(note);
|
|
||||||
Revision.saveNoteRevision(note, _callback);
|
|
||||||
} else if (lastchangeAt.isAfter(savedAt.add(10, 'minutes'))) {
|
|
||||||
savedNotes.push(note);
|
|
||||||
Revision.saveNoteRevision(note, _callback);
|
|
||||||
} else {
|
|
||||||
return _callback(null, null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
savedNotes.push(note);
|
|
||||||
Revision.saveNoteRevision(note, _callback);
|
|
||||||
}
|
|
||||||
}, function (err) {
|
|
||||||
if (err) return callback(err, null);
|
|
||||||
// return null when no notes need saving at this moment but have delayed tasks to be done
|
|
||||||
var result = ((savedNotes.length == 0) && (notes.length > savedNotes.length)) ? null : savedNotes;
|
|
||||||
return callback(null, result);
|
|
||||||
});
|
|
||||||
}).catch(function (err) {
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
saveNoteRevision: function (note, callback) {
|
|
||||||
Revision.findAll({
|
|
||||||
where: {
|
|
||||||
noteId: note.id
|
|
||||||
},
|
|
||||||
order: '"createdAt" DESC'
|
|
||||||
}).then(function (revisions) {
|
|
||||||
if (revisions.length <= 0) {
|
|
||||||
// if no revision available
|
|
||||||
Revision.create({
|
|
||||||
noteId: note.id,
|
|
||||||
lastContent: note.content,
|
|
||||||
length: note.content.length,
|
|
||||||
authorship: note.authorship
|
|
||||||
}).then(function (revision) {
|
|
||||||
Revision.finishSaveNoteRevision(note, revision, callback);
|
|
||||||
}).catch(function (err) {
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var latestRevision = revisions[0];
|
|
||||||
var lastContent = latestRevision.content || latestRevision.lastContent;
|
|
||||||
var content = note.content;
|
|
||||||
sendDmpWorker({
|
|
||||||
msg: 'create patch',
|
|
||||||
lastDoc: lastContent,
|
|
||||||
currDoc: content,
|
|
||||||
}, function (err, patch) {
|
|
||||||
if (err) logger.error('save note revision error', err);
|
|
||||||
if (!patch) {
|
|
||||||
// if patch is empty (means no difference) then just update the latest revision updated time
|
|
||||||
latestRevision.changed('updatedAt', true);
|
|
||||||
latestRevision.update({
|
|
||||||
updatedAt: Date.now()
|
|
||||||
}).then(function (revision) {
|
|
||||||
Revision.finishSaveNoteRevision(note, revision, callback);
|
|
||||||
}).catch(function (err) {
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Revision.create({
|
|
||||||
noteId: note.id,
|
|
||||||
patch: patch,
|
|
||||||
content: note.content,
|
|
||||||
length: note.content.length,
|
|
||||||
authorship: note.authorship
|
|
||||||
}).then(function (revision) {
|
|
||||||
// clear last revision content to reduce db size
|
|
||||||
latestRevision.update({
|
|
||||||
content: null
|
|
||||||
}).then(function () {
|
|
||||||
Revision.finishSaveNoteRevision(note, revision, callback);
|
|
||||||
}).catch(function (err) {
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
}).catch(function (err) {
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).catch(function (err) {
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
finishSaveNoteRevision: function (note, revision, callback) {
|
|
||||||
note.update({
|
|
||||||
savedAt: revision.updatedAt
|
|
||||||
}).then(function () {
|
|
||||||
return callback(null, revision);
|
|
||||||
}).catch(function (err) {
|
|
||||||
return callback(err, null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}, function (err) {
|
||||||
});
|
if (err) {
|
||||||
|
return callback(err, null)
|
||||||
|
}
|
||||||
|
// return null when no notes need saving at this moment but have delayed tasks to be done
|
||||||
|
var result = ((savedNotes.length === 0) && (notes.length > savedNotes.length)) ? null : savedNotes
|
||||||
|
return callback(null, result)
|
||||||
|
})
|
||||||
|
}).catch(function (err) {
|
||||||
|
return callback(err, null)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
saveNoteRevision: function (note, callback) {
|
||||||
|
Revision.findAll({
|
||||||
|
where: {
|
||||||
|
noteId: note.id
|
||||||
|
},
|
||||||
|
order: '"createdAt" DESC'
|
||||||
|
}).then(function (revisions) {
|
||||||
|
if (revisions.length <= 0) {
|
||||||
|
// if no revision available
|
||||||
|
Revision.create({
|
||||||
|
noteId: note.id,
|
||||||
|
lastContent: note.content,
|
||||||
|
length: note.content.length,
|
||||||
|
authorship: note.authorship
|
||||||
|
}).then(function (revision) {
|
||||||
|
Revision.finishSaveNoteRevision(note, revision, callback)
|
||||||
|
}).catch(function (err) {
|
||||||
|
return callback(err, null)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
var latestRevision = revisions[0]
|
||||||
|
var lastContent = latestRevision.content || latestRevision.lastContent
|
||||||
|
var content = note.content
|
||||||
|
sendDmpWorker({
|
||||||
|
msg: 'create patch',
|
||||||
|
lastDoc: lastContent,
|
||||||
|
currDoc: content
|
||||||
|
}, function (err, patch) {
|
||||||
|
if (err) logger.error('save note revision error', err)
|
||||||
|
if (!patch) {
|
||||||
|
// if patch is empty (means no difference) then just update the latest revision updated time
|
||||||
|
latestRevision.changed('updatedAt', true)
|
||||||
|
latestRevision.update({
|
||||||
|
updatedAt: Date.now()
|
||||||
|
}).then(function (revision) {
|
||||||
|
Revision.finishSaveNoteRevision(note, revision, callback)
|
||||||
|
}).catch(function (err) {
|
||||||
|
return callback(err, null)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Revision.create({
|
||||||
|
noteId: note.id,
|
||||||
|
patch: patch,
|
||||||
|
content: note.content,
|
||||||
|
length: note.content.length,
|
||||||
|
authorship: note.authorship
|
||||||
|
}).then(function (revision) {
|
||||||
|
// clear last revision content to reduce db size
|
||||||
|
latestRevision.update({
|
||||||
|
content: null
|
||||||
|
}).then(function () {
|
||||||
|
Revision.finishSaveNoteRevision(note, revision, callback)
|
||||||
|
}).catch(function (err) {
|
||||||
|
return callback(err, null)
|
||||||
|
})
|
||||||
|
}).catch(function (err) {
|
||||||
|
return callback(err, null)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}).catch(function (err) {
|
||||||
|
return callback(err, null)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
finishSaveNoteRevision: function (note, revision, callback) {
|
||||||
|
note.update({
|
||||||
|
savedAt: revision.updatedAt
|
||||||
|
}).then(function () {
|
||||||
|
return callback(null, revision)
|
||||||
|
}).catch(function (err) {
|
||||||
|
return callback(err, null)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return Revision;
|
return Revision
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
"use strict";
|
// external modules
|
||||||
|
var shortId = require('shortid')
|
||||||
//external modules
|
|
||||||
var shortId = require('shortid');
|
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function (sequelize, DataTypes) {
|
||||||
var Temp = sequelize.define("Temp", {
|
var Temp = sequelize.define('Temp', {
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
defaultValue: shortId.generate
|
defaultValue: shortId.generate
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
type: DataTypes.TEXT
|
type: DataTypes.TEXT
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
return Temp;
|
return Temp
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,149 +1,147 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// external modules
|
// external modules
|
||||||
var md5 = require("blueimp-md5");
|
var md5 = require('blueimp-md5')
|
||||||
var Sequelize = require("sequelize");
|
var Sequelize = require('sequelize')
|
||||||
var scrypt = require('scrypt');
|
var scrypt = require('scrypt')
|
||||||
|
|
||||||
// core
|
// core
|
||||||
var logger = require("../logger.js");
|
var logger = require('../logger.js')
|
||||||
var letterAvatars = require('../letter-avatars.js');
|
var letterAvatars = require('../letter-avatars.js')
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function (sequelize, DataTypes) {
|
||||||
var User = sequelize.define("User", {
|
var User = sequelize.define('User', {
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
defaultValue: Sequelize.UUIDV4
|
defaultValue: Sequelize.UUIDV4
|
||||||
},
|
},
|
||||||
profileid: {
|
profileid: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
unique: true
|
unique: true
|
||||||
},
|
},
|
||||||
profile: {
|
profile: {
|
||||||
type: DataTypes.TEXT
|
type: DataTypes.TEXT
|
||||||
},
|
},
|
||||||
history: {
|
history: {
|
||||||
type: DataTypes.TEXT
|
type: DataTypes.TEXT
|
||||||
},
|
},
|
||||||
accessToken: {
|
accessToken: {
|
||||||
type: DataTypes.STRING
|
type: DataTypes.STRING
|
||||||
},
|
},
|
||||||
refreshToken: {
|
refreshToken: {
|
||||||
type: DataTypes.STRING
|
type: DataTypes.STRING
|
||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
type: Sequelize.TEXT,
|
type: Sequelize.TEXT,
|
||||||
validate: {
|
validate: {
|
||||||
isEmail: true
|
isEmail: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
password: {
|
password: {
|
||||||
type: Sequelize.TEXT,
|
type: Sequelize.TEXT,
|
||||||
set: function(value) {
|
set: function (value) {
|
||||||
var hash = scrypt.kdfSync(value, scrypt.paramsSync(0.1)).toString("hex");
|
var hash = scrypt.kdfSync(value, scrypt.paramsSync(0.1)).toString('hex')
|
||||||
this.setDataValue('password', hash);
|
this.setDataValue('password', hash)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
instanceMethods: {
|
||||||
|
verifyPassword: function (attempt) {
|
||||||
|
if (scrypt.verifyKdfSync(new Buffer(this.password, 'hex'), attempt)) {
|
||||||
|
return this
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}, {
|
}
|
||||||
instanceMethods: {
|
},
|
||||||
verifyPassword: function(attempt) {
|
classMethods: {
|
||||||
if (scrypt.verifyKdfSync(new Buffer(this.password, "hex"), attempt)) {
|
associate: function (models) {
|
||||||
return this;
|
User.hasMany(models.Note, {
|
||||||
} else {
|
foreignKey: 'ownerId',
|
||||||
return false;
|
constraints: false
|
||||||
}
|
})
|
||||||
}
|
User.hasMany(models.Note, {
|
||||||
},
|
foreignKey: 'lastchangeuserId',
|
||||||
classMethods: {
|
constraints: false
|
||||||
associate: function (models) {
|
})
|
||||||
User.hasMany(models.Note, {
|
},
|
||||||
foreignKey: "ownerId",
|
getProfile: function (user) {
|
||||||
constraints: false
|
return user.profile ? User.parseProfile(user.profile) : (user.email ? User.parseProfileByEmail(user.email) : null)
|
||||||
});
|
},
|
||||||
User.hasMany(models.Note, {
|
parseProfile: function (profile) {
|
||||||
foreignKey: "lastchangeuserId",
|
try {
|
||||||
constraints: false
|
profile = JSON.parse(profile)
|
||||||
});
|
} catch (err) {
|
||||||
},
|
logger.error(err)
|
||||||
getProfile: function (user) {
|
profile = null
|
||||||
return user.profile ? User.parseProfile(user.profile) : (user.email ? User.parseProfileByEmail(user.email) : null);
|
|
||||||
},
|
|
||||||
parseProfile: function (profile) {
|
|
||||||
try {
|
|
||||||
var profile = JSON.parse(profile);
|
|
||||||
} catch (err) {
|
|
||||||
logger.error(err);
|
|
||||||
profile = null;
|
|
||||||
}
|
|
||||||
if (profile) {
|
|
||||||
profile = {
|
|
||||||
name: profile.displayName || profile.username,
|
|
||||||
photo: User.parsePhotoByProfile(profile),
|
|
||||||
biggerphoto: User.parsePhotoByProfile(profile, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return profile;
|
|
||||||
},
|
|
||||||
parsePhotoByProfile: function (profile, bigger) {
|
|
||||||
var photo = null;
|
|
||||||
switch (profile.provider) {
|
|
||||||
case "facebook":
|
|
||||||
photo = 'https://graph.facebook.com/' + profile.id + '/picture';
|
|
||||||
if (bigger) photo += '?width=400';
|
|
||||||
else photo += '?width=96';
|
|
||||||
break;
|
|
||||||
case "twitter":
|
|
||||||
photo = 'https://twitter.com/' + profile.username + '/profile_image';
|
|
||||||
if (bigger) photo += '?size=original';
|
|
||||||
else photo += '?size=bigger';
|
|
||||||
break;
|
|
||||||
case "github":
|
|
||||||
photo = 'https://avatars.githubusercontent.com/u/' + profile.id;
|
|
||||||
if (bigger) photo += '?s=400';
|
|
||||||
else photo += '?s=96';
|
|
||||||
break;
|
|
||||||
case "gitlab":
|
|
||||||
photo = profile.avatarUrl;
|
|
||||||
if (bigger) photo = photo.replace(/(\?s=)\d*$/i, '$1400');
|
|
||||||
else photo = photo.replace(/(\?s=)\d*$/i, '$196');
|
|
||||||
break;
|
|
||||||
case "dropbox":
|
|
||||||
//no image api provided, use gravatar
|
|
||||||
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value);
|
|
||||||
if (bigger) photo += '?s=400';
|
|
||||||
else photo += '?s=96';
|
|
||||||
break;
|
|
||||||
case "google":
|
|
||||||
photo = profile.photos[0].value;
|
|
||||||
if (bigger) photo = photo.replace(/(\?sz=)\d*$/i, '$1400');
|
|
||||||
else photo = photo.replace(/(\?sz=)\d*$/i, '$196');
|
|
||||||
break;
|
|
||||||
case "ldap":
|
|
||||||
//no image api provided,
|
|
||||||
//use gravatar if email exists,
|
|
||||||
//otherwise generate a letter avatar
|
|
||||||
if (profile.emails[0]) {
|
|
||||||
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0]);
|
|
||||||
if (bigger) photo += '?s=400';
|
|
||||||
else photo += '?s=96';
|
|
||||||
} else {
|
|
||||||
photo = letterAvatars(profile.username);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return photo;
|
|
||||||
},
|
|
||||||
parseProfileByEmail: function (email) {
|
|
||||||
var photoUrl = 'https://www.gravatar.com/avatar/' + md5(email);
|
|
||||||
return {
|
|
||||||
name: email.substring(0, email.lastIndexOf("@")),
|
|
||||||
photo: photoUrl += '?s=96',
|
|
||||||
biggerphoto: photoUrl += '?s=400'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
if (profile) {
|
||||||
|
profile = {
|
||||||
|
name: profile.displayName || profile.username,
|
||||||
|
photo: User.parsePhotoByProfile(profile),
|
||||||
|
biggerphoto: User.parsePhotoByProfile(profile, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return profile
|
||||||
|
},
|
||||||
|
parsePhotoByProfile: function (profile, bigger) {
|
||||||
|
var photo = null
|
||||||
|
switch (profile.provider) {
|
||||||
|
case 'facebook':
|
||||||
|
photo = 'https://graph.facebook.com/' + profile.id + '/picture'
|
||||||
|
if (bigger) photo += '?width=400'
|
||||||
|
else photo += '?width=96'
|
||||||
|
break
|
||||||
|
case 'twitter':
|
||||||
|
photo = 'https://twitter.com/' + profile.username + '/profile_image'
|
||||||
|
if (bigger) photo += '?size=original'
|
||||||
|
else photo += '?size=bigger'
|
||||||
|
break
|
||||||
|
case 'github':
|
||||||
|
photo = 'https://avatars.githubusercontent.com/u/' + profile.id
|
||||||
|
if (bigger) photo += '?s=400'
|
||||||
|
else photo += '?s=96'
|
||||||
|
break
|
||||||
|
case 'gitlab':
|
||||||
|
photo = profile.avatarUrl
|
||||||
|
if (bigger) photo = photo.replace(/(\?s=)\d*$/i, '$1400')
|
||||||
|
else photo = photo.replace(/(\?s=)\d*$/i, '$196')
|
||||||
|
break
|
||||||
|
case 'dropbox':
|
||||||
|
// no image api provided, use gravatar
|
||||||
|
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value)
|
||||||
|
if (bigger) photo += '?s=400'
|
||||||
|
else photo += '?s=96'
|
||||||
|
break
|
||||||
|
case 'google':
|
||||||
|
photo = profile.photos[0].value
|
||||||
|
if (bigger) photo = photo.replace(/(\?sz=)\d*$/i, '$1400')
|
||||||
|
else photo = photo.replace(/(\?sz=)\d*$/i, '$196')
|
||||||
|
break
|
||||||
|
case 'ldap':
|
||||||
|
// no image api provided,
|
||||||
|
// use gravatar if email exists,
|
||||||
|
// otherwise generate a letter avatar
|
||||||
|
if (profile.emails[0]) {
|
||||||
|
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0])
|
||||||
|
if (bigger) photo += '?s=400'
|
||||||
|
else photo += '?s=96'
|
||||||
|
} else {
|
||||||
|
photo = letterAvatars(profile.username)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return photo
|
||||||
|
},
|
||||||
|
parseProfileByEmail: function (email) {
|
||||||
|
var photoUrl = 'https://www.gravatar.com/avatar/' + md5(email)
|
||||||
|
return {
|
||||||
|
name: email.substring(0, email.lastIndexOf('@')),
|
||||||
|
photo: photoUrl + '?s=96',
|
||||||
|
biggerphoto: photoUrl + '?s=400'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return User;
|
return User
|
||||||
};
|
}
|
||||||
|
|
1793
lib/realtime.js
1793
lib/realtime.js
File diff suppressed because it is too large
Load diff
1128
lib/response.js
1128
lib/response.js
File diff suppressed because it is too large
Load diff
|
@ -1,140 +1,137 @@
|
||||||
// external modules
|
// external modules
|
||||||
var DiffMatchPatch = require('diff-match-patch');
|
var DiffMatchPatch = require('diff-match-patch')
|
||||||
var dmp = new DiffMatchPatch();
|
var dmp = new DiffMatchPatch()
|
||||||
|
|
||||||
// core
|
// core
|
||||||
var config = require("../config.js");
|
var config = require('../config.js')
|
||||||
var logger = require("../logger.js");
|
var logger = require('../logger.js')
|
||||||
|
|
||||||
process.on('message', function(data) {
|
process.on('message', function (data) {
|
||||||
if (!data || !data.msg || !data.cacheKey) {
|
if (!data || !data.msg || !data.cacheKey) {
|
||||||
return logger.error('dmp worker error: not enough data');
|
return logger.error('dmp worker error: not enough data')
|
||||||
}
|
}
|
||||||
switch (data.msg) {
|
switch (data.msg) {
|
||||||
case 'create patch':
|
case 'create patch':
|
||||||
if (!data.hasOwnProperty('lastDoc') || !data.hasOwnProperty('currDoc')) {
|
if (!data.hasOwnProperty('lastDoc') || !data.hasOwnProperty('currDoc')) {
|
||||||
return logger.error('dmp worker error: not enough data on create patch');
|
return logger.error('dmp worker error: not enough data on create patch')
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var patch = createPatch(data.lastDoc, data.currDoc);
|
var patch = createPatch(data.lastDoc, data.currDoc)
|
||||||
process.send({
|
process.send({
|
||||||
msg: 'check',
|
msg: 'check',
|
||||||
result: patch,
|
result: patch,
|
||||||
cacheKey: data.cacheKey
|
cacheKey: data.cacheKey
|
||||||
});
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('dmp worker error', err);
|
logger.error('dmp worker error', err)
|
||||||
process.send({
|
process.send({
|
||||||
msg: 'error',
|
msg: 'error',
|
||||||
error: err,
|
error: err,
|
||||||
cacheKey: data.cacheKey
|
cacheKey: data.cacheKey
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
break;
|
break
|
||||||
case 'get revision':
|
case 'get revision':
|
||||||
if (!data.hasOwnProperty('revisions') || !data.hasOwnProperty('count')) {
|
if (!data.hasOwnProperty('revisions') || !data.hasOwnProperty('count')) {
|
||||||
return logger.error('dmp worker error: not enough data on get revision');
|
return logger.error('dmp worker error: not enough data on get revision')
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var result = getRevision(data.revisions, data.count);
|
var result = getRevision(data.revisions, data.count)
|
||||||
process.send({
|
process.send({
|
||||||
msg: 'check',
|
msg: 'check',
|
||||||
result: result,
|
result: result,
|
||||||
cacheKey: data.cacheKey
|
cacheKey: data.cacheKey
|
||||||
});
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('dmp worker error', err);
|
logger.error('dmp worker error', err)
|
||||||
process.send({
|
process.send({
|
||||||
msg: 'error',
|
msg: 'error',
|
||||||
error: err,
|
error: err,
|
||||||
cacheKey: data.cacheKey
|
cacheKey: data.cacheKey
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
function createPatch(lastDoc, currDoc) {
|
function createPatch (lastDoc, currDoc) {
|
||||||
var ms_start = (new Date()).getTime();
|
var msStart = (new Date()).getTime()
|
||||||
var diff = dmp.diff_main(lastDoc, currDoc);
|
var diff = dmp.diff_main(lastDoc, currDoc)
|
||||||
var patch = dmp.patch_make(lastDoc, diff);
|
var patch = dmp.patch_make(lastDoc, diff)
|
||||||
patch = dmp.patch_toText(patch);
|
patch = dmp.patch_toText(patch)
|
||||||
var ms_end = (new Date()).getTime();
|
var msEnd = (new Date()).getTime()
|
||||||
if (config.debug) {
|
if (config.debug) {
|
||||||
logger.info(patch);
|
logger.info(patch)
|
||||||
logger.info((ms_end - ms_start) + 'ms');
|
logger.info((msEnd - msStart) + 'ms')
|
||||||
}
|
}
|
||||||
return patch;
|
return patch
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRevision(revisions, count) {
|
function getRevision (revisions, count) {
|
||||||
var ms_start = (new Date()).getTime();
|
var msStart = (new Date()).getTime()
|
||||||
var startContent = null;
|
var startContent = null
|
||||||
var lastPatch = [];
|
var lastPatch = []
|
||||||
var applyPatches = [];
|
var applyPatches = []
|
||||||
var authorship = [];
|
var authorship = []
|
||||||
if (count <= Math.round(revisions.length / 2)) {
|
if (count <= Math.round(revisions.length / 2)) {
|
||||||
// start from top to target
|
// start from top to target
|
||||||
for (var i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
var revision = revisions[i];
|
let revision = revisions[i]
|
||||||
if (i == 0) {
|
if (i === 0) {
|
||||||
startContent = revision.content || revision.lastContent;
|
startContent = revision.content || revision.lastContent
|
||||||
}
|
}
|
||||||
if (i != count - 1) {
|
if (i !== count - 1) {
|
||||||
var patch = dmp.patch_fromText(revision.patch);
|
let patch = dmp.patch_fromText(revision.patch)
|
||||||
applyPatches = applyPatches.concat(patch);
|
applyPatches = applyPatches.concat(patch)
|
||||||
}
|
}
|
||||||
lastPatch = revision.patch;
|
lastPatch = revision.patch
|
||||||
authorship = revision.authorship;
|
authorship = revision.authorship
|
||||||
}
|
|
||||||
// swap DIFF_INSERT and DIFF_DELETE to achieve unpatching
|
|
||||||
for (var i = 0, l = applyPatches.length; i < l; i++) {
|
|
||||||
for (var j = 0, m = applyPatches[i].diffs.length; j < m; j++) {
|
|
||||||
var diff = applyPatches[i].diffs[j];
|
|
||||||
if (diff[0] == DiffMatchPatch.DIFF_INSERT)
|
|
||||||
diff[0] = DiffMatchPatch.DIFF_DELETE;
|
|
||||||
else if (diff[0] == DiffMatchPatch.DIFF_DELETE)
|
|
||||||
diff[0] = DiffMatchPatch.DIFF_INSERT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// start from bottom to target
|
|
||||||
var l = revisions.length - 1;
|
|
||||||
for (var i = l; i >= count - 1; i--) {
|
|
||||||
var revision = revisions[i];
|
|
||||||
if (i == l) {
|
|
||||||
startContent = revision.lastContent;
|
|
||||||
authorship = revision.authorship;
|
|
||||||
}
|
|
||||||
if (revision.patch) {
|
|
||||||
var patch = dmp.patch_fromText(revision.patch);
|
|
||||||
applyPatches = applyPatches.concat(patch);
|
|
||||||
}
|
|
||||||
lastPatch = revision.patch;
|
|
||||||
authorship = revision.authorship;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
try {
|
// swap DIFF_INSERT and DIFF_DELETE to achieve unpatching
|
||||||
var finalContent = dmp.patch_apply(applyPatches, startContent)[0];
|
for (let i = 0, l = applyPatches.length; i < l; i++) {
|
||||||
} catch (err) {
|
for (let j = 0, m = applyPatches[i].diffs.length; j < m; j++) {
|
||||||
throw new Error(err);
|
var diff = applyPatches[i].diffs[j]
|
||||||
|
if (diff[0] === DiffMatchPatch.DIFF_INSERT) { diff[0] = DiffMatchPatch.DIFF_DELETE } else if (diff[0] === DiffMatchPatch.DIFF_DELETE) { diff[0] = DiffMatchPatch.DIFF_INSERT }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var data = {
|
} else {
|
||||||
content: finalContent,
|
// start from bottom to target
|
||||||
patch: dmp.patch_fromText(lastPatch),
|
var l = revisions.length - 1
|
||||||
authorship: authorship
|
for (var i = l; i >= count - 1; i--) {
|
||||||
};
|
let revision = revisions[i]
|
||||||
var ms_end = (new Date()).getTime();
|
if (i === l) {
|
||||||
if (config.debug) {
|
startContent = revision.lastContent
|
||||||
logger.info((ms_end - ms_start) + 'ms');
|
authorship = revision.authorship
|
||||||
|
}
|
||||||
|
if (revision.patch) {
|
||||||
|
let patch = dmp.patch_fromText(revision.patch)
|
||||||
|
applyPatches = applyPatches.concat(patch)
|
||||||
|
}
|
||||||
|
lastPatch = revision.patch
|
||||||
|
authorship = revision.authorship
|
||||||
}
|
}
|
||||||
return data;
|
}
|
||||||
|
try {
|
||||||
|
var finalContent = dmp.patch_apply(applyPatches, startContent)[0]
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(err)
|
||||||
|
}
|
||||||
|
var data = {
|
||||||
|
content: finalContent,
|
||||||
|
patch: dmp.patch_fromText(lastPatch),
|
||||||
|
authorship: authorship
|
||||||
|
}
|
||||||
|
var msEnd = (new Date()).getTime()
|
||||||
|
if (config.debug) {
|
||||||
|
logger.info((msEnd - msStart) + 'ms')
|
||||||
|
}
|
||||||
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// log uncaught exception
|
// log uncaught exception
|
||||||
process.on('uncaughtException', function (err) {
|
process.on('uncaughtException', function (err) {
|
||||||
logger.error('An uncaught exception has occured.');
|
logger.error('An uncaught exception has occured.')
|
||||||
logger.error(err);
|
logger.error(err)
|
||||||
logger.error('Process will exit now.');
|
logger.error('Process will exit now.')
|
||||||
process.exit(1);
|
process.exit(1)
|
||||||
});
|
})
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run-script lint",
|
"test": "node ./node_modules/standard/bin/cmd.js && npm run-script lint",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"dev": "webpack --config webpack.config.js --progress --colors --watch",
|
"dev": "webpack --config webpack.config.js --progress --colors --watch",
|
||||||
"build": "webpack --config webpack.production.js --progress --colors",
|
"build": "webpack --config webpack.production.js --progress --colors",
|
||||||
|
@ -165,8 +165,15 @@
|
||||||
"optimize-css-assets-webpack-plugin": "^1.3.0",
|
"optimize-css-assets-webpack-plugin": "^1.3.0",
|
||||||
"script-loader": "^0.7.0",
|
"script-loader": "^0.7.0",
|
||||||
"style-loader": "^0.13.1",
|
"style-loader": "^0.13.1",
|
||||||
|
"standard": "^9.0.1",
|
||||||
"url-loader": "^0.5.7",
|
"url-loader": "^0.5.7",
|
||||||
"webpack": "^1.14.0",
|
"webpack": "^1.14.0",
|
||||||
"webpack-parallel-uglify-plugin": "^0.2.0"
|
"webpack-parallel-uglify-plugin": "^0.2.0"
|
||||||
|
},
|
||||||
|
"standard": {
|
||||||
|
"ignore": [
|
||||||
|
"lib/ot",
|
||||||
|
"public/vendor"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
require('./locale');
|
/* eslint-env browser, jquery */
|
||||||
|
/* global moment, serverurl */
|
||||||
|
|
||||||
require('../css/cover.css');
|
require('./locale')
|
||||||
require('../css/site.css');
|
|
||||||
|
require('../css/cover.css')
|
||||||
|
require('../css/site.css')
|
||||||
|
|
||||||
import {
|
import {
|
||||||
checkIfAuth,
|
checkIfAuth,
|
||||||
|
@ -9,7 +12,7 @@ import {
|
||||||
getLoginState,
|
getLoginState,
|
||||||
resetCheckAuth,
|
resetCheckAuth,
|
||||||
setloginStateChangeEvent
|
setloginStateChangeEvent
|
||||||
} from './lib/common/login';
|
} from './lib/common/login'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
clearDuplicatedHistory,
|
clearDuplicatedHistory,
|
||||||
|
@ -23,411 +26,403 @@ import {
|
||||||
removeHistory,
|
removeHistory,
|
||||||
saveHistory,
|
saveHistory,
|
||||||
saveStorageHistoryToServer
|
saveStorageHistoryToServer
|
||||||
} from './history';
|
} from './history'
|
||||||
|
|
||||||
import { saveAs } from 'file-saver';
|
import { saveAs } from 'file-saver'
|
||||||
import List from 'list.js';
|
import List from 'list.js'
|
||||||
import S from 'string';
|
import S from 'string'
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
|
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
|
||||||
item: '<li class="col-xs-12 col-sm-6 col-md-6 col-lg-4">\
|
item: '<li class="col-xs-12 col-sm-6 col-md-6 col-lg-4">' +
|
||||||
<span class="id" style="display:none;"></span>\
|
'<span class="id" style="display:none;"></span>' +
|
||||||
<a href="#">\
|
'<a href="#">' +
|
||||||
<div class="item">\
|
'<div class="item">' +
|
||||||
<div class="ui-history-pin fa fa-thumb-tack fa-fw"></div>\
|
'<div class="ui-history-pin fa fa-thumb-tack fa-fw"></div>' +
|
||||||
<div class="ui-history-close fa fa-close fa-fw" data-toggle="modal" data-target=".delete-modal"></div>\
|
'<div class="ui-history-close fa fa-close fa-fw" data-toggle="modal" data-target=".delete-modal"></div>' +
|
||||||
<div class="content">\
|
'<div class="content">' +
|
||||||
<h4 class="text"></h4>\
|
'<h4 class="text"></h4>' +
|
||||||
<p>\
|
'<p>' +
|
||||||
<i><i class="fa fa-clock-o"></i> visited </i><i class="fromNow"></i>\
|
'<i><i class="fa fa-clock-o"></i> visited </i><i class="fromNow"></i>' +
|
||||||
<br>\
|
'<br>' +
|
||||||
<i class="timestamp" style="display:none;"></i>\
|
'<i class="timestamp" style="display:none;"></i>' +
|
||||||
<i class="time"></i>\
|
'<i class="time"></i>' +
|
||||||
</p>\
|
'</p>' +
|
||||||
<p class="tags"></p>\
|
'<p class="tags"></p>' +
|
||||||
</div>\
|
'</div>' +
|
||||||
</div>\
|
'</div>' +
|
||||||
</a>\
|
'</a>' +
|
||||||
</li>',
|
'</li>',
|
||||||
page: 18,
|
page: 18,
|
||||||
plugins: [
|
plugins: [
|
||||||
ListPagination({
|
window.ListPagination({
|
||||||
outerWindow: 1
|
outerWindow: 1
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
};
|
}
|
||||||
const historyList = new List('history', options);
|
const historyList = new List('history', options)
|
||||||
|
|
||||||
migrateHistoryFromTempCallback = pageInit;
|
window.migrateHistoryFromTempCallback = pageInit
|
||||||
setloginStateChangeEvent(pageInit);
|
setloginStateChangeEvent(pageInit)
|
||||||
|
|
||||||
pageInit();
|
pageInit()
|
||||||
|
|
||||||
function pageInit() {
|
function pageInit () {
|
||||||
checkIfAuth(
|
checkIfAuth(
|
||||||
data => {
|
data => {
|
||||||
$('.ui-signin').hide();
|
$('.ui-signin').hide()
|
||||||
$('.ui-or').hide();
|
$('.ui-or').hide()
|
||||||
$('.ui-welcome').show();
|
$('.ui-welcome').show()
|
||||||
if (data.photo) $('.ui-avatar').prop('src', data.photo).show();
|
if (data.photo) $('.ui-avatar').prop('src', data.photo).show()
|
||||||
else $('.ui-avatar').prop('src', '').hide();
|
else $('.ui-avatar').prop('src', '').hide()
|
||||||
$('.ui-name').html(data.name);
|
$('.ui-name').html(data.name)
|
||||||
$('.ui-signout').show();
|
$('.ui-signout').show()
|
||||||
$(".ui-history").click();
|
$('.ui-history').click()
|
||||||
parseServerToHistory(historyList, parseHistoryCallback);
|
parseServerToHistory(historyList, parseHistoryCallback)
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
$('.ui-signin').show();
|
$('.ui-signin').show()
|
||||||
$('.ui-or').show();
|
$('.ui-or').show()
|
||||||
$('.ui-welcome').hide();
|
$('.ui-welcome').hide()
|
||||||
$('.ui-avatar').prop('src', '').hide();
|
$('.ui-avatar').prop('src', '').hide()
|
||||||
$('.ui-name').html('');
|
$('.ui-name').html('')
|
||||||
$('.ui-signout').hide();
|
$('.ui-signout').hide()
|
||||||
parseStorageToHistory(historyList, parseHistoryCallback);
|
parseStorageToHistory(historyList, parseHistoryCallback)
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".masthead-nav li").click(function () {
|
$('.masthead-nav li').click(function () {
|
||||||
$(this).siblings().removeClass("active");
|
$(this).siblings().removeClass('active')
|
||||||
$(this).addClass("active");
|
$(this).addClass('active')
|
||||||
});
|
})
|
||||||
|
|
||||||
// prevent empty link change hash
|
// prevent empty link change hash
|
||||||
$('a[href="#"]').click(function (e) {
|
$('a[href="#"]').click(function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault()
|
||||||
});
|
})
|
||||||
|
|
||||||
$(".ui-home").click(function (e) {
|
$('.ui-home').click(function (e) {
|
||||||
if (!$("#home").is(':visible')) {
|
if (!$('#home').is(':visible')) {
|
||||||
$(".section:visible").hide();
|
$('.section:visible').hide()
|
||||||
$("#home").fadeIn();
|
$('#home').fadeIn()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
$(".ui-history").click(() => {
|
$('.ui-history').click(() => {
|
||||||
if (!$("#history").is(':visible')) {
|
if (!$('#history').is(':visible')) {
|
||||||
$(".section:visible").hide();
|
$('.section:visible').hide()
|
||||||
$("#history").fadeIn();
|
$('#history').fadeIn()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
function checkHistoryList() {
|
function checkHistoryList () {
|
||||||
if ($("#history-list").children().length > 0) {
|
if ($('#history-list').children().length > 0) {
|
||||||
$('.pagination').show();
|
$('.pagination').show()
|
||||||
$(".ui-nohistory").hide();
|
$('.ui-nohistory').hide()
|
||||||
$(".ui-import-from-browser").hide();
|
$('.ui-import-from-browser').hide()
|
||||||
} else if ($("#history-list").children().length == 0) {
|
} else if ($('#history-list').children().length === 0) {
|
||||||
$('.pagination').hide();
|
$('.pagination').hide()
|
||||||
$(".ui-nohistory").slideDown();
|
$('.ui-nohistory').slideDown()
|
||||||
getStorageHistory(data => {
|
getStorageHistory(data => {
|
||||||
if (data && data.length > 0 && getLoginState() && historyList.items.length == 0) {
|
if (data && data.length > 0 && getLoginState() && historyList.items.length === 0) {
|
||||||
$(".ui-import-from-browser").slideDown();
|
$('.ui-import-from-browser').slideDown()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseHistoryCallback(list, notehistory) {
|
function parseHistoryCallback (list, notehistory) {
|
||||||
checkHistoryList();
|
checkHistoryList()
|
||||||
//sort by pinned then timestamp
|
// sort by pinned then timestamp
|
||||||
list.sort('', {
|
list.sort('', {
|
||||||
sortFunction(a, b) {
|
sortFunction (a, b) {
|
||||||
const notea = a.values();
|
const notea = a.values()
|
||||||
const noteb = b.values();
|
const noteb = b.values()
|
||||||
if (notea.pinned && !noteb.pinned) {
|
if (notea.pinned && !noteb.pinned) {
|
||||||
return -1;
|
return -1
|
||||||
} else if (!notea.pinned && noteb.pinned) {
|
} else if (!notea.pinned && noteb.pinned) {
|
||||||
return 1;
|
return 1
|
||||||
} else {
|
} else {
|
||||||
if (notea.timestamp > noteb.timestamp) {
|
if (notea.timestamp > noteb.timestamp) {
|
||||||
return -1;
|
return -1
|
||||||
} else if (notea.timestamp < noteb.timestamp) {
|
} else if (notea.timestamp < noteb.timestamp) {
|
||||||
return 1;
|
return 1
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 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
|
|
||||||
let found = false;
|
|
||||||
if (filtertags.includes(tags[j]))
|
|
||||||
found = true;
|
|
||||||
if (!found)
|
|
||||||
filtertags.push(tags[j]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buildTagsFilter(filtertags);
|
})
|
||||||
|
// 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
|
||||||
|
let found = false
|
||||||
|
if (filtertags.includes(tags[j])) { found = true }
|
||||||
|
if (!found) { filtertags.push(tags[j]) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buildTagsFilter(filtertags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update items whenever list updated
|
// update items whenever list updated
|
||||||
historyList.on('updated', e => {
|
historyList.on('updated', e => {
|
||||||
for (let i = 0, l = e.items.length; i < l; i++) {
|
for (let i = 0, l = e.items.length; i < l; i++) {
|
||||||
const item = e.items[i];
|
const item = e.items[i]
|
||||||
if (item.visible()) {
|
if (item.visible()) {
|
||||||
const itemEl = $(item.elm);
|
const itemEl = $(item.elm)
|
||||||
const values = item._values;
|
const values = item._values
|
||||||
const a = itemEl.find("a");
|
const a = itemEl.find('a')
|
||||||
const pin = itemEl.find(".ui-history-pin");
|
const pin = itemEl.find('.ui-history-pin')
|
||||||
const tagsEl = itemEl.find(".tags");
|
const tagsEl = itemEl.find('.tags')
|
||||||
//parse link to element a
|
// parse link to element a
|
||||||
a.attr('href', `${serverurl}/${values.id}`);
|
a.attr('href', `${serverurl}/${values.id}`)
|
||||||
//parse pinned
|
// parse pinned
|
||||||
if (values.pinned) {
|
if (values.pinned) {
|
||||||
pin.addClass('active');
|
pin.addClass('active')
|
||||||
} else {
|
} else {
|
||||||
pin.removeClass('active');
|
pin.removeClass('active')
|
||||||
}
|
}
|
||||||
//parse tags
|
// parse tags
|
||||||
const tags = values.tags;
|
const tags = values.tags
|
||||||
if (tags && tags.length > 0 && tagsEl.children().length <= 0) {
|
if (tags && tags.length > 0 && tagsEl.children().length <= 0) {
|
||||||
const labels = [];
|
const labels = []
|
||||||
for (let j = 0; j < tags.length; j++) {
|
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>`);
|
labels.push(`<span class='label label-default'>${tags[j]}</span>`)
|
||||||
}
|
|
||||||
tagsEl.html(labels.join(' '));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
tagsEl.html(labels.join(' '))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$(".ui-history-close").off('click');
|
}
|
||||||
$(".ui-history-close").on('click', historyCloseClick);
|
$('.ui-history-close').off('click')
|
||||||
$(".ui-history-pin").off('click');
|
$('.ui-history-close').on('click', historyCloseClick)
|
||||||
$(".ui-history-pin").on('click', historyPinClick);
|
$('.ui-history-pin').off('click')
|
||||||
});
|
$('.ui-history-pin').on('click', historyPinClick)
|
||||||
|
})
|
||||||
|
|
||||||
function historyCloseClick(e) {
|
function historyCloseClick (e) {
|
||||||
e.preventDefault();
|
e.preventDefault()
|
||||||
const id = $(this).closest("a").siblings("span").html();
|
const id = $(this).closest('a').siblings('span').html()
|
||||||
const value = historyList.get('id', id)[0]._values;
|
const value = historyList.get('id', id)[0]._values
|
||||||
$('.ui-delete-modal-msg').text('Do you really want to delete below history?');
|
$('.ui-delete-modal-msg').text('Do you really want to delete below history?')
|
||||||
$('.ui-delete-modal-item').html(`<i class="fa fa-file-text"></i> ${value.text}<br><i class="fa fa-clock-o"></i> ${value.time}`);
|
$('.ui-delete-modal-item').html(`<i class="fa fa-file-text"></i> ${value.text}<br><i class="fa fa-clock-o"></i> ${value.time}`)
|
||||||
clearHistory = false;
|
clearHistory = false
|
||||||
deleteId = id;
|
deleteId = id
|
||||||
}
|
}
|
||||||
|
|
||||||
function historyPinClick(e) {
|
function historyPinClick (e) {
|
||||||
e.preventDefault();
|
e.preventDefault()
|
||||||
const $this = $(this);
|
const $this = $(this)
|
||||||
const id = $this.closest("a").siblings("span").html();
|
const id = $this.closest('a').siblings('span').html()
|
||||||
const item = historyList.get('id', id)[0];
|
const item = historyList.get('id', id)[0]
|
||||||
const values = item._values;
|
const values = item._values
|
||||||
let pinned = values.pinned;
|
let pinned = values.pinned
|
||||||
if (!values.pinned) {
|
if (!values.pinned) {
|
||||||
pinned = true;
|
pinned = true
|
||||||
item._values.pinned = true;
|
item._values.pinned = true
|
||||||
} else {
|
} else {
|
||||||
pinned = false;
|
pinned = false
|
||||||
item._values.pinned = false;
|
item._values.pinned = false
|
||||||
}
|
}
|
||||||
checkIfAuth(() => {
|
checkIfAuth(() => {
|
||||||
postHistoryToServer(id, {
|
postHistoryToServer(id, {
|
||||||
pinned
|
pinned
|
||||||
}, (err, result) => {
|
}, (err, result) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
if (pinned)
|
if (pinned) { $this.addClass('active') } else { $this.removeClass('active') }
|
||||||
$this.addClass('active');
|
}
|
||||||
else
|
})
|
||||||
$this.removeClass('active');
|
}, () => {
|
||||||
}
|
getHistory(notehistory => {
|
||||||
});
|
for (let i = 0; i < notehistory.length; i++) {
|
||||||
}, () => {
|
if (notehistory[i].id === id) {
|
||||||
getHistory(notehistory => {
|
notehistory[i].pinned = pinned
|
||||||
for(let i = 0; i < notehistory.length; i++) {
|
break
|
||||||
if (notehistory[i].id == id) {
|
}
|
||||||
notehistory[i].pinned = pinned;
|
}
|
||||||
break;
|
saveHistory(notehistory)
|
||||||
}
|
if (pinned) { $this.addClass('active') } else { $this.removeClass('active') }
|
||||||
}
|
})
|
||||||
saveHistory(notehistory);
|
})
|
||||||
if (pinned)
|
|
||||||
$this.addClass('active');
|
|
||||||
else
|
|
||||||
$this.removeClass('active');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//auto update item fromNow every minutes
|
// auto update item fromNow every minutes
|
||||||
setInterval(updateItemFromNow, 60000);
|
setInterval(updateItemFromNow, 60000)
|
||||||
|
|
||||||
function updateItemFromNow() {
|
function updateItemFromNow () {
|
||||||
const items = $('.item').toArray();
|
const items = $('.item').toArray()
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
const item = $(items[i]);
|
const item = $(items[i])
|
||||||
const timestamp = parseInt(item.find('.timestamp').text());
|
const timestamp = parseInt(item.find('.timestamp').text())
|
||||||
item.find('.fromNow').text(moment(timestamp).fromNow());
|
item.find('.fromNow').text(moment(timestamp).fromNow())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var clearHistory = false;
|
var clearHistory = false
|
||||||
var deleteId = null;
|
var deleteId = null
|
||||||
|
|
||||||
function deleteHistory() {
|
function deleteHistory () {
|
||||||
checkIfAuth(() => {
|
checkIfAuth(() => {
|
||||||
deleteServerHistory(deleteId, (err, result) => {
|
deleteServerHistory(deleteId, (err, result) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
if (clearHistory) {
|
|
||||||
historyList.clear();
|
|
||||||
checkHistoryList();
|
|
||||||
} else {
|
|
||||||
historyList.remove('id', deleteId);
|
|
||||||
checkHistoryList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$('.delete-modal').modal('hide');
|
|
||||||
deleteId = null;
|
|
||||||
clearHistory = false;
|
|
||||||
});
|
|
||||||
}, () => {
|
|
||||||
if (clearHistory) {
|
if (clearHistory) {
|
||||||
saveHistory([]);
|
historyList.clear()
|
||||||
historyList.clear();
|
checkHistoryList()
|
||||||
checkHistoryList();
|
|
||||||
deleteId = null;
|
|
||||||
} else {
|
} else {
|
||||||
if (!deleteId) return;
|
historyList.remove('id', deleteId)
|
||||||
getHistory(notehistory => {
|
checkHistoryList()
|
||||||
const newnotehistory = removeHistory(deleteId, notehistory);
|
|
||||||
saveHistory(newnotehistory);
|
|
||||||
historyList.remove('id', deleteId);
|
|
||||||
checkHistoryList();
|
|
||||||
deleteId = null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
$('.delete-modal').modal('hide');
|
}
|
||||||
clearHistory = false;
|
$('.delete-modal').modal('hide')
|
||||||
});
|
deleteId = null
|
||||||
}
|
clearHistory = false
|
||||||
|
})
|
||||||
$(".ui-delete-modal-confirm").click(() => {
|
}, () => {
|
||||||
deleteHistory();
|
if (clearHistory) {
|
||||||
});
|
saveHistory([])
|
||||||
|
historyList.clear()
|
||||||
$(".ui-import-from-browser").click(() => {
|
checkHistoryList()
|
||||||
saveStorageHistoryToServer(() => {
|
deleteId = null
|
||||||
parseStorageToHistory(historyList, parseHistoryCallback);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".ui-save-history").click(() => {
|
|
||||||
getHistory(data => {
|
|
||||||
const history = JSON.stringify(data);
|
|
||||||
const blob = new Blob([history], {
|
|
||||||
type: "application/json;charset=utf-8"
|
|
||||||
});
|
|
||||||
saveAs(blob, `hackmd_history_${moment().format('YYYYMMDDHHmmss')}`, true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".ui-open-history").bind("change", e => {
|
|
||||||
const files = e.target.files || e.dataTransfer.files;
|
|
||||||
const file = files[0];
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = () => {
|
|
||||||
const notehistory = JSON.parse(reader.result);
|
|
||||||
//console.log(notehistory);
|
|
||||||
if (!reader.result) return;
|
|
||||||
getHistory(data => {
|
|
||||||
let mergedata = data.concat(notehistory);
|
|
||||||
mergedata = clearDuplicatedHistory(mergedata);
|
|
||||||
saveHistory(mergedata);
|
|
||||||
parseHistory(historyList, parseHistoryCallback);
|
|
||||||
});
|
|
||||||
$(".ui-open-history").replaceWith($(".ui-open-history").val('').clone(true));
|
|
||||||
};
|
|
||||||
reader.readAsText(file);
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".ui-clear-history").click(() => {
|
|
||||||
$('.ui-delete-modal-msg').text('Do you really want to clear all history?');
|
|
||||||
$('.ui-delete-modal-item').html('There is no turning back.');
|
|
||||||
clearHistory = true;
|
|
||||||
deleteId = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".ui-refresh-history").click(() => {
|
|
||||||
const lastTags = $(".ui-use-tags").select2('val');
|
|
||||||
$(".ui-use-tags").select2('val', '');
|
|
||||||
historyList.filter();
|
|
||||||
const lastKeyword = $('.search').val();
|
|
||||||
$('.search').val('');
|
|
||||||
historyList.search();
|
|
||||||
$('#history-list').slideUp('fast');
|
|
||||||
$('.pagination').hide();
|
|
||||||
|
|
||||||
resetCheckAuth();
|
|
||||||
historyList.clear();
|
|
||||||
parseHistory(historyList, (list, notehistory) => {
|
|
||||||
parseHistoryCallback(list, notehistory);
|
|
||||||
$(".ui-use-tags").select2('val', lastTags);
|
|
||||||
$(".ui-use-tags").trigger('change');
|
|
||||||
historyList.search(lastKeyword);
|
|
||||||
$('.search').val(lastKeyword);
|
|
||||||
checkHistoryList();
|
|
||||||
$('#history-list').slideDown('fast');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(".ui-logout").click(() => {
|
|
||||||
clearLoginState();
|
|
||||||
location.href = `${serverurl}/logout`;
|
|
||||||
});
|
|
||||||
|
|
||||||
let filtertags = [];
|
|
||||||
$(".ui-use-tags").select2({
|
|
||||||
placeholder: $(".ui-use-tags").attr('placeholder'),
|
|
||||||
multiple: true,
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
results: filtertags
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$('.select2-input').css('width', 'inherit');
|
|
||||||
buildTagsFilter([]);
|
|
||||||
|
|
||||||
function buildTagsFilter(tags) {
|
|
||||||
for (let i = 0; i < tags.length; i++)
|
|
||||||
tags[i] = {
|
|
||||||
id: i,
|
|
||||||
text: S(tags[i]).unescapeHTML().s
|
|
||||||
};
|
|
||||||
filtertags = tags;
|
|
||||||
}
|
|
||||||
$(".ui-use-tags").on('change', function () {
|
|
||||||
const tags = [];
|
|
||||||
const data = $(this).select2('data');
|
|
||||||
for (let i = 0; i < data.length; i++)
|
|
||||||
tags.push(data[i].text);
|
|
||||||
if (tags.length > 0) {
|
|
||||||
historyList.filter(item => {
|
|
||||||
const values = item.values();
|
|
||||||
if (!values.tags) return false;
|
|
||||||
let found = false;
|
|
||||||
for (let i = 0; i < tags.length; i++) {
|
|
||||||
if (values.tags.includes(tags[i])) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return found;
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
historyList.filter();
|
if (!deleteId) return
|
||||||
|
getHistory(notehistory => {
|
||||||
|
const newnotehistory = removeHistory(deleteId, notehistory)
|
||||||
|
saveHistory(newnotehistory)
|
||||||
|
historyList.remove('id', deleteId)
|
||||||
|
checkHistoryList()
|
||||||
|
deleteId = null
|
||||||
|
})
|
||||||
}
|
}
|
||||||
checkHistoryList();
|
$('.delete-modal').modal('hide')
|
||||||
});
|
clearHistory = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.ui-delete-modal-confirm').click(() => {
|
||||||
|
deleteHistory()
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.ui-import-from-browser').click(() => {
|
||||||
|
saveStorageHistoryToServer(() => {
|
||||||
|
parseStorageToHistory(historyList, parseHistoryCallback)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.ui-save-history').click(() => {
|
||||||
|
getHistory(data => {
|
||||||
|
const history = JSON.stringify(data)
|
||||||
|
const blob = new Blob([history], {
|
||||||
|
type: 'application/json;charset=utf-8'
|
||||||
|
})
|
||||||
|
saveAs(blob, `hackmd_history_${moment().format('YYYYMMDDHHmmss')}`, true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.ui-open-history').bind('change', e => {
|
||||||
|
const files = e.target.files || e.dataTransfer.files
|
||||||
|
const file = files[0]
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.onload = () => {
|
||||||
|
const notehistory = JSON.parse(reader.result)
|
||||||
|
// console.log(notehistory);
|
||||||
|
if (!reader.result) return
|
||||||
|
getHistory(data => {
|
||||||
|
let mergedata = data.concat(notehistory)
|
||||||
|
mergedata = clearDuplicatedHistory(mergedata)
|
||||||
|
saveHistory(mergedata)
|
||||||
|
parseHistory(historyList, parseHistoryCallback)
|
||||||
|
})
|
||||||
|
$('.ui-open-history').replaceWith($('.ui-open-history').val('').clone(true))
|
||||||
|
}
|
||||||
|
reader.readAsText(file)
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.ui-clear-history').click(() => {
|
||||||
|
$('.ui-delete-modal-msg').text('Do you really want to clear all history?')
|
||||||
|
$('.ui-delete-modal-item').html('There is no turning back.')
|
||||||
|
clearHistory = true
|
||||||
|
deleteId = null
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.ui-refresh-history').click(() => {
|
||||||
|
const lastTags = $('.ui-use-tags').select2('val')
|
||||||
|
$('.ui-use-tags').select2('val', '')
|
||||||
|
historyList.filter()
|
||||||
|
const lastKeyword = $('.search').val()
|
||||||
|
$('.search').val('')
|
||||||
|
historyList.search()
|
||||||
|
$('#history-list').slideUp('fast')
|
||||||
|
$('.pagination').hide()
|
||||||
|
|
||||||
|
resetCheckAuth()
|
||||||
|
historyList.clear()
|
||||||
|
parseHistory(historyList, (list, notehistory) => {
|
||||||
|
parseHistoryCallback(list, notehistory)
|
||||||
|
$('.ui-use-tags').select2('val', lastTags)
|
||||||
|
$('.ui-use-tags').trigger('change')
|
||||||
|
historyList.search(lastKeyword)
|
||||||
|
$('.search').val(lastKeyword)
|
||||||
|
checkHistoryList()
|
||||||
|
$('#history-list').slideDown('fast')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.ui-logout').click(() => {
|
||||||
|
clearLoginState()
|
||||||
|
location.href = `${serverurl}/logout`
|
||||||
|
})
|
||||||
|
|
||||||
|
let filtertags = []
|
||||||
|
$('.ui-use-tags').select2({
|
||||||
|
placeholder: $('.ui-use-tags').attr('placeholder'),
|
||||||
|
multiple: true,
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
results: filtertags
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
$('.select2-input').css('width', 'inherit')
|
||||||
|
buildTagsFilter([])
|
||||||
|
|
||||||
|
function buildTagsFilter (tags) {
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
|
tags[i] = {
|
||||||
|
id: i,
|
||||||
|
text: S(tags[i]).unescapeHTML().s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filtertags = tags
|
||||||
|
}
|
||||||
|
$('.ui-use-tags').on('change', function () {
|
||||||
|
const tags = []
|
||||||
|
const data = $(this).select2('data')
|
||||||
|
for (let i = 0; i < data.length; i++) { tags.push(data[i].text) }
|
||||||
|
if (tags.length > 0) {
|
||||||
|
historyList.filter(item => {
|
||||||
|
const values = item.values()
|
||||||
|
if (!values.tags) return false
|
||||||
|
let found = false
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
|
if (values.tags.includes(tags[i])) {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
historyList.filter()
|
||||||
|
}
|
||||||
|
checkHistoryList()
|
||||||
|
})
|
||||||
|
|
||||||
$('.search').keyup(() => {
|
$('.search').keyup(() => {
|
||||||
checkHistoryList();
|
checkHistoryList()
|
||||||
});
|
})
|
||||||
|
|
1944
public/js/extra.js
1944
public/js/extra.js
File diff suppressed because it is too large
Load diff
|
@ -1,119 +1,118 @@
|
||||||
/**!
|
/** !
|
||||||
* Google Drive File Picker Example
|
* Google Drive File Picker Example
|
||||||
* By Daniel Lo Nigro (http://dan.cx/)
|
* By Daniel Lo Nigro (http://dan.cx/)
|
||||||
*/
|
*/
|
||||||
(function() {
|
(function () {
|
||||||
/**
|
/**
|
||||||
* Initialise a Google Driver file picker
|
* Initialise a Google Driver file picker
|
||||||
*/
|
*/
|
||||||
var FilePicker = window.FilePicker = function(options) {
|
var FilePicker = window.FilePicker = function (options) {
|
||||||
// Config
|
// Config
|
||||||
this.apiKey = options.apiKey;
|
this.apiKey = options.apiKey
|
||||||
this.clientId = options.clientId;
|
this.clientId = options.clientId
|
||||||
|
|
||||||
// Elements
|
|
||||||
this.buttonEl = options.buttonEl;
|
|
||||||
|
|
||||||
// Events
|
|
||||||
this.onSelect = options.onSelect;
|
|
||||||
this.buttonEl.on('click', this.open.bind(this));
|
|
||||||
|
|
||||||
// Disable the button until the API loads, as it won't work properly until then.
|
|
||||||
this.buttonEl.prop('disabled', true);
|
|
||||||
|
|
||||||
// Load the drive API
|
// Elements
|
||||||
gapi.client.setApiKey(this.apiKey);
|
this.buttonEl = options.buttonEl
|
||||||
gapi.client.load('drive', 'v2', this._driveApiLoaded.bind(this));
|
|
||||||
google.load('picker', '1', { callback: this._pickerApiLoaded.bind(this) });
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePicker.prototype = {
|
// Events
|
||||||
/**
|
this.onSelect = options.onSelect
|
||||||
* Open the file picker.
|
this.buttonEl.on('click', this.open.bind(this))
|
||||||
*/
|
|
||||||
open: function() {
|
// Disable the button until the API loads, as it won't work properly until then.
|
||||||
// Check if the user has already authenticated
|
this.buttonEl.prop('disabled', true)
|
||||||
var token = gapi.auth.getToken();
|
|
||||||
if (token) {
|
// Load the drive API
|
||||||
this._showPicker();
|
window.gapi.client.setApiKey(this.apiKey)
|
||||||
} else {
|
window.gapi.client.load('drive', 'v2', this._driveApiLoaded.bind(this))
|
||||||
// The user has not yet authenticated with Google
|
window.google.load('picker', '1', { callback: this._pickerApiLoaded.bind(this) })
|
||||||
// We need to do the authentication before displaying the Drive picker.
|
}
|
||||||
this._doAuth(false, function() { this._showPicker(); }.bind(this));
|
|
||||||
}
|
FilePicker.prototype = {
|
||||||
},
|
/**
|
||||||
|
* Open the file picker.
|
||||||
/**
|
*/
|
||||||
* Show the file picker once authentication has been done.
|
open: function () {
|
||||||
* @private
|
// Check if the user has already authenticated
|
||||||
*/
|
var token = window.gapi.auth.getToken()
|
||||||
_showPicker: function() {
|
if (token) {
|
||||||
var accessToken = gapi.auth.getToken().access_token;
|
this._showPicker()
|
||||||
var view = new google.picker.DocsView();
|
} else {
|
||||||
view.setMimeTypes("text/markdown,text/html");
|
// The user has not yet authenticated with Google
|
||||||
view.setIncludeFolders(true);
|
// We need to do the authentication before displaying the Drive picker.
|
||||||
view.setOwnedByMe(true);
|
this._doAuth(false, function () { this._showPicker() }.bind(this))
|
||||||
this.picker = new google.picker.PickerBuilder().
|
}
|
||||||
enableFeature(google.picker.Feature.NAV_HIDDEN).
|
},
|
||||||
addView(view).
|
|
||||||
setAppId(this.clientId).
|
/**
|
||||||
setOAuthToken(accessToken).
|
* Show the file picker once authentication has been done.
|
||||||
setCallback(this._pickerCallback.bind(this)).
|
* @private
|
||||||
build().
|
*/
|
||||||
setVisible(true);
|
_showPicker: function () {
|
||||||
},
|
var accessToken = window.gapi.auth.getToken().access_token
|
||||||
|
var view = new window.google.picker.DocsView()
|
||||||
/**
|
view.setMimeTypes('text/markdown,text/html')
|
||||||
* Called when a file has been selected in the Google Drive file picker.
|
view.setIncludeFolders(true)
|
||||||
* @private
|
view.setOwnedByMe(true)
|
||||||
*/
|
this.picker = new window.google.picker.PickerBuilder()
|
||||||
_pickerCallback: function(data) {
|
.enableFeature(window.google.picker.Feature.NAV_HIDDEN)
|
||||||
if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
|
.addView(view)
|
||||||
var file = data[google.picker.Response.DOCUMENTS][0],
|
.setAppId(this.clientId)
|
||||||
id = file[google.picker.Document.ID],
|
.setOAuthToken(accessToken)
|
||||||
request = gapi.client.drive.files.get({
|
.setCallback(this._pickerCallback.bind(this))
|
||||||
fileId: id
|
.build()
|
||||||
});
|
.setVisible(true)
|
||||||
|
},
|
||||||
request.execute(this._fileGetCallback.bind(this));
|
|
||||||
}
|
/**
|
||||||
},
|
* Called when a file has been selected in the Google Drive file picker.
|
||||||
/**
|
* @private
|
||||||
* Called when file details have been retrieved from Google Drive.
|
*/
|
||||||
* @private
|
_pickerCallback: function (data) {
|
||||||
*/
|
if (data[window.google.picker.Response.ACTION] === window.google.picker.Action.PICKED) {
|
||||||
_fileGetCallback: function(file) {
|
var file = data[window.google.picker.Response.DOCUMENTS][0]
|
||||||
if (this.onSelect) {
|
var id = file[window.google.picker.Document.ID]
|
||||||
this.onSelect(file);
|
var request = window.gapi.client.drive.files.get({
|
||||||
}
|
fileId: id
|
||||||
},
|
})
|
||||||
|
request.execute(this._fileGetCallback.bind(this))
|
||||||
/**
|
}
|
||||||
* Called when the Google Drive file picker API has finished loading.
|
},
|
||||||
* @private
|
/**
|
||||||
*/
|
* Called when file details have been retrieved from Google Drive.
|
||||||
_pickerApiLoaded: function() {
|
* @private
|
||||||
this.buttonEl.prop('disabled', false);
|
*/
|
||||||
},
|
_fileGetCallback: function (file) {
|
||||||
|
if (this.onSelect) {
|
||||||
/**
|
this.onSelect(file)
|
||||||
* Called when the Google Drive API has finished loading.
|
}
|
||||||
* @private
|
},
|
||||||
*/
|
|
||||||
_driveApiLoaded: function() {
|
/**
|
||||||
this._doAuth(true);
|
* Called when the Google Drive file picker API has finished loading.
|
||||||
},
|
* @private
|
||||||
|
*/
|
||||||
/**
|
_pickerApiLoaded: function () {
|
||||||
* Authenticate with Google Drive via the Google JavaScript API.
|
this.buttonEl.prop('disabled', false)
|
||||||
* @private
|
},
|
||||||
*/
|
|
||||||
_doAuth: function(immediate, callback) {
|
/**
|
||||||
gapi.auth.authorize({
|
* Called when the Google Drive API has finished loading.
|
||||||
client_id: this.clientId,
|
* @private
|
||||||
scope: 'https://www.googleapis.com/auth/drive.readonly',
|
*/
|
||||||
immediate: immediate
|
_driveApiLoaded: function () {
|
||||||
}, callback ? callback : function() {});
|
this._doAuth(true)
|
||||||
}
|
},
|
||||||
};
|
|
||||||
}());
|
/**
|
||||||
|
* Authenticate with Google Drive via the Google JavaScript API.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_doAuth: function (immediate, callback) {
|
||||||
|
window.gapi.auth.authorize({
|
||||||
|
client_id: this.clientId,
|
||||||
|
scope: 'https://www.googleapis.com/auth/drive.readonly',
|
||||||
|
immediate: immediate
|
||||||
|
}, callback || function () {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}())
|
||||||
|
|
|
@ -1,30 +1,31 @@
|
||||||
|
/* eslint-env browser, jquery */
|
||||||
/**
|
/**
|
||||||
* Helper for implementing retries with backoff. Initial retry
|
* Helper for implementing retries with backoff. Initial retry
|
||||||
* delay is 1 second, increasing by 2x (+jitter) for subsequent retries
|
* delay is 1 second, increasing by 2x (+jitter) for subsequent retries
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
var RetryHandler = function() {
|
var RetryHandler = function () {
|
||||||
this.interval = 1000; // Start at one second
|
this.interval = 1000 // Start at one second
|
||||||
this.maxInterval = 60 * 1000; // Don't wait longer than a minute
|
this.maxInterval = 60 * 1000 // Don't wait longer than a minute
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke the function after waiting
|
* Invoke the function after waiting
|
||||||
*
|
*
|
||||||
* @param {function} fn Function to invoke
|
* @param {function} fn Function to invoke
|
||||||
*/
|
*/
|
||||||
RetryHandler.prototype.retry = function(fn) {
|
RetryHandler.prototype.retry = function (fn) {
|
||||||
setTimeout(fn, this.interval);
|
setTimeout(fn, this.interval)
|
||||||
this.interval = this.nextInterval_();
|
this.interval = this.nextInterval_()
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the counter (e.g. after successful request.)
|
* Reset the counter (e.g. after successful request.)
|
||||||
*/
|
*/
|
||||||
RetryHandler.prototype.reset = function() {
|
RetryHandler.prototype.reset = function () {
|
||||||
this.interval = 1000;
|
this.interval = 1000
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the next wait time.
|
* Calculate the next wait time.
|
||||||
|
@ -32,10 +33,10 @@ RetryHandler.prototype.reset = function() {
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
RetryHandler.prototype.nextInterval_ = function() {
|
RetryHandler.prototype.nextInterval_ = function () {
|
||||||
var interval = this.interval * 2 + this.getRandomInt_(0, 1000);
|
var interval = this.interval * 2 + this.getRandomInt_(0, 1000)
|
||||||
return Math.min(interval, this.maxInterval);
|
return Math.min(interval, this.maxInterval)
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a random int in the range of min to max. Used to add jitter to wait times.
|
* Get a random int in the range of min to max. Used to add jitter to wait times.
|
||||||
|
@ -44,10 +45,9 @@ RetryHandler.prototype.nextInterval_ = function() {
|
||||||
* @param {number} max Upper bounds
|
* @param {number} max Upper bounds
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
RetryHandler.prototype.getRandomInt_ = function(min, max) {
|
RetryHandler.prototype.getRandomInt_ = function (min, max) {
|
||||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
return Math.floor(Math.random() * (max - min + 1) + min)
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for resumable uploads using XHR/CORS. Can upload any Blob-like item, whether
|
* Helper class for resumable uploads using XHR/CORS. Can upload any Blob-like item, whether
|
||||||
|
@ -75,116 +75,115 @@ RetryHandler.prototype.getRandomInt_ = function(min, max) {
|
||||||
* @param {function} [options.onProgress] Callback for status for the in-progress upload
|
* @param {function} [options.onProgress] Callback for status for the in-progress upload
|
||||||
* @param {function} [options.onError] Callback if upload fails
|
* @param {function} [options.onError] Callback if upload fails
|
||||||
*/
|
*/
|
||||||
var MediaUploader = function(options) {
|
var MediaUploader = function (options) {
|
||||||
var noop = function() {};
|
var noop = function () {}
|
||||||
this.file = options.file;
|
this.file = options.file
|
||||||
this.contentType = options.contentType || this.file.type || 'application/octet-stream';
|
this.contentType = options.contentType || this.file.type || 'application/octet-stream'
|
||||||
this.metadata = options.metadata || {
|
this.metadata = options.metadata || {
|
||||||
'title': this.file.name,
|
'title': this.file.name,
|
||||||
'mimeType': this.contentType
|
'mimeType': this.contentType
|
||||||
};
|
|
||||||
this.token = options.token;
|
|
||||||
this.onComplete = options.onComplete || noop;
|
|
||||||
this.onProgress = options.onProgress || noop;
|
|
||||||
this.onError = options.onError || noop;
|
|
||||||
this.offset = options.offset || 0;
|
|
||||||
this.chunkSize = options.chunkSize || 0;
|
|
||||||
this.retryHandler = new RetryHandler();
|
|
||||||
|
|
||||||
this.url = options.url;
|
|
||||||
if (!this.url) {
|
|
||||||
var params = options.params || {};
|
|
||||||
params.uploadType = 'resumable';
|
|
||||||
this.url = this.buildUrl_(options.fileId, params, options.baseUrl);
|
|
||||||
}
|
}
|
||||||
this.httpMethod = options.fileId ? 'PUT' : 'POST';
|
this.token = options.token
|
||||||
};
|
this.onComplete = options.onComplete || noop
|
||||||
|
this.onProgress = options.onProgress || noop
|
||||||
|
this.onError = options.onError || noop
|
||||||
|
this.offset = options.offset || 0
|
||||||
|
this.chunkSize = options.chunkSize || 0
|
||||||
|
this.retryHandler = new RetryHandler()
|
||||||
|
|
||||||
|
this.url = options.url
|
||||||
|
if (!this.url) {
|
||||||
|
var params = options.params || {}
|
||||||
|
params.uploadType = 'resumable'
|
||||||
|
this.url = this.buildUrl_(options.fileId, params, options.baseUrl)
|
||||||
|
}
|
||||||
|
this.httpMethod = options.fileId ? 'PUT' : 'POST'
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiate the upload.
|
* Initiate the upload.
|
||||||
*/
|
*/
|
||||||
MediaUploader.prototype.upload = function() {
|
MediaUploader.prototype.upload = function () {
|
||||||
var self = this;
|
var xhr = new XMLHttpRequest()
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
|
|
||||||
xhr.open(this.httpMethod, this.url, true);
|
xhr.open(this.httpMethod, this.url, true)
|
||||||
xhr.setRequestHeader('Authorization', 'Bearer ' + this.token);
|
xhr.setRequestHeader('Authorization', 'Bearer ' + this.token)
|
||||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
xhr.setRequestHeader('Content-Type', 'application/json')
|
||||||
xhr.setRequestHeader('X-Upload-Content-Length', this.file.size);
|
xhr.setRequestHeader('X-Upload-Content-Length', this.file.size)
|
||||||
xhr.setRequestHeader('X-Upload-Content-Type', this.contentType);
|
xhr.setRequestHeader('X-Upload-Content-Type', this.contentType)
|
||||||
|
|
||||||
xhr.onload = function(e) {
|
xhr.onload = function (e) {
|
||||||
if (e.target.status < 400) {
|
if (e.target.status < 400) {
|
||||||
var location = e.target.getResponseHeader('Location');
|
var location = e.target.getResponseHeader('Location')
|
||||||
this.url = location;
|
this.url = location
|
||||||
this.sendFile_();
|
this.sendFile_()
|
||||||
} else {
|
} else {
|
||||||
this.onUploadError_(e);
|
this.onUploadError_(e)
|
||||||
}
|
}
|
||||||
}.bind(this);
|
}.bind(this)
|
||||||
xhr.onerror = this.onUploadError_.bind(this);
|
xhr.onerror = this.onUploadError_.bind(this)
|
||||||
xhr.send(JSON.stringify(this.metadata));
|
xhr.send(JSON.stringify(this.metadata))
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the actual file content.
|
* Send the actual file content.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
MediaUploader.prototype.sendFile_ = function() {
|
MediaUploader.prototype.sendFile_ = function () {
|
||||||
var content = this.file;
|
var content = this.file
|
||||||
var end = this.file.size;
|
var end = this.file.size
|
||||||
|
|
||||||
if (this.offset || this.chunkSize) {
|
if (this.offset || this.chunkSize) {
|
||||||
// Only bother to slice the file if we're either resuming or uploading in chunks
|
// Only bother to slice the file if we're either resuming or uploading in chunks
|
||||||
if (this.chunkSize) {
|
if (this.chunkSize) {
|
||||||
end = Math.min(this.offset + this.chunkSize, this.file.size);
|
end = Math.min(this.offset + this.chunkSize, this.file.size)
|
||||||
}
|
}
|
||||||
content = content.slice(this.offset, end);
|
content = content.slice(this.offset, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest()
|
||||||
xhr.open('PUT', this.url, true);
|
xhr.open('PUT', this.url, true)
|
||||||
xhr.setRequestHeader('Content-Type', this.contentType);
|
xhr.setRequestHeader('Content-Type', this.contentType)
|
||||||
xhr.setRequestHeader('Content-Range', "bytes " + this.offset + "-" + (end - 1) + "/" + this.file.size);
|
xhr.setRequestHeader('Content-Range', 'bytes ' + this.offset + '-' + (end - 1) + '/' + this.file.size)
|
||||||
xhr.setRequestHeader('X-Upload-Content-Type', this.file.type);
|
xhr.setRequestHeader('X-Upload-Content-Type', this.file.type)
|
||||||
if (xhr.upload) {
|
if (xhr.upload) {
|
||||||
xhr.upload.addEventListener('progress', this.onProgress);
|
xhr.upload.addEventListener('progress', this.onProgress)
|
||||||
}
|
}
|
||||||
xhr.onload = this.onContentUploadSuccess_.bind(this);
|
xhr.onload = this.onContentUploadSuccess_.bind(this)
|
||||||
xhr.onerror = this.onContentUploadError_.bind(this);
|
xhr.onerror = this.onContentUploadError_.bind(this)
|
||||||
xhr.send(content);
|
xhr.send(content)
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query for the state of the file for resumption.
|
* Query for the state of the file for resumption.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
MediaUploader.prototype.resume_ = function() {
|
MediaUploader.prototype.resume_ = function () {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest()
|
||||||
xhr.open('PUT', this.url, true);
|
xhr.open('PUT', this.url, true)
|
||||||
xhr.setRequestHeader('Content-Range', "bytes */" + this.file.size);
|
xhr.setRequestHeader('Content-Range', 'bytes */' + this.file.size)
|
||||||
xhr.setRequestHeader('X-Upload-Content-Type', this.file.type);
|
xhr.setRequestHeader('X-Upload-Content-Type', this.file.type)
|
||||||
if (xhr.upload) {
|
if (xhr.upload) {
|
||||||
xhr.upload.addEventListener('progress', this.onProgress);
|
xhr.upload.addEventListener('progress', this.onProgress)
|
||||||
}
|
}
|
||||||
xhr.onload = this.onContentUploadSuccess_.bind(this);
|
xhr.onload = this.onContentUploadSuccess_.bind(this)
|
||||||
xhr.onerror = this.onContentUploadError_.bind(this);
|
xhr.onerror = this.onContentUploadError_.bind(this)
|
||||||
xhr.send();
|
xhr.send()
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the last saved range if available in the request.
|
* Extract the last saved range if available in the request.
|
||||||
*
|
*
|
||||||
* @param {XMLHttpRequest} xhr Request object
|
* @param {XMLHttpRequest} xhr Request object
|
||||||
*/
|
*/
|
||||||
MediaUploader.prototype.extractRange_ = function(xhr) {
|
MediaUploader.prototype.extractRange_ = function (xhr) {
|
||||||
var range = xhr.getResponseHeader('Range');
|
var range = xhr.getResponseHeader('Range')
|
||||||
if (range) {
|
if (range) {
|
||||||
this.offset = parseInt(range.match(/\d+/g).pop(), 10) + 1;
|
this.offset = parseInt(range.match(/\d+/g).pop(), 10) + 1
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle successful responses for uploads. Depending on the context,
|
* Handle successful responses for uploads. Depending on the context,
|
||||||
|
@ -194,17 +193,17 @@ MediaUploader.prototype.extractRange_ = function(xhr) {
|
||||||
* @private
|
* @private
|
||||||
* @param {object} e XHR event
|
* @param {object} e XHR event
|
||||||
*/
|
*/
|
||||||
MediaUploader.prototype.onContentUploadSuccess_ = function(e) {
|
MediaUploader.prototype.onContentUploadSuccess_ = function (e) {
|
||||||
if (e.target.status == 200 || e.target.status == 201) {
|
if (e.target.status === 200 || e.target.status === 201) {
|
||||||
this.onComplete(e.target.response);
|
this.onComplete(e.target.response)
|
||||||
} else if (e.target.status == 308) {
|
} else if (e.target.status === 308) {
|
||||||
this.extractRange_(e.target);
|
this.extractRange_(e.target)
|
||||||
this.retryHandler.reset();
|
this.retryHandler.reset()
|
||||||
this.sendFile_();
|
this.sendFile_()
|
||||||
} else {
|
} else {
|
||||||
this.onContentUploadError_(e);
|
this.onContentUploadError_(e)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles errors for uploads. Either retries or aborts depending
|
* Handles errors for uploads. Either retries or aborts depending
|
||||||
|
@ -213,13 +212,13 @@ MediaUploader.prototype.onContentUploadSuccess_ = function(e) {
|
||||||
* @private
|
* @private
|
||||||
* @param {object} e XHR event
|
* @param {object} e XHR event
|
||||||
*/
|
*/
|
||||||
MediaUploader.prototype.onContentUploadError_ = function(e) {
|
MediaUploader.prototype.onContentUploadError_ = function (e) {
|
||||||
if (e.target.status && e.target.status < 500) {
|
if (e.target.status && e.target.status < 500) {
|
||||||
this.onError(e.target.response);
|
this.onError(e.target.response)
|
||||||
} else {
|
} else {
|
||||||
this.retryHandler.retry(this.resume_.bind(this));
|
this.retryHandler.retry(this.resume_.bind(this))
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles errors for the initial request.
|
* Handles errors for the initial request.
|
||||||
|
@ -227,9 +226,9 @@ MediaUploader.prototype.onContentUploadError_ = function(e) {
|
||||||
* @private
|
* @private
|
||||||
* @param {object} e XHR event
|
* @param {object} e XHR event
|
||||||
*/
|
*/
|
||||||
MediaUploader.prototype.onUploadError_ = function(e) {
|
MediaUploader.prototype.onUploadError_ = function (e) {
|
||||||
this.onError(e.target.response); // TODO - Retries for initial upload
|
this.onError(e.target.response) // TODO - Retries for initial upload
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a query string from a hash/object
|
* Construct a query string from a hash/object
|
||||||
|
@ -238,12 +237,12 @@ MediaUploader.prototype.onUploadError_ = function(e) {
|
||||||
* @param {object} [params] Key/value pairs for query string
|
* @param {object} [params] Key/value pairs for query string
|
||||||
* @return {string} query string
|
* @return {string} query string
|
||||||
*/
|
*/
|
||||||
MediaUploader.prototype.buildQuery_ = function(params) {
|
MediaUploader.prototype.buildQuery_ = function (params) {
|
||||||
params = params || {};
|
params = params || {}
|
||||||
return Object.keys(params).map(function(key) {
|
return Object.keys(params).map(function (key) {
|
||||||
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
|
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
|
||||||
}).join('&');
|
}).join('&')
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the drive upload URL
|
* Build the drive upload URL
|
||||||
|
@ -253,16 +252,16 @@ MediaUploader.prototype.buildQuery_ = function(params) {
|
||||||
* @param {object} [params] Query parameters
|
* @param {object} [params] Query parameters
|
||||||
* @return {string} URL
|
* @return {string} URL
|
||||||
*/
|
*/
|
||||||
MediaUploader.prototype.buildUrl_ = function(id, params, baseUrl) {
|
MediaUploader.prototype.buildUrl_ = function (id, params, baseUrl) {
|
||||||
var url = baseUrl || 'https://www.googleapis.com/upload/drive/v2/files/';
|
var url = baseUrl || 'https://www.googleapis.com/upload/drive/v2/files/'
|
||||||
if (id) {
|
if (id) {
|
||||||
url += id;
|
url += id
|
||||||
}
|
}
|
||||||
var query = this.buildQuery_(params);
|
var query = this.buildQuery_(params)
|
||||||
if (query) {
|
if (query) {
|
||||||
url += '?' + query;
|
url += '?' + query
|
||||||
}
|
}
|
||||||
return url;
|
return url
|
||||||
};
|
}
|
||||||
|
|
||||||
window.MediaUploader = MediaUploader;
|
window.MediaUploader = MediaUploader
|
||||||
|
|
|
@ -1,372 +1,328 @@
|
||||||
import store from 'store';
|
/* eslint-env browser, jquery */
|
||||||
import S from 'string';
|
/* global serverurl, Cookies, moment */
|
||||||
|
|
||||||
|
import store from 'store'
|
||||||
|
import S from 'string'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
checkIfAuth
|
checkIfAuth
|
||||||
} from './lib/common/login';
|
} from './lib/common/login'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
urlpath
|
urlpath
|
||||||
} from './lib/config';
|
} from './lib/config'
|
||||||
|
|
||||||
window.migrateHistoryFromTempCallback = null;
|
window.migrateHistoryFromTempCallback = null
|
||||||
|
|
||||||
migrateHistoryFromTemp();
|
migrateHistoryFromTemp()
|
||||||
|
|
||||||
function migrateHistoryFromTemp() {
|
function migrateHistoryFromTemp () {
|
||||||
if (url('#tempid')) {
|
if (window.url('#tempid')) {
|
||||||
$.get(`${serverurl}/temp`, {
|
$.get(`${serverurl}/temp`, {
|
||||||
tempid: url('#tempid')
|
tempid: window.url('#tempid')
|
||||||
})
|
})
|
||||||
.done(data => {
|
.done(data => {
|
||||||
if (data && data.temp) {
|
if (data && data.temp) {
|
||||||
getStorageHistory(olddata => {
|
getStorageHistory(olddata => {
|
||||||
if (!olddata || olddata.length == 0) {
|
if (!olddata || olddata.length === 0) {
|
||||||
saveHistoryToStorage(JSON.parse(data.temp));
|
saveHistoryToStorage(JSON.parse(data.temp))
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.always(() => {
|
.always(() => {
|
||||||
let hash = location.hash.split('#')[1];
|
let hash = location.hash.split('#')[1]
|
||||||
hash = hash.split('&');
|
hash = hash.split('&')
|
||||||
for (let i = 0; i < hash.length; i++)
|
for (let i = 0; i < hash.length; i++) {
|
||||||
if (hash[i].indexOf('tempid') == 0) {
|
if (hash[i].indexOf('tempid') === 0) {
|
||||||
hash.splice(i, 1);
|
hash.splice(i, 1)
|
||||||
i--;
|
i--
|
||||||
}
|
}
|
||||||
hash = hash.join('&');
|
}
|
||||||
location.hash = hash;
|
hash = hash.join('&')
|
||||||
if (migrateHistoryFromTempCallback)
|
location.hash = hash
|
||||||
migrateHistoryFromTempCallback();
|
if (window.migrateHistoryFromTempCallback) { window.migrateHistoryFromTempCallback() }
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveHistory(notehistory) {
|
export function saveHistory (notehistory) {
|
||||||
checkIfAuth(
|
checkIfAuth(
|
||||||
() => {
|
() => {
|
||||||
saveHistoryToServer(notehistory);
|
saveHistoryToServer(notehistory)
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
saveHistoryToStorage(notehistory);
|
saveHistoryToStorage(notehistory)
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveHistoryToStorage(notehistory) {
|
function saveHistoryToStorage (notehistory) {
|
||||||
if (store.enabled)
|
if (store.enabled) { store.set('notehistory', JSON.stringify(notehistory)) } else { saveHistoryToCookie(notehistory) }
|
||||||
store.set('notehistory', JSON.stringify(notehistory));
|
|
||||||
else
|
|
||||||
saveHistoryToCookie(notehistory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveHistoryToCookie(notehistory) {
|
function saveHistoryToCookie (notehistory) {
|
||||||
Cookies.set('notehistory', notehistory, {
|
Cookies.set('notehistory', notehistory, {
|
||||||
expires: 365
|
expires: 365
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveHistoryToServer(notehistory) {
|
function saveHistoryToServer (notehistory) {
|
||||||
|
$.post(`${serverurl}/history`, {
|
||||||
|
history: JSON.stringify(notehistory)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveStorageHistoryToServer (callback) {
|
||||||
|
const data = store.get('notehistory')
|
||||||
|
if (data) {
|
||||||
$.post(`${serverurl}/history`, {
|
$.post(`${serverurl}/history`, {
|
||||||
history: JSON.stringify(notehistory)
|
history: data
|
||||||
});
|
})
|
||||||
}
|
|
||||||
|
|
||||||
function saveCookieHistoryToStorage(callback) {
|
|
||||||
store.set('notehistory', Cookies.get('notehistory'));
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function saveStorageHistoryToServer(callback) {
|
|
||||||
const data = store.get('notehistory');
|
|
||||||
if (data) {
|
|
||||||
$.post(`${serverurl}/history`, {
|
|
||||||
history: data
|
|
||||||
})
|
|
||||||
.done(data => {
|
.done(data => {
|
||||||
callback(data);
|
callback(data)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveCookieHistoryToServer(callback) {
|
export function clearDuplicatedHistory (notehistory) {
|
||||||
$.post(`${serverurl}/history`, {
|
const newnotehistory = []
|
||||||
history: Cookies.get('notehistory')
|
for (let i = 0; i < notehistory.length; i++) {
|
||||||
})
|
let found = false
|
||||||
.done(data => {
|
for (let j = 0; j < newnotehistory.length; j++) {
|
||||||
callback(data);
|
const id = notehistory[i].id.replace(/=+$/, '')
|
||||||
});
|
const newId = newnotehistory[j].id.replace(/=+$/, '')
|
||||||
}
|
if (id === newId || notehistory[i].id === newnotehistory[j].id || !notehistory[i].id || !newnotehistory[j].id) {
|
||||||
|
const time = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'))
|
||||||
export function clearDuplicatedHistory(notehistory) {
|
const newTime = (typeof newnotehistory[i].time === 'number' ? moment(newnotehistory[i].time) : moment(newnotehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'))
|
||||||
const newnotehistory = [];
|
if (time >= newTime) {
|
||||||
for (let i = 0; i < notehistory.length; i++) {
|
newnotehistory[j] = notehistory[i]
|
||||||
let found = false;
|
|
||||||
for (let j = 0; j < newnotehistory.length; j++) {
|
|
||||||
const id = notehistory[i].id.replace(/\=+$/, '');
|
|
||||||
const newId = newnotehistory[j].id.replace(/\=+$/, '');
|
|
||||||
if (id == newId || notehistory[i].id == newnotehistory[j].id || !notehistory[i].id || !newnotehistory[j].id) {
|
|
||||||
const time = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
|
|
||||||
const newTime = (typeof newnotehistory[i].time === 'number' ? moment(newnotehistory[i].time) : moment(newnotehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'));
|
|
||||||
if(time >= newTime) {
|
|
||||||
newnotehistory[j] = notehistory[i];
|
|
||||||
}
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!found)
|
found = true
|
||||||
newnotehistory.push(notehistory[i]);
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return newnotehistory;
|
if (!found) { newnotehistory.push(notehistory[i]) }
|
||||||
|
}
|
||||||
|
return newnotehistory
|
||||||
}
|
}
|
||||||
|
|
||||||
function addHistory(id, text, time, tags, pinned, notehistory) {
|
function addHistory (id, text, time, tags, pinned, notehistory) {
|
||||||
// only add when note id exists
|
// only add when note id exists
|
||||||
if (id) {
|
if (id) {
|
||||||
notehistory.push({
|
notehistory.push({
|
||||||
id,
|
id,
|
||||||
text,
|
text,
|
||||||
time,
|
time,
|
||||||
tags,
|
tags,
|
||||||
pinned
|
pinned
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
return notehistory;
|
return notehistory
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeHistory(id, notehistory) {
|
export function removeHistory (id, notehistory) {
|
||||||
for (let i = 0; i < notehistory.length; i++) {
|
for (let i = 0; i < notehistory.length; i++) {
|
||||||
if (notehistory[i].id == id) {
|
if (notehistory[i].id === id) {
|
||||||
notehistory.splice(i, 1);
|
notehistory.splice(i, 1)
|
||||||
i -= 1;
|
i -= 1
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return notehistory;
|
}
|
||||||
|
return notehistory
|
||||||
}
|
}
|
||||||
|
|
||||||
//used for inner
|
// used for inner
|
||||||
export function writeHistory(title, tags) {
|
export function writeHistory (title, tags) {
|
||||||
checkIfAuth(
|
checkIfAuth(
|
||||||
() => {
|
() => {
|
||||||
// no need to do this anymore, this will count from server-side
|
// no need to do this anymore, this will count from server-side
|
||||||
// writeHistoryToServer(title, tags);
|
// writeHistoryToServer(title, tags);
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
writeHistoryToStorage(title, tags);
|
writeHistoryToStorage(title, tags)
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeHistoryToServer(title, tags) {
|
function writeHistoryToCookie (title, tags) {
|
||||||
$.get(`${serverurl}/history`)
|
var notehistory
|
||||||
.done(data => {
|
try {
|
||||||
try {
|
notehistory = Cookies.getJSON('notehistory')
|
||||||
if (data.history) {
|
} catch (err) {
|
||||||
var notehistory = data.history;
|
notehistory = []
|
||||||
} else {
|
}
|
||||||
var notehistory = [];
|
if (!notehistory) { notehistory = [] }
|
||||||
}
|
const newnotehistory = generateHistory(title, tags, notehistory)
|
||||||
} catch (err) {
|
saveHistoryToCookie(newnotehistory)
|
||||||
var notehistory = [];
|
|
||||||
}
|
|
||||||
if (!notehistory)
|
|
||||||
notehistory = [];
|
|
||||||
|
|
||||||
const newnotehistory = generateHistory(title, tags, notehistory);
|
|
||||||
saveHistoryToServer(newnotehistory);
|
|
||||||
})
|
|
||||||
.fail((xhr, status, error) => {
|
|
||||||
console.error(xhr.responseText);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeHistoryToCookie(title, tags) {
|
function writeHistoryToStorage (title, tags) {
|
||||||
try {
|
if (store.enabled) {
|
||||||
var notehistory = Cookies.getJSON('notehistory');
|
let data = store.get('notehistory')
|
||||||
} catch (err) {
|
var notehistory
|
||||||
var notehistory = [];
|
if (data) {
|
||||||
}
|
if (typeof data === 'string') { data = JSON.parse(data) }
|
||||||
if (!notehistory)
|
notehistory = data
|
||||||
notehistory = [];
|
|
||||||
|
|
||||||
const newnotehistory = generateHistory(title, tags, notehistory);
|
|
||||||
saveHistoryToCookie(newnotehistory);
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeHistoryToStorage(title, tags) {
|
|
||||||
if (store.enabled) {
|
|
||||||
let data = store.get('notehistory');
|
|
||||||
if (data) {
|
|
||||||
if (typeof data == "string")
|
|
||||||
data = JSON.parse(data);
|
|
||||||
var notehistory = data;
|
|
||||||
} else
|
|
||||||
var notehistory = [];
|
|
||||||
if (!notehistory)
|
|
||||||
notehistory = [];
|
|
||||||
|
|
||||||
const newnotehistory = generateHistory(title, tags, notehistory);
|
|
||||||
saveHistoryToStorage(newnotehistory);
|
|
||||||
} else {
|
} else {
|
||||||
writeHistoryToCookie(title, tags);
|
notehistory = []
|
||||||
}
|
}
|
||||||
|
if (!notehistory) { notehistory = [] }
|
||||||
|
|
||||||
|
const newnotehistory = generateHistory(title, tags, notehistory)
|
||||||
|
saveHistoryToStorage(newnotehistory)
|
||||||
|
} else {
|
||||||
|
writeHistoryToCookie(title, tags)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray) {
|
if (!Array.isArray) {
|
||||||
Array.isArray = arg => Object.prototype.toString.call(arg) === '[object Array]';
|
Array.isArray = arg => Object.prototype.toString.call(arg) === '[object Array]'
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderHistory(title, tags) {
|
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];
|
const id = urlpath ? location.pathname.slice(urlpath.length + 1, location.pathname.length).split('/')[1] : location.pathname.split('/')[1]
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
text: title,
|
text: title,
|
||||||
time: moment().valueOf(),
|
time: moment().valueOf(),
|
||||||
tags
|
tags
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateHistory(title, tags, notehistory) {
|
function generateHistory (title, tags, notehistory) {
|
||||||
const info = renderHistory(title, tags);
|
const info = renderHistory(title, tags)
|
||||||
//keep any pinned data
|
// keep any pinned data
|
||||||
let pinned = false;
|
let pinned = false
|
||||||
|
for (let i = 0; i < notehistory.length; i++) {
|
||||||
|
if (notehistory[i].id === info.id && notehistory[i].pinned) {
|
||||||
|
pinned = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notehistory = removeHistory(info.id, notehistory)
|
||||||
|
notehistory = addHistory(info.id, info.text, info.time, info.tags, pinned, notehistory)
|
||||||
|
notehistory = clearDuplicatedHistory(notehistory)
|
||||||
|
return notehistory
|
||||||
|
}
|
||||||
|
|
||||||
|
// used for outer
|
||||||
|
export function getHistory (callback) {
|
||||||
|
checkIfAuth(
|
||||||
|
() => {
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCookieHistory (callback) {
|
||||||
|
callback(Cookies.getJSON('notehistory'))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStorageHistory (callback) {
|
||||||
|
if (store.enabled) {
|
||||||
|
let data = store.get('notehistory')
|
||||||
|
if (data) {
|
||||||
|
if (typeof data === 'string') { data = JSON.parse(data) }
|
||||||
|
callback(data)
|
||||||
|
} else { getCookieHistory(callback) }
|
||||||
|
} else {
|
||||||
|
getCookieHistory(callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseHistory (list, callback) {
|
||||||
|
checkIfAuth(
|
||||||
|
() => {
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCookieToHistory (list, callback) {
|
||||||
|
const notehistory = Cookies.getJSON('notehistory')
|
||||||
|
parseToHistory(list, notehistory, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseStorageToHistory (list, callback) {
|
||||||
|
if (store.enabled) {
|
||||||
|
let data = store.get('notehistory')
|
||||||
|
if (data) {
|
||||||
|
if (typeof data === 'string') { data = JSON.parse(data) }
|
||||||
|
parseToHistory(list, data, callback)
|
||||||
|
} else { parseCookieToHistory(list, callback) }
|
||||||
|
} else {
|
||||||
|
parseCookieToHistory(list, callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseToHistory (list, notehistory, callback) {
|
||||||
|
if (!callback) return
|
||||||
|
else if (!list || !notehistory) callback(list, notehistory)
|
||||||
|
else if (notehistory && notehistory.length > 0) {
|
||||||
for (let i = 0; i < notehistory.length; i++) {
|
for (let i = 0; i < notehistory.length; i++) {
|
||||||
if (notehistory[i].id == info.id && notehistory[i].pinned) {
|
// parse time to timestamp and fromNow
|
||||||
pinned = true;
|
const timestamp = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'))
|
||||||
break;
|
notehistory[i].timestamp = timestamp.valueOf()
|
||||||
}
|
notehistory[i].fromNow = timestamp.fromNow()
|
||||||
}
|
notehistory[i].time = timestamp.format('llll')
|
||||||
notehistory = removeHistory(info.id, notehistory);
|
|
||||||
notehistory = addHistory(info.id, info.text, info.time, info.tags, pinned, notehistory);
|
|
||||||
notehistory = clearDuplicatedHistory(notehistory);
|
|
||||||
return notehistory;
|
|
||||||
}
|
|
||||||
|
|
||||||
//used for outer
|
|
||||||
export function getHistory(callback) {
|
|
||||||
checkIfAuth(
|
|
||||||
() => {
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCookieHistory(callback) {
|
|
||||||
callback(Cookies.getJSON('notehistory'));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getStorageHistory(callback) {
|
|
||||||
if (store.enabled) {
|
|
||||||
let data = store.get('notehistory');
|
|
||||||
if (data) {
|
|
||||||
if (typeof data == "string")
|
|
||||||
data = JSON.parse(data);
|
|
||||||
callback(data);
|
|
||||||
} else
|
|
||||||
getCookieHistory(callback);
|
|
||||||
} else {
|
|
||||||
getCookieHistory(callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseHistory(list, callback) {
|
|
||||||
checkIfAuth(
|
|
||||||
() => {
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCookieToHistory(list, callback) {
|
|
||||||
const notehistory = Cookies.getJSON('notehistory');
|
|
||||||
parseToHistory(list, notehistory, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseStorageToHistory(list, callback) {
|
|
||||||
if (store.enabled) {
|
|
||||||
let data = store.get('notehistory');
|
|
||||||
if (data) {
|
|
||||||
if (typeof data == "string")
|
|
||||||
data = JSON.parse(data);
|
|
||||||
parseToHistory(list, data, callback);
|
|
||||||
} else
|
|
||||||
parseCookieToHistory(list, callback);
|
|
||||||
} else {
|
|
||||||
parseCookieToHistory(list, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseToHistory(list, notehistory, callback) {
|
|
||||||
if (!callback) return;
|
|
||||||
else if (!list || !notehistory) callback(list, notehistory);
|
|
||||||
else if (notehistory && notehistory.length > 0) {
|
|
||||||
for (let i = 0; i < notehistory.length; i++) {
|
|
||||||
//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].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(',') : [];
|
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)
|
if (notehistory[i].id && list.get('id', notehistory[i].id).length === 0) { list.add(notehistory[i]) }
|
||||||
list.add(notehistory[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
callback(list, notehistory);
|
}
|
||||||
|
callback(list, notehistory)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function postHistoryToServer(noteId, data, callback) {
|
export function postHistoryToServer (noteId, data, callback) {
|
||||||
$.post(`${serverurl}/history/${noteId}`, data)
|
$.post(`${serverurl}/history/${noteId}`, data)
|
||||||
.done(result => callback(null, result))
|
.done(result => callback(null, result))
|
||||||
.fail((xhr, status, error) => {
|
.fail((xhr, status, error) => {
|
||||||
console.error(xhr.responseText);
|
console.error(xhr.responseText)
|
||||||
return callback(error, null);
|
return callback(error, null)
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function deleteServerHistory(noteId, callback) {
|
|
||||||
$.ajax({
|
|
||||||
url: `${serverurl}/history${noteId ? '/' + noteId : ""}`,
|
|
||||||
type: 'DELETE'
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteServerHistory (noteId, callback) {
|
||||||
|
$.ajax({
|
||||||
|
url: `${serverurl}/history${noteId ? '/' + noteId : ''}`,
|
||||||
|
type: 'DELETE'
|
||||||
|
})
|
||||||
.done(result => callback(null, result))
|
.done(result => callback(null, result))
|
||||||
.fail((xhr, status, error) => {
|
.fail((xhr, status, error) => {
|
||||||
console.error(xhr.responseText);
|
console.error(xhr.responseText)
|
||||||
return callback(error, null);
|
return callback(error, null)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require('../css/github-extract.css');
|
require('../css/github-extract.css')
|
||||||
require('../css/markdown.css');
|
require('../css/markdown.css')
|
||||||
require('../css/extra.css');
|
require('../css/extra.css')
|
||||||
require('../css/slide-preview.css');
|
require('../css/slide-preview.css')
|
||||||
require('../css/google-font.css');
|
require('../css/google-font.css')
|
||||||
require('../css/site.css');
|
require('../css/site.css')
|
||||||
|
|
6863
public/js/index.js
6863
public/js/index.js
File diff suppressed because it is too large
Load diff
|
@ -1,89 +1,92 @@
|
||||||
import { serverurl } from '../config';
|
/* eslint-env browser, jquery */
|
||||||
|
/* global Cookies */
|
||||||
|
|
||||||
let checkAuth = false;
|
import { serverurl } from '../config'
|
||||||
let profile = null;
|
|
||||||
let lastLoginState = getLoginState();
|
|
||||||
let lastUserId = getUserId();
|
|
||||||
var loginStateChangeEvent = null;
|
|
||||||
|
|
||||||
export function setloginStateChangeEvent(func) {
|
let checkAuth = false
|
||||||
loginStateChangeEvent = func;
|
let profile = null
|
||||||
|
let lastLoginState = getLoginState()
|
||||||
|
let lastUserId = getUserId()
|
||||||
|
var loginStateChangeEvent = null
|
||||||
|
|
||||||
|
export function setloginStateChangeEvent (func) {
|
||||||
|
loginStateChangeEvent = func
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resetCheckAuth() {
|
export function resetCheckAuth () {
|
||||||
checkAuth = false;
|
checkAuth = false
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setLoginState(bool, id) {
|
export function setLoginState (bool, id) {
|
||||||
Cookies.set('loginstate', bool, {
|
Cookies.set('loginstate', bool, {
|
||||||
expires: 365
|
expires: 365
|
||||||
});
|
})
|
||||||
if (id) {
|
if (id) {
|
||||||
Cookies.set('userid', id, {
|
Cookies.set('userid', id, {
|
||||||
expires: 365
|
expires: 365
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
Cookies.remove('userid');
|
Cookies.remove('userid')
|
||||||
}
|
}
|
||||||
lastLoginState = bool;
|
lastLoginState = bool
|
||||||
lastUserId = id;
|
lastUserId = id
|
||||||
checkLoginStateChanged();
|
checkLoginStateChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkLoginStateChanged() {
|
export function checkLoginStateChanged () {
|
||||||
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
|
if (getLoginState() !== lastLoginState || getUserId() !== lastUserId) {
|
||||||
if (loginStateChangeEvent) setTimeout(loginStateChangeEvent, 100);
|
if (loginStateChangeEvent) setTimeout(loginStateChangeEvent, 100)
|
||||||
return true;
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLoginState() {
|
export function getLoginState () {
|
||||||
const state = Cookies.get('loginstate');
|
const state = Cookies.get('loginstate')
|
||||||
return state === "true" || state === true;
|
return state === 'true' || state === true
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUserId() {
|
export function getUserId () {
|
||||||
return Cookies.get('userid');
|
return Cookies.get('userid')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearLoginState() {
|
export function clearLoginState () {
|
||||||
Cookies.remove('loginstate');
|
Cookies.remove('loginstate')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkIfAuth(yesCallback, noCallback) {
|
export function checkIfAuth (yesCallback, noCallback) {
|
||||||
const cookieLoginState = getLoginState();
|
const cookieLoginState = getLoginState()
|
||||||
if (checkLoginStateChanged()) checkAuth = false;
|
if (checkLoginStateChanged()) checkAuth = false
|
||||||
if (!checkAuth || typeof cookieLoginState == 'undefined') {
|
if (!checkAuth || typeof cookieLoginState === 'undefined') {
|
||||||
$.get(`${serverurl}/me`)
|
$.get(`${serverurl}/me`)
|
||||||
.done(data => {
|
.done(data => {
|
||||||
if (data && data.status == 'ok') {
|
if (data && data.status === 'ok') {
|
||||||
profile = data;
|
profile = data
|
||||||
yesCallback(profile);
|
yesCallback(profile)
|
||||||
setLoginState(true, data.id);
|
setLoginState(true, data.id)
|
||||||
} else {
|
} else {
|
||||||
noCallback();
|
noCallback()
|
||||||
setLoginState(false);
|
setLoginState(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fail(() => {
|
.fail(() => {
|
||||||
noCallback();
|
noCallback()
|
||||||
})
|
})
|
||||||
.always(() => {
|
.always(() => {
|
||||||
checkAuth = true;
|
checkAuth = true
|
||||||
});
|
})
|
||||||
} else if (cookieLoginState) {
|
} else if (cookieLoginState) {
|
||||||
yesCallback(profile);
|
yesCallback(profile)
|
||||||
} else {
|
} else {
|
||||||
noCallback();
|
noCallback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
checkAuth,
|
checkAuth,
|
||||||
profile,
|
profile,
|
||||||
lastLoginState,
|
lastLoginState,
|
||||||
lastUserId,
|
lastUserId,
|
||||||
loginStateChangeEvent
|
loginStateChangeEvent
|
||||||
};
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
import configJson from '../../../../config.json'; // root path json config
|
import configJson from '../../../../config.json' // root path json config
|
||||||
|
|
||||||
const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development;
|
const config = process.env.NODE_ENV === 'production' ? configJson.production : configJson.development
|
||||||
|
|
||||||
export const GOOGLE_API_KEY = (config.google && config.google.apiKey) || '';
|
export const GOOGLE_API_KEY = (config.google && config.google.apiKey) || ''
|
||||||
export const GOOGLE_CLIENT_ID = (config.google && config.google.clientID) || '';
|
export const GOOGLE_CLIENT_ID = (config.google && config.google.clientID) || ''
|
||||||
export const DROPBOX_APP_KEY = (config.dropbox && config.dropbox.appKey) || '';
|
export const DROPBOX_APP_KEY = (config.dropbox && config.dropbox.appKey) || ''
|
||||||
|
|
||||||
export const domain = config.domain || ''; // domain name
|
export const domain = config.domain || '' // domain name
|
||||||
export const urlpath = config.urlpath || ''; // sub url path, like: www.example.com/<urlpath>
|
export const urlpath = config.urlpath || '' // sub url path, like: www.example.com/<urlpath>
|
||||||
export const debug = config.debug || false;
|
export const debug = config.debug || false
|
||||||
|
|
||||||
export const port = window.location.port;
|
export const port = window.location.port
|
||||||
export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`;
|
export const serverurl = `${window.location.protocol}//${domain || window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`
|
||||||
window.serverurl = serverurl;
|
window.serverurl = serverurl
|
||||||
export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1];
|
export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1]
|
||||||
export const noteurl = `${serverurl}/${noteid}`;
|
export const noteurl = `${serverurl}/${noteid}`
|
||||||
|
|
||||||
export const version = '0.5.0';
|
export const version = '0.5.0'
|
||||||
|
|
|
@ -1,26 +1,28 @@
|
||||||
var lang = "en";
|
/* eslint-env browser, jquery */
|
||||||
var userLang = navigator.language || navigator.userLanguage;
|
/* global Cookies */
|
||||||
var userLangCode = userLang.split('-')[0];
|
|
||||||
var userCountryCode = userLang.split('-')[1];
|
var lang = 'en'
|
||||||
var locale = $('.ui-locale');
|
var userLang = navigator.language || navigator.userLanguage
|
||||||
var supportLangs = [];
|
var userLangCode = userLang.split('-')[0]
|
||||||
$(".ui-locale option").each(function() {
|
var locale = $('.ui-locale')
|
||||||
supportLangs.push($(this).val());
|
var supportLangs = []
|
||||||
});
|
$('.ui-locale option').each(function () {
|
||||||
|
supportLangs.push($(this).val())
|
||||||
|
})
|
||||||
if (Cookies.get('locale')) {
|
if (Cookies.get('locale')) {
|
||||||
lang = Cookies.get('locale');
|
lang = Cookies.get('locale')
|
||||||
} else if (supportLangs.indexOf(userLang) !== -1) {
|
} else if (supportLangs.indexOf(userLang) !== -1) {
|
||||||
lang = supportLangs[supportLangs.indexOf(userLang)];
|
lang = supportLangs[supportLangs.indexOf(userLang)]
|
||||||
} else if (supportLangs.indexOf(userLangCode) !== -1) {
|
} else if (supportLangs.indexOf(userLangCode) !== -1) {
|
||||||
lang = supportLangs[supportLangs.indexOf(userLangCode)];
|
lang = supportLangs[supportLangs.indexOf(userLangCode)]
|
||||||
}
|
}
|
||||||
|
|
||||||
locale.val(lang);
|
locale.val(lang)
|
||||||
$('select.ui-locale option[value="' + lang + '"]').attr('selected','selected');
|
$('select.ui-locale option[value="' + lang + '"]').attr('selected', 'selected')
|
||||||
|
|
||||||
locale.change(function() {
|
locale.change(function () {
|
||||||
Cookies.set('locale', $(this).val(), {
|
Cookies.set('locale', $(this).val(), {
|
||||||
expires: 365
|
expires: 365
|
||||||
});
|
})
|
||||||
window.location.reload();
|
window.location.reload()
|
||||||
});
|
})
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
require('../css/extra.css');
|
/* eslint-env browser, jquery */
|
||||||
require('../css/slide-preview.css');
|
/* global refreshView */
|
||||||
require('../css/site.css');
|
|
||||||
|
|
||||||
require('highlight.js/styles/github-gist.css');
|
require('../css/extra.css')
|
||||||
|
require('../css/slide-preview.css')
|
||||||
|
require('../css/site.css')
|
||||||
|
|
||||||
|
require('highlight.js/styles/github-gist.css')
|
||||||
|
|
||||||
import {
|
import {
|
||||||
autoLinkify,
|
autoLinkify,
|
||||||
|
@ -16,126 +19,126 @@ import {
|
||||||
scrollToHash,
|
scrollToHash,
|
||||||
smoothHashScroll,
|
smoothHashScroll,
|
||||||
updateLastChange
|
updateLastChange
|
||||||
} from './extra';
|
} from './extra'
|
||||||
|
|
||||||
import { preventXSS } from './render';
|
import { preventXSS } from './render'
|
||||||
|
|
||||||
const markdown = $("#doc.markdown-body");
|
const markdown = $('#doc.markdown-body')
|
||||||
const text = markdown.text();
|
const text = markdown.text()
|
||||||
const lastMeta = md.meta;
|
const lastMeta = md.meta
|
||||||
md.meta = {};
|
md.meta = {}
|
||||||
delete md.metaError;
|
delete md.metaError
|
||||||
let rendered = md.render(text);
|
let rendered = md.render(text)
|
||||||
if (md.meta.type && md.meta.type === 'slide') {
|
if (md.meta.type && md.meta.type === 'slide') {
|
||||||
const slideOptions = {
|
const slideOptions = {
|
||||||
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
|
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
|
||||||
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
|
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
|
||||||
};
|
}
|
||||||
const slides = RevealMarkdown.slidify(text, slideOptions);
|
const slides = window.RevealMarkdown.slidify(text, slideOptions)
|
||||||
markdown.html(slides);
|
markdown.html(slides)
|
||||||
RevealMarkdown.initialize();
|
window.RevealMarkdown.initialize()
|
||||||
// prevent XSS
|
// prevent XSS
|
||||||
markdown.html(preventXSS(markdown.html()));
|
markdown.html(preventXSS(markdown.html()))
|
||||||
markdown.addClass('slides');
|
markdown.addClass('slides')
|
||||||
} else {
|
} else {
|
||||||
if (lastMeta.type && lastMeta.type === 'slide') {
|
if (lastMeta.type && lastMeta.type === 'slide') {
|
||||||
refreshView();
|
refreshView()
|
||||||
markdown.removeClass('slides');
|
markdown.removeClass('slides')
|
||||||
}
|
}
|
||||||
// only render again when meta changed
|
// only render again when meta changed
|
||||||
if (JSON.stringify(md.meta) != JSON.stringify(lastMeta)) {
|
if (JSON.stringify(md.meta) !== JSON.stringify(lastMeta)) {
|
||||||
parseMeta(md, null, markdown, $('#ui-toc'), $('#ui-toc-affix'));
|
parseMeta(md, null, markdown, $('#ui-toc'), $('#ui-toc-affix'))
|
||||||
rendered = md.render(text);
|
rendered = md.render(text)
|
||||||
}
|
}
|
||||||
// prevent XSS
|
// prevent XSS
|
||||||
rendered = preventXSS(rendered);
|
rendered = preventXSS(rendered)
|
||||||
const result = postProcess(rendered);
|
const result = postProcess(rendered)
|
||||||
markdown.html(result.html());
|
markdown.html(result.html())
|
||||||
}
|
}
|
||||||
$(document.body).show();
|
$(document.body).show()
|
||||||
|
|
||||||
finishView(markdown);
|
finishView(markdown)
|
||||||
autoLinkify(markdown);
|
autoLinkify(markdown)
|
||||||
deduplicatedHeaderId(markdown);
|
deduplicatedHeaderId(markdown)
|
||||||
renderTOC(markdown);
|
renderTOC(markdown)
|
||||||
generateToc('ui-toc');
|
generateToc('ui-toc')
|
||||||
generateToc('ui-toc-affix');
|
generateToc('ui-toc-affix')
|
||||||
smoothHashScroll();
|
smoothHashScroll()
|
||||||
createtime = lastchangeui.time.attr('data-createtime');
|
window.createtime = window.lastchangeui.time.attr('data-createtime')
|
||||||
lastchangetime = lastchangeui.time.attr('data-updatetime');
|
window.lastchangetime = window.lastchangeui.time.attr('data-updatetime')
|
||||||
updateLastChange();
|
updateLastChange()
|
||||||
|
|
||||||
const url = window.location.pathname;
|
const url = window.location.pathname
|
||||||
$('.ui-edit').attr('href', `${url}/edit`);
|
$('.ui-edit').attr('href', `${url}/edit`)
|
||||||
const toc = $('.ui-toc');
|
const toc = $('.ui-toc')
|
||||||
const tocAffix = $('.ui-affix-toc');
|
const tocAffix = $('.ui-affix-toc')
|
||||||
const tocDropdown = $('.ui-toc-dropdown');
|
const tocDropdown = $('.ui-toc-dropdown')
|
||||||
//toc
|
// toc
|
||||||
tocDropdown.click(e => {
|
tocDropdown.click(e => {
|
||||||
e.stopPropagation();
|
e.stopPropagation()
|
||||||
});
|
})
|
||||||
|
|
||||||
let enoughForAffixToc = true;
|
let enoughForAffixToc = true
|
||||||
|
|
||||||
function generateScrollspy() {
|
function generateScrollspy () {
|
||||||
$(document.body).scrollspy({
|
$(document.body).scrollspy({
|
||||||
target: ''
|
target: ''
|
||||||
});
|
})
|
||||||
$(document.body).scrollspy('refresh');
|
$(document.body).scrollspy('refresh')
|
||||||
if (enoughForAffixToc) {
|
if (enoughForAffixToc) {
|
||||||
toc.hide();
|
toc.hide()
|
||||||
tocAffix.show();
|
tocAffix.show()
|
||||||
} else {
|
} else {
|
||||||
tocAffix.hide();
|
tocAffix.hide()
|
||||||
toc.show();
|
toc.show()
|
||||||
}
|
}
|
||||||
$(document.body).scroll();
|
$(document.body).scroll()
|
||||||
}
|
}
|
||||||
|
|
||||||
function windowResize() {
|
function windowResize () {
|
||||||
//toc right
|
// toc right
|
||||||
const paddingRight = parseFloat(markdown.css('padding-right'));
|
const paddingRight = parseFloat(markdown.css('padding-right'))
|
||||||
const right = ($(window).width() - (markdown.offset().left + markdown.outerWidth() - paddingRight));
|
const right = ($(window).width() - (markdown.offset().left + markdown.outerWidth() - paddingRight))
|
||||||
toc.css('right', `${right}px`);
|
toc.css('right', `${right}px`)
|
||||||
//affix toc left
|
// affix toc left
|
||||||
let newbool;
|
let newbool
|
||||||
const rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2;
|
const rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2
|
||||||
//for ipad or wider device
|
// for ipad or wider device
|
||||||
if (rightMargin >= 133) {
|
if (rightMargin >= 133) {
|
||||||
newbool = true;
|
newbool = true
|
||||||
const affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2;
|
const affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2
|
||||||
const left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin;
|
const left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin
|
||||||
tocAffix.css('left', `${left}px`);
|
tocAffix.css('left', `${left}px`)
|
||||||
} else {
|
} else {
|
||||||
newbool = false;
|
newbool = false
|
||||||
}
|
}
|
||||||
if (newbool != enoughForAffixToc) {
|
if (newbool !== enoughForAffixToc) {
|
||||||
enoughForAffixToc = newbool;
|
enoughForAffixToc = newbool
|
||||||
generateScrollspy();
|
generateScrollspy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$(window).resize(() => {
|
$(window).resize(() => {
|
||||||
windowResize();
|
windowResize()
|
||||||
});
|
})
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
windowResize();
|
windowResize()
|
||||||
generateScrollspy();
|
generateScrollspy()
|
||||||
setTimeout(scrollToHash, 0);
|
setTimeout(scrollToHash, 0)
|
||||||
//tooltip
|
// tooltip
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip()
|
||||||
});
|
})
|
||||||
|
|
||||||
export function scrollToTop() {
|
export function scrollToTop () {
|
||||||
$('body, html').stop(true, true).animate({
|
$('body, html').stop(true, true).animate({
|
||||||
scrollTop: 0
|
scrollTop: 0
|
||||||
}, 100, "linear");
|
}, 100, 'linear')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function scrollToBottom() {
|
export function scrollToBottom () {
|
||||||
$('body, html').stop(true, true).animate({
|
$('body, html').stop(true, true).animate({
|
||||||
scrollTop: $(document.body)[0].scrollHeight
|
scrollTop: $(document.body)[0].scrollHeight
|
||||||
}, 100, "linear");
|
}, 100, 'linear')
|
||||||
}
|
}
|
||||||
|
|
||||||
window.scrollToTop = scrollToTop;
|
window.scrollToTop = scrollToTop
|
||||||
window.scrollToBottom = scrollToBottom;
|
window.scrollToBottom = scrollToBottom
|
||||||
|
|
|
@ -1,62 +1,64 @@
|
||||||
|
/* eslint-env browser, jquery */
|
||||||
|
/* global filterXSS */
|
||||||
// allow some attributes
|
// allow some attributes
|
||||||
var whiteListAttr = ['id', 'class', 'style'];
|
var whiteListAttr = ['id', 'class', 'style']
|
||||||
window.whiteListAttr = whiteListAttr;
|
window.whiteListAttr = whiteListAttr
|
||||||
// allow link starts with '.', '/' and custom protocol with '://'
|
// allow link starts with '.', '/' and custom protocol with '://'
|
||||||
var linkRegex = /^([\w|-]+:\/\/)|^([\.|\/])+/;
|
var linkRegex = /^([\w|-]+:\/\/)|^([.|/])+/
|
||||||
// allow data uri, from https://gist.github.com/bgrins/6194623
|
// allow data uri, from https://gist.github.com/bgrins/6194623
|
||||||
var dataUriRegex = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*)\s*$/i;
|
var dataUriRegex = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s]*)\s*$/i
|
||||||
// custom white list
|
// custom white list
|
||||||
var whiteList = filterXSS.whiteList;
|
var whiteList = filterXSS.whiteList
|
||||||
// allow ol specify start number
|
// allow ol specify start number
|
||||||
whiteList['ol'] = ['start'];
|
whiteList['ol'] = ['start']
|
||||||
// allow li specify value number
|
// allow li specify value number
|
||||||
whiteList['li'] = ['value'];
|
whiteList['li'] = ['value']
|
||||||
// allow style tag
|
// allow style tag
|
||||||
whiteList['style'] = [];
|
whiteList['style'] = []
|
||||||
// allow kbd tag
|
// allow kbd tag
|
||||||
whiteList['kbd'] = [];
|
whiteList['kbd'] = []
|
||||||
// allow ifram tag with some safe attributes
|
// allow ifram tag with some safe attributes
|
||||||
whiteList['iframe'] = ['allowfullscreen', 'name', 'referrerpolicy', 'sandbox', 'src', 'srcdoc', 'width', 'height'];
|
whiteList['iframe'] = ['allowfullscreen', 'name', 'referrerpolicy', 'sandbox', 'src', 'srcdoc', 'width', 'height']
|
||||||
// allow summary tag
|
// allow summary tag
|
||||||
whiteList['summary'] = [];
|
whiteList['summary'] = []
|
||||||
|
|
||||||
var filterXSSOptions = {
|
var filterXSSOptions = {
|
||||||
allowCommentTag: true,
|
allowCommentTag: true,
|
||||||
whiteList: whiteList,
|
whiteList: whiteList,
|
||||||
escapeHtml: function (html) {
|
escapeHtml: function (html) {
|
||||||
// allow html comment in multiple lines
|
// allow html comment in multiple lines
|
||||||
return html.replace(/<(.*?)>/g, '<$1>');
|
return html.replace(/<(.*?)>/g, '<$1>')
|
||||||
},
|
},
|
||||||
onIgnoreTag: function (tag, html, options) {
|
onIgnoreTag: function (tag, html, options) {
|
||||||
// allow comment tag
|
// allow comment tag
|
||||||
if (tag == "!--") {
|
if (tag === '!--') {
|
||||||
// do not filter its attributes
|
// do not filter its attributes
|
||||||
return html;
|
return html
|
||||||
}
|
|
||||||
},
|
|
||||||
onTagAttr: function (tag, name, value, isWhiteAttr) {
|
|
||||||
// allow href and src that match linkRegex
|
|
||||||
if (isWhiteAttr && (name === 'href' || name === 'src') && linkRegex.test(value)) {
|
|
||||||
return name + '="' + filterXSS.escapeAttrValue(value) + '"';
|
|
||||||
}
|
|
||||||
// allow data uri in img src
|
|
||||||
if (isWhiteAttr && (tag == "img" && name === 'src') && dataUriRegex.test(value)) {
|
|
||||||
return name + '="' + filterXSS.escapeAttrValue(value) + '"';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onIgnoreTagAttr: function (tag, name, value, isWhiteAttr) {
|
|
||||||
// allow attr start with 'data-' or in the whiteListAttr
|
|
||||||
if (name.substr(0, 5) === 'data-' || whiteListAttr.indexOf(name) !== -1) {
|
|
||||||
// escape its value using built-in escapeAttrValue function
|
|
||||||
return name + '="' + filterXSS.escapeAttrValue(value) + '"';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
onTagAttr: function (tag, name, value, isWhiteAttr) {
|
||||||
function preventXSS(html) {
|
// allow href and src that match linkRegex
|
||||||
return filterXSS(html, filterXSSOptions);
|
if (isWhiteAttr && (name === 'href' || name === 'src') && linkRegex.test(value)) {
|
||||||
|
return name + '="' + filterXSS.escapeAttrValue(value) + '"'
|
||||||
|
}
|
||||||
|
// allow data uri in img src
|
||||||
|
if (isWhiteAttr && (tag === 'img' && name === 'src') && dataUriRegex.test(value)) {
|
||||||
|
return name + '="' + filterXSS.escapeAttrValue(value) + '"'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onIgnoreTagAttr: function (tag, name, value, isWhiteAttr) {
|
||||||
|
// allow attr start with 'data-' or in the whiteListAttr
|
||||||
|
if (name.substr(0, 5) === 'data-' || window.whiteListAttr.indexOf(name) !== -1) {
|
||||||
|
// escape its value using built-in escapeAttrValue function
|
||||||
|
return name + '="' + filterXSS.escapeAttrValue(value) + '"'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.preventXSS = preventXSS;
|
|
||||||
|
function preventXSS (html) {
|
||||||
|
return filterXSS(html, filterXSSOptions)
|
||||||
|
}
|
||||||
|
window.preventXSS = preventXSS
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
preventXSS: preventXSS
|
preventXSS: preventXSS
|
||||||
|
|
|
@ -1,396 +1,355 @@
|
||||||
|
/* eslint-env browser, jquery */
|
||||||
|
|
||||||
|
import { preventXSS } from './render'
|
||||||
|
import { md } from './extra'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reveal.js markdown plugin. Handles parsing of
|
* The reveal.js markdown plugin. Handles parsing of
|
||||||
* markdown inside of presentations as well as loading
|
* markdown inside of presentations as well as loading
|
||||||
* of external markdown documents.
|
* of external markdown documents.
|
||||||
*/
|
*/
|
||||||
(function( root, factory ) {
|
(function (root, factory) {
|
||||||
if( typeof exports === 'object' ) {
|
if (typeof exports === 'object') {
|
||||||
module.exports = factory();
|
module.exports = factory()
|
||||||
}
|
} else {
|
||||||
else {
|
// Browser globals (root is window)
|
||||||
// Browser globals (root is window)
|
root.RevealMarkdown = factory()
|
||||||
root.RevealMarkdown = factory();
|
root.RevealMarkdown.initialize()
|
||||||
root.RevealMarkdown.initialize();
|
}
|
||||||
}
|
}(this, function () {
|
||||||
}( this, function() {
|
var DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$'
|
||||||
|
var DEFAULT_NOTES_SEPARATOR = 'note:'
|
||||||
var DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$',
|
var DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\.element\\s*?(.+?)$'
|
||||||
DEFAULT_NOTES_SEPARATOR = 'note:',
|
var DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\.slide:\\s*?(\\S.+?)$'
|
||||||
DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\\.element\\\s*?(.+?)$',
|
|
||||||
DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\\.slide:\\\s*?(\\\S.+?)$';
|
var SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__'
|
||||||
|
|
||||||
var SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__';
|
/**
|
||||||
|
* Retrieves the markdown contents of a slide section
|
||||||
|
* element. Normalizes leading tabs/whitespace.
|
||||||
/**
|
*/
|
||||||
* Retrieves the markdown contents of a slide section
|
function getMarkdownFromSlide (section) {
|
||||||
* element. Normalizes leading tabs/whitespace.
|
var template = section.querySelector('script')
|
||||||
*/
|
|
||||||
function getMarkdownFromSlide( section ) {
|
// strip leading whitespace so it isn't evaluated as code
|
||||||
|
var text = (template || section).textContent
|
||||||
var template = section.querySelector( 'script' );
|
|
||||||
|
// restore script end tags
|
||||||
// strip leading whitespace so it isn't evaluated as code
|
text = text.replace(new RegExp(SCRIPT_END_PLACEHOLDER, 'g'), '</script>')
|
||||||
var text = ( template || section ).textContent;
|
|
||||||
|
var leadingWs = text.match(/^\n?(\s*)/)[1].length
|
||||||
// restore script end tags
|
var leadingTabs = text.match(/^\n?(\t*)/)[1].length
|
||||||
text = text.replace( new RegExp( SCRIPT_END_PLACEHOLDER, 'g' ), '</script>' );
|
|
||||||
|
if (leadingTabs > 0) {
|
||||||
var leadingWs = text.match( /^\n?(\s*)/ )[1].length,
|
text = text.replace(new RegExp('\\n?\\t{' + leadingTabs + '}', 'g'), '\n')
|
||||||
leadingTabs = text.match( /^\n?(\t*)/ )[1].length;
|
} else if (leadingWs > 1) {
|
||||||
|
text = text.replace(new RegExp('\\n? {' + leadingWs + '}', 'g'), '\n')
|
||||||
if( leadingTabs > 0 ) {
|
}
|
||||||
text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' );
|
|
||||||
}
|
return text
|
||||||
else if( leadingWs > 1 ) {
|
}
|
||||||
text = text.replace( new RegExp('\\n? {' + leadingWs + '}', 'g'), '\n' );
|
|
||||||
}
|
/**
|
||||||
|
* Given a markdown slide section element, this will
|
||||||
return text;
|
* return all arguments that aren't related to markdown
|
||||||
|
* parsing. Used to forward any other user-defined arguments
|
||||||
}
|
* to the output markdown slide.
|
||||||
|
*/
|
||||||
/**
|
function getForwardedAttributes (section) {
|
||||||
* Given a markdown slide section element, this will
|
var attributes = section.attributes
|
||||||
* return all arguments that aren't related to markdown
|
var result = []
|
||||||
* parsing. Used to forward any other user-defined arguments
|
|
||||||
* to the output markdown slide.
|
for (var i = 0, len = attributes.length; i < len; i++) {
|
||||||
*/
|
var name = attributes[i].name
|
||||||
function getForwardedAttributes( section ) {
|
var value = attributes[i].value
|
||||||
|
|
||||||
var attributes = section.attributes;
|
// disregard attributes that are used for markdown loading/parsing
|
||||||
var result = [];
|
if (/data-(markdown|separator|vertical|notes)/gi.test(name)) continue
|
||||||
|
|
||||||
for( var i = 0, len = attributes.length; i < len; i++ ) {
|
if (value) {
|
||||||
var name = attributes[i].name,
|
result.push(name + '="' + value + '"')
|
||||||
value = attributes[i].value;
|
} else {
|
||||||
|
result.push(name)
|
||||||
// disregard attributes that are used for markdown loading/parsing
|
}
|
||||||
if( /data\-(markdown|separator|vertical|notes)/gi.test( name ) ) continue;
|
}
|
||||||
|
|
||||||
if( value ) {
|
return result.join(' ')
|
||||||
result.push( name + '="' + value + '"' );
|
}
|
||||||
}
|
|
||||||
else {
|
/**
|
||||||
result.push( name );
|
* Inspects the given options and fills out default
|
||||||
}
|
* values for what's not defined.
|
||||||
}
|
*/
|
||||||
|
function getSlidifyOptions (options) {
|
||||||
return result.join( ' ' );
|
options = options || {}
|
||||||
|
options.separator = options.separator || DEFAULT_SLIDE_SEPARATOR
|
||||||
}
|
options.notesSeparator = options.notesSeparator || DEFAULT_NOTES_SEPARATOR
|
||||||
|
options.attributes = options.attributes || ''
|
||||||
/**
|
|
||||||
* Inspects the given options and fills out default
|
return options
|
||||||
* values for what's not defined.
|
}
|
||||||
*/
|
|
||||||
function getSlidifyOptions( options ) {
|
/**
|
||||||
|
* Helper function for constructing a markdown slide.
|
||||||
options = options || {};
|
*/
|
||||||
options.separator = options.separator || DEFAULT_SLIDE_SEPARATOR;
|
function createMarkdownSlide (content, options) {
|
||||||
options.notesSeparator = options.notesSeparator || DEFAULT_NOTES_SEPARATOR;
|
options = getSlidifyOptions(options)
|
||||||
options.attributes = options.attributes || '';
|
|
||||||
|
var notesMatch = content.split(new RegExp(options.notesSeparator, 'mgi'))
|
||||||
return options;
|
|
||||||
|
if (notesMatch.length === 2) {
|
||||||
}
|
content = notesMatch[0] + '<aside class="notes" data-markdown>' + notesMatch[1].trim() + '</aside>'
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Helper function for constructing a markdown slide.
|
// prevent script end tags in the content from interfering
|
||||||
*/
|
// with parsing
|
||||||
function createMarkdownSlide( content, options ) {
|
content = content.replace(/<\/script>/g, SCRIPT_END_PLACEHOLDER)
|
||||||
|
|
||||||
options = getSlidifyOptions( options );
|
return '<script type="text/template">' + content + '</script>'
|
||||||
|
}
|
||||||
var notesMatch = content.split( new RegExp( options.notesSeparator, 'mgi' ) );
|
|
||||||
|
/**
|
||||||
if( notesMatch.length === 2 ) {
|
* Parses a data string into multiple slides based
|
||||||
content = notesMatch[0] + '<aside class="notes" data-markdown>' + notesMatch[1].trim() + '</aside>';
|
* on the passed in separator arguments.
|
||||||
}
|
*/
|
||||||
|
function slidify (markdown, options) {
|
||||||
// prevent script end tags in the content from interfering
|
options = getSlidifyOptions(options)
|
||||||
// with parsing
|
|
||||||
content = content.replace( /<\/script>/g, SCRIPT_END_PLACEHOLDER );
|
var separatorRegex = new RegExp(options.separator + (options.verticalSeparator ? '|' + options.verticalSeparator : ''), 'mg')
|
||||||
|
var horizontalSeparatorRegex = new RegExp(options.separator)
|
||||||
return '<script type="text/template">' + content + '</script>';
|
|
||||||
|
var matches
|
||||||
}
|
var lastIndex = 0
|
||||||
|
var isHorizontal
|
||||||
/**
|
var wasHorizontal = true
|
||||||
* Parses a data string into multiple slides based
|
var content
|
||||||
* on the passed in separator arguments.
|
var sectionStack = []
|
||||||
*/
|
|
||||||
function slidify( markdown, options ) {
|
// iterate until all blocks between separators are stacked up
|
||||||
|
while ((matches = separatorRegex.exec(markdown)) !== null) {
|
||||||
options = getSlidifyOptions( options );
|
// determine direction (horizontal by default)
|
||||||
|
isHorizontal = horizontalSeparatorRegex.test(matches[0])
|
||||||
var separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ),
|
|
||||||
horizontalSeparatorRegex = new RegExp( options.separator );
|
if (!isHorizontal && wasHorizontal) {
|
||||||
|
// create vertical stack
|
||||||
var matches,
|
sectionStack.push([])
|
||||||
lastIndex = 0,
|
}
|
||||||
isHorizontal,
|
|
||||||
wasHorizontal = true,
|
// pluck slide content from markdown input
|
||||||
content,
|
content = markdown.substring(lastIndex, matches.index)
|
||||||
sectionStack = [];
|
|
||||||
|
if (isHorizontal && wasHorizontal) {
|
||||||
// iterate until all blocks between separators are stacked up
|
// add to horizontal stack
|
||||||
while( matches = separatorRegex.exec( markdown ) ) {
|
sectionStack.push(content)
|
||||||
notes = null;
|
} else {
|
||||||
|
// add to vertical stack
|
||||||
// determine direction (horizontal by default)
|
sectionStack[sectionStack.length - 1].push(content)
|
||||||
isHorizontal = horizontalSeparatorRegex.test( matches[0] );
|
}
|
||||||
|
|
||||||
if( !isHorizontal && wasHorizontal ) {
|
lastIndex = separatorRegex.lastIndex
|
||||||
// create vertical stack
|
wasHorizontal = isHorizontal
|
||||||
sectionStack.push( [] );
|
}
|
||||||
}
|
|
||||||
|
// add the remaining slide
|
||||||
// pluck slide content from markdown input
|
(wasHorizontal ? sectionStack : sectionStack[sectionStack.length - 1]).push(markdown.substring(lastIndex))
|
||||||
content = markdown.substring( lastIndex, matches.index );
|
|
||||||
|
var markdownSections = ''
|
||||||
if( isHorizontal && wasHorizontal ) {
|
|
||||||
// add to horizontal stack
|
// flatten the hierarchical stack, and insert <section data-markdown> tags
|
||||||
sectionStack.push( content );
|
for (var i = 0, len = sectionStack.length; i < len; i++) {
|
||||||
}
|
// vertical
|
||||||
else {
|
if (sectionStack[i] instanceof Array) {
|
||||||
// add to vertical stack
|
markdownSections += '<section ' + options.attributes + '>'
|
||||||
sectionStack[sectionStack.length-1].push( content );
|
|
||||||
}
|
sectionStack[i].forEach(function (child) {
|
||||||
|
markdownSections += '<section data-markdown>' + createMarkdownSlide(child, options) + '</section>'
|
||||||
lastIndex = separatorRegex.lastIndex;
|
})
|
||||||
wasHorizontal = isHorizontal;
|
|
||||||
}
|
markdownSections += '</section>'
|
||||||
|
} else {
|
||||||
// add the remaining slide
|
markdownSections += '<section ' + options.attributes + ' data-markdown>' + createMarkdownSlide(sectionStack[i], options) + '</section>'
|
||||||
( wasHorizontal ? sectionStack : sectionStack[sectionStack.length-1] ).push( markdown.substring( lastIndex ) );
|
}
|
||||||
|
}
|
||||||
var markdownSections = '';
|
|
||||||
|
return markdownSections
|
||||||
// flatten the hierarchical stack, and insert <section data-markdown> tags
|
}
|
||||||
for( var i = 0, len = sectionStack.length; i < len; i++ ) {
|
|
||||||
// vertical
|
/**
|
||||||
if( sectionStack[i] instanceof Array ) {
|
* Parses any current data-markdown slides, splits
|
||||||
markdownSections += '<section '+ options.attributes +'>';
|
* multi-slide markdown into separate sections and
|
||||||
|
* handles loading of external markdown.
|
||||||
sectionStack[i].forEach( function( child ) {
|
*/
|
||||||
markdownSections += '<section data-markdown>' + createMarkdownSlide( child, options ) + '</section>';
|
function processSlides () {
|
||||||
} );
|
var sections = document.querySelectorAll('[data-markdown]')
|
||||||
|
var section
|
||||||
markdownSections += '</section>';
|
|
||||||
}
|
for (var i = 0, len = sections.length; i < len; i++) {
|
||||||
else {
|
section = sections[i]
|
||||||
markdownSections += '<section '+ options.attributes +' data-markdown>' + createMarkdownSlide( sectionStack[i], options ) + '</section>';
|
|
||||||
}
|
if (section.getAttribute('data-markdown').length) {
|
||||||
}
|
var xhr = new XMLHttpRequest()
|
||||||
|
var url = section.getAttribute('data-markdown')
|
||||||
return markdownSections;
|
|
||||||
|
var datacharset = section.getAttribute('data-charset')
|
||||||
}
|
|
||||||
|
// see https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute#Notes
|
||||||
/**
|
if (datacharset !== null && datacharset !== '') {
|
||||||
* Parses any current data-markdown slides, splits
|
xhr.overrideMimeType('text/html; charset=' + datacharset)
|
||||||
* multi-slide markdown into separate sections and
|
}
|
||||||
* handles loading of external markdown.
|
|
||||||
*/
|
xhr.onreadystatechange = function () {
|
||||||
function processSlides() {
|
if (xhr.readyState === 4) {
|
||||||
|
// file protocol yields status code 0 (useful for local debug, mobile applications etc.)
|
||||||
var sections = document.querySelectorAll( '[data-markdown]'),
|
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 0) {
|
||||||
section;
|
section.outerHTML = slidify(xhr.responseText, {
|
||||||
|
separator: section.getAttribute('data-separator'),
|
||||||
for( var i = 0, len = sections.length; i < len; i++ ) {
|
verticalSeparator: section.getAttribute('data-separator-vertical'),
|
||||||
|
notesSeparator: section.getAttribute('data-separator-notes'),
|
||||||
section = sections[i];
|
attributes: getForwardedAttributes(section)
|
||||||
|
})
|
||||||
if( section.getAttribute( 'data-markdown' ).length ) {
|
} else {
|
||||||
|
section.outerHTML = '<section data-state="alert">' +
|
||||||
var xhr = new XMLHttpRequest(),
|
'ERROR: The attempt to fetch ' + url + ' failed with HTTP status ' + xhr.status + '.' +
|
||||||
url = section.getAttribute( 'data-markdown' );
|
'Check your browser\'s JavaScript console for more details.' +
|
||||||
|
'<p>Remember that you need to serve the presentation HTML from a HTTP server.</p>' +
|
||||||
datacharset = section.getAttribute( 'data-charset' );
|
'</section>'
|
||||||
|
}
|
||||||
// see https://developer.mozilla.org/en-US/docs/Web/API/element.getAttribute#Notes
|
}
|
||||||
if( datacharset != null && datacharset != '' ) {
|
}
|
||||||
xhr.overrideMimeType( 'text/html; charset=' + datacharset );
|
|
||||||
}
|
xhr.open('GET', url, false)
|
||||||
|
|
||||||
xhr.onreadystatechange = function() {
|
try {
|
||||||
if( xhr.readyState === 4 ) {
|
xhr.send()
|
||||||
// file protocol yields status code 0 (useful for local debug, mobile applications etc.)
|
} catch (e) {
|
||||||
if ( ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status === 0 ) {
|
alert('Failed to get the Markdown file ' + url + '. Make sure that the presentation and the file are served by a HTTP server and the file can be found there. ' + e)
|
||||||
|
}
|
||||||
section.outerHTML = slidify( xhr.responseText, {
|
} else if (section.getAttribute('data-separator') || section.getAttribute('data-separator-vertical') || section.getAttribute('data-separator-notes')) {
|
||||||
separator: section.getAttribute( 'data-separator' ),
|
section.outerHTML = slidify(getMarkdownFromSlide(section), {
|
||||||
verticalSeparator: section.getAttribute( 'data-separator-vertical' ),
|
separator: section.getAttribute('data-separator'),
|
||||||
notesSeparator: section.getAttribute( 'data-separator-notes' ),
|
verticalSeparator: section.getAttribute('data-separator-vertical'),
|
||||||
attributes: getForwardedAttributes( section )
|
notesSeparator: section.getAttribute('data-separator-notes'),
|
||||||
});
|
attributes: getForwardedAttributes(section)
|
||||||
|
})
|
||||||
}
|
} else {
|
||||||
else {
|
section.innerHTML = createMarkdownSlide(getMarkdownFromSlide(section))
|
||||||
|
}
|
||||||
section.outerHTML = '<section data-state="alert">' +
|
}
|
||||||
'ERROR: The attempt to fetch ' + url + ' failed with HTTP status ' + xhr.status + '.' +
|
}
|
||||||
'Check your browser\'s JavaScript console for more details.' +
|
|
||||||
'<p>Remember that you need to serve the presentation HTML from a HTTP server.</p>' +
|
/**
|
||||||
'</section>';
|
* Check if a node value has the attributes pattern.
|
||||||
|
* If yes, extract it and add that value as one or several attributes
|
||||||
}
|
* the the terget element.
|
||||||
}
|
*
|
||||||
};
|
* You need Cache Killer on Chrome to see the effect on any FOM transformation
|
||||||
|
* directly on refresh (F5)
|
||||||
xhr.open( 'GET', url, false );
|
* http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development/7000899#answer-11786277
|
||||||
|
*/
|
||||||
try {
|
function addAttributeInElement (node, elementTarget, separator) {
|
||||||
xhr.send();
|
var mardownClassesInElementsRegex = new RegExp(separator, 'mg')
|
||||||
}
|
var mardownClassRegex = new RegExp('([^"= ]+?)="([^"=]+?)"', 'mg')
|
||||||
catch ( e ) {
|
var nodeValue = node.nodeValue
|
||||||
alert( 'Failed to get the Markdown file ' + url + '. Make sure that the presentation and the file are served by a HTTP server and the file can be found there. ' + e );
|
var matches
|
||||||
}
|
var matchesClass
|
||||||
|
if ((matches = mardownClassesInElementsRegex.exec(nodeValue))) {
|
||||||
}
|
var classes = matches[1]
|
||||||
else if( section.getAttribute( 'data-separator' ) || section.getAttribute( 'data-separator-vertical' ) || section.getAttribute( 'data-separator-notes' ) ) {
|
nodeValue = nodeValue.substring(0, matches.index) + nodeValue.substring(mardownClassesInElementsRegex.lastIndex)
|
||||||
|
node.nodeValue = nodeValue
|
||||||
section.outerHTML = slidify( getMarkdownFromSlide( section ), {
|
while ((matchesClass = mardownClassRegex.exec(classes))) {
|
||||||
separator: section.getAttribute( 'data-separator' ),
|
var name = matchesClass[1]
|
||||||
verticalSeparator: section.getAttribute( 'data-separator-vertical' ),
|
var value = matchesClass[2]
|
||||||
notesSeparator: section.getAttribute( 'data-separator-notes' ),
|
if (name.substr(0, 5) === 'data-' || window.whiteListAttr.indexOf(name) !== -1) { elementTarget.setAttribute(name, window.filterXSS.escapeAttrValue(value)) }
|
||||||
attributes: getForwardedAttributes( section )
|
}
|
||||||
});
|
return true
|
||||||
|
}
|
||||||
}
|
return false
|
||||||
else {
|
}
|
||||||
section.innerHTML = createMarkdownSlide( getMarkdownFromSlide( section ) );
|
|
||||||
}
|
/**
|
||||||
}
|
* Add attributes to the parent element of a text node,
|
||||||
|
* or the element of an attribute node.
|
||||||
}
|
*/
|
||||||
|
function addAttributes (section, element, previousElement, separatorElementAttributes, separatorSectionAttributes) {
|
||||||
/**
|
if (element != null && element.childNodes !== undefined && element.childNodes.length > 0) {
|
||||||
* Check if a node value has the attributes pattern.
|
var previousParentElement = element
|
||||||
* If yes, extract it and add that value as one or several attributes
|
for (var i = 0; i < element.childNodes.length; i++) {
|
||||||
* the the terget element.
|
var childElement = element.childNodes[i]
|
||||||
*
|
if (i > 0) {
|
||||||
* You need Cache Killer on Chrome to see the effect on any FOM transformation
|
let j = i - 1
|
||||||
* directly on refresh (F5)
|
while (j >= 0) {
|
||||||
* http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development/7000899#answer-11786277
|
var aPreviousChildElement = element.childNodes[j]
|
||||||
*/
|
if (typeof aPreviousChildElement.setAttribute === 'function' && aPreviousChildElement.tagName !== 'BR') {
|
||||||
function addAttributeInElement( node, elementTarget, separator ) {
|
previousParentElement = aPreviousChildElement
|
||||||
|
break
|
||||||
var mardownClassesInElementsRegex = new RegExp( separator, 'mg' );
|
}
|
||||||
var mardownClassRegex = new RegExp( "([^\"= ]+?)=\"([^\"=]+?)\"", 'mg' );
|
j = j - 1
|
||||||
var nodeValue = node.nodeValue;
|
}
|
||||||
if( matches = mardownClassesInElementsRegex.exec( nodeValue ) ) {
|
}
|
||||||
|
var parentSection = section
|
||||||
var classes = matches[1];
|
if (childElement.nodeName === 'section') {
|
||||||
nodeValue = nodeValue.substring( 0, matches.index ) + nodeValue.substring( mardownClassesInElementsRegex.lastIndex );
|
parentSection = childElement
|
||||||
node.nodeValue = nodeValue;
|
previousParentElement = childElement
|
||||||
while( matchesClass = mardownClassRegex.exec( classes ) ) {
|
}
|
||||||
var name = matchesClass[1];
|
if (typeof childElement.setAttribute === 'function' || childElement.nodeType === Node.COMMENT_NODE) {
|
||||||
var value = matchesClass[2];
|
addAttributes(parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes)
|
||||||
if (name.substr(0, 5) === 'data-' || whiteListAttr.indexOf(name) !== -1)
|
}
|
||||||
elementTarget.setAttribute( name, filterXSS.escapeAttrValue(value) );
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
if (element.nodeType === Node.COMMENT_NODE) {
|
||||||
return false;
|
if (addAttributeInElement(element, previousElement, separatorElementAttributes) === false) {
|
||||||
}
|
addAttributeInElement(element, section, separatorSectionAttributes)
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Add attributes to the parent element of a text node,
|
}
|
||||||
* or the element of an attribute node.
|
|
||||||
*/
|
/**
|
||||||
function addAttributes( section, element, previousElement, separatorElementAttributes, separatorSectionAttributes ) {
|
* Converts any current data-markdown slides in the
|
||||||
|
* DOM to HTML.
|
||||||
if ( element != null && element.childNodes != undefined && element.childNodes.length > 0 ) {
|
*/
|
||||||
previousParentElement = element;
|
function convertSlides () {
|
||||||
for( var i = 0; i < element.childNodes.length; i++ ) {
|
var sections = document.querySelectorAll('[data-markdown]')
|
||||||
childElement = element.childNodes[i];
|
|
||||||
if ( i > 0 ) {
|
for (var i = 0, len = sections.length; i < len; i++) {
|
||||||
j = i - 1;
|
var section = sections[i]
|
||||||
while ( j >= 0 ) {
|
|
||||||
aPreviousChildElement = element.childNodes[j];
|
// Only parse the same slide once
|
||||||
if ( typeof aPreviousChildElement.setAttribute == 'function' && aPreviousChildElement.tagName != "BR" ) {
|
if (!section.getAttribute('data-markdown-parsed')) {
|
||||||
previousParentElement = aPreviousChildElement;
|
section.setAttribute('data-markdown-parsed', true)
|
||||||
break;
|
|
||||||
}
|
var notes = section.querySelector('aside.notes')
|
||||||
j = j - 1;
|
var markdown = getMarkdownFromSlide(section)
|
||||||
}
|
|
||||||
}
|
var rendered = md.render(markdown)
|
||||||
parentSection = section;
|
rendered = preventXSS(rendered)
|
||||||
if( childElement.nodeName == "section" ) {
|
var result = window.postProcess(rendered)
|
||||||
parentSection = childElement ;
|
section.innerHTML = result[0].outerHTML
|
||||||
previousParentElement = childElement ;
|
addAttributes(section, section, null, section.getAttribute('data-element-attributes') ||
|
||||||
}
|
section.parentNode.getAttribute('data-element-attributes') ||
|
||||||
if ( typeof childElement.setAttribute == 'function' || childElement.nodeType == Node.COMMENT_NODE ) {
|
DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR,
|
||||||
addAttributes( parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes );
|
section.getAttribute('data-attributes') ||
|
||||||
}
|
section.parentNode.getAttribute('data-attributes') ||
|
||||||
}
|
DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR)
|
||||||
}
|
|
||||||
|
// If there were notes, we need to re-add them after
|
||||||
if ( element.nodeType == Node.COMMENT_NODE ) {
|
// having overwritten the section's HTML
|
||||||
if ( addAttributeInElement( element, previousElement, separatorElementAttributes ) == false ) {
|
if (notes) {
|
||||||
addAttributeInElement( element, section, separatorSectionAttributes );
|
section.appendChild(notes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Converts any current data-markdown slides in the
|
// API
|
||||||
* DOM to HTML.
|
return {
|
||||||
*/
|
initialize: function () {
|
||||||
function convertSlides() {
|
processSlides()
|
||||||
|
convertSlides()
|
||||||
var sections = document.querySelectorAll( '[data-markdown]');
|
},
|
||||||
|
// TODO: Do these belong in the API?
|
||||||
for( var i = 0, len = sections.length; i < len; i++ ) {
|
processSlides: processSlides,
|
||||||
|
convertSlides: convertSlides,
|
||||||
var section = sections[i];
|
slidify: slidify
|
||||||
|
}
|
||||||
// Only parse the same slide once
|
}))
|
||||||
if( !section.getAttribute( 'data-markdown-parsed' ) ) {
|
|
||||||
|
|
||||||
section.setAttribute( 'data-markdown-parsed', true )
|
|
||||||
|
|
||||||
var notes = section.querySelector( 'aside.notes' );
|
|
||||||
var markdown = getMarkdownFromSlide( section );
|
|
||||||
|
|
||||||
var rendered = md.render(markdown);
|
|
||||||
rendered = preventXSS(rendered);
|
|
||||||
var result = postProcess(rendered);
|
|
||||||
section.innerHTML = result[0].outerHTML;
|
|
||||||
addAttributes( section, section, null, section.getAttribute( 'data-element-attributes' ) ||
|
|
||||||
section.parentNode.getAttribute( 'data-element-attributes' ) ||
|
|
||||||
DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR,
|
|
||||||
section.getAttribute( 'data-attributes' ) ||
|
|
||||||
section.parentNode.getAttribute( 'data-attributes' ) ||
|
|
||||||
DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR);
|
|
||||||
|
|
||||||
// If there were notes, we need to re-add them after
|
|
||||||
// having overwritten the section's HTML
|
|
||||||
if( notes ) {
|
|
||||||
section.appendChild( notes );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// API
|
|
||||||
return {
|
|
||||||
|
|
||||||
initialize: function() {
|
|
||||||
processSlides();
|
|
||||||
convertSlides();
|
|
||||||
},
|
|
||||||
|
|
||||||
// TODO: Do these belong in the API?
|
|
||||||
processSlides: processSlides,
|
|
||||||
convertSlides: convertSlides,
|
|
||||||
slidify: slidify
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}));
|
|
||||||
|
|
|
@ -1,138 +1,139 @@
|
||||||
require('../css/extra.css');
|
/* eslint-env browser, jquery */
|
||||||
require('../css/site.css');
|
/* global serverurl, Reveal */
|
||||||
|
|
||||||
import { md, updateLastChange, finishView } from './extra';
|
require('../css/extra.css')
|
||||||
|
require('../css/site.css')
|
||||||
|
|
||||||
import { preventXSS } from './render';
|
import { md, updateLastChange, finishView } from './extra'
|
||||||
|
|
||||||
const body = $(".slides").text();
|
const body = $('.slides').text()
|
||||||
|
|
||||||
createtime = lastchangeui.time.attr('data-createtime');
|
window.createtime = window.lastchangeui.time.attr('data-createtime')
|
||||||
lastchangetime = lastchangeui.time.attr('data-updatetime');
|
window.lastchangetime = window.lastchangeui.time.attr('data-updatetime')
|
||||||
updateLastChange();
|
updateLastChange()
|
||||||
const url = window.location.pathname;
|
const url = window.location.pathname
|
||||||
$('.ui-edit').attr('href', `${url}/edit`);
|
$('.ui-edit').attr('href', `${url}/edit`)
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
//tooltip
|
// tooltip
|
||||||
$('[data-toggle="tooltip"]').tooltip();
|
$('[data-toggle="tooltip"]').tooltip()
|
||||||
});
|
})
|
||||||
|
|
||||||
function extend() {
|
function extend () {
|
||||||
const target = {};
|
const target = {}
|
||||||
|
|
||||||
for (const source of arguments) {
|
for (const source of arguments) {
|
||||||
for (const key in source) {
|
for (const key in source) {
|
||||||
if (source.hasOwnProperty(key)) {
|
if (source.hasOwnProperty(key)) {
|
||||||
target[key] = source[key];
|
target[key] = source[key]
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return target;
|
return target
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional libraries used to extend on reveal.js
|
// Optional libraries used to extend on reveal.js
|
||||||
const deps = [{
|
const deps = [{
|
||||||
src: `${serverurl}/build/reveal.js/lib/js/classList.js`,
|
src: `${serverurl}/build/reveal.js/lib/js/classList.js`,
|
||||||
condition() {
|
condition () {
|
||||||
return !document.body.classList;
|
return !document.body.classList
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
src: `${serverurl}/js/reveal-markdown.js`,
|
src: `${serverurl}/js/reveal-markdown.js`,
|
||||||
callback() {
|
callback () {
|
||||||
const slideOptions = {
|
const slideOptions = {
|
||||||
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
|
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
|
||||||
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
|
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
|
||||||
};
|
|
||||||
const slides = RevealMarkdown.slidify(body, slideOptions);
|
|
||||||
$(".slides").html(slides);
|
|
||||||
RevealMarkdown.initialize();
|
|
||||||
$(".slides").show();
|
|
||||||
}
|
}
|
||||||
|
const slides = window.RevealMarkdown.slidify(body, slideOptions)
|
||||||
|
$('.slides').html(slides)
|
||||||
|
window.RevealMarkdown.initialize()
|
||||||
|
$('.slides').show()
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
src: `${serverurl}/build/reveal.js/plugin/notes/notes.js`,
|
src: `${serverurl}/build/reveal.js/plugin/notes/notes.js`,
|
||||||
async: true,
|
async: true,
|
||||||
condition() {
|
condition () {
|
||||||
return !!document.body.classList;
|
return !!document.body.classList
|
||||||
}
|
}
|
||||||
}];
|
}]
|
||||||
|
|
||||||
// default options to init reveal.js
|
// default options to init reveal.js
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
controls: true,
|
controls: true,
|
||||||
progress: true,
|
progress: true,
|
||||||
slideNumber: true,
|
slideNumber: true,
|
||||||
history: true,
|
history: true,
|
||||||
center: true,
|
center: true,
|
||||||
transition: 'none',
|
transition: 'none',
|
||||||
dependencies: deps
|
dependencies: deps
|
||||||
};
|
}
|
||||||
|
|
||||||
// options from yaml meta
|
// options from yaml meta
|
||||||
const meta = JSON.parse($("#meta").text());
|
const meta = JSON.parse($('#meta').text())
|
||||||
var options = meta.slideOptions || {};
|
var options = meta.slideOptions || {}
|
||||||
|
|
||||||
const view = $('.reveal');
|
const view = $('.reveal')
|
||||||
|
|
||||||
//text language
|
// text language
|
||||||
if (meta.lang && typeof meta.lang == "string") {
|
if (meta.lang && typeof meta.lang === 'string') {
|
||||||
view.attr('lang', meta.lang);
|
view.attr('lang', meta.lang)
|
||||||
} else {
|
} else {
|
||||||
view.removeAttr('lang');
|
view.removeAttr('lang')
|
||||||
}
|
}
|
||||||
//text direction
|
// text direction
|
||||||
if (meta.dir && typeof meta.dir == "string" && meta.dir == "rtl") {
|
if (meta.dir && typeof meta.dir === 'string' && meta.dir === 'rtl') {
|
||||||
options.rtl = true;
|
options.rtl = true
|
||||||
} else {
|
} else {
|
||||||
options.rtl = false;
|
options.rtl = false
|
||||||
}
|
}
|
||||||
//breaks
|
// breaks
|
||||||
if (typeof meta.breaks === 'boolean' && !meta.breaks) {
|
if (typeof meta.breaks === 'boolean' && !meta.breaks) {
|
||||||
md.options.breaks = false;
|
md.options.breaks = false
|
||||||
} else {
|
} else {
|
||||||
md.options.breaks = true;
|
md.options.breaks = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// options from URL query string
|
// options from URL query string
|
||||||
const queryOptions = Reveal.getQueryHash() || {};
|
const queryOptions = Reveal.getQueryHash() || {}
|
||||||
|
|
||||||
var options = extend(defaultOptions, options, queryOptions);
|
options = extend(defaultOptions, options, queryOptions)
|
||||||
Reveal.initialize(options);
|
Reveal.initialize(options)
|
||||||
|
|
||||||
window.viewAjaxCallback = () => {
|
window.viewAjaxCallback = () => {
|
||||||
Reveal.layout();
|
Reveal.layout()
|
||||||
};
|
}
|
||||||
|
|
||||||
function renderSlide(event) {
|
function renderSlide (event) {
|
||||||
if (window.location.search.match( /print-pdf/gi )) {
|
if (window.location.search.match(/print-pdf/gi)) {
|
||||||
const slides = $('.slides');
|
const slides = $('.slides')
|
||||||
var title = document.title;
|
let title = document.title
|
||||||
finishView(slides);
|
finishView(slides)
|
||||||
document.title = title;
|
document.title = title
|
||||||
Reveal.layout();
|
Reveal.layout()
|
||||||
} else {
|
} else {
|
||||||
const markdown = $(event.currentSlide);
|
const markdown = $(event.currentSlide)
|
||||||
if (!markdown.attr('data-rendered')) {
|
if (!markdown.attr('data-rendered')) {
|
||||||
var title = document.title;
|
let title = document.title
|
||||||
finishView(markdown);
|
finishView(markdown)
|
||||||
markdown.attr('data-rendered', 'true');
|
markdown.attr('data-rendered', 'true')
|
||||||
document.title = title;
|
document.title = title
|
||||||
Reveal.layout();
|
Reveal.layout()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reveal.addEventListener('ready', event => {
|
Reveal.addEventListener('ready', event => {
|
||||||
renderSlide(event);
|
renderSlide(event)
|
||||||
const markdown = $(event.currentSlide);
|
const markdown = $(event.currentSlide)
|
||||||
// force browser redraw
|
// force browser redraw
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
markdown.hide().show(0);
|
markdown.hide().show(0)
|
||||||
}, 0);
|
}, 0)
|
||||||
});
|
})
|
||||||
Reveal.addEventListener('slidechanged', renderSlide);
|
Reveal.addEventListener('slidechanged', renderSlide)
|
||||||
|
|
||||||
const isMacLike = navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) ? true : false;
|
const isMacLike = !!navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)
|
||||||
|
|
||||||
if (!isMacLike) $('.container').addClass('hidescrollbar');
|
if (!isMacLike) $('.container').addClass('hidescrollbar')
|
||||||
|
|
|
@ -1,365 +1,367 @@
|
||||||
|
/* eslint-env browser, jquery */
|
||||||
|
/* global _ */
|
||||||
// Inject line numbers for sync scroll.
|
// Inject line numbers for sync scroll.
|
||||||
|
|
||||||
import markdownitContainer from 'markdown-it-container';
|
import markdownitContainer from 'markdown-it-container'
|
||||||
|
|
||||||
import { md } from './extra';
|
import { md } from './extra'
|
||||||
|
|
||||||
function addPart(tokens, idx) {
|
function addPart (tokens, idx) {
|
||||||
if (tokens[idx].map && tokens[idx].level === 0) {
|
if (tokens[idx].map && tokens[idx].level === 0) {
|
||||||
const startline = tokens[idx].map[0] + 1;
|
const startline = tokens[idx].map[0] + 1
|
||||||
const endline = tokens[idx].map[1];
|
const endline = tokens[idx].map[1]
|
||||||
tokens[idx].attrJoin('class', 'part');
|
tokens[idx].attrJoin('class', 'part')
|
||||||
tokens[idx].attrJoin('data-startline', startline);
|
tokens[idx].attrJoin('data-startline', startline)
|
||||||
tokens[idx].attrJoin('data-endline', endline);
|
tokens[idx].attrJoin('data-endline', endline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
md.renderer.rules.blockquote_open = function (tokens, idx, options, env, self) {
|
md.renderer.rules.blockquote_open = function (tokens, idx, options, env, self) {
|
||||||
tokens[idx].attrJoin('class', 'raw');
|
tokens[idx].attrJoin('class', 'raw')
|
||||||
addPart(tokens, idx);
|
addPart(tokens, idx)
|
||||||
return self.renderToken(...arguments);
|
return self.renderToken(...arguments)
|
||||||
};
|
}
|
||||||
md.renderer.rules.table_open = function (tokens, idx, options, env, self) {
|
md.renderer.rules.table_open = function (tokens, idx, options, env, self) {
|
||||||
addPart(tokens, idx);
|
addPart(tokens, idx)
|
||||||
return self.renderToken(...arguments);
|
return self.renderToken(...arguments)
|
||||||
};
|
}
|
||||||
md.renderer.rules.bullet_list_open = function (tokens, idx, options, env, self) {
|
md.renderer.rules.bullet_list_open = function (tokens, idx, options, env, self) {
|
||||||
addPart(tokens, idx);
|
addPart(tokens, idx)
|
||||||
return self.renderToken(...arguments);
|
return self.renderToken(...arguments)
|
||||||
};
|
}
|
||||||
md.renderer.rules.list_item_open = function (tokens, idx, options, env, self) {
|
md.renderer.rules.list_item_open = function (tokens, idx, options, env, self) {
|
||||||
tokens[idx].attrJoin('class', 'raw');
|
tokens[idx].attrJoin('class', 'raw')
|
||||||
if (tokens[idx].map) {
|
if (tokens[idx].map) {
|
||||||
const startline = tokens[idx].map[0] + 1;
|
const startline = tokens[idx].map[0] + 1
|
||||||
const endline = tokens[idx].map[1];
|
const endline = tokens[idx].map[1]
|
||||||
tokens[idx].attrJoin('data-startline', startline);
|
tokens[idx].attrJoin('data-startline', startline)
|
||||||
tokens[idx].attrJoin('data-endline', endline);
|
tokens[idx].attrJoin('data-endline', endline)
|
||||||
}
|
}
|
||||||
return self.renderToken(...arguments);
|
return self.renderToken(...arguments)
|
||||||
};
|
}
|
||||||
md.renderer.rules.ordered_list_open = function (tokens, idx, options, env, self) {
|
md.renderer.rules.ordered_list_open = function (tokens, idx, options, env, self) {
|
||||||
addPart(tokens, idx);
|
addPart(tokens, idx)
|
||||||
return self.renderToken(...arguments);
|
return self.renderToken(...arguments)
|
||||||
};
|
}
|
||||||
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
||||||
addPart(tokens, idx);
|
addPart(tokens, idx)
|
||||||
return self.renderToken(...arguments);
|
return self.renderToken(...arguments)
|
||||||
};
|
}
|
||||||
md.renderer.rules.paragraph_open = function (tokens, idx, options, env, self) {
|
md.renderer.rules.paragraph_open = function (tokens, idx, options, env, self) {
|
||||||
addPart(tokens, idx);
|
addPart(tokens, idx)
|
||||||
return self.renderToken(...arguments);
|
return self.renderToken(...arguments)
|
||||||
};
|
}
|
||||||
md.renderer.rules.heading_open = function (tokens, idx, options, env, self) {
|
md.renderer.rules.heading_open = function (tokens, idx, options, env, self) {
|
||||||
tokens[idx].attrJoin('class', 'raw');
|
tokens[idx].attrJoin('class', 'raw')
|
||||||
addPart(tokens, idx);
|
addPart(tokens, idx)
|
||||||
return self.renderToken(...arguments);
|
return self.renderToken(...arguments)
|
||||||
};
|
}
|
||||||
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
|
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
|
||||||
const token = tokens[idx];
|
const token = tokens[idx]
|
||||||
const info = token.info ? md.utils.unescapeAll(token.info).trim() : '';
|
const info = token.info ? md.utils.unescapeAll(token.info).trim() : ''
|
||||||
let langName = '';
|
let langName = ''
|
||||||
let highlighted;
|
let highlighted
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
langName = info.split(/\s+/g)[0];
|
langName = info.split(/\s+/g)[0]
|
||||||
if (/\!$/.test(info)) token.attrJoin('class', 'wrap');
|
if (/!$/.test(info)) token.attrJoin('class', 'wrap')
|
||||||
token.attrJoin('class', options.langPrefix + langName.replace(/\=$|\=\d+$|\=\+$|\!$|\=\!/, ''));
|
token.attrJoin('class', options.langPrefix + langName.replace(/=$|=\d+$|=\+$|!$|=!/, ''))
|
||||||
token.attrJoin('class', 'hljs');
|
token.attrJoin('class', 'hljs')
|
||||||
token.attrJoin('class', 'raw');
|
token.attrJoin('class', 'raw')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.highlight) {
|
if (options.highlight) {
|
||||||
highlighted = options.highlight(token.content, langName) || md.utils.escapeHtml(token.content);
|
highlighted = options.highlight(token.content, langName) || md.utils.escapeHtml(token.content)
|
||||||
} else {
|
} else {
|
||||||
highlighted = md.utils.escapeHtml(token.content);
|
highlighted = md.utils.escapeHtml(token.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highlighted.indexOf('<pre') === 0) {
|
if (highlighted.indexOf('<pre') === 0) {
|
||||||
return `${highlighted}\n`;
|
return `${highlighted}\n`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokens[idx].map && tokens[idx].level === 0) {
|
if (tokens[idx].map && tokens[idx].level === 0) {
|
||||||
const startline = tokens[idx].map[0] + 1;
|
const startline = tokens[idx].map[0] + 1
|
||||||
const endline = tokens[idx].map[1];
|
const endline = tokens[idx].map[1]
|
||||||
return `<pre class="part" data-startline="${startline}" data-endline="${endline}"><code${self.renderAttrs(token)}>${highlighted}</code></pre>\n`;
|
return `<pre class="part" data-startline="${startline}" data-endline="${endline}"><code${self.renderAttrs(token)}>${highlighted}</code></pre>\n`
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<pre><code${self.renderAttrs(token)}>${highlighted}</code></pre>\n`;
|
return `<pre><code${self.renderAttrs(token)}>${highlighted}</code></pre>\n`
|
||||||
};
|
}
|
||||||
md.renderer.rules.code_block = (tokens, idx, options, env, self) => {
|
md.renderer.rules.code_block = (tokens, idx, options, env, self) => {
|
||||||
if (tokens[idx].map && tokens[idx].level === 0) {
|
if (tokens[idx].map && tokens[idx].level === 0) {
|
||||||
const startline = tokens[idx].map[0] + 1;
|
const startline = tokens[idx].map[0] + 1
|
||||||
const endline = tokens[idx].map[1];
|
const endline = tokens[idx].map[1]
|
||||||
return `<pre class="part" data-startline="${startline}" data-endline="${endline}"><code>${md.utils.escapeHtml(tokens[idx].content)}</code></pre>\n`;
|
return `<pre class="part" data-startline="${startline}" data-endline="${endline}"><code>${md.utils.escapeHtml(tokens[idx].content)}</code></pre>\n`
|
||||||
}
|
}
|
||||||
return `<pre><code>${md.utils.escapeHtml(tokens[idx].content)}</code></pre>\n`;
|
return `<pre><code>${md.utils.escapeHtml(tokens[idx].content)}</code></pre>\n`
|
||||||
};
|
}
|
||||||
function renderContainer(tokens, idx, options, env, self) {
|
function renderContainer (tokens, idx, options, env, self) {
|
||||||
tokens[idx].attrJoin('role', 'alert');
|
tokens[idx].attrJoin('role', 'alert')
|
||||||
tokens[idx].attrJoin('class', 'alert');
|
tokens[idx].attrJoin('class', 'alert')
|
||||||
tokens[idx].attrJoin('class', `alert-${tokens[idx].info.trim()}`);
|
tokens[idx].attrJoin('class', `alert-${tokens[idx].info.trim()}`)
|
||||||
addPart(tokens, idx);
|
addPart(tokens, idx)
|
||||||
return self.renderToken(...arguments);
|
return self.renderToken(...arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
md.use(markdownitContainer, 'success', { render: renderContainer });
|
md.use(markdownitContainer, 'success', { render: renderContainer })
|
||||||
md.use(markdownitContainer, 'info', { render: renderContainer });
|
md.use(markdownitContainer, 'info', { render: renderContainer })
|
||||||
md.use(markdownitContainer, 'warning', { render: renderContainer });
|
md.use(markdownitContainer, 'warning', { render: renderContainer })
|
||||||
md.use(markdownitContainer, 'danger', { render: renderContainer });
|
md.use(markdownitContainer, 'danger', { render: renderContainer })
|
||||||
|
|
||||||
// FIXME: expose syncscroll to window
|
// FIXME: expose syncscroll to window
|
||||||
window.syncscroll = true;
|
window.syncscroll = true
|
||||||
|
|
||||||
window.preventSyncScrollToEdit = false;
|
window.preventSyncScrollToEdit = false
|
||||||
window.preventSyncScrollToView = false;
|
window.preventSyncScrollToView = false
|
||||||
|
|
||||||
const editScrollThrottle = 5;
|
const editScrollThrottle = 5
|
||||||
const viewScrollThrottle = 5;
|
const viewScrollThrottle = 5
|
||||||
const buildMapThrottle = 100;
|
const buildMapThrottle = 100
|
||||||
|
|
||||||
let viewScrolling = false;
|
let viewScrolling = false
|
||||||
let editScrolling = false;
|
let editScrolling = false
|
||||||
|
|
||||||
let editArea = null;
|
let editArea = null
|
||||||
let viewArea = null;
|
let viewArea = null
|
||||||
let markdownArea = null;
|
let markdownArea = null
|
||||||
|
|
||||||
export function setupSyncAreas(edit, view, markdown) {
|
export function setupSyncAreas (edit, view, markdown) {
|
||||||
editArea = edit;
|
editArea = edit
|
||||||
viewArea = view;
|
viewArea = view
|
||||||
markdownArea = markdown;
|
markdownArea = markdown
|
||||||
editArea.on('scroll', _.throttle(syncScrollToView, editScrollThrottle));
|
editArea.on('scroll', _.throttle(syncScrollToView, editScrollThrottle))
|
||||||
viewArea.on('scroll', _.throttle(syncScrollToEdit, viewScrollThrottle));
|
viewArea.on('scroll', _.throttle(syncScrollToEdit, viewScrollThrottle))
|
||||||
}
|
}
|
||||||
|
|
||||||
let scrollMap, lineHeightMap, viewTop, viewBottom;
|
let scrollMap, lineHeightMap, viewTop, viewBottom
|
||||||
|
|
||||||
export function clearMap() {
|
export function clearMap () {
|
||||||
scrollMap = null;
|
scrollMap = null
|
||||||
lineHeightMap = null;
|
lineHeightMap = null
|
||||||
viewTop = null;
|
viewTop = null
|
||||||
viewBottom = null;
|
viewBottom = null
|
||||||
}
|
}
|
||||||
window.viewAjaxCallback = clearMap;
|
window.viewAjaxCallback = clearMap
|
||||||
|
|
||||||
const buildMap = _.throttle(buildMapInner, buildMapThrottle);
|
const buildMap = _.throttle(buildMapInner, buildMapThrottle)
|
||||||
|
|
||||||
// Build offsets for each line (lines can be wrapped)
|
// Build offsets for each line (lines can be wrapped)
|
||||||
// That's a bit dirty to process each line everytime, but ok for demo.
|
// That's a bit dirty to process each line everytime, but ok for demo.
|
||||||
// Optimizations are required only for big texts.
|
// Optimizations are required only for big texts.
|
||||||
function buildMapInner(callback) {
|
function buildMapInner (callback) {
|
||||||
if (!viewArea || !markdownArea) return;
|
if (!viewArea || !markdownArea) return
|
||||||
let i, offset, nonEmptyList, pos, a, b, _lineHeightMap, linesCount, acc, _scrollMap;
|
let i, offset, nonEmptyList, pos, a, b, _lineHeightMap, linesCount, acc, _scrollMap
|
||||||
|
|
||||||
offset = viewArea.scrollTop() - viewArea.offset().top;
|
offset = viewArea.scrollTop() - viewArea.offset().top
|
||||||
_scrollMap = [];
|
_scrollMap = []
|
||||||
nonEmptyList = [];
|
nonEmptyList = []
|
||||||
_lineHeightMap = [];
|
_lineHeightMap = []
|
||||||
viewTop = 0;
|
viewTop = 0
|
||||||
viewBottom = viewArea[0].scrollHeight - viewArea.height();
|
viewBottom = viewArea[0].scrollHeight - viewArea.height()
|
||||||
|
|
||||||
acc = 0;
|
acc = 0
|
||||||
const lines = editor.getValue().split('\n');
|
const lines = window.editor.getValue().split('\n')
|
||||||
const lineHeight = editor.defaultTextHeight();
|
const lineHeight = window.editor.defaultTextHeight()
|
||||||
for (i = 0; i < lines.length; i++) {
|
for (i = 0; i < lines.length; i++) {
|
||||||
const str = lines[i];
|
const str = lines[i]
|
||||||
|
|
||||||
_lineHeightMap.push(acc);
|
_lineHeightMap.push(acc)
|
||||||
|
|
||||||
if (str.length === 0) {
|
if (str.length === 0) {
|
||||||
acc++;
|
acc++
|
||||||
continue;
|
continue
|
||||||
}
|
|
||||||
|
|
||||||
const h = editor.heightAtLine(i + 1) - editor.heightAtLine(i);
|
|
||||||
acc += Math.round(h / lineHeight);
|
|
||||||
}
|
|
||||||
_lineHeightMap.push(acc);
|
|
||||||
linesCount = acc;
|
|
||||||
|
|
||||||
for (i = 0; i < linesCount; i++) {
|
|
||||||
_scrollMap.push(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nonEmptyList.push(0);
|
const h = window.editor.heightAtLine(i + 1) - window.editor.heightAtLine(i)
|
||||||
|
acc += Math.round(h / lineHeight)
|
||||||
|
}
|
||||||
|
_lineHeightMap.push(acc)
|
||||||
|
linesCount = acc
|
||||||
|
|
||||||
|
for (i = 0; i < linesCount; i++) {
|
||||||
|
_scrollMap.push(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
nonEmptyList.push(0)
|
||||||
// make the first line go top
|
// make the first line go top
|
||||||
_scrollMap[0] = viewTop;
|
_scrollMap[0] = viewTop
|
||||||
|
|
||||||
const parts = markdownArea.find('.part').toArray();
|
const parts = markdownArea.find('.part').toArray()
|
||||||
for (i = 0; i < parts.length; i++) {
|
for (i = 0; i < parts.length; i++) {
|
||||||
const $el = $(parts[i]);
|
const $el = $(parts[i])
|
||||||
let t = $el.attr('data-startline') - 1;
|
let t = $el.attr('data-startline') - 1
|
||||||
if (t === '') {
|
if (t === '') {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
t = _lineHeightMap[t];
|
t = _lineHeightMap[t]
|
||||||
if (t !== 0 && t !== nonEmptyList[nonEmptyList.length - 1]) {
|
if (t !== 0 && t !== nonEmptyList[nonEmptyList.length - 1]) {
|
||||||
nonEmptyList.push(t);
|
nonEmptyList.push(t)
|
||||||
}
|
}
|
||||||
_scrollMap[t] = Math.round($el.offset().top + offset - 10);
|
_scrollMap[t] = Math.round($el.offset().top + offset - 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
nonEmptyList.push(linesCount)
|
||||||
|
_scrollMap[linesCount] = viewArea[0].scrollHeight
|
||||||
|
|
||||||
|
pos = 0
|
||||||
|
for (i = 1; i < linesCount; i++) {
|
||||||
|
if (_scrollMap[i] !== -1) {
|
||||||
|
pos++
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
nonEmptyList.push(linesCount);
|
a = nonEmptyList[pos]
|
||||||
_scrollMap[linesCount] = viewArea[0].scrollHeight;
|
b = nonEmptyList[pos + 1]
|
||||||
|
_scrollMap[i] = Math.round((_scrollMap[b] * (i - a) + _scrollMap[a] * (b - i)) / (b - a))
|
||||||
|
}
|
||||||
|
|
||||||
pos = 0;
|
_scrollMap[0] = 0
|
||||||
for (i = 1; i < linesCount; i++) {
|
|
||||||
if (_scrollMap[i] !== -1) {
|
|
||||||
pos++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
a = nonEmptyList[pos];
|
scrollMap = _scrollMap
|
||||||
b = nonEmptyList[pos + 1];
|
lineHeightMap = _lineHeightMap
|
||||||
_scrollMap[i] = Math.round((_scrollMap[b] * (i - a) + _scrollMap[a] * (b - i)) / (b - a));
|
|
||||||
}
|
|
||||||
|
|
||||||
_scrollMap[0] = 0;
|
if (window.loaded && callback) callback()
|
||||||
|
|
||||||
scrollMap = _scrollMap;
|
|
||||||
lineHeightMap = _lineHeightMap;
|
|
||||||
|
|
||||||
if (loaded && callback) callback();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sync view scroll progress to edit
|
// sync view scroll progress to edit
|
||||||
let viewScrollingTimer = null;
|
let viewScrollingTimer = null
|
||||||
|
|
||||||
export function syncScrollToEdit(event, preventAnimate) {
|
export function syncScrollToEdit (event, preventAnimate) {
|
||||||
if (currentMode != modeType.both || !syncscroll || !editArea) return;
|
if (window.currentMode !== window.modeType.both || !window.syncscroll || !editArea) return
|
||||||
if (preventSyncScrollToEdit) {
|
if (window.preventSyncScrollToEdit) {
|
||||||
if (typeof preventSyncScrollToEdit === 'number') {
|
if (typeof window.preventSyncScrollToEdit === 'number') {
|
||||||
preventSyncScrollToEdit--;
|
window.preventSyncScrollToEdit--
|
||||||
} else {
|
|
||||||
preventSyncScrollToEdit = false;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!scrollMap || !lineHeightMap) {
|
|
||||||
buildMap(() => {
|
|
||||||
syncScrollToEdit(event, preventAnimate);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (editScrolling) return;
|
|
||||||
|
|
||||||
const scrollTop = viewArea[0].scrollTop;
|
|
||||||
let lineIndex = 0;
|
|
||||||
for (var i = 0, l = scrollMap.length; i < l; i++) {
|
|
||||||
if (scrollMap[i] > scrollTop) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
lineIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let lineNo = 0;
|
|
||||||
let lineDiff = 0;
|
|
||||||
for (var i = 0, l = lineHeightMap.length; i < l; i++) {
|
|
||||||
if (lineHeightMap[i] > lineIndex) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
lineNo = lineHeightMap[i];
|
|
||||||
lineDiff = lineHeightMap[i + 1] - lineNo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let posTo = 0;
|
|
||||||
let topDiffPercent = 0;
|
|
||||||
let posToNextDiff = 0;
|
|
||||||
const scrollInfo = editor.getScrollInfo();
|
|
||||||
const textHeight = editor.defaultTextHeight();
|
|
||||||
const preLastLineHeight = scrollInfo.height - scrollInfo.clientHeight - textHeight;
|
|
||||||
const preLastLineNo = Math.round(preLastLineHeight / textHeight);
|
|
||||||
const preLastLinePos = scrollMap[preLastLineNo];
|
|
||||||
|
|
||||||
if (scrollInfo.height > scrollInfo.clientHeight && scrollTop >= preLastLinePos) {
|
|
||||||
posTo = preLastLineHeight;
|
|
||||||
topDiffPercent = (scrollTop - preLastLinePos) / (viewBottom - preLastLinePos);
|
|
||||||
posToNextDiff = textHeight * topDiffPercent;
|
|
||||||
posTo += Math.ceil(posToNextDiff);
|
|
||||||
} else {
|
} else {
|
||||||
posTo = lineNo * textHeight;
|
window.preventSyncScrollToEdit = false
|
||||||
topDiffPercent = (scrollTop - scrollMap[lineNo]) / (scrollMap[lineNo + lineDiff] - scrollMap[lineNo]);
|
|
||||||
posToNextDiff = textHeight * lineDiff * topDiffPercent;
|
|
||||||
posTo += Math.ceil(posToNextDiff);
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!scrollMap || !lineHeightMap) {
|
||||||
|
buildMap(() => {
|
||||||
|
syncScrollToEdit(event, preventAnimate)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (editScrolling) return
|
||||||
|
|
||||||
if (preventAnimate) {
|
const scrollTop = viewArea[0].scrollTop
|
||||||
editArea.scrollTop(posTo);
|
let lineIndex = 0
|
||||||
|
for (let i = 0, l = scrollMap.length; i < l; i++) {
|
||||||
|
if (scrollMap[i] > scrollTop) {
|
||||||
|
break
|
||||||
} else {
|
} else {
|
||||||
const posDiff = Math.abs(scrollInfo.top - posTo);
|
lineIndex = i
|
||||||
var duration = posDiff / 50;
|
|
||||||
duration = duration >= 100 ? duration : 100;
|
|
||||||
editArea.stop(true, true).animate({
|
|
||||||
scrollTop: posTo
|
|
||||||
}, duration, "linear");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
let lineNo = 0
|
||||||
|
let lineDiff = 0
|
||||||
|
for (let i = 0, l = lineHeightMap.length; i < l; i++) {
|
||||||
|
if (lineHeightMap[i] > lineIndex) {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
lineNo = lineHeightMap[i]
|
||||||
|
lineDiff = lineHeightMap[i + 1] - lineNo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
viewScrolling = true;
|
let posTo = 0
|
||||||
clearTimeout(viewScrollingTimer);
|
let topDiffPercent = 0
|
||||||
viewScrollingTimer = setTimeout(viewScrollingTimeoutInner, duration * 1.5);
|
let posToNextDiff = 0
|
||||||
|
const scrollInfo = window.editor.getScrollInfo()
|
||||||
|
const textHeight = window.editor.defaultTextHeight()
|
||||||
|
const preLastLineHeight = scrollInfo.height - scrollInfo.clientHeight - textHeight
|
||||||
|
const preLastLineNo = Math.round(preLastLineHeight / textHeight)
|
||||||
|
const preLastLinePos = scrollMap[preLastLineNo]
|
||||||
|
|
||||||
|
if (scrollInfo.height > scrollInfo.clientHeight && scrollTop >= preLastLinePos) {
|
||||||
|
posTo = preLastLineHeight
|
||||||
|
topDiffPercent = (scrollTop - preLastLinePos) / (viewBottom - preLastLinePos)
|
||||||
|
posToNextDiff = textHeight * topDiffPercent
|
||||||
|
posTo += Math.ceil(posToNextDiff)
|
||||||
|
} else {
|
||||||
|
posTo = lineNo * textHeight
|
||||||
|
topDiffPercent = (scrollTop - scrollMap[lineNo]) / (scrollMap[lineNo + lineDiff] - scrollMap[lineNo])
|
||||||
|
posToNextDiff = textHeight * lineDiff * topDiffPercent
|
||||||
|
posTo += Math.ceil(posToNextDiff)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preventAnimate) {
|
||||||
|
editArea.scrollTop(posTo)
|
||||||
|
} else {
|
||||||
|
const posDiff = Math.abs(scrollInfo.top - posTo)
|
||||||
|
var duration = posDiff / 50
|
||||||
|
duration = duration >= 100 ? duration : 100
|
||||||
|
editArea.stop(true, true).animate({
|
||||||
|
scrollTop: posTo
|
||||||
|
}, duration, 'linear')
|
||||||
|
}
|
||||||
|
|
||||||
|
viewScrolling = true
|
||||||
|
clearTimeout(viewScrollingTimer)
|
||||||
|
viewScrollingTimer = setTimeout(viewScrollingTimeoutInner, duration * 1.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
function viewScrollingTimeoutInner() {
|
function viewScrollingTimeoutInner () {
|
||||||
viewScrolling = false;
|
viewScrolling = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// sync edit scroll progress to view
|
// sync edit scroll progress to view
|
||||||
let editScrollingTimer = null;
|
let editScrollingTimer = null
|
||||||
|
|
||||||
export function syncScrollToView(event, preventAnimate) {
|
export function syncScrollToView (event, preventAnimate) {
|
||||||
if (currentMode != modeType.both || !syncscroll || !viewArea) return;
|
if (window.currentMode !== window.modeType.both || !window.syncscroll || !viewArea) return
|
||||||
if (preventSyncScrollToView) {
|
if (window.preventSyncScrollToView) {
|
||||||
if (typeof preventSyncScrollToView === 'number') {
|
if (typeof preventSyncScrollToView === 'number') {
|
||||||
preventSyncScrollToView--;
|
window.preventSyncScrollToView--
|
||||||
} else {
|
} else {
|
||||||
preventSyncScrollToView = false;
|
window.preventSyncScrollToView = false
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!scrollMap || !lineHeightMap) {
|
return
|
||||||
buildMap(() => {
|
}
|
||||||
syncScrollToView(event, preventAnimate);
|
if (!scrollMap || !lineHeightMap) {
|
||||||
});
|
buildMap(() => {
|
||||||
return;
|
syncScrollToView(event, preventAnimate)
|
||||||
}
|
})
|
||||||
if (viewScrolling) return;
|
return
|
||||||
|
}
|
||||||
|
if (viewScrolling) return
|
||||||
|
|
||||||
let lineNo, posTo;
|
let lineNo, posTo
|
||||||
let topDiffPercent, posToNextDiff;
|
let topDiffPercent, posToNextDiff
|
||||||
const scrollInfo = editor.getScrollInfo();
|
const scrollInfo = window.editor.getScrollInfo()
|
||||||
const textHeight = editor.defaultTextHeight();
|
const textHeight = window.editor.defaultTextHeight()
|
||||||
lineNo = Math.floor(scrollInfo.top / textHeight);
|
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);
|
const diffToBottom = (scrollInfo.top + scrollInfo.clientHeight) - (scrollInfo.height - textHeight)
|
||||||
if (scrollInfo.height > scrollInfo.clientHeight && diffToBottom > 0) {
|
if (scrollInfo.height > scrollInfo.clientHeight && diffToBottom > 0) {
|
||||||
topDiffPercent = diffToBottom / textHeight;
|
topDiffPercent = diffToBottom / textHeight
|
||||||
posTo = scrollMap[lineNo + 1];
|
posTo = scrollMap[lineNo + 1]
|
||||||
posToNextDiff = (viewBottom - posTo) * topDiffPercent;
|
posToNextDiff = (viewBottom - posTo) * topDiffPercent
|
||||||
posTo += Math.floor(posToNextDiff);
|
posTo += Math.floor(posToNextDiff)
|
||||||
} else {
|
} else {
|
||||||
topDiffPercent = (scrollInfo.top % textHeight) / textHeight;
|
topDiffPercent = (scrollInfo.top % textHeight) / textHeight
|
||||||
posTo = scrollMap[lineNo];
|
posTo = scrollMap[lineNo]
|
||||||
posToNextDiff = (scrollMap[lineNo + 1] - posTo) * topDiffPercent;
|
posToNextDiff = (scrollMap[lineNo + 1] - posTo) * topDiffPercent
|
||||||
posTo += Math.floor(posToNextDiff);
|
posTo += Math.floor(posToNextDiff)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preventAnimate) {
|
if (preventAnimate) {
|
||||||
viewArea.scrollTop(posTo);
|
viewArea.scrollTop(posTo)
|
||||||
} else {
|
} else {
|
||||||
const posDiff = Math.abs(viewArea.scrollTop() - posTo);
|
const posDiff = Math.abs(viewArea.scrollTop() - posTo)
|
||||||
var duration = posDiff / 50;
|
var duration = posDiff / 50
|
||||||
duration = duration >= 100 ? duration : 100;
|
duration = duration >= 100 ? duration : 100
|
||||||
viewArea.stop(true, true).animate({
|
viewArea.stop(true, true).animate({
|
||||||
scrollTop: posTo
|
scrollTop: posTo
|
||||||
}, duration, "linear");
|
}, duration, 'linear')
|
||||||
}
|
}
|
||||||
|
|
||||||
editScrolling = true;
|
editScrolling = true
|
||||||
clearTimeout(editScrollingTimer);
|
clearTimeout(editScrollingTimer)
|
||||||
editScrollingTimer = setTimeout(editScrollingTimeoutInner, duration * 1.5);
|
editScrollingTimer = setTimeout(editScrollingTimeoutInner, duration * 1.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
function editScrollingTimeoutInner() {
|
function editScrollingTimeoutInner () {
|
||||||
editScrolling = false;
|
editScrolling = false
|
||||||
}
|
}
|
||||||
|
|
226
public/vendor/md-toc.js
vendored
226
public/vendor/md-toc.js
vendored
|
@ -1,129 +1,123 @@
|
||||||
|
/* eslint-env browser, jquery */
|
||||||
/**
|
/**
|
||||||
* md-toc.js v1.0.2
|
* md-toc.js v1.0.2
|
||||||
* https://github.com/yijian166/md-toc.js
|
* https://github.com/yijian166/md-toc.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function (window) {
|
(function (window) {
|
||||||
function Toc(id, options) {
|
function Toc (id, options) {
|
||||||
this.el = document.getElementById(id);
|
this.el = document.getElementById(id)
|
||||||
if (!this.el) return;
|
if (!this.el) return
|
||||||
this.options = options || {};
|
this.options = options || {}
|
||||||
this.tocLevel = parseInt(options.level) || 0;
|
this.tocLevel = parseInt(options.level) || 0
|
||||||
this.tocClass = options['class'] || 'toc';
|
this.tocClass = options['class'] || 'toc'
|
||||||
this.ulClass = options['ulClass'];
|
this.ulClass = options['ulClass']
|
||||||
this.tocTop = parseInt(options.top) || 0;
|
this.tocTop = parseInt(options.top) || 0
|
||||||
this.elChilds = this.el.children;
|
this.elChilds = this.el.children
|
||||||
this.process = options['process'];
|
this.process = options['process']
|
||||||
if (!this.elChilds.length) return;
|
if (!this.elChilds.length) return
|
||||||
this._init();
|
this._init()
|
||||||
|
}
|
||||||
|
|
||||||
|
Toc.prototype._init = function () {
|
||||||
|
this._collectTitleElements()
|
||||||
|
this._createTocContent()
|
||||||
|
this._showToc()
|
||||||
|
}
|
||||||
|
|
||||||
|
Toc.prototype._collectTitleElements = function () {
|
||||||
|
this._elTitlesNames = []
|
||||||
|
this.elTitleElements = []
|
||||||
|
for (var i = 1; i < 7; i++) {
|
||||||
|
if (this.el.getElementsByTagName('h' + i).length) {
|
||||||
|
this._elTitlesNames.push('h' + i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Toc.prototype._init = function () {
|
this._elTitlesNames.length = this._elTitlesNames.length > this.tocLevel ? this.tocLevel : this._elTitlesNames.length
|
||||||
this._collectTitleElements();
|
|
||||||
this._createTocContent();
|
|
||||||
this._showToc();
|
|
||||||
};
|
|
||||||
|
|
||||||
Toc.prototype._collectTitleElements = function () {
|
for (var j = 0; j < this.elChilds.length; j++) {
|
||||||
this._elTitlesNames = [],
|
this._elChildName = this.elChilds[j].tagName.toLowerCase()
|
||||||
this.elTitleElements = [];
|
if (this._elTitlesNames.toString().match(this._elChildName)) {
|
||||||
for (var i = 1; i < 7; i++) {
|
this.elTitleElements.push(this.elChilds[j])
|
||||||
if (this.el.getElementsByTagName('h' + i).length) {
|
}
|
||||||
this._elTitlesNames.push('h' + i);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Toc.prototype._createTocContent = function () {
|
||||||
|
this._elTitleElementsLen = this.elTitleElements.length
|
||||||
|
if (!this._elTitleElementsLen) return
|
||||||
|
this.tocContent = ''
|
||||||
|
this._tempLists = []
|
||||||
|
|
||||||
|
for (var i = 0; i < this._elTitleElementsLen; i++) {
|
||||||
|
var j = i + 1
|
||||||
|
this._elTitleElement = this.elTitleElements[i]
|
||||||
|
this._elTitleElementName = this._elTitleElement.tagName
|
||||||
|
this._elTitleElementText = (typeof this.process === 'function' ? this.process(this._elTitleElement) : this._elTitleElement.innerHTML).replace(/<(?:.|\n)*?>/gm, '')
|
||||||
|
var id = this._elTitleElement.getAttribute('id')
|
||||||
|
if (!id) {
|
||||||
|
this._elTitleElement.setAttribute('id', 'tip' + i)
|
||||||
|
id = '#tip' + i
|
||||||
|
} else {
|
||||||
|
id = '#' + id
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tocContent += '<li><a href="' + id + '">' + this._elTitleElementText + '</a>'
|
||||||
|
|
||||||
|
if (j !== this._elTitleElementsLen) {
|
||||||
|
this._elNextTitleElementName = this.elTitleElements[j].tagName
|
||||||
|
if (this._elTitleElementName !== this._elNextTitleElementName) {
|
||||||
|
var checkColse = false
|
||||||
|
var y = 1
|
||||||
|
for (var t = this._tempLists.length - 1; t >= 0; t--) {
|
||||||
|
if (this._tempLists[t].tagName === this._elNextTitleElementName) {
|
||||||
|
checkColse = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
y++
|
||||||
|
}
|
||||||
this._elTitlesNames.length = this._elTitlesNames.length > this.tocLevel ? this.tocLevel : this._elTitlesNames.length;
|
if (checkColse) {
|
||||||
|
this.tocContent += new Array(y + 1).join('</li></ul>')
|
||||||
for (var j = 0; j < this.elChilds.length; j++) {
|
this._tempLists.length = this._tempLists.length - y
|
||||||
this._elChildName = this.elChilds[j].tagName.toLowerCase();
|
} else {
|
||||||
if (this._elTitlesNames.toString().match(this._elChildName)) {
|
this._tempLists.push(this._elTitleElement)
|
||||||
this.elTitleElements.push(this.elChilds[j]);
|
if (this.ulClass) { this.tocContent += '<ul class="' + this.ulClass + '">' } else { this.tocContent += '<ul>' }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Toc.prototype._createTocContent = function () {
|
|
||||||
this._elTitleElementsLen = this.elTitleElements.length;
|
|
||||||
if (!this._elTitleElementsLen) return;
|
|
||||||
this.tocContent = '';
|
|
||||||
this._tempLists = [];
|
|
||||||
|
|
||||||
var url = location.origin + location.pathname;
|
|
||||||
for (var i = 0; i < this._elTitleElementsLen; i++) {
|
|
||||||
var j = i + 1;
|
|
||||||
this._elTitleElement = this.elTitleElements[i];
|
|
||||||
this._elTitleElementName = this._elTitleElement.tagName;
|
|
||||||
this._elTitleElementText = (typeof this.process === 'function' ? this.process(this._elTitleElement) : this._elTitleElement.innerHTML).replace(/<(?:.|\n)*?>/gm, '');
|
|
||||||
var id = this._elTitleElement.getAttribute('id');
|
|
||||||
if (!id) {
|
|
||||||
this._elTitleElement.setAttribute('id', 'tip' + i);
|
|
||||||
id = '#tip' + i;
|
|
||||||
} else {
|
|
||||||
id = '#' + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tocContent += '<li><a href="' + id + '">' + this._elTitleElementText + '</a>';
|
|
||||||
|
|
||||||
if (j != this._elTitleElementsLen) {
|
|
||||||
this._elNextTitleElementName = this.elTitleElements[j].tagName;
|
|
||||||
if (this._elTitleElementName != this._elNextTitleElementName) {
|
|
||||||
var checkColse = false,
|
|
||||||
y = 1;
|
|
||||||
for (var t = this._tempLists.length - 1; t >= 0; t--) {
|
|
||||||
if (this._tempLists[t].tagName == this._elNextTitleElementName) {
|
|
||||||
checkColse = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
if (checkColse) {
|
|
||||||
this.tocContent += new Array(y + 1).join('</li></ul>');
|
|
||||||
this._tempLists.length = this._tempLists.length - y;
|
|
||||||
} else {
|
|
||||||
this._tempLists.push(this._elTitleElement);
|
|
||||||
if (this.ulClass)
|
|
||||||
this.tocContent += '<ul class="' + this.ulClass + '">';
|
|
||||||
else
|
|
||||||
this.tocContent += '<ul>';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.tocContent += '</li>';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this._tempLists.length) {
|
|
||||||
this.tocContent += new Array(this._tempLists.length + 1).join('</li></ul>');
|
|
||||||
} else {
|
|
||||||
this.tocContent += '</li>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.ulClass)
|
|
||||||
this.tocContent = '<ul class="' + this.ulClass + '">' + this.tocContent + '</ul>';
|
|
||||||
else
|
|
||||||
this.tocContent = '<ul>' + this.tocContent + '</ul>';
|
|
||||||
};
|
|
||||||
|
|
||||||
Toc.prototype._showToc = function () {
|
|
||||||
this.toc = document.createElement('div');
|
|
||||||
this.toc.innerHTML = this.tocContent;
|
|
||||||
this.toc.setAttribute('class', this.tocClass);
|
|
||||||
if (!this.options.targetId) {
|
|
||||||
this.el.appendChild(this.toc);
|
|
||||||
} else {
|
} else {
|
||||||
document.getElementById(this.options.targetId).appendChild(this.toc);
|
this.tocContent += '</li>'
|
||||||
}
|
}
|
||||||
var self = this;
|
} else {
|
||||||
if (this.tocTop > -1) {
|
if (this._tempLists.length) {
|
||||||
window.onscroll = function () {
|
this.tocContent += new Array(this._tempLists.length + 1).join('</li></ul>')
|
||||||
var t = document.documentElement.scrollTop || document.body.scrollTop;
|
} else {
|
||||||
if (t < self.tocTop) {
|
this.tocContent += '</li>'
|
||||||
self.toc.setAttribute('style', 'position:absolute;top:' + self.tocTop + 'px;');
|
|
||||||
} else {
|
|
||||||
self.toc.setAttribute('style', 'position:fixed;top:10px;');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
window.Toc = Toc;
|
}
|
||||||
})(window);
|
if (this.ulClass) { this.tocContent = '<ul class="' + this.ulClass + '">' + this.tocContent + '</ul>' } else { this.tocContent = '<ul>' + this.tocContent + '</ul>' }
|
||||||
|
}
|
||||||
|
|
||||||
|
Toc.prototype._showToc = function () {
|
||||||
|
this.toc = document.createElement('div')
|
||||||
|
this.toc.innerHTML = this.tocContent
|
||||||
|
this.toc.setAttribute('class', this.tocClass)
|
||||||
|
if (!this.options.targetId) {
|
||||||
|
this.el.appendChild(this.toc)
|
||||||
|
} else {
|
||||||
|
document.getElementById(this.options.targetId).appendChild(this.toc)
|
||||||
|
}
|
||||||
|
var self = this
|
||||||
|
if (this.tocTop > -1) {
|
||||||
|
window.onscroll = function () {
|
||||||
|
var t = document.documentElement.scrollTop || document.body.scrollTop
|
||||||
|
if (t < self.tocTop) {
|
||||||
|
self.toc.setAttribute('style', 'position:absolute;top:' + self.tocTop + 'px;')
|
||||||
|
} else {
|
||||||
|
self.toc.setAttribute('style', 'position:fixed;top:10px;')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.Toc = Toc
|
||||||
|
})(window)
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
var baseConfig = require('./webpackBaseConfig');
|
var baseConfig = require('./webpackBaseConfig')
|
||||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
var ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||||||
var path = require('path');
|
var path = require('path')
|
||||||
|
|
||||||
module.exports = [Object.assign({}, baseConfig, {
|
module.exports = [Object.assign({}, baseConfig, {
|
||||||
plugins: baseConfig.plugins.concat([
|
plugins: baseConfig.plugins.concat([
|
||||||
new ExtractTextPlugin("[name].css")
|
new ExtractTextPlugin('[name].css')
|
||||||
])
|
])
|
||||||
}), {
|
}), {
|
||||||
entry: {
|
entry: {
|
||||||
htmlExport: path.join(__dirname, 'public/js/htmlExport.js')
|
htmlExport: path.join(__dirname, 'public/js/htmlExport.js')
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
loaders: [{
|
loaders: [{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
|
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
|
||||||
}, {
|
}, {
|
||||||
test: /\.scss$/,
|
test: /\.scss$/,
|
||||||
loader: ExtractTextPlugin.extract('style-loader', 'sass-loader')
|
loader: ExtractTextPlugin.extract('style-loader', 'sass-loader')
|
||||||
}, {
|
}, {
|
||||||
test: /\.less$/,
|
test: /\.less$/,
|
||||||
loader: ExtractTextPlugin.extract('style-loader', 'less-loader')
|
loader: ExtractTextPlugin.extract('style-loader', 'less-loader')
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, 'public/build'),
|
path: path.join(__dirname, 'public/build'),
|
||||||
publicPath: '/build/',
|
publicPath: '/build/',
|
||||||
filename: '[name].js'
|
filename: '[name].js'
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new ExtractTextPlugin("html.min.css")
|
new ExtractTextPlugin('html.min.css')
|
||||||
]
|
]
|
||||||
}];
|
}]
|
||||||
|
|
|
@ -1,63 +1,63 @@
|
||||||
var baseConfig = require('./webpackBaseConfig');
|
var baseConfig = require('./webpackBaseConfig')
|
||||||
var webpack = require('webpack');
|
var webpack = require('webpack')
|
||||||
var path = require('path');
|
var path = require('path')
|
||||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
var ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||||||
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
||||||
var ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin');
|
var ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')
|
||||||
|
|
||||||
module.exports = [Object.assign({}, baseConfig, {
|
module.exports = [Object.assign({}, baseConfig, {
|
||||||
plugins: baseConfig.plugins.concat([
|
plugins: baseConfig.plugins.concat([
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
'process.env': {
|
||||||
'NODE_ENV': JSON.stringify('production')
|
'NODE_ENV': JSON.stringify('production')
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
new ParallelUglifyPlugin({
|
new ParallelUglifyPlugin({
|
||||||
uglifyJS: {
|
uglifyJS: {
|
||||||
compress: {
|
compress: {
|
||||||
warnings: false
|
warnings: false
|
||||||
},
|
},
|
||||||
mangle: false,
|
mangle: false,
|
||||||
sourceMap: false
|
sourceMap: false
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
new ExtractTextPlugin("[name].[hash].css")
|
new ExtractTextPlugin('[name].[hash].css')
|
||||||
]),
|
]),
|
||||||
|
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, 'public/build'),
|
path: path.join(__dirname, 'public/build'),
|
||||||
publicPath: '/build/',
|
publicPath: '/build/',
|
||||||
filename: '[id].[name].[hash].js',
|
filename: '[id].[name].[hash].js',
|
||||||
baseUrl: '<%- url %>'
|
baseUrl: '<%- url %>'
|
||||||
}
|
}
|
||||||
}), {
|
}), {
|
||||||
entry: {
|
entry: {
|
||||||
htmlExport: path.join(__dirname, 'public/js/htmlExport.js')
|
htmlExport: path.join(__dirname, 'public/js/htmlExport.js')
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
loaders: [{
|
loaders: [{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
|
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
|
||||||
}, {
|
}, {
|
||||||
test: /\.scss$/,
|
test: /\.scss$/,
|
||||||
loader: ExtractTextPlugin.extract('style-loader', 'sass-loader')
|
loader: ExtractTextPlugin.extract('style-loader', 'sass-loader')
|
||||||
}, {
|
}, {
|
||||||
test: /\.less$/,
|
test: /\.less$/,
|
||||||
loader: ExtractTextPlugin.extract('style-loader', 'less-loader')
|
loader: ExtractTextPlugin.extract('style-loader', 'less-loader')
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, 'public/build'),
|
path: path.join(__dirname, 'public/build'),
|
||||||
publicPath: '/build/',
|
publicPath: '/build/',
|
||||||
filename: '[name].js'
|
filename: '[name].js'
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
'process.env': {
|
||||||
'NODE_ENV': JSON.stringify('production')
|
'NODE_ENV': JSON.stringify('production')
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
new ExtractTextPlugin("html.min.css"),
|
new ExtractTextPlugin('html.min.css'),
|
||||||
new OptimizeCssAssetsPlugin()
|
new OptimizeCssAssetsPlugin()
|
||||||
]
|
]
|
||||||
}];
|
}]
|
||||||
|
|
|
@ -1,441 +1,439 @@
|
||||||
var webpack = require('webpack');
|
var webpack = require('webpack')
|
||||||
var path = require('path');
|
var path = require('path')
|
||||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
var ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||||||
var HtmlWebpackPlugin = require('html-webpack-plugin');
|
var HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||||
var CopyWebpackPlugin = require('copy-webpack-plugin');
|
var CopyWebpackPlugin = require('copy-webpack-plugin')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.ProvidePlugin({
|
new webpack.ProvidePlugin({
|
||||||
Visibility: "visibilityjs",
|
Visibility: 'visibilityjs',
|
||||||
Cookies: "js-cookie",
|
Cookies: 'js-cookie',
|
||||||
key: "keymaster",
|
key: 'keymaster',
|
||||||
$: "jquery",
|
$: 'jquery',
|
||||||
jQuery: "jquery",
|
jQuery: 'jquery',
|
||||||
"window.jQuery": "jquery",
|
'window.jQuery': 'jquery',
|
||||||
"moment": "moment",
|
'moment': 'moment',
|
||||||
"Handlebars": "handlebars"
|
'Handlebars': 'handlebars'
|
||||||
}),
|
}),
|
||||||
new webpack.optimize.OccurrenceOrderPlugin(true),
|
new webpack.optimize.OccurrenceOrderPlugin(true),
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
new webpack.optimize.CommonsChunkPlugin({
|
||||||
names: ["cover", "index", "pretty", "slide", "vendor"],
|
names: ['cover', 'index', 'pretty', 'slide', 'vendor'],
|
||||||
children: true,
|
children: true,
|
||||||
async: true,
|
async: true,
|
||||||
filename: '[name].js',
|
filename: '[name].js',
|
||||||
minChunks: Infinity
|
minChunks: Infinity
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/header.ejs',
|
template: 'public/views/includes/header.ejs',
|
||||||
chunks: ['font', 'index-styles', 'index'],
|
chunks: ['font', 'index-styles', 'index'],
|
||||||
filename: path.join(__dirname, 'public/views/build/index-header.ejs'),
|
filename: path.join(__dirname, 'public/views/build/index-header.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/header.ejs',
|
template: 'public/views/includes/header.ejs',
|
||||||
chunks: ['font-pack', 'index-styles-pack', 'index-styles', 'index'],
|
chunks: ['font-pack', 'index-styles-pack', 'index-styles', 'index'],
|
||||||
filename: path.join(__dirname, 'public/views/build/index-pack-header.ejs'),
|
filename: path.join(__dirname, 'public/views/build/index-pack-header.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/scripts.ejs',
|
template: 'public/views/includes/scripts.ejs',
|
||||||
chunks: ['index'],
|
chunks: ['index'],
|
||||||
filename: path.join(__dirname, 'public/views/build/index-scripts.ejs'),
|
filename: path.join(__dirname, 'public/views/build/index-scripts.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/scripts.ejs',
|
template: 'public/views/includes/scripts.ejs',
|
||||||
chunks: ['common', 'index-pack'],
|
chunks: ['common', 'index-pack'],
|
||||||
filename: path.join(__dirname, 'public/views/build/index-pack-scripts.ejs'),
|
filename: path.join(__dirname, 'public/views/build/index-pack-scripts.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/header.ejs',
|
template: 'public/views/includes/header.ejs',
|
||||||
chunks: ['font', 'cover'],
|
chunks: ['font', 'cover'],
|
||||||
filename: path.join(__dirname, 'public/views/build/cover-header.ejs'),
|
filename: path.join(__dirname, 'public/views/build/cover-header.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/header.ejs',
|
template: 'public/views/includes/header.ejs',
|
||||||
chunks: ['font-pack', 'cover-styles-pack', 'cover'],
|
chunks: ['font-pack', 'cover-styles-pack', 'cover'],
|
||||||
filename: path.join(__dirname, 'public/views/build/cover-pack-header.ejs'),
|
filename: path.join(__dirname, 'public/views/build/cover-pack-header.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/scripts.ejs',
|
template: 'public/views/includes/scripts.ejs',
|
||||||
chunks: ['cover'],
|
chunks: ['cover'],
|
||||||
filename: path.join(__dirname, 'public/views/build/cover-scripts.ejs'),
|
filename: path.join(__dirname, 'public/views/build/cover-scripts.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/scripts.ejs',
|
template: 'public/views/includes/scripts.ejs',
|
||||||
chunks: ['common', 'cover-pack'],
|
chunks: ['common', 'cover-pack'],
|
||||||
filename: path.join(__dirname, 'public/views/build/cover-pack-scripts.ejs'),
|
filename: path.join(__dirname, 'public/views/build/cover-pack-scripts.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/header.ejs',
|
template: 'public/views/includes/header.ejs',
|
||||||
chunks: ['font', 'pretty-styles', 'pretty'],
|
chunks: ['font', 'pretty-styles', 'pretty'],
|
||||||
filename: path.join(__dirname, 'public/views/build/pretty-header.ejs'),
|
filename: path.join(__dirname, 'public/views/build/pretty-header.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/header.ejs',
|
template: 'public/views/includes/header.ejs',
|
||||||
chunks: ['font-pack', 'pretty-styles-pack', 'pretty-styles', 'pretty'],
|
chunks: ['font-pack', 'pretty-styles-pack', 'pretty-styles', 'pretty'],
|
||||||
filename: path.join(__dirname, 'public/views/build/pretty-pack-header.ejs'),
|
filename: path.join(__dirname, 'public/views/build/pretty-pack-header.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/scripts.ejs',
|
template: 'public/views/includes/scripts.ejs',
|
||||||
chunks: ['pretty'],
|
chunks: ['pretty'],
|
||||||
filename: path.join(__dirname, 'public/views/build/pretty-scripts.ejs'),
|
filename: path.join(__dirname, 'public/views/build/pretty-scripts.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/scripts.ejs',
|
template: 'public/views/includes/scripts.ejs',
|
||||||
chunks: ['common', 'pretty-pack'],
|
chunks: ['common', 'pretty-pack'],
|
||||||
filename: path.join(__dirname, 'public/views/build/pretty-pack-scripts.ejs'),
|
filename: path.join(__dirname, 'public/views/build/pretty-pack-scripts.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/header.ejs',
|
template: 'public/views/includes/header.ejs',
|
||||||
chunks: ['font', 'slide-styles', 'slide'],
|
chunks: ['font', 'slide-styles', 'slide'],
|
||||||
filename: path.join(__dirname, 'public/views/build/slide-header.ejs'),
|
filename: path.join(__dirname, 'public/views/build/slide-header.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/header.ejs',
|
template: 'public/views/includes/header.ejs',
|
||||||
chunks: ['font-pack', 'slide-styles-pack', 'slide-styles', 'slide'],
|
chunks: ['font-pack', 'slide-styles-pack', 'slide-styles', 'slide'],
|
||||||
filename: path.join(__dirname, 'public/views/build/slide-pack-header.ejs'),
|
filename: path.join(__dirname, 'public/views/build/slide-pack-header.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/scripts.ejs',
|
template: 'public/views/includes/scripts.ejs',
|
||||||
chunks: ['slide'],
|
chunks: ['slide'],
|
||||||
filename: path.join(__dirname, 'public/views/build/slide-scripts.ejs'),
|
filename: path.join(__dirname, 'public/views/build/slide-scripts.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'public/views/includes/scripts.ejs',
|
template: 'public/views/includes/scripts.ejs',
|
||||||
chunks: ['slide-pack'],
|
chunks: ['slide-pack'],
|
||||||
filename: path.join(__dirname, 'public/views/build/slide-pack-scripts.ejs'),
|
filename: path.join(__dirname, 'public/views/build/slide-pack-scripts.ejs'),
|
||||||
inject: false
|
inject: false
|
||||||
}),
|
}),
|
||||||
new CopyWebpackPlugin([
|
new CopyWebpackPlugin([
|
||||||
{
|
{
|
||||||
context: path.join(__dirname, 'node_modules/mathjax'),
|
context: path.join(__dirname, 'node_modules/mathjax'),
|
||||||
from: {
|
from: {
|
||||||
glob: '**/*',
|
glob: '**/*',
|
||||||
dot: false
|
dot: false
|
||||||
},
|
},
|
||||||
to: 'MathJax/'
|
to: 'MathJax/'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
context: path.join(__dirname, 'node_modules/emojify.js'),
|
context: path.join(__dirname, 'node_modules/emojify.js'),
|
||||||
from: {
|
from: {
|
||||||
glob: 'dist/**/*',
|
glob: 'dist/**/*',
|
||||||
dot: false
|
dot: false
|
||||||
},
|
},
|
||||||
to: 'emojify.js/'
|
to: 'emojify.js/'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
context: path.join(__dirname, 'node_modules/reveal.js'),
|
context: path.join(__dirname, 'node_modules/reveal.js'),
|
||||||
from: 'js',
|
from: 'js',
|
||||||
to: 'reveal.js/js'
|
to: 'reveal.js/js'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
context: path.join(__dirname, 'node_modules/reveal.js'),
|
context: path.join(__dirname, 'node_modules/reveal.js'),
|
||||||
from: 'css',
|
from: 'css',
|
||||||
to: 'reveal.js/css'
|
to: 'reveal.js/css'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
context: path.join(__dirname, 'node_modules/reveal.js'),
|
context: path.join(__dirname, 'node_modules/reveal.js'),
|
||||||
from: 'lib',
|
from: 'lib',
|
||||||
to: 'reveal.js/lib'
|
to: 'reveal.js/lib'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
context: path.join(__dirname, 'node_modules/reveal.js'),
|
context: path.join(__dirname, 'node_modules/reveal.js'),
|
||||||
from: 'plugin',
|
from: 'plugin',
|
||||||
to: 'reveal.js/plugin'
|
to: 'reveal.js/plugin'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
],
|
||||||
|
entry: {
|
||||||
|
font: path.join(__dirname, 'public/css/google-font.css'),
|
||||||
|
'font-pack': path.join(__dirname, 'public/css/font.css'),
|
||||||
|
common: [
|
||||||
|
'expose?jQuery!expose?$!jquery',
|
||||||
|
'velocity-animate',
|
||||||
|
'imports?$=jquery!jquery-mousewheel',
|
||||||
|
'bootstrap'
|
||||||
],
|
],
|
||||||
|
cover: [
|
||||||
|
'babel-polyfill',
|
||||||
|
path.join(__dirname, 'public/js/cover.js')
|
||||||
|
],
|
||||||
|
'cover-styles-pack': [
|
||||||
|
path.join(__dirname, 'node_modules/bootstrap/dist/css/bootstrap.min.css'),
|
||||||
|
path.join(__dirname, 'node_modules/font-awesome/css/font-awesome.min.css'),
|
||||||
|
path.join(__dirname, 'public/css/bootstrap-social.css'),
|
||||||
|
path.join(__dirname, 'node_modules/select2/select2.css'),
|
||||||
|
path.join(__dirname, 'node_modules/select2/select2-bootstrap.css')
|
||||||
|
],
|
||||||
|
'cover-pack': [
|
||||||
|
'babel-polyfill',
|
||||||
|
'bootstrap-validator',
|
||||||
|
'script!listPagnation',
|
||||||
|
'expose?select2!select2',
|
||||||
|
'expose?moment!moment',
|
||||||
|
'script!js-url',
|
||||||
|
path.join(__dirname, 'public/js/cover.js')
|
||||||
|
],
|
||||||
|
index: [
|
||||||
|
'babel-polyfill',
|
||||||
|
'script!jquery-ui-resizable',
|
||||||
|
'script!js-url',
|
||||||
|
'expose?filterXSS!xss',
|
||||||
|
'script!Idle.Js',
|
||||||
|
'expose?LZString!lz-string',
|
||||||
|
'script!codemirror',
|
||||||
|
'script!inlineAttachment',
|
||||||
|
'script!jqueryTextcomplete',
|
||||||
|
'script!codemirrorSpellChecker',
|
||||||
|
'script!codemirrorInlineAttachment',
|
||||||
|
'script!ot',
|
||||||
|
'flowchart.js',
|
||||||
|
'js-sequence-diagrams',
|
||||||
|
'expose?RevealMarkdown!reveal-markdown',
|
||||||
|
path.join(__dirname, 'public/js/google-drive-upload.js'),
|
||||||
|
path.join(__dirname, 'public/js/google-drive-picker.js'),
|
||||||
|
path.join(__dirname, 'public/js/index.js')
|
||||||
|
],
|
||||||
|
'index-styles': [
|
||||||
|
path.join(__dirname, 'public/vendor/jquery-ui/jquery-ui.min.css'),
|
||||||
|
path.join(__dirname, 'public/vendor/codemirror-spell-checker/spell-checker.min.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/lib/codemirror.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/addon/fold/foldgutter.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/addon/display/fullscreen.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/addon/dialog/dialog.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/addon/scroll/simplescrollbars.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/addon/search/matchesonscrollbar.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/theme/monokai.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/theme/one-dark.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/mode/tiddlywiki/tiddlywiki.css'),
|
||||||
|
path.join(__dirname, 'node_modules/codemirror/mode/mediawiki/mediawiki.css'),
|
||||||
|
path.join(__dirname, 'public/css/github-extract.css'),
|
||||||
|
path.join(__dirname, 'public/vendor/showup/showup.css'),
|
||||||
|
path.join(__dirname, 'public/css/mermaid.css'),
|
||||||
|
path.join(__dirname, 'public/css/markdown.css'),
|
||||||
|
path.join(__dirname, 'public/css/slide-preview.css')
|
||||||
|
],
|
||||||
|
'index-styles-pack': [
|
||||||
|
path.join(__dirname, 'node_modules/bootstrap/dist/css/bootstrap.min.css'),
|
||||||
|
path.join(__dirname, 'node_modules/font-awesome/css/font-awesome.min.css'),
|
||||||
|
path.join(__dirname, 'public/css/bootstrap-social.css'),
|
||||||
|
path.join(__dirname, 'node_modules/ionicons/css/ionicons.min.css'),
|
||||||
|
path.join(__dirname, 'node_modules/octicons/octicons/octicons.css')
|
||||||
|
],
|
||||||
|
'index-pack': [
|
||||||
|
'babel-polyfill',
|
||||||
|
'expose?Spinner!spin.js',
|
||||||
|
'script!jquery-ui-resizable',
|
||||||
|
'bootstrap-validator',
|
||||||
|
'expose?jsyaml!js-yaml',
|
||||||
|
'script!mermaid',
|
||||||
|
'expose?moment!moment',
|
||||||
|
'script!js-url',
|
||||||
|
'script!handlebars',
|
||||||
|
'expose?hljs!highlight.js',
|
||||||
|
'expose?emojify!emojify.js',
|
||||||
|
'expose?filterXSS!xss',
|
||||||
|
'script!Idle.Js',
|
||||||
|
'script!gist-embed',
|
||||||
|
'expose?LZString!lz-string',
|
||||||
|
'script!codemirror',
|
||||||
|
'script!inlineAttachment',
|
||||||
|
'script!jqueryTextcomplete',
|
||||||
|
'script!codemirrorSpellChecker',
|
||||||
|
'script!codemirrorInlineAttachment',
|
||||||
|
'script!ot',
|
||||||
|
'flowchart.js',
|
||||||
|
'js-sequence-diagrams',
|
||||||
|
'expose?Viz!viz.js',
|
||||||
|
'expose?io!socket.io-client',
|
||||||
|
'expose?RevealMarkdown!reveal-markdown',
|
||||||
|
path.join(__dirname, 'public/js/google-drive-upload.js'),
|
||||||
|
path.join(__dirname, 'public/js/google-drive-picker.js'),
|
||||||
|
path.join(__dirname, 'public/js/index.js')
|
||||||
|
],
|
||||||
|
pretty: [
|
||||||
|
'babel-polyfill',
|
||||||
|
'expose?filterXSS!xss',
|
||||||
|
'flowchart.js',
|
||||||
|
'js-sequence-diagrams',
|
||||||
|
'expose?RevealMarkdown!reveal-markdown',
|
||||||
|
path.join(__dirname, 'public/js/pretty.js')
|
||||||
|
],
|
||||||
|
'pretty-styles': [
|
||||||
|
path.join(__dirname, 'public/css/github-extract.css'),
|
||||||
|
path.join(__dirname, 'public/css/mermaid.css'),
|
||||||
|
path.join(__dirname, 'public/css/markdown.css'),
|
||||||
|
path.join(__dirname, 'public/css/slide-preview.css')
|
||||||
|
],
|
||||||
|
'pretty-styles-pack': [
|
||||||
|
path.join(__dirname, 'node_modules/bootstrap/dist/css/bootstrap.min.css'),
|
||||||
|
path.join(__dirname, 'node_modules/font-awesome/css/font-awesome.min.css'),
|
||||||
|
path.join(__dirname, 'node_modules/ionicons/css/ionicons.min.css'),
|
||||||
|
path.join(__dirname, 'node_modules/octicons/octicons/octicons.css')
|
||||||
|
],
|
||||||
|
'pretty-pack': [
|
||||||
|
'babel-polyfill',
|
||||||
|
'expose?jsyaml!js-yaml',
|
||||||
|
'script!mermaid',
|
||||||
|
'expose?moment!moment',
|
||||||
|
'script!handlebars',
|
||||||
|
'expose?hljs!highlight.js',
|
||||||
|
'expose?emojify!emojify.js',
|
||||||
|
'expose?filterXSS!xss',
|
||||||
|
'script!gist-embed',
|
||||||
|
'flowchart.js',
|
||||||
|
'js-sequence-diagrams',
|
||||||
|
'expose?Viz!viz.js',
|
||||||
|
'expose?RevealMarkdown!reveal-markdown',
|
||||||
|
path.join(__dirname, 'public/js/pretty.js')
|
||||||
|
],
|
||||||
|
slide: [
|
||||||
|
'babel-polyfill',
|
||||||
|
'bootstrap-tooltip',
|
||||||
|
'expose?filterXSS!xss',
|
||||||
|
'flowchart.js',
|
||||||
|
'js-sequence-diagrams',
|
||||||
|
'expose?RevealMarkdown!reveal-markdown',
|
||||||
|
path.join(__dirname, 'public/js/slide.js')
|
||||||
|
],
|
||||||
|
'slide-styles': [
|
||||||
|
path.join(__dirname, 'public/vendor/bootstrap/tooltip.min.css'),
|
||||||
|
path.join(__dirname, 'public/css/github-extract.css'),
|
||||||
|
path.join(__dirname, 'public/css/mermaid.css'),
|
||||||
|
path.join(__dirname, 'public/css/markdown.css')
|
||||||
|
],
|
||||||
|
'slide-styles-pack': [
|
||||||
|
path.join(__dirname, 'node_modules/font-awesome/css/font-awesome.min.css'),
|
||||||
|
path.join(__dirname, 'node_modules/ionicons/css/ionicons.min.css'),
|
||||||
|
path.join(__dirname, 'node_modules/octicons/octicons/octicons.css')
|
||||||
|
],
|
||||||
|
'slide-pack': [
|
||||||
|
'babel-polyfill',
|
||||||
|
'expose?jQuery!expose?$!jquery',
|
||||||
|
'velocity-animate',
|
||||||
|
'imports?$=jquery!jquery-mousewheel',
|
||||||
|
'bootstrap-tooltip',
|
||||||
|
'expose?jsyaml!js-yaml',
|
||||||
|
'script!mermaid',
|
||||||
|
'expose?moment!moment',
|
||||||
|
'script!handlebars',
|
||||||
|
'expose?hljs!highlight.js',
|
||||||
|
'expose?emojify!emojify.js',
|
||||||
|
'expose?filterXSS!xss',
|
||||||
|
'script!gist-embed',
|
||||||
|
'flowchart.js',
|
||||||
|
'js-sequence-diagrams',
|
||||||
|
'expose?Viz!viz.js',
|
||||||
|
'headjs',
|
||||||
|
'expose?Reveal!reveal.js',
|
||||||
|
'expose?RevealMarkdown!reveal-markdown',
|
||||||
|
path.join(__dirname, 'public/js/slide.js')
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
entry: {
|
output: {
|
||||||
font: path.join(__dirname, 'public/css/google-font.css'),
|
path: path.join(__dirname, 'public/build'),
|
||||||
"font-pack": path.join(__dirname, 'public/css/font.css'),
|
publicPath: '/build/',
|
||||||
common: [
|
filename: '[name].js',
|
||||||
"expose?jQuery!expose?$!jquery",
|
baseUrl: '<%- url %>'
|
||||||
"velocity-animate",
|
},
|
||||||
"imports?$=jquery!jquery-mousewheel",
|
|
||||||
"bootstrap"
|
|
||||||
],
|
|
||||||
cover: [
|
|
||||||
"babel-polyfill",
|
|
||||||
path.join(__dirname, 'public/js/cover.js')
|
|
||||||
],
|
|
||||||
"cover-styles-pack": [
|
|
||||||
path.join(__dirname, 'node_modules/bootstrap/dist/css/bootstrap.min.css'),
|
|
||||||
path.join(__dirname, 'node_modules/font-awesome/css/font-awesome.min.css'),
|
|
||||||
path.join(__dirname, 'public/css/bootstrap-social.css'),
|
|
||||||
path.join(__dirname, 'node_modules/select2/select2.css'),
|
|
||||||
path.join(__dirname, 'node_modules/select2/select2-bootstrap.css'),
|
|
||||||
],
|
|
||||||
"cover-pack": [
|
|
||||||
"babel-polyfill",
|
|
||||||
"bootstrap-validator",
|
|
||||||
"script!listPagnation",
|
|
||||||
"expose?select2!select2",
|
|
||||||
"expose?moment!moment",
|
|
||||||
"script!js-url",
|
|
||||||
path.join(__dirname, 'public/js/cover.js')
|
|
||||||
],
|
|
||||||
index: [
|
|
||||||
"babel-polyfill",
|
|
||||||
"script!jquery-ui-resizable",
|
|
||||||
"script!js-url",
|
|
||||||
"expose?filterXSS!xss",
|
|
||||||
"script!Idle.Js",
|
|
||||||
"expose?LZString!lz-string",
|
|
||||||
"script!codemirror",
|
|
||||||
"script!inlineAttachment",
|
|
||||||
"script!jqueryTextcomplete",
|
|
||||||
"script!codemirrorSpellChecker",
|
|
||||||
"script!codemirrorInlineAttachment",
|
|
||||||
"script!ot",
|
|
||||||
"flowchart.js",
|
|
||||||
"js-sequence-diagrams",
|
|
||||||
"expose?RevealMarkdown!reveal-markdown",
|
|
||||||
path.join(__dirname, 'public/js/google-drive-upload.js'),
|
|
||||||
path.join(__dirname, 'public/js/google-drive-picker.js'),
|
|
||||||
path.join(__dirname, 'public/js/index.js')
|
|
||||||
],
|
|
||||||
"index-styles": [
|
|
||||||
path.join(__dirname, 'public/vendor/jquery-ui/jquery-ui.min.css'),
|
|
||||||
path.join(__dirname, 'public/vendor/codemirror-spell-checker/spell-checker.min.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/lib/codemirror.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/addon/fold/foldgutter.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/addon/display/fullscreen.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/addon/dialog/dialog.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/addon/scroll/simplescrollbars.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/addon/search/matchesonscrollbar.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/theme/monokai.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/theme/one-dark.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/mode/tiddlywiki/tiddlywiki.css'),
|
|
||||||
path.join(__dirname, 'node_modules/codemirror/mode/mediawiki/mediawiki.css'),
|
|
||||||
path.join(__dirname, 'public/css/github-extract.css'),
|
|
||||||
path.join(__dirname, 'public/vendor/showup/showup.css'),
|
|
||||||
path.join(__dirname, 'public/css/mermaid.css'),
|
|
||||||
path.join(__dirname, 'public/css/markdown.css'),
|
|
||||||
path.join(__dirname, 'public/css/slide-preview.css')
|
|
||||||
],
|
|
||||||
"index-styles-pack": [
|
|
||||||
path.join(__dirname, 'node_modules/bootstrap/dist/css/bootstrap.min.css'),
|
|
||||||
path.join(__dirname, 'node_modules/font-awesome/css/font-awesome.min.css'),
|
|
||||||
path.join(__dirname, 'public/css/bootstrap-social.css'),
|
|
||||||
path.join(__dirname, 'node_modules/ionicons/css/ionicons.min.css'),
|
|
||||||
path.join(__dirname, 'node_modules/octicons/octicons/octicons.css')
|
|
||||||
],
|
|
||||||
"index-pack": [
|
|
||||||
"babel-polyfill",
|
|
||||||
"expose?Spinner!spin.js",
|
|
||||||
"script!jquery-ui-resizable",
|
|
||||||
"bootstrap-validator",
|
|
||||||
"expose?jsyaml!js-yaml",
|
|
||||||
"script!mermaid",
|
|
||||||
"expose?moment!moment",
|
|
||||||
"script!js-url",
|
|
||||||
"script!handlebars",
|
|
||||||
"expose?hljs!highlight.js",
|
|
||||||
"expose?emojify!emojify.js",
|
|
||||||
"expose?filterXSS!xss",
|
|
||||||
"script!Idle.Js",
|
|
||||||
"script!gist-embed",
|
|
||||||
"expose?LZString!lz-string",
|
|
||||||
"script!codemirror",
|
|
||||||
"script!inlineAttachment",
|
|
||||||
"script!jqueryTextcomplete",
|
|
||||||
"script!codemirrorSpellChecker",
|
|
||||||
"script!codemirrorInlineAttachment",
|
|
||||||
"script!ot",
|
|
||||||
"flowchart.js",
|
|
||||||
"js-sequence-diagrams",
|
|
||||||
"expose?Viz!viz.js",
|
|
||||||
"expose?io!socket.io-client",
|
|
||||||
"expose?RevealMarkdown!reveal-markdown",
|
|
||||||
path.join(__dirname, 'public/js/google-drive-upload.js'),
|
|
||||||
path.join(__dirname, 'public/js/google-drive-picker.js'),
|
|
||||||
path.join(__dirname, 'public/js/index.js')
|
|
||||||
],
|
|
||||||
pretty: [
|
|
||||||
"babel-polyfill",
|
|
||||||
"expose?filterXSS!xss",
|
|
||||||
"flowchart.js",
|
|
||||||
"js-sequence-diagrams",
|
|
||||||
"expose?RevealMarkdown!reveal-markdown",
|
|
||||||
path.join(__dirname, 'public/js/pretty.js')
|
|
||||||
],
|
|
||||||
"pretty-styles": [
|
|
||||||
path.join(__dirname, 'public/css/github-extract.css'),
|
|
||||||
path.join(__dirname, 'public/css/mermaid.css'),
|
|
||||||
path.join(__dirname, 'public/css/markdown.css'),
|
|
||||||
path.join(__dirname, 'public/css/slide-preview.css')
|
|
||||||
],
|
|
||||||
"pretty-styles-pack": [
|
|
||||||
path.join(__dirname, 'node_modules/bootstrap/dist/css/bootstrap.min.css'),
|
|
||||||
path.join(__dirname, 'node_modules/font-awesome/css/font-awesome.min.css'),
|
|
||||||
path.join(__dirname, 'node_modules/ionicons/css/ionicons.min.css'),
|
|
||||||
path.join(__dirname, 'node_modules/octicons/octicons/octicons.css')
|
|
||||||
],
|
|
||||||
"pretty-pack": [
|
|
||||||
"babel-polyfill",
|
|
||||||
"expose?jsyaml!js-yaml",
|
|
||||||
"script!mermaid",
|
|
||||||
"expose?moment!moment",
|
|
||||||
"script!handlebars",
|
|
||||||
"expose?hljs!highlight.js",
|
|
||||||
"expose?emojify!emojify.js",
|
|
||||||
"expose?filterXSS!xss",
|
|
||||||
"script!gist-embed",
|
|
||||||
"flowchart.js",
|
|
||||||
"js-sequence-diagrams",
|
|
||||||
"expose?Viz!viz.js",
|
|
||||||
"expose?RevealMarkdown!reveal-markdown",
|
|
||||||
path.join(__dirname, 'public/js/pretty.js')
|
|
||||||
],
|
|
||||||
slide: [
|
|
||||||
"babel-polyfill",
|
|
||||||
"bootstrap-tooltip",
|
|
||||||
"expose?filterXSS!xss",
|
|
||||||
"flowchart.js",
|
|
||||||
"js-sequence-diagrams",
|
|
||||||
"expose?RevealMarkdown!reveal-markdown",
|
|
||||||
path.join(__dirname, 'public/js/slide.js')
|
|
||||||
],
|
|
||||||
"slide-styles": [
|
|
||||||
path.join(__dirname, 'public/vendor/bootstrap/tooltip.min.css'),
|
|
||||||
path.join(__dirname, 'public/css/github-extract.css'),
|
|
||||||
path.join(__dirname, 'public/css/mermaid.css'),
|
|
||||||
path.join(__dirname, 'public/css/markdown.css')
|
|
||||||
],
|
|
||||||
"slide-styles-pack": [
|
|
||||||
path.join(__dirname, 'node_modules/font-awesome/css/font-awesome.min.css'),
|
|
||||||
path.join(__dirname, 'node_modules/ionicons/css/ionicons.min.css'),
|
|
||||||
path.join(__dirname, 'node_modules/octicons/octicons/octicons.css')
|
|
||||||
],
|
|
||||||
"slide-pack": [
|
|
||||||
"babel-polyfill",
|
|
||||||
"expose?jQuery!expose?$!jquery",
|
|
||||||
"velocity-animate",
|
|
||||||
"imports?$=jquery!jquery-mousewheel",
|
|
||||||
"bootstrap-tooltip",
|
|
||||||
"expose?jsyaml!js-yaml",
|
|
||||||
"script!mermaid",
|
|
||||||
"expose?moment!moment",
|
|
||||||
"script!handlebars",
|
|
||||||
"expose?hljs!highlight.js",
|
|
||||||
"expose?emojify!emojify.js",
|
|
||||||
"expose?filterXSS!xss",
|
|
||||||
"script!gist-embed",
|
|
||||||
"flowchart.js",
|
|
||||||
"js-sequence-diagrams",
|
|
||||||
"expose?Viz!viz.js",
|
|
||||||
"headjs",
|
|
||||||
"expose?Reveal!reveal.js",
|
|
||||||
"expose?RevealMarkdown!reveal-markdown",
|
|
||||||
path.join(__dirname, 'public/js/slide.js')
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
output: {
|
resolve: {
|
||||||
path: path.join(__dirname, 'public/build'),
|
modulesDirectories: [
|
||||||
publicPath: '/build/',
|
path.resolve(__dirname, 'src'),
|
||||||
filename: '[name].js',
|
path.resolve(__dirname, 'node_modules')
|
||||||
baseUrl: '<%- url %>'
|
],
|
||||||
},
|
extensions: ['', '.js'],
|
||||||
|
alias: {
|
||||||
resolve: {
|
codemirror: path.join(__dirname, 'node_modules/codemirror/codemirror.min.js'),
|
||||||
modulesDirectories: [
|
inlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/inline-attachment.js'),
|
||||||
path.resolve(__dirname, 'src'),
|
jqueryTextcomplete: path.join(__dirname, 'public/vendor/jquery-textcomplete/jquery.textcomplete.js'),
|
||||||
path.resolve(__dirname, 'node_modules')
|
codemirrorSpellChecker: path.join(__dirname, 'public/vendor/codemirror-spell-checker/spell-checker.min.js'),
|
||||||
],
|
codemirrorInlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/codemirror.inline-attachment.js'),
|
||||||
extensions: ["", ".js"],
|
ot: path.join(__dirname, 'public/vendor/ot/ot.min.js'),
|
||||||
alias: {
|
listPagnation: path.join(__dirname, 'node_modules/list.pagination.js/dist/list.pagination.min.js'),
|
||||||
codemirror: path.join(__dirname, 'node_modules/codemirror/codemirror.min.js'),
|
mermaid: path.join(__dirname, 'node_modules/mermaid/dist/mermaid.min.js'),
|
||||||
inlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/inline-attachment.js'),
|
handlebars: path.join(__dirname, 'node_modules/handlebars/dist/handlebars.min.js'),
|
||||||
jqueryTextcomplete: path.join(__dirname, 'public/vendor/jquery-textcomplete/jquery.textcomplete.js'),
|
'jquery-ui-resizable': path.join(__dirname, 'public/vendor/jquery-ui/jquery-ui.min.js'),
|
||||||
codemirrorSpellChecker: path.join(__dirname, 'public/vendor/codemirror-spell-checker/spell-checker.min.js'),
|
'gist-embed': path.join(__dirname, 'node_modules/gist-embed/gist-embed.min.js'),
|
||||||
codemirrorInlineAttachment: path.join(__dirname, 'public/vendor/inlineAttachment/codemirror.inline-attachment.js'),
|
'bootstrap-tooltip': path.join(__dirname, 'public/vendor/bootstrap/tooltip.min.js'),
|
||||||
ot: path.join(__dirname, 'public/vendor/ot/ot.min.js'),
|
'headjs': path.join(__dirname, 'node_modules/reveal.js/lib/js/head.min.js'),
|
||||||
listPagnation: path.join(__dirname, 'node_modules/list.pagination.js/dist/list.pagination.min.js'),
|
'reveal-markdown': path.join(__dirname, 'public/js/reveal-markdown.js')
|
||||||
mermaid: path.join(__dirname, 'node_modules/mermaid/dist/mermaid.min.js'),
|
|
||||||
handlebars: path.join(__dirname, 'node_modules/handlebars/dist/handlebars.min.js'),
|
|
||||||
"jquery-ui-resizable": path.join(__dirname, 'public/vendor/jquery-ui/jquery-ui.min.js'),
|
|
||||||
"gist-embed": path.join(__dirname, 'node_modules/gist-embed/gist-embed.min.js'),
|
|
||||||
"bootstrap-tooltip": path.join(__dirname, 'public/vendor/bootstrap/tooltip.min.js'),
|
|
||||||
"headjs": path.join(__dirname, 'node_modules/reveal.js/lib/js/head.min.js'),
|
|
||||||
"reveal-markdown": path.join(__dirname, 'public/js/reveal-markdown.js')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
externals: {
|
|
||||||
"viz.js": "Viz",
|
|
||||||
"socket.io-client": "io",
|
|
||||||
"lodash": "_",
|
|
||||||
"jquery": "$",
|
|
||||||
"moment": "moment",
|
|
||||||
"handlebars": "Handlebars",
|
|
||||||
"highlight.js": "hljs",
|
|
||||||
"select2": "select2"
|
|
||||||
},
|
|
||||||
|
|
||||||
module: {
|
|
||||||
loaders: [{
|
|
||||||
test: /\.json$/,
|
|
||||||
loader: 'json-loader'
|
|
||||||
}, {
|
|
||||||
test: /\.js$/,
|
|
||||||
loader: 'babel',
|
|
||||||
exclude: [/node_modules/, /public\/vendor/]
|
|
||||||
}, {
|
|
||||||
test: /\.css$/,
|
|
||||||
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
|
|
||||||
}, {
|
|
||||||
test: /\.scss$/,
|
|
||||||
loader: ExtractTextPlugin.extract('style-loader', 'sass-loader')
|
|
||||||
}, {
|
|
||||||
test: /\.less$/,
|
|
||||||
loader: ExtractTextPlugin.extract('style-loader', 'less-loader')
|
|
||||||
}, {
|
|
||||||
test: require.resolve("js-sequence-diagrams"),
|
|
||||||
loader: "imports?Raphael=raphael"
|
|
||||||
}, {
|
|
||||||
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
|
|
||||||
loader: "file"
|
|
||||||
}, {
|
|
||||||
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
|
|
||||||
loader: "url?prefix=font/&limit=5000"
|
|
||||||
}, {
|
|
||||||
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
|
|
||||||
loader: "url?limit=10000&mimetype=application/octet-stream"
|
|
||||||
}, {
|
|
||||||
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
|
|
||||||
loader: "url?limit=10000&mimetype=image/svg+xml"
|
|
||||||
}, {
|
|
||||||
test: /\.png(\?v=\d+\.\d+\.\d+)?$/,
|
|
||||||
loader: "url?limit=10000&mimetype=image/png"
|
|
||||||
}, {
|
|
||||||
test: /\.gif(\?v=\d+\.\d+\.\d+)?$/,
|
|
||||||
loader: "url?limit=10000&mimetype=image/gif"
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
|
|
||||||
node: {
|
|
||||||
fs: "empty"
|
|
||||||
},
|
|
||||||
|
|
||||||
quiet: false,
|
|
||||||
noInfo: false,
|
|
||||||
stats: {
|
|
||||||
assets: false
|
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
|
||||||
|
externals: {
|
||||||
|
'viz.js': 'Viz',
|
||||||
|
'socket.io-client': 'io',
|
||||||
|
'lodash': '_',
|
||||||
|
'jquery': '$',
|
||||||
|
'moment': 'moment',
|
||||||
|
'handlebars': 'Handlebars',
|
||||||
|
'highlight.js': 'hljs',
|
||||||
|
'select2': 'select2'
|
||||||
|
},
|
||||||
|
|
||||||
|
module: {
|
||||||
|
loaders: [{
|
||||||
|
test: /\.json$/,
|
||||||
|
loader: 'json-loader'
|
||||||
|
}, {
|
||||||
|
test: /\.js$/,
|
||||||
|
loader: 'babel',
|
||||||
|
exclude: [/node_modules/, /public\/vendor/]
|
||||||
|
}, {
|
||||||
|
test: /\.css$/,
|
||||||
|
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
|
||||||
|
}, {
|
||||||
|
test: /\.scss$/,
|
||||||
|
loader: ExtractTextPlugin.extract('style-loader', 'sass-loader')
|
||||||
|
}, {
|
||||||
|
test: /\.less$/,
|
||||||
|
loader: ExtractTextPlugin.extract('style-loader', 'less-loader')
|
||||||
|
}, {
|
||||||
|
test: require.resolve('js-sequence-diagrams'),
|
||||||
|
loader: 'imports?Raphael=raphael'
|
||||||
|
}, {
|
||||||
|
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
|
||||||
|
loader: 'file'
|
||||||
|
}, {
|
||||||
|
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
|
||||||
|
loader: 'url?prefix=font/&limit=5000'
|
||||||
|
}, {
|
||||||
|
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
|
||||||
|
loader: 'url?limit=10000&mimetype=application/octet-stream'
|
||||||
|
}, {
|
||||||
|
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
|
||||||
|
loader: 'url?limit=10000&mimetype=image/svg+xml'
|
||||||
|
}, {
|
||||||
|
test: /\.png(\?v=\d+\.\d+\.\d+)?$/,
|
||||||
|
loader: 'url?limit=10000&mimetype=image/png'
|
||||||
|
}, {
|
||||||
|
test: /\.gif(\?v=\d+\.\d+\.\d+)?$/,
|
||||||
|
loader: 'url?limit=10000&mimetype=image/gif'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
node: {
|
||||||
|
fs: 'empty'
|
||||||
|
},
|
||||||
|
|
||||||
|
quiet: false,
|
||||||
|
noInfo: false,
|
||||||
|
stats: {
|
||||||
|
assets: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue