Merge lp:~wallyworld/lazr-js/activator-flash-node into lp:lazr-js

Proposed by Ian Booth
Status: Merged
Approved by: Ian Booth
Approved revision: 207
Merged at revision: 206
Proposed branch: lp:~wallyworld/lazr-js/activator-flash-node
Merge into: lp:lazr-js
Diff against target: 106 lines (+36/-3)
3 files modified
examples/activator/index.html (+16/-0)
src-js/lazrjs/activator/activator.js (+7/-3)
src-js/lazrjs/activator/tests/activator.js (+13/-0)
To merge this branch: bzr merge lp:~wallyworld/lazr-js/activator-flash-node
Reviewer Review Type Date Requested Status
Deryck Hodge (community) code Approve
Review via email: mp+53349@code.launchpad.net

Commit message

[r=deryck][bug=735832] Add support to the Activator for a custom animation node to be specified for success, failure or cancellation.

Description of the change

The branch adds support to the Activator for a custom animation node to be specified for success, failure or cancellation.

The default behaviour is to animate the content_box node but this is not always sufficient to get the correct items being flashed. Depending on the HTML inside the content box, it may be necessary to specify a custom node to animate to get the desired effect.

A new Activator config parameter - animationNode - is supported. If undefined, the content box is used.

== Tests ==

A new test_correct_animation_node() test was added.

== Lint ==

jslint: 2 files to lint.
jslint: No problem found in '/home/ian/projects/lazrjs-branches/devel/src-js/lazrjs/activator/activator.js'.

jslint: No problem found in '/home/ian/projects/lazrjs-branches/devel/src-js/lazrjs/activator/tests/activator.js'.

To post a comment you must log in.
207. By Ian Booth

Lint

Revision history for this message
Deryck Hodge (deryck) wrote :

This looks good, thanks!

I'll just not for future reference that the activator widget breaks from good YUI widget design, by declaring all attributes local on "this". The ATTRS object is unused -- i.e. this.some_node rather than this.get('some_node'). It's fine how you've done your code, following the pattern already there, but good widget design would store this node in ATTRS and take advantage of YUI's widget framework. Most of the other widgets do this correctly in lazr-js.

As I say, the way you've done it here is fine. Just wanted you to know, if you didn't already. I wouldn't ask you to refactor the widget to follow the others, just for this simple change.

Cheers,
deryck

review: Approve (code)
208. By Ian Booth

Formatting fix

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/activator/index.html'
--- examples/activator/index.html 2011-01-14 17:34:54 +0000
+++ examples/activator/index.html 2011-03-16 00:09:14 +0000
@@ -35,6 +35,13 @@
35 var activator = new Y.lazr.activator.Activator(35 var activator = new Y.lazr.activator.Activator(
36 {contentBox: content_box});36 {contentBox: content_box});
3737
38 // Optionally, it's possible to specify a custom node to animate on
39 // success, failure, or cancellation. The default is to use the
40 // content_box but depending on the HTML inside the content box, we may
41 // need to specify a different node to get the required animation.
42 //var activator = new Y.lazr.activator.Activator(
43 // {contentBox: content_box, animationNode: custom_node});
44
38 activator.subscribe('act', function (e) {45 activator.subscribe('act', function (e) {
39 editor.setStyle('visibility', 'visible');46 editor.setStyle('visibility', 'visible');
40 });47 });
@@ -221,6 +228,15 @@
221228
222</ul>229</ul>
223230
231<p>Optionally, these DOM elements can be specified:</p>
232
233<ul>
234 <li><strong>Animation node:</strong>
235 A node that is animated on success, failure, or cancellation. The default
236 is to use the content box node.
237 </li>
238</ul>
239
224<h3>Custom events</h3>240<h3>Custom events</h3>
225241
226<table>242<table>
227243
=== modified file 'src-js/lazrjs/activator/activator.js'
--- src-js/lazrjs/activator/activator.js 2010-04-13 13:02:44 +0000
+++ src-js/lazrjs/activator/activator.js 2011-03-16 00:09:14 +0000
@@ -156,7 +156,7 @@
156 }156 }
157 this._setStatusClass(C_SUCCESS);157 this._setStatusClass(C_SUCCESS);
158 this._renderMessage('Message', message_node);158 this._renderMessage('Message', message_node);
159 var anim = Y.lazr.anim.green_flash({node: this.get('contentBox')});159 var anim = Y.lazr.anim.green_flash({node: this.animation_node});
160 anim.run();160 anim.run();
161 },161 },
162162
@@ -170,7 +170,7 @@
170 renderFailure: function(message_node) {170 renderFailure: function(message_node) {
171 this._renderMessage('Error', message_node);171 this._renderMessage('Error', message_node);
172 this._setStatusClass(C_FAILURE);172 this._setStatusClass(C_FAILURE);
173 var anim = Y.lazr.anim.red_flash({node: this.get('contentBox')});173 var anim = Y.lazr.anim.red_flash({node: this.animation_node});
174 anim.run();174 anim.run();
175 },175 },
176176
@@ -184,7 +184,7 @@
184 renderCancellation: function(message_node) {184 renderCancellation: function(message_node) {
185 this._renderMessage('Message', message_node);185 this._renderMessage('Message', message_node);
186 this._setStatusClass(C_CANCEL);186 this._setStatusClass(C_CANCEL);
187 var anim = Y.lazr.anim.red_flash({node: this.get('contentBox')});187 var anim = Y.lazr.anim.red_flash({node: this.animation_node});
188 anim.run();188 anim.run();
189 },189 },
190190
@@ -231,6 +231,10 @@
231 throw new Error("Can't find element with CSS class " +231 throw new Error("Can't find element with CSS class " +
232 C_ACT + ".");232 C_ACT + ".");
233 }233 }
234 this.animation_node = cfg.animationNode;
235 if (this.animation_node === undefined) {
236 this.animation_node = this.get('contentBox');
237 }
234 },238 },
235239
236 /**240 /**
237241
=== modified file 'src-js/lazrjs/activator/tests/activator.js'
--- src-js/lazrjs/activator/tests/activator.js 2011-01-14 17:13:05 +0000
+++ src-js/lazrjs/activator/tests/activator.js 2011-03-16 00:09:14 +0000
@@ -46,6 +46,7 @@
46 }46 }
47 this.workspace.appendChild(Y.Node.create(47 this.workspace.appendChild(Y.Node.create(
48 '<div id="example-1">' +48 '<div id="example-1">' +
49 '<div id="custom-animation-node"/>' +
49 '<span class="yui3-activator-data-box">' +50 '<span class="yui3-activator-data-box">' +
50 ' Original Value' +51 ' Original Value' +
51 '</span>' +52 '</span>' +
@@ -67,6 +68,18 @@
67 this.workspace.set('innerHTML', '');68 this.workspace.set('innerHTML', '');
68 },69 },
6970
71 test_correct_animation_node: function() {
72 // Check that the correct animation node is used.
73 // First check the default.
74 Assert.areEqual(this.activator.get('contentBox'),
75 this.activator.animation_node);
76 // Now check a custom one.
77 var custom_node = Y.one('#custom-animation-node');
78 this.activator = new Y.lazr.activator.Activator(
79 {contentBox: Y.one('#example-1'), animationNode: custom_node});
80s Assert.areEqual(custom_node, this.activator.animation_node);
81 },
82
70 test_unhiding_action_button: function() {83 test_unhiding_action_button: function() {
71 this.action_button.addClass('yui3-activator-hidden');84 this.action_button.addClass('yui3-activator-hidden');
72 Assert.isTrue(this.action_button.hasClass('yui3-activator-hidden'));85 Assert.isTrue(this.action_button.hasClass('yui3-activator-hidden'));

Subscribers

People subscribed via source and target branches