From 339baea8762885a85ac755ef51d57ba441bf3e53 Mon Sep 17 00:00:00 2001 From: Micooz Date: Fri, 28 Jul 2017 10:27:42 +0800 Subject: [PATCH 1/3] utils: add isMobile --- src/utils.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utils.js b/src/utils.js index 3aaa562..c74a47f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -35,4 +35,10 @@ module.exports = { } return actualLeft - elementScrollLeft; }, + + /** + * check if user is using mobile or not + */ + isMobile: /mobile/i.test(window.navigator.userAgent) + }; From 5f9e1a3c3fd22fcd2ac3af72dd1987912b41f3b8 Mon Sep 17 00:00:00 2001 From: Micooz Date: Fri, 28 Jul 2017 10:30:41 +0800 Subject: [PATCH 2/3] core: use import --- src/DPlayer.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/DPlayer.js b/src/DPlayer.js index e76a1e0..a2d8624 100644 --- a/src/DPlayer.js +++ b/src/DPlayer.js @@ -1,13 +1,13 @@ console.log('\n %c DPlayer 1.5.0 %c http://dplayer.js.org \n\n', 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;'); -require('./DPlayer.scss'); -const utils = require('./utils.js'); -const svg = require('./svg.js'); -const handleOption = require('./option.js'); -const i18n = require('./i18n.js'); -const html = require('./html.js'); -const Video = require('./video.js'); -const isMobile = /mobile/i.test(window.navigator.userAgent); +import './DPlayer.scss'; + +import utils, {isMobile} from './utils'; +import svg from './svg'; +import handleOption from './option'; +import i18n from './i18n'; +import html from './html'; +import Video from './video'; let index = 0; @@ -160,7 +160,7 @@ class DPlayer { const clearCheckLoadingTime = () => { clearInterval(this.checkLoading); }; - + this.animationFrame = () => { if (this.playedTime) { this.updateBar('played', this.video.currentTime() / this.video.duration, 'width'); @@ -933,7 +933,6 @@ class DPlayer { * Read danmaku from API */ readDanmaku () { - const isMobile = /mobile/i.test(window.navigator.userAgent); let apiurl; if (this.option.danmaku.maximum) { apiurl = `${this.option.danmaku.api}?id=${this.option.danmaku.id}&max=${this.option.danmaku.maximum}`; From 0a7ff403117038114ee6ec13c53bb86564642d1e Mon Sep 17 00:00:00 2001 From: Micooz Date: Fri, 28 Jul 2017 10:58:14 +0800 Subject: [PATCH 3/3] build: define DPLAYER_VERSION using webpack.DefinePlugin --- src/DPlayer.js | 2 -- src/index.js | 3 +++ webpack/dev.config.js | 5 ++++- webpack/prod.config.js | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/DPlayer.js b/src/DPlayer.js index a2d8624..18c4313 100644 --- a/src/DPlayer.js +++ b/src/DPlayer.js @@ -1,5 +1,3 @@ -console.log('\n %c DPlayer 1.5.0 %c http://dplayer.js.org \n\n', 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;'); - import './DPlayer.scss'; import utils, {isMobile} from './utils'; diff --git a/src/index.js b/src/index.js index 8ab4544..4afeb79 100644 --- a/src/index.js +++ b/src/index.js @@ -1 +1,4 @@ +// eslint-disable-next-line +console.log(`\n %c DPlayer ${DPLAYER_VERSION} %c http://dplayer.js.org \n\n`, 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;'); + module.exports = require('./DPlayer'); \ No newline at end of file diff --git a/webpack/dev.config.js b/webpack/dev.config.js index 29c85ec..a184b81 100644 --- a/webpack/dev.config.js +++ b/webpack/dev.config.js @@ -91,7 +91,10 @@ module.exports = { }, plugins: [ - new webpack.NamedModulesPlugin() + new webpack.NamedModulesPlugin(), + new webpack.DefinePlugin({ + DPLAYER_VERSION: `"${require('../package.json').version}"` + }) ], node: { diff --git a/webpack/prod.config.js b/webpack/prod.config.js index 92f3907..266d3ac 100644 --- a/webpack/prod.config.js +++ b/webpack/prod.config.js @@ -85,6 +85,9 @@ module.exports = { }, plugins: [ + new webpack.DefinePlugin({ + DPLAYER_VERSION: `"${require('../package.json').version}"` + }), new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false