diff options
author | Yukai Huang | 2017-01-15 03:45:19 +0000 |
---|---|---|
committer | Yukai Huang | 2017-01-15 03:45:19 +0000 |
commit | 75e28a1d5e0476d73b59b2255aec2b7e6d0a6cdc (patch) | |
tree | 12838f33d941e8734c87383c4653b8b63bbd95a6 /public | |
parent | b3ed4445651b373b14217a55e6382f9025ab345a (diff) | |
parent | c0e8306961a47e7a2ba52d0445c12aaa5fe07949 (diff) |
Merge branch 't216-refactor-common' into 'frontend-next'
T216 refactor common
See merge request !5
Diffstat (limited to '')
-rw-r--r-- | public/js/config.js.example | 11 | ||||
-rw-r--r-- | public/js/cover.js | 2 | ||||
-rw-r--r-- | public/js/extra.js | 2 | ||||
-rw-r--r-- | public/js/history.js | 8 | ||||
-rw-r--r-- | public/js/index.js | 7 | ||||
-rw-r--r-- | public/js/lib/common/login.js (renamed from public/js/common.js) | 27 | ||||
-rw-r--r-- | public/js/lib/config/index.js | 19 |
7 files changed, 34 insertions, 42 deletions
diff --git a/public/js/config.js.example b/public/js/config.js.example deleted file mode 100644 index c5de388f..00000000 --- a/public/js/config.js.example +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - domain: '', // domain name - urlpath: '', // sub url path, like: www.example.com/<urlpath> - - // settings - debug: false, - - GOOGLE_API_KEY: '', - GOOGLE_CLIENT_ID: '', - DROPBOX_APP_KEY: '' -}; diff --git a/public/js/cover.js b/public/js/cover.js index 08e0d225..a3ed7784 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -9,7 +9,7 @@ import { getLoginState, resetCheckAuth, setloginStateChangeEvent -} from './common'; +} from './lib/common/login'; import { clearDuplicatedHistory, diff --git a/public/js/extra.js b/public/js/extra.js index 6cfb5b0a..b651d9e6 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -11,7 +11,7 @@ import PDFObject from 'pdfobject'; import S from 'string'; import { saveAs } from 'file-saver'; -require('./common'); +require('./lib/common/login'); require('../vendor/md-toc'); var Viz = require("viz.js"); diff --git a/public/js/history.js b/public/js/history.js index f1201683..34b2cba7 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -1,9 +1,13 @@ import store from 'store'; import S from 'string'; + +import { + checkIfAuth +} from './lib/common/login'; + import { - checkIfAuth, urlpath -} from './common'; +} from './lib/config'; window.migrateHistoryFromTempCallback = null; diff --git a/public/js/index.js b/public/js/index.js index 946dfc3e..a7e69e81 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -19,7 +19,10 @@ var List = require('list.js'); import { checkLoginStateChanged, - setloginStateChangeEvent, + setloginStateChangeEvent +} from './lib/common/login'; + +import { debug, DROPBOX_APP_KEY, GOOGLE_API_KEY, @@ -28,7 +31,7 @@ import { noteurl, urlpath, version -} from './common'; +} from './lib/config'; import { autoLinkify, diff --git a/public/js/common.js b/public/js/lib/common/login.js index 6d54b450..f1a03c72 100644 --- a/public/js/common.js +++ b/public/js/lib/common/login.js @@ -1,21 +1,4 @@ -// import config from './config'; - -import { - domain, // domain name - urlpath, // sub url path, like: www.example.com/<urlpath> - debug, - GOOGLE_API_KEY, - GOOGLE_CLIENT_ID, - DROPBOX_APP_KEY -} from './config'; - -//common -export const port = window.location.port; -window.serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`; -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 version = '0.5.0'; +import { serverurl } from '../config'; let checkAuth = false; let profile = null; @@ -49,7 +32,7 @@ export function setLoginState(bool, id) { export function checkLoginStateChanged() { if (getLoginState() != lastLoginState || getUserId() != lastUserId) { - if(loginStateChangeEvent) { + if (loginStateChangeEvent) { loginStateChangeEvent(); } return true; @@ -101,12 +84,6 @@ export function checkIfAuth(yesCallback, noCallback) { } export default { - domain, - urlpath, - debug, - GOOGLE_API_KEY, - GOOGLE_CLIENT_ID, - DROPBOX_APP_KEY, checkAuth, profile, lastLoginState, diff --git a/public/js/lib/config/index.js b/public/js/lib/config/index.js new file mode 100644 index 00000000..2b73679f --- /dev/null +++ b/public/js/lib/config/index.js @@ -0,0 +1,19 @@ +import configJson from '../../../../config.json'; // root path json config + +const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development; + +export const GOOGLE_API_KEY = (config.google && config.google.apiKey) || ''; +export const GOOGLE_CLIENT_ID = (config.google && config.google.clientID) || ''; +export const DROPBOX_APP_KEY = (config.dropbox && config.dropbox.appKey) || ''; + +export const domain = config.domain || ''; // domain name +export const urlpath = config.urlpath || ''; // sub url path, like: www.example.com/<urlpath> +export const debug = config.debug || false; + +export const port = window.location.port; +export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`; +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 noteurl = `${serverurl}/${noteid}`; + +export const version = '0.5.0'; |