Do not set offset initially, sometimes ended up overflowing parent element.

Do calculation before setting popup offset.
HFJ-1867
pull/23/head
Thomas Marstrander 2016-05-04 11:53:46 +02:00
parent 6e7e144900
commit 7782b19e99
1 changed files with 6 additions and 3 deletions

View File

@ -154,9 +154,13 @@ H5P.ConfirmationDialog = (function (EventDispatcher) {
/** /**
* Fit popup to container. Makes sure it doesn't overflow. * Fit popup to container. Makes sure it doesn't overflow.
* @params {number} [offsetTop] Offset of popup
*/ */
var fitToContainer = function () { var fitToContainer = function (offsetTop) {
var popupOffsetTop = parseInt(popup.style.top, 10); var popupOffsetTop = parseInt(popup.style.top, 10);
if (offsetTop) {
popupOffsetTop = offsetTop;
}
// Overflows height // Overflows height
if (popupOffsetTop + popup.offsetHeight > wrapperElement.offsetHeight) { if (popupOffsetTop + popup.offsetHeight > wrapperElement.offsetHeight) {
@ -178,9 +182,8 @@ H5P.ConfirmationDialog = (function (EventDispatcher) {
* @returns {H5P.ConfirmationDialog} * @returns {H5P.ConfirmationDialog}
*/ */
this.show = function (offsetTop) { this.show = function (offsetTop) {
popup.style.top = offsetTop + 'px';
popupBackground.classList.remove('hidden'); popupBackground.classList.remove('hidden');
fitToContainer(); fitToContainer(offsetTop);
setTimeout(function () { setTimeout(function () {
popup.classList.remove('hidden'); popup.classList.remove('hidden');
popupBackground.classList.remove('hiding'); popupBackground.classList.remove('hiding');