Skip to content

Commit 5e4f449

Browse files
committed
Improve browser compatibility of pat-modal.
1 parent 96beda2 commit 5e4f449

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

src/pat/modal.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ define([
6666
},
6767

6868
setPosition: function() {
69+
// bail if repositioning already in progress
70+
if ($('#pat-modal-clone').length > 0) {
71+
return;
72+
}
73+
6974
var $el = $('div.pat-modal,#pat-modal'),
7075
maxHeight = $(window).innerHeight() - $el.outerHeight(true) +
7176
$el.outerHeight();
@@ -74,13 +79,42 @@ define([
7479
return;
7580
}
7681

77-
// set max-height first, then measure and change if necessary
78-
$el.css('max-height', maxHeight).css('height', '');
79-
if (maxHeight - $el.outerHeight() < 0) {
82+
var $clone = $el.clone();
83+
84+
$clone
85+
.attr('id', 'pat-modal-clone')
86+
.css({
87+
'visibility': 'hidden',
88+
'position': 'absolute',
89+
'height': '',
90+
'max-height': maxHeight
91+
}).appendTo('body');
92+
93+
// wait for browser to update DOM
94+
setTimeout(modal.measure, 0);
95+
},
96+
97+
measure: function() {
98+
var $el = $('div.pat-modal,#pat-modal'),
99+
$clone = $('#pat-modal-clone'),
100+
maxHeight = $(window).innerHeight() - $clone.outerHeight(true) +
101+
$clone.outerHeight(),
102+
height = $clone.outerHeight();
103+
104+
$clone.remove();
105+
106+
if (maxHeight - height < 0) {
80107
$el.addClass('max-height')
81-
.css('height', maxHeight).css('max-height', '');
108+
.css({
109+
'height': maxHeight,
110+
'max-height': ''
111+
});
82112
} else {
83-
$el.removeClass('max-height');
113+
$el.removeClass('max-height')
114+
.css({
115+
'height': '',
116+
'max-height': maxHeight
117+
});
84118
}
85119

86120
var top = ($(window).innerHeight() - $el.outerHeight(true)) / 2;

0 commit comments

Comments
 (0)