diff --git a/src/js/views/App.js b/src/js/views/App.js index 427cd1bd..e7e3b31e 100755 --- a/src/js/views/App.js +++ b/src/js/views/App.js @@ -20,20 +20,42 @@ class App extends React.Component{ constructor(props){ super(props); - this.handleKeyUp = this.handleKeyUp.bind(this); + this.handleKeyDown = this.handleKeyDown.bind(this); } componentWillMount(){ this.props.mopidyActions.connect(); window.addEventListener("keyup", this.handleKeyUp, false); + window.addEventListener("keydown", this.handleKeyDown, false); } componentWillUnmount(){ window.removeEventListener("keyup", this.handleKeyUp, false); + window.removeEventListener("keydown", this.handleKeyDown, false); + } + + shouldTriggerShortcut(e){ + var ignoreNodes = ['INPUT', 'TEXTAREA']; + var keyCodes = [32]; + + if( ignoreNodes.indexOf(e.target.nodeName) > -1 ){ + return false; + } + + if( keyCodes.indexOf(e.keyCode) > -1 ){ + e.preventDefault(); + return true; + } + } + + handleKeyDown(e){ + this.shouldTriggerShortcut(e); } handleKeyUp(e){ + if( !this.shouldTriggerShortcut(e) ) return; + switch(e.keyCode){ case 32: // spacebar if( this.props.mopidy.state == 'playing' ){