diff options
author | nickago <ngonella@calpoly.edu> | 2015-08-10 11:24:32 -0700 |
---|---|---|
committer | nickago <ngonella@calpoly.edu> | 2015-08-10 11:24:32 -0700 |
commit | 66056ad36d5ae1ba1fbf0ca50e68654c48bbb18d (patch) | |
tree | 0bb72a561cdcb11e43ed670c2513f0c669114b9b /web/react/components | |
parent | b398819198b2ebd86787ae054b6d5229beeead71 (diff) | |
download | chat-66056ad36d5ae1ba1fbf0ca50e68654c48bbb18d.tar.gz chat-66056ad36d5ae1ba1fbf0ca50e68654c48bbb18d.tar.bz2 chat-66056ad36d5ae1ba1fbf0ca50e68654c48bbb18d.zip |
Added event to window scope so react can autobind
Diffstat (limited to 'web/react/components')
-rw-r--r-- | web/react/components/view_image.jsx | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/web/react/components/view_image.jsx b/web/react/components/view_image.jsx index 6be6f62a0..dc85b53e5 100644 --- a/web/react/components/view_image.jsx +++ b/web/react/components/view_image.jsx @@ -23,6 +23,15 @@ module.exports = React.createClass({ this.setState({imgId: id}); this.loadImage(id); }, + handleKeyPress: function handleKeyPress(e) { + if (!e) { + return; + } else if (e.keyCode === 39) { + this.handleNext(); + } else if (e.keyCode === 37) { + this.handlePrev(); + } + }, componentWillReceiveProps: function(nextProps) { this.setState({imgId: nextProps.startId}); }, @@ -93,22 +102,14 @@ module.exports = React.createClass({ } ); - $(this.getDOMNode()).on('keyup', function(e) { - if (!e) { - return; - } else if (e.keyCode === 39) { - self.handleNext(); - } else if (e.keyCode === 37) { - self.handlePrev(); - } - }); + $(window).on('keyup', this.handleKeyPress); // keep track of whether or not this component is mounted so we can safely set the state asynchronously this.canSetState = true; }, componentWillUnmount: function() { this.canSetState = false; - $(this.getDOMNode()).off('keyup'); + $(window).off('keyup', this.handleKeyPress); }, getPublicLink: function() { var data = {}; |