New option: hotkey; Fix hotkey bug

This commit is contained in:
DIYgod 2016-08-22 20:07:31 +08:00
parent c5c9188e4d
commit a70b1229ab
No known key found for this signature in database
GPG Key ID: F8797DD1088C6506
6 changed files with 15 additions and 8 deletions

View File

@ -50,6 +50,7 @@ var option = {
loop: true, // Optional, loop play music, default: true loop: true, // Optional, loop play music, default: true
lang: 'zh', // Optional, language, `zh` for Chinese, `en` for English, default: Navigator language lang: 'zh', // Optional, language, `zh` for Chinese, `en` for English, default: Navigator language
screenshot: true, // Optional, enable screenshot function, default: false, NOTICE: if set it to true, video and video poster must enable Cross-Origin screenshot: true, // Optional, enable screenshot function, default: false, NOTICE: if set it to true, video and video poster must enable Cross-Origin
hotkey: true, // Optional, binding hot key, including left right and Space, default: true
video: { // Required, video info video: { // Required, video info
url: '若能绽放光芒.mp4', // Required, video url url: '若能绽放光芒.mp4', // Required, video url
pic: '若能绽放光芒.png' // Optional, music picture pic: '若能绽放光芒.png' // Optional, music picture

View File

@ -62,6 +62,7 @@
theme: '#FADFA3', theme: '#FADFA3',
loop: true, loop: true,
screenshot: true, screenshot: true,
hotkey: true,
video: { video: {
url: 'http://devtest.qiniudn.com/若能绽放光芒.mp4', url: 'http://devtest.qiniudn.com/若能绽放光芒.mp4',
pic: 'http://devtest.qiniudn.com/若能绽放光芒.png' pic: 'http://devtest.qiniudn.com/若能绽放光芒.png'

4
dist/DPlayer.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "dplayer", "name": "dplayer",
"version": "1.0.5", "version": "1.0.6",
"description": "Wow, such a lovely HTML5 danmaku video player", "description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js", "main": "dist/DPlayer.min.js",
"scripts": { "scripts": {

View File

@ -1,4 +1,4 @@
console.log("\n %c DPlayer 1.0.5 %c http://dplayer.js.org \n\n","color: #fadfa3; background: #030307; padding:5px 0;","background: #fadfa3; padding:5px 0;"); console.log("\n %c DPlayer 1.0.6 %c http://dplayer.js.org \n\n","color: #fadfa3; background: #030307; padding:5px 0;","background: #fadfa3; padding:5px 0;");
require('./DPlayer.scss'); require('./DPlayer.scss');
@ -48,7 +48,8 @@ class DPlayer {
theme: '#b7daff', theme: '#b7daff',
loop: false, loop: false,
lang: navigator.language.indexOf('zh') !== -1 ? 'zh' : 'en', lang: navigator.language.indexOf('zh') !== -1 ? 'zh' : 'en',
screenshot: false screenshot: false,
hotkey: true
}; };
for (let defaultKey in defaultOption) { for (let defaultKey in defaultOption) {
if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) { if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
@ -1143,7 +1144,9 @@ class DPlayer {
* hot key * hot key
*/ */
const handleKeyDown = (e) => { const handleKeyDown = (e) => {
if (document.activeElement.tagName.toUpperCase() !== 'INPUT') { const tag = document.activeElement.tagName.toUpperCase();
const editable = document.activeElement.getAttribute('contenteditable');
if (tag !== 'INPUT' && tag !== 'TEXTAREA' && editable !== '' && editable !== 'true') {
const event = e || window.event; const event = e || window.event;
let percentage; let percentage;
switch (event.keyCode) { switch (event.keyCode) {
@ -1172,7 +1175,9 @@ class DPlayer {
} }
} }
}; };
document.addEventListener('keydown', handleKeyDown); if (option.hotkey) {
document.addEventListener('keydown', handleKeyDown);
}
/** /**
* right key * right key