all the way fixed

This commit is contained in:
Peter Cottle 2015-04-17 17:39:55 +10:00
parent 9206820a8d
commit 1ede0389ce
2 changed files with 29 additions and 8 deletions

View file

@ -49,10 +49,9 @@ var Level = Sandbox.extend({
this.initGoalData(options); this.initGoalData(options);
this.initName(options); this.initName(options);
this.on('toggleGoal', this.toggleGoal);
this.on('minimizeCanvas', this.minimizeGoal); this.on('minimizeCanvas', this.minimizeGoal);
this.on('resizeCanvas', this.resizeGoal); this.on('resizeCanvas', this.resizeGoal);
this.on('toggleObjective', this.toggleObjective); this.isGoalExpanded = false;
Level.__super__.initialize.apply(this, [options]); Level.__super__.initialize.apply(this, [options]);
this.startOffCommand(); this.startOffCommand();
@ -60,6 +59,10 @@ var Level = Sandbox.extend({
this.handleOpen(options.deferred); this.handleOpen(options.deferred);
}, },
getIsGoalExpanded: function() {
return this.isGoalExpanded;
},
handleOpen: function(deferred) { handleOpen: function(deferred) {
deferred = deferred || Q.defer(); deferred = deferred || Q.defer();
@ -132,10 +135,10 @@ var Level = Sandbox.extend({
{ {
name: name, name: name,
onGoalClick: this.toggleGoal.bind(this), onGoalClick: this.toggleGoal.bind(this),
onObjectiveClick: this.toggleObjective.bind(this) onObjectiveClick: this.toggleObjective.bind(this),
parent: this
} }
); );
debugger;
React.render( React.render(
this.levelToolbar, this.levelToolbar,
document.getElementById('levelToolbarMount') document.getElementById('levelToolbarMount')
@ -219,6 +222,8 @@ var Level = Sandbox.extend({
}, },
minimizeGoal: function (position, size) { minimizeGoal: function (position, size) {
this.isGoalExpanded = false;
this.trigger('goalToggled');
this.goalVis.hide(); this.goalVis.hide();
this.goalWindowPos = position; this.goalWindowPos = position;
this.goalWindowSize = size; this.goalWindowSize = size;
@ -229,6 +234,9 @@ var Level = Sandbox.extend({
}, },
resizeGoal: function () { resizeGoal: function () {
if (!this.goalVis) {
return;
}
this.goalVis.myResize(); this.goalVis.myResize();
}, },
@ -290,6 +298,8 @@ var Level = Sandbox.extend({
}, },
showGoal: function(command, defer) { showGoal: function(command, defer) {
this.isGoalExpanded = true;
this.trigger('goalToggled');
this.showSideVis(command, defer, this.goalCanvasHolder, this.initGoalVisualization); this.showSideVis(command, defer, this.goalCanvasHolder, this.initGoalVisualization);
// show the squeezer again we are to the side // show the squeezer again we are to the side
if ($(this.goalVis.el).offset().left > 0.5 * $(window).width()) { if ($(this.goalVis.el).offset().left > 0.5 * $(window).width()) {
@ -311,6 +321,8 @@ var Level = Sandbox.extend({
}, },
hideGoal: function(command, defer) { hideGoal: function(command, defer) {
this.isGoalExpanded = false;
this.trigger('goalToggled');
this.hideSideVis(command, defer, this.goalCanvasHolder); this.hideSideVis(command, defer, this.goalCanvasHolder);
}, },
@ -487,7 +499,9 @@ var Level = Sandbox.extend({
}, },
die: function() { die: function() {
this.levelToolbar.die(); React.unmountComponentAtNode(
document.getElementById('levelToolbarMount')
);
this.hideGoal(); this.hideGoal();
this.mainVis.die(); this.mainVis.die();

View file

@ -9,12 +9,14 @@ var LevelToolbarView = React.createClass({
propTypes: { propTypes: {
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
onGoalClick: PropTypes.func.isRequired, onGoalClick: PropTypes.func.isRequired,
onObjectiveClick: PropTypes.func.isRequired onObjectiveClick: PropTypes.func.isRequired,
parent: PropTypes.object.isRequired
}, },
getInitialState: function() { getInitialState: function() {
return { return {
isHidden: true isHidden: true,
isGoalExpanded: false
}; };
}, },
@ -22,6 +24,11 @@ var LevelToolbarView = React.createClass({
this.setState({ this.setState({
isHidden: false isHidden: false
}); });
this.props.parent.on('goalToggled', function() {
this.setState({
isGoalExpanded: this.props.parent.getIsGoalExpanded()
});
}.bind(this));
}, },
render: function() { render: function() {
@ -49,7 +56,7 @@ var LevelToolbarView = React.createClass({
<button <button
onClick={this.props.onGoalClick} onClick={this.props.onGoalClick}
type="button"> type="button">
{false ? {this.state.isGoalExpanded ?
intl.str('show-goal-button') : intl.str('show-goal-button') :
intl.str('hide-goal-button') intl.str('hide-goal-button')
} }