chore: Fix ESLint errors.

pull/165/head
jaywcjlove 5 years ago
parent d3c0d4830b
commit bcb3f691f1

@ -10,6 +10,7 @@
"jasmine": true
},
"rules": {
"object-curly-newline": 0,
"linebreak-style": 0,
"arrow-body-style": 0,
"max-len": 0,

@ -7,10 +7,9 @@ let _scope = 'all'; // 默认热键范围
const elementHasBindEvent = []; // 已绑定事件的节点记录
// 返回键码
const code = x =>
_keyMap[x.toLowerCase()] ||
_modifier[x.toLowerCase()] ||
x.toUpperCase().charCodeAt(0);
const code = (x) => _keyMap[x.toLowerCase()]
|| _modifier[x.toLowerCase()]
|| x.toUpperCase().charCodeAt(0);
// 设置获取当前范围(默认为'所有'
function setScope(scope) {
@ -33,8 +32,8 @@ function filter(event) {
let flag = true;
// ignore: isContentEditable === 'true', <input> and <textarea> when readOnly state is false, <select>
if (
target.isContentEditable ||
((tagName === 'INPUT' || tagName === 'TEXTAREA') && !target.readOnly)
target.isContentEditable
|| ((tagName === 'INPUT' || tagName === 'TEXTAREA') && !target.readOnly)
) {
flag = false;
}
@ -98,7 +97,7 @@ function clearModifier(event) {
function unbind(keysInfo, ...args) {
// unbind(), unbind all keys
if (!keysInfo) {
Object.keys(_handlers).forEach(key => delete _handlers[key]);
Object.keys(_handlers).forEach((key) => delete _handlers[key]);
} else if (Array.isArray(keysInfo)) {
// support like : unbind([{key: 'ctrl+a', scope: 's1'}, {key: 'ctrl-a', scope: 's2', splitKey: '-'}])
keysInfo.forEach((info) => {
@ -142,9 +141,9 @@ const eachUnbind = ({
// 通过函数判断,是否解除绑定,函数相等直接返回
const isMatchingMethod = method ? record.method === method : true;
if (
isMatchingMethod &&
record.scope === scope &&
compareArray(record.mods, mods)
isMatchingMethod
&& record.scope === scope
&& compareArray(record.mods, mods)
) {
return {};
}
@ -165,8 +164,8 @@ function eventHandler(event, handler, scope) {
for (const y in _mods) {
if (Object.prototype.hasOwnProperty.call(_mods, y)) {
if (
(!_mods[y] && handler.mods.indexOf(+y) > -1) ||
(_mods[y] && handler.mods.indexOf(+y) === -1)
(!_mods[y] && handler.mods.indexOf(+y) > -1)
|| (_mods[y] && handler.mods.indexOf(+y) === -1)
) {
modifiersMatch = false;
}
@ -175,13 +174,13 @@ function eventHandler(event, handler, scope) {
// 调用处理程序,如果是修饰键不做处理
if (
(handler.mods.length === 0 &&
!_mods[16] &&
!_mods[18] &&
!_mods[17] &&
!_mods[91]) ||
modifiersMatch ||
handler.shortcut === '*'
(handler.mods.length === 0
&& !_mods[16]
&& !_mods[18]
&& !_mods[17]
&& !_mods[91])
|| modifiersMatch
|| handler.shortcut === '*'
) {
if (handler.method(event, handler) === false) {
if (event.preventDefault) event.preventDefault();
@ -270,9 +269,9 @@ function dispatch(event) {
if (asterisk) {
for (let i = 0; i < asterisk.length; i++) {
if (
asterisk[i].scope === scope &&
((event.type === 'keydown' && asterisk[i].keydown) ||
(event.type === 'keyup' && asterisk[i].keyup))
asterisk[i].scope === scope
&& ((event.type === 'keydown' && asterisk[i].keydown)
|| (event.type === 'keyup' && asterisk[i].keyup))
) {
eventHandler(event, asterisk[i], scope);
}
@ -283,8 +282,8 @@ function dispatch(event) {
for (let i = 0; i < _handlers[key].length; i++) {
if (
(event.type === 'keydown' && _handlers[key][i].keydown) ||
(event.type === 'keyup' && _handlers[key][i].keyup)
(event.type === 'keydown' && _handlers[key][i].keydown)
|| (event.type === 'keyup' && _handlers[key][i].keyup)
) {
if (_handlers[key][i].key) {
const record = _handlers[key][i];

@ -18,6 +18,7 @@ export default class App extends Component {
};
this.onKeyUpEvent = this.onKeyUpEvent.bind(this);
}
componentDidMount() {
document.addEventListener('keyup', this.onKeyUpEvent);
function pkeys(keys, key) {
@ -58,40 +59,49 @@ export default class App extends Component {
});
return false;
}
componentWillUnmount() {
document.removeEventListener('keyup', this.onKeyUpEvent);
}
onKeyUpEvent() {
this.setState({ keyCode: [], keyStr: [] });
}
onKeyBoardMouseDown(item) {
if (item.keycode > -1) {
this.setState({ keyStr: [item.keycode] });
}
}
onKeyBoardMouseUp() {
this.setState({ keyStr: [] });
}
openVersionWebsite(e) {
if (e.target && e.target.value) {
window.location.href = e.target.value;
}
}
render() {
const { keyStr } = this.state;
const { keyStr, keyCode } = this.state;
let DocumentStrSource = DocumentStr;
if (DocumentStrSource) DocumentStrSource = DocumentStr.replace(/([\s\S]*)<!--dividing-->/, '');
return (
<div>
<select className={styles.version} onChange={this.openVersionWebsite.bind(this)}>
<option value="https://jaywcjlove.github.io/hotkeys">v{pkg.version}</option>
<option value="https://jaywcjlove.github.io/hotkeys">
v
{pkg.version}
</option>
<option value="https://unpkg.com/hotkeys-js@3.4.3/doc/index.html">v3.4.3</option>
<option value="https://unpkg.com/hotkeys-js@3.4.2/doc/index.html">v3.4.2</option>
<option value="https://unpkg.com/hotkeys-js@2.0.10/doc/index.html">v2.0.10</option>
</select>
{keyStr.length > -1 && (
<div className={styles.keyCodeInfo}>
{keyStr.map(item => <span key={`${item}`}>{item}</span>)}
{keyStr.map((item) => <span key={`${item}`}>{item}</span>)}
</div>
)}
<GithubCorner href="https://github.com/jaywcjlove/hotkeys" target="__blank" />
@ -99,16 +109,16 @@ export default class App extends Component {
<div className={styles.title}>HotKeys.js</div>
<div className={styles.github}>
<a href="https://www.npmjs.com/package/hotkeys-js">
<button>On NPM</button>
<button type="button">On NPM</button>
</a>
<a href="https://github.com/jaywcjlove/hotkeys/">
<button>Fork on Github</button>
<button type="button">Fork on Github</button>
</a>
<a href="https://github.com/jaywcjlove/hotkeys/">
<button>Doc on Github</button>
<button type="button">Doc on Github</button>
</a>
<a href="https://jaywcjlove.gitee.io/hotkeys/">
<button>Doc on Gitee</button>
<button type="button">Doc on Gitee</button>
</a>
</div>
<div className={styles.info}>A robust Javascript library for capturing keyboard input and key combinations entered. It has no dependencies. Try to press your keyboard, The following button will highlight.</div>
@ -116,7 +126,7 @@ export default class App extends Component {
<KeyBoard
onMouseDown={this.onKeyBoardMouseDown.bind(this)}
onMouseUp={this.onKeyBoardMouseUp.bind(this)}
keyCode={this.state.keyCode}
keyCode={keyCode}
/>
<Markdown source={DocumentStrSource} />
<GithubShields

@ -4,9 +4,15 @@ import style from './Footer.less';
export default function Footer({ name, href, year }) {
return (
<div className={style.footer}>
<div>Licensed under MIT. (Yes it&acute;s free and <a href="https://github.com/jaywcjlove/hotkeys">open-sourced</a>)</div>
<div>
© <a target="_blank" rel="noopener noreferrer" href={href}>{name}</a> {year}
Licensed under MIT. (Yes it&acute;s free and
<a href="https://github.com/jaywcjlove/hotkeys">open-sourced</a>
)
</div>
<div>
©
<a target="_blank" rel="noopener noreferrer" href={href}>{name}</a>
{year}
</div>
</div>
);

@ -18,6 +18,7 @@ export default class Markdown extends Component {
}
}
}
render() {
const { source } = this.props;
return (

Loading…
Cancel
Save