Added event to window scope so react can autobind
Этот коммит содержится в:
@@ -23,6 +23,15 @@ module.exports = React.createClass({
|
|||||||
this.setState({imgId: id});
|
this.setState({imgId: id});
|
||||||
this.loadImage(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) {
|
componentWillReceiveProps: function(nextProps) {
|
||||||
this.setState({imgId: nextProps.startId});
|
this.setState({imgId: nextProps.startId});
|
||||||
},
|
},
|
||||||
@@ -93,22 +102,14 @@ module.exports = React.createClass({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$(this.getDOMNode()).on('keyup', function(e) {
|
$(window).on('keyup', this.handleKeyPress);
|
||||||
if (!e) {
|
|
||||||
return;
|
|
||||||
} else if (e.keyCode === 39) {
|
|
||||||
self.handleNext();
|
|
||||||
} else if (e.keyCode === 37) {
|
|
||||||
self.handlePrev();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// keep track of whether or not this component is mounted so we can safely set the state asynchronously
|
// keep track of whether or not this component is mounted so we can safely set the state asynchronously
|
||||||
this.canSetState = true;
|
this.canSetState = true;
|
||||||
},
|
},
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
this.canSetState = false;
|
this.canSetState = false;
|
||||||
$(this.getDOMNode()).off('keyup');
|
$(window).off('keyup', this.handleKeyPress);
|
||||||
},
|
},
|
||||||
getPublicLink: function() {
|
getPublicLink: function() {
|
||||||
var data = {};
|
var data = {};
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user