Simplify unpressing dropdown buttons
parent
ca97953d23
commit
75065941f3
30
mail.js
30
mail.js
|
@ -199,30 +199,6 @@ var DropDownMenu = React.createClass({
|
|||
});
|
||||
|
||||
var DropDownButton = React.createClass({
|
||||
statics: {
|
||||
instances: [],
|
||||
setBodyListener: false,
|
||||
hideAll: function(ev)
|
||||
{
|
||||
for (var i = 0; i < DropDownButton.instances.length; i++)
|
||||
DropDownButton.instances[i].setState({ pressed: false });
|
||||
}
|
||||
},
|
||||
componentDidMount: function()
|
||||
{
|
||||
if (!DropDownButton.setBodyListener)
|
||||
{
|
||||
window.addEventListener('click', DropDownButton.hideAll);
|
||||
DropDownButton.setBodyListener = true;
|
||||
}
|
||||
DropDownButton.instances.push(this);
|
||||
},
|
||||
componentWillUnmount: function()
|
||||
{
|
||||
for (var i = DropDownButton.instances.length-1; i >= 0; i--)
|
||||
if (DropDownButton.instances[i] == this)
|
||||
DropDownButton.instances.splice(i, 1);
|
||||
},
|
||||
render: function()
|
||||
{
|
||||
return <a ref="btn" title={(this.state.checked ? this.props.checkedTitle : null) || this.props.title} onClick={this.onClickButton}
|
||||
|
@ -242,12 +218,16 @@ var DropDownButton = React.createClass({
|
|||
if (!this.state.pressed)
|
||||
{
|
||||
DropDownBase.hideAll();
|
||||
DropDownBase.instances[this.props.dropdownId].showAt(this.refs.btn);
|
||||
DropDownBase.instances[this.props.dropdownId].showAt(this.refs.btn, this.unpress);
|
||||
}
|
||||
else
|
||||
DropDownBase.instances[this.props.dropdownId].hide();
|
||||
this.setState({ pressed: !this.state.pressed });
|
||||
},
|
||||
unpress: function()
|
||||
{
|
||||
this.setState({ pressed: false });
|
||||
},
|
||||
onClickButton: function(ev)
|
||||
{
|
||||
if (this.props.whole || this.props.checkable && this.state.pressed)
|
||||
|
|
Loading…
Reference in New Issue