From: Elias Fleckenstein Date: Fri, 4 Jun 2021 16:21:25 +0000 (+0200) Subject: Fix dblib.centerVertical when the parent element is the body X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=f2c5fa4710bd40c728fcef56498f87d83b203d1d;p=dragonblocks.git Fix dblib.centerVertical when the parent element is the body --- diff --git a/lib/dblib.js b/lib/dblib.js index f167d51..df2189b 100755 --- a/lib/dblib.js +++ b/lib/dblib.js @@ -4,7 +4,10 @@ class dblib{ elem.style.left = elem.parentNode.clientWidth / 2 - parseInt(elem.clientWidth) / 2 + "px"; } static centerVertical(elem){ - elem.style.top = elem.parentNode.clientHeight / 2 - parseInt(elem.clientHeight) / 2 + "px"; + let parent = elem.parentNode; + if (parent == document.body) + parent = document.documentElement; + elem.style.top = parent.clientHeight / 2 - parseInt(elem.clientHeight) / 2 + "px"; } static remove(elem){ if(elem) @@ -16,7 +19,7 @@ class dblib{ static humanFormat(str){ var str = str.replace("_", " "); str = str[0].toUpperCase() + str.slice(1, str.length); - return str; + return str; } static copy(dest, src){ for(let prop in src){ @@ -64,7 +67,7 @@ class dblib{ if(obj[prop] === search) obj[prop] = replace; else if(obj[prop] instanceof Object) - obj[prop] = this.replaceRecursive(obj[prop], search, replace); + obj[prop] = this.replaceRecursive(obj[prop], search, replace); } return obj; }