@@ -48,11 +48,36 @@ Blockly.WidgetDiv.owner_ = null;
48
48
49
49
/**
50
50
* Optional cleanup function set by whichever object uses the widget.
51
+ * This is called as soon as a dispose is desired. If the dispose should
52
+ * be animated, the animation should start on the call of dispose_.
51
53
* @type {Function }
52
54
* @private
53
55
*/
54
56
Blockly . WidgetDiv . dispose_ = null ;
55
57
58
+ /**
59
+ * Optional function called at the end of a dispose animation.
60
+ * Set by whichever object is using the widget.
61
+ * @type {Function }
62
+ * @private
63
+ */
64
+ Blockly . WidgetDiv . disposeAnimationFinished_ = null ;
65
+
66
+ /**
67
+ * Timer ID for the dispose animation.
68
+ * @type {number }
69
+ * @private
70
+ */
71
+ Blockly . WidgetDiv . disposeAnimationTimer_ = null ;
72
+
73
+ /**
74
+ * Length of time in seconds for the dispose animation.
75
+ * @type {number }
76
+ * @private
77
+ */
78
+ Blockly . WidgetDiv . disposeAnimationTimerLength_ = 0 ;
79
+
80
+
56
81
/**
57
82
* Create the widget div and inject it onto the page.
58
83
*/
@@ -69,13 +94,20 @@ Blockly.WidgetDiv.createDom = function() {
69
94
* Initialize and display the widget div. Close the old one if needed.
70
95
* @param {!Object } newOwner The object that will be using this container.
71
96
* @param {boolean } rtl Right-to-left (true) or left-to-right (false).
72
- * @param {Function } dispose Optional cleanup function to be run when the widget
73
- * is closed.
97
+ * @param {Function= } opt_dispose Optional cleanup function to be run when the widget
98
+ * is closed. If the dispose is animated, this function must start the animation.
99
+ * @param {Function= } opt_disposeAnimationFinished Optional cleanup function to be run
100
+ * when the widget is done animating and must disappear.
101
+ * @param {number= } opt_disposeAnimationTimerLength Length of animation time in seconds
102
+ if a dispose animation is provided.
74
103
*/
75
- Blockly . WidgetDiv . show = function ( newOwner , rtl , dispose ) {
104
+ Blockly . WidgetDiv . show = function ( newOwner , rtl , opt_dispose ,
105
+ opt_disposeAnimationFinished , opt_disposeAnimationTimerLength ) {
76
106
Blockly . WidgetDiv . hide ( ) ;
77
107
Blockly . WidgetDiv . owner_ = newOwner ;
78
- Blockly . WidgetDiv . dispose_ = dispose ;
108
+ Blockly . WidgetDiv . dispose_ = opt_dispose ;
109
+ Blockly . WidgetDiv . disposeAnimationFinished_ = opt_disposeAnimationFinished ;
110
+ Blockly . WidgetDiv . disposeAnimationTimerLength_ = opt_disposeAnimationTimerLength ;
79
111
// Temporarily move the widget to the top of the screen so that it does not
80
112
// cause a scrollbar jump in Firefox when displayed.
81
113
var xy = goog . style . getViewportPageOffset ( document ) ;
@@ -89,19 +121,49 @@ Blockly.WidgetDiv.show = function(newOwner, rtl, dispose) {
89
121
* Destroy the widget and hide the div.
90
122
*/
91
123
Blockly . WidgetDiv . hide = function ( ) {
92
- if ( Blockly . WidgetDiv . owner_ ) {
124
+ if ( Blockly . WidgetDiv . disposeAnimationTimer_ ) {
125
+ // An animation timer is set already.
126
+ // This happens when a previous widget was animating out,
127
+ // but Blockly is hiding the widget to create a new one.
128
+ // So, short-circuit the animation and clear the timer.
129
+ window . clearTimeout ( Blockly . WidgetDiv . disposeAnimationTimer_ ) ;
130
+ Blockly . WidgetDiv . disposeAnimationFinished_ && Blockly . WidgetDiv . disposeAnimationFinished_ ( ) ;
131
+ Blockly . WidgetDiv . disposeAnimationFinished_ = null ;
132
+ Blockly . WidgetDiv . disposeAnimationTimer_ = null ;
93
133
Blockly . WidgetDiv . owner_ = null ;
94
- Blockly . WidgetDiv . DIV . style . display = 'none' ;
95
- Blockly . WidgetDiv . DIV . style . left = '' ;
96
- Blockly . WidgetDiv . DIV . style . top = '' ;
97
- Blockly . WidgetDiv . DIV . style . height = '' ;
134
+ Blockly . WidgetDiv . hideAndClearDom_ ( ) ;
135
+ } else if ( Blockly . WidgetDiv . isVisible ( ) ) {
136
+ // No animation timer set, but the widget is visible
137
+ // Start animation out (or immediately hide)
98
138
Blockly . WidgetDiv . dispose_ && Blockly . WidgetDiv . dispose_ ( ) ;
99
139
Blockly . WidgetDiv . dispose_ = null ;
100
- goog . dom . removeChildren ( Blockly . WidgetDiv . DIV ) ;
140
+ // If we want to animate out, set the appropriate timer for final dispose.
141
+ if ( Blockly . WidgetDiv . disposeAnimationFinished_ ) {
142
+ Blockly . WidgetDiv . disposeAnimationTimer_ = window . setTimeout (
143
+ Blockly . WidgetDiv . hide , // Come back to hide and take the first branch.
144
+ Blockly . WidgetDiv . disposeAnimationTimerLength_ * 1000
145
+ ) ;
146
+ } else {
147
+ // No timer provided - auto-hide the DOM now.
148
+ Blockly . WidgetDiv . owner_ = null ;
149
+ Blockly . WidgetDiv . hideAndClearDom_ ( ) ;
150
+ }
101
151
Blockly . Events . setGroup ( false ) ;
102
152
}
103
153
} ;
104
154
155
+ /**
156
+ * Hide all DOM for the WidgetDiv, and clear its children.
157
+ * @private
158
+ */
159
+ Blockly . WidgetDiv . hideAndClearDom_ = function ( ) {
160
+ Blockly . WidgetDiv . DIV . style . display = 'none' ;
161
+ Blockly . WidgetDiv . DIV . style . left = '' ;
162
+ Blockly . WidgetDiv . DIV . style . top = '' ;
163
+ Blockly . WidgetDiv . DIV . style . height = '' ;
164
+ goog . dom . removeChildren ( Blockly . WidgetDiv . DIV ) ;
165
+ } ;
166
+
105
167
/**
106
168
* Is the container visible?
107
169
* @return {boolean } True if visible.
0 commit comments