Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 2857627

Browse files
author
Yvonne Yip
committed
polymer-overlay: auto horizontal centering
1 parent 034f5a9 commit 2857627

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

polymer-overlay/polymer-overlay.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,20 @@
249249
}
250250
},
251251
positionTarget: function() {
252-
var computedStyle = getComputedStyle(this.target);
253-
if (this.opened && computedStyle.top === 'auto' && computedStyle.bottom === 'auto') {
254-
this.target.style.top = ((window.innerHeight - this.target.getBoundingClientRect().height) / 2) + 'px';
252+
if (this.opened) {
253+
// vertically and horizontally center if not positioned
254+
var computedStyle = getComputedStyle(this.target);
255+
if (computedStyle.top === 'auto' && computedStyle.bottom === 'auto') {
256+
this.target.style.top = ((window.innerHeight - this.target.getBoundingClientRect().height) / 2) + 'px';
257+
}
258+
if (computedStyle.left === 'auto' && computedStyle.right === 'auto') {
259+
this.target.style.left = ((window.innerWidth - this.target.getBoundingClientRect().width) / 2) + 'px';
260+
}
255261
}
256262
},
263+
resetTargetPosition: function() {
264+
this.target.style.top = this.target.style.left = null;
265+
},
257266
renderOpened: function() {
258267
this.target.classList.remove('closing');
259268
this.target.classList.add('revealed');
@@ -272,6 +281,9 @@
272281
this.animating = null;
273282
this.target.classList.remove('closing');
274283
this.target.classList.toggle('revealed', this.opened);
284+
if (!this.opened) {
285+
this.resetTargetPosition();
286+
}
275287
this.applyFocus();
276288
},
277289
openedAnimationEnd: function(e) {

0 commit comments

Comments
 (0)