Description:
Fix GUI breakage on browser resizing.
Fixed how yui events are handled by the component framework.
Also added two tests:
- ensure that the module synthetic events binding works;
- ensure that the custom events 'beforePageSizeRecalculation'
and 'afterPageSizeRecalculation' are correctly fired by
the environment view when the browser is resized.
QA: resize the browser, open the charm panel, resize the
browser again, close the charm panel, resize again,
re-open the panel...
+ it('must handle the window resize event', function(done) {
+ var view = new views.environment({container: container, db: db});
+ view.render();
+ var beforeResizeEventFired = false;
+ Y.once('beforePageSizeRecalculation', function() {
+ // This event must be fired by
views.MegaModule.setSizesFromViewport.
+ beforeResizeEventFired = true;
+ });
+ Y.once('afterPageSizeRecalculation', function() {
+ // This event must be fired by
views.MegaModule.setSizesFromViewport.
+ assert.isTrue(beforeResizeEventFired);
+ done();
+ });
+ Y.one('window').simulate('resize');
+ });
+
// Ensure the environment view loads properly
it('must be able to render service blocks and relations', function() {
Index: app/assets/javascripts/d3-components.js
=== modified file 'app/assets/javascripts/d3-components.js'
--- app/assets/javascripts/d3-components.js 2012-12-11 15:35:25 +0000
+++ app/assets/javascripts/d3-components.js 2012-12-14 15:25:55 +0000
@@ -231,9 +231,12 @@
// Bind resolved event handlers as a group.
if (Y.Object.keys(resolvedHandler).length) { Y.each(resolvedHandler, function(handler, name) {
- subscriptions.push(Y[eventPhase](name,
- handler.callback,
- handler.context));
+ // DOM and synthetic events are subscribed using Y.on with
+ // this signature: Y.on(event, callback, target, context).
+ // For this reason, it is not possible here to just pass the
+ // context as third argument.
+ var callback = Y.bind(handler.callback, handler.context);
+ subscriptions.push(Y[eventPhase](name, callback));
});
}
});
Reviewers: mp+139959_ code.launchpad. net,
Message:
Please take a look.
Description:
Fix GUI breakage on browser resizing.
Fixed how yui events are handled by the component framework. Recalculation' ecalculation' are correctly fired by
Also added two tests:
- ensure that the module synthetic events binding works;
- ensure that the custom events 'beforePageSize
and 'afterPageSizeR
the environment view when the browser is resized.
QA: resize the browser, open the charm panel, resize the
browser again, close the charm panel, resize again,
re-open the panel...
https:/ /code.launchpad .net/~frankban/ juju-gui/ bug-1090046- resize/ +merge/ 139959
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6941053/
Affected files: javascripts/ d3-components. js d3_components. js environment_ view.js
A [revision details]
M app/assets/
M test/test_
M test/test_
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision:
<email address hidden>
Index: test/test_ d3_components. js d3_components. js' d3_components. js 2012-11-09 14:17:58 +0000 d3_components. js 2012-12-14 15:25:55 +0000
=== modified file 'test/test_
--- test/test_
+++ test/test_
@@ -129,6 +129,24 @@
});
+ it('should correctly handle synthetic event bindings', function(done) { {container: container}); zeHandler = function(evt) { yui.windowresiz e = 'windowResizeHa ndler'; modA); 'windowresize' , function(evt) { detach( ); isTrue( resized) ; window' ).simulate( 'resize' );
+ comp = new NS.Component();
+ comp.setAttrs(
+ modA = new TestModule();
+ var resized = false;
+ modA.windowResi
+ resized = true;
+ };
+ modA.events.
+ comp.addModule(
+ var subscription = Y.after(
+ subscription.
+ assert.
+ done();
+ });
+ Y.one('
+ });
+
it('should support basic rendering from all modules',
function() {
var modA = new TestModule(),
Index: test/test_ environment_ view.js environment_ view.js' environment_ view.js 2012-12-05 18:37:01 +0000 environment_ view.js 2012-12-14 15:25:55 +0000
=== modified file 'test/test_
--- test/test_
+++ test/test_
@@ -103,7 +103,7 @@
});
beforeEac h(function( done) { 'visibility' , 'hidden');
Y.one( 'body') .prepend( container) ;
db.on_ delta({ data: environment_ delta}) ;
- container = Y.Node.create('<div id="test-container" />');
+ container = Y.Node.create('<div
/>').setStyle(
db = new models.Database();
@@ -118,6 +118,22 @@
done();
});
+ it('must handle the window resize event', function(done) { nt({container: container, db: db}); ntFired = false; 'beforePageSize Recalculation' , function() { e.setSizesFromV iewport. ntFired = true; 'afterPageSizeR ecalculation' , function() { e.setSizesFromV iewport. isTrue( beforeResizeEve ntFired) ; window' ).simulate( 'resize' );
function( ) {
+ var view = new views.environme
+ view.render();
+ var beforeResizeEve
+ Y.once(
+ // This event must be fired by
views.MegaModul
+ beforeResizeEve
+ });
+ Y.once(
+ // This event must be fired by
views.MegaModul
+ assert.
+ done();
+ });
+ Y.one('
+ });
+
// Ensure the environment view loads properly
it('must be able to render service blocks and relations',
Index: app/assets/ javascripts/ d3-components. js javascripts/ d3-components. js' javascripts/ d3-components. js 2012-12-11 15:35:25 +0000 javascripts/ d3-components. js 2012-12-14 15:25:55 +0000 keys(resolvedHa ndler). length) {
Y.each( resolvedHandler , function(handler, name) { push(Y[ eventPhase] (name, handler. callback, handler.context); push(Y[ eventPhase] (name, callback));
=== modified file 'app/assets/
--- app/assets/
+++ app/assets/
@@ -231,9 +231,12 @@
// Bind resolved event handlers as a group.
if (Y.Object.
- subscriptions.
- handler.callback,
- handler.context));
+ // DOM and synthetic events are subscribed using Y.on with
+ // this signature: Y.on(event, callback, target, context).
+ // For this reason, it is not possible here to just pass the
+ // context as third argument.
+ var callback = Y.bind(
+ subscriptions.
});
}
});