Skip to content

Commit 428d7fe

Browse files
committed
materialbox tests added and overlay with transformed ancestor bug fixed
1 parent 53eaec4 commit 428d7fe

File tree

11 files changed

+80
-21
lines changed

11 files changed

+80
-21
lines changed

_SpecRunner.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
<script src="tests/spec/collapsible/collapsibleSpec.js"></script>
3838

39+
<script src="tests/spec/materialbox/materialboxSpec.js"></script>
40+
3941
<script src="tests/spec/scrollFire/scrollFireSpec.js"></script>
4042

4143
<script src="tests/spec/select/selectSpec.js"></script>

bin/materialize.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5649,9 +5649,9 @@ button.btn-floating {
56495649
#materialbox-overlay {
56505650
position: fixed;
56515651
top: 0;
5652-
left: 0;
56535652
right: 0;
56545653
bottom: 0;
5654+
left: 0;
56555655
background-color: #292929;
56565656
z-index: 1000;
56575657
will-change: opacity;

bin/materialize.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/ghpages-materialize.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/materialbox.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,21 @@
9292
if (doneAnimating === true)
9393
returnToOriginal();
9494
});
95-
// Animate Overlay
96-
// Put before in origin image to preserve z-index layering.
97-
origin.before(overlay);
98-
overlay.velocity({opacity: 1},
95+
96+
// Put before in origin image to preserve z-index layering.
97+
origin.before(overlay);
98+
99+
// Set dimensions if needed
100+
var overlayOffset = overlay[0].getBoundingClientRect();
101+
overlay.css({
102+
width: windowWidth,
103+
height: windowHeight,
104+
left: -1 * overlayOffset.left,
105+
top: -1 * overlayOffset.top
106+
})
107+
108+
// Animate Overlay
109+
overlay.velocity({opacity: 1},
99110
{duration: inDuration, queue: false, easing: 'easeOutQuad'} );
100111

101112
// Add and animate caption if it exists

sass.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,4 @@ <h5 class="white-text">Connect</h5>
336336
</script>
337337

338338
</body>
339-
</html>
339+
</html>

sass/components/_materialbox.scss

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
.materialboxed {
2+
&:hover {
3+
&:not(.active) {
4+
opacity: .8;
5+
}
6+
}
7+
28
display: block;
39
cursor: zoom-in;
410
position: relative;
511
transition: opacity .4s;
612
-webkit-backface-visibility: hidden;
713

8-
&:hover {
9-
&:not(.active) {
10-
opacity: .8;
11-
}
14+
&.active {
15+
cursor: zoom-out;
1216
}
1317
}
1418

15-
.materialboxed.active {
16-
cursor: zoom-out;
17-
}
18-
1919
#materialbox-overlay {
2020
position:fixed;
21-
top:0;
22-
left:0;
21+
top: 0;
2322
right: 0;
2423
bottom: 0;
24+
left: 0;
25+
2526
background-color: #292929;
2627
z-index: 1000;
27-
2828
will-change: opacity;
2929
}
30+
3031
.materialbox-caption {
3132
position: fixed;
3233
display: none;

side-nav.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,4 @@ <h5 class="white-text">Connect</h5>
361361
</script>
362362

363363
</body>
364-
</html>
364+
</html>

test/html/materialbox.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
</div>
4949
</div>
5050

51+
<div class="row">
52+
53+
<div class="col s6 right">
54+
<div style="transform: translate3d(1px,1px,1px)">
55+
<h3>Materialbox inside transformed parent</h3>
56+
<img materialize="" class="materialboxed" width="650" src="https://images.unsplash.com/photo-1439694458393-78ecf14da7f9?q=80&fm=jpg&s=643e44f5177366de6cc914c8bcfbe064">
57+
</div>
58+
</div>
59+
</div>
5160

5261

5362
<ul id="slide-out" class="side-nav fixed rtl grey darken-3 white-text center row">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div id="transformTest" style="transform: translate3d(1px,1px,1px)">
2+
<img class="materialboxed" width="650" src="https://images.unsplash.com/photo-1439694458393-78ecf14da7f9?q=80&fm=jpg&s=643e44f5177366de6cc914c8bcfbe064">
3+
</div>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
describe( 'Materialbox:', function() {
2+
var transformMaterialbox;
3+
4+
beforeEach(function() {
5+
loadFixtures('materialbox/materialboxFixture.html');
6+
});
7+
8+
describe('Materialbox opens correctly with transformed ancestor', function() {
9+
it('Opens a correctly placed overlay when clicked', function(done) {
10+
transformMaterialbox = $('#transformTest');
11+
$('.materialboxed').materialbox();
12+
13+
// Mouse click
14+
transformMaterialbox.find('.materialboxed').trigger('click');
15+
setTimeout(function() {
16+
// Check overlay is attached
17+
var overlay = transformMaterialbox.find('#materialbox-overlay');
18+
var overlayRect = overlay[0].getBoundingClientRect();
19+
var windowWidth = window.innerWidth;
20+
var windowHeight = window.innerHeight;
21+
expect(overlay).toExist('because it is generated on init');
22+
expect(overlay).toBeVisible('because materialbox was clicked');
23+
expect(overlayRect.top).toEqual(0);
24+
expect(overlayRect.left).toEqual(0);
25+
expect(overlayRect.width).toEqual(windowWidth);
26+
expect(overlayRect.height).toEqual(windowHeight);
27+
28+
done();
29+
}, 1000);
30+
});
31+
});
32+
33+
});

0 commit comments

Comments
 (0)