Merge lp:~rvb/maas/reveal-bug into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1414
Proposed branch: lp:~rvb/maas/reveal-bug
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 52 lines (+20/-1)
2 files modified
src/maasserver/static/js/reveal.js (+9/-1)
src/maasserver/static/js/tests/test_reveal.js (+11/-0)
To merge this branch: bzr merge lp:~rvb/maas/reveal-bug
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+140860@code.launchpad.net

Commit message

Fix computation of height in reveal.js (take margin and padding into account).

Description of the change

The reveal.js module was computing the height of the 'revealed' panel incorrectly, not taking into account the padding and the margin. This branch fixes that.

Here is how it looks with that fix: http://people.canonical.com/~rvb/new_com_scripts_view.png.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

The screenshot is a nice touch. I tried to find some helpful utility function or attribute in YUI to simplify this job, but the documentation was so terse it was just meaningless to me. Might be docHeight, for instance, but it might not. :(

One question: should this really include the margin? It seems a bit "greedy" to take that space too. Then again I guess it depends on the page.

review: Approve
Revision history for this message
Raphaël Badin (rvb) wrote :

Thanks for the review.

> The screenshot is a nice touch. I tried to find some helpful utility function
> or attribute in YUI to simplify this job, but the documentation was so terse
> it was just meaningless to me. Might be docHeight, for instance, but it might
> not. :(

Yeah, I had the same reaction but I did not find any shortcut, I even found some that was doing exactly what I'm doing here: adding all the heights.

> One question: should this really include the margin? It seems a bit "greedy"
> to take that space too. Then again I guess it depends on the page.

In this case we have to include the margin because the HTML we're dealing with is like this:
<span class="ahah">
   <pre class="content"></pre>
<span>
And what we're doing is that we set the height of '.ahah' based on the height (and now margin and padding to) of '.content'.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/static/js/reveal.js'
2--- src/maasserver/static/js/reveal.js 2012-12-04 01:43:12 +0000
3+++ src/maasserver/static/js/reveal.js 2012-12-20 10:54:22 +0000
4@@ -85,10 +85,18 @@
5 * @method _create_slide_out
6 */
7 module._create_slide_out = function(node, publisher) {
8+ var content_node = node.one('.content');
9+ var height = parseInt(content_node.getStyle('height'));
10+ var padding_top = parseInt(content_node.getStyle('paddingTop'));
11+ var padding_bottom = parseInt(content_node.getStyle('paddingBottom'));
12+ var margin_top = parseInt(content_node.getStyle('marginTop'));
13+ var margin_bottom = parseInt(content_node.getStyle('marginBottom'));
14+ var new_height = (
15+ height + padding_top + padding_bottom + margin_top + margin_bottom);
16 var anim = new Y.Anim({
17 node: node,
18 duration: 0.2,
19- to: {height: parseInt(node.one('.content').getStyle('height'))}
20+ to: {height: new_height}
21 });
22 anim.on('end', function () {
23 publisher.fire('revealed');
24
25=== modified file 'src/maasserver/static/js/tests/test_reveal.js'
26--- src/maasserver/static/js/tests/test_reveal.js 2012-12-02 16:44:19 +0000
27+++ src/maasserver/static/js/tests/test_reveal.js 2012-12-20 10:54:22 +0000
28@@ -24,6 +24,12 @@
29 },
30
31 test_slides_out: function() {
32+ var original_height = (
33+ parseInt(Y.one('.panel .content').getStyle('height')) +
34+ parseInt(Y.one('.panel .content').getStyle('marginTop')) +
35+ parseInt(Y.one('.panel .content').getStyle('marginBottom')) +
36+ parseInt(Y.one('.panel .content').getStyle('paddingTop')) +
37+ parseInt(Y.one('.panel .content').getStyle('paddingBottom')));
38 Y.one('.panel').setStyle('height', '0');
39 Y.one('.link').set('text', 'View log');
40 Y.Assert.areEqual('View log', Y.one('.link').get('text'));
41@@ -36,6 +42,11 @@
42 parseInt(Y.one('.panel').getStyle('height')) > 0,
43 'The panel should be revealed'
44 );
45+ Y.Assert.areEqual(
46+ original_height,
47+ parseInt(Y.one('.panel').getStyle('height')),
48+ 'The panel has not been resized properly'
49+ );
50 Y.Assert.areEqual('Hide log', Y.one('.link').get('text'));
51 });
52 });