Use an array comparison to check for a valid parent position rather than three separate comparisons

This commit is contained in:
Kevin MacMartin 2015-07-02 11:41:37 -04:00
parent 5226ead17d
commit ae68564e88
2 changed files with 2 additions and 2 deletions

View file

@ -9,7 +9,7 @@ function ContainElement(options) {
element.style.position = 'absolute';
if (element.parentElement.style.overflow != 'hidden')
element.parentElement.style.overflow = 'hidden';
if (element.parentElement.style.position != 'relative' && element.parentElement.style.position != 'absolute' && element.parentElement.style.position != 'fixed')
if (['relative', 'absolute', 'fixed'].indexOf(element.parentElement.style.position) === -1)
element.parentElement.style.position = 'relative';
function updateContain() {

View file

@ -1 +1 @@
function ContainElement(e){function t(){var o=s.parentElement.offsetWidth,p=s.parentElement.offsetHeight;if(o&&p){if(l=o>p/(n*l)*i*l?o/i:p/n,s.style.width=i*l+"px",s.style.height=n*l+"px",i*l>o)switch(e.halign){case"left":s.style.left="0px";break;case"right":s.style.left=0-(i*l-o)+"px";break;default:s.style.left=0-(i*l-o)/2+"px"}else s.style.left="0px";if(n*l>p)switch(e.valign){case"top":s.style.top="0px";break;case"bottom":s.style.top=0-(n*l-p)+"px";break;default:s.style.top=0-(n*l-p)/2+"px"}else s.style.top="0px"}else window.setTimeout(t,30)}var l=1,s=document.getElementById(e.id),i=e.width||s.offsetWidth,n=e.height||s.offsetHeight;"absolute"!=s.style.position&&(s.style.position="absolute"),"hidden"!=s.parentElement.style.overflow&&(s.parentElement.style.overflow="hidden"),"relative"!=s.parentElement.style.position&&"absolute"!=s.parentElement.style.position&&"fixed"!=s.parentElement.style.position&&(s.parentElement.style.position="relative"),t(),this.update=t}
function ContainElement(e){function t(){var n=s.parentElement.offsetWidth,a=s.parentElement.offsetHeight;if(n&&a){if(l=n>a/(o*l)*i*l?n/i:a/o,s.style.width=i*l+"px",s.style.height=o*l+"px",i*l>n)switch(e.halign){case"left":s.style.left="0px";break;case"right":s.style.left=0-(i*l-n)+"px";break;default:s.style.left=0-(i*l-n)/2+"px"}else s.style.left="0px";if(o*l>a)switch(e.valign){case"top":s.style.top="0px";break;case"bottom":s.style.top=0-(o*l-a)+"px";break;default:s.style.top=0-(o*l-a)/2+"px"}else s.style.top="0px"}else window.setTimeout(t,30)}var l=1,s=document.getElementById(e.id),i=e.width||s.offsetWidth,o=e.height||s.offsetHeight;"absolute"!=s.style.position&&(s.style.position="absolute"),"hidden"!=s.parentElement.style.overflow&&(s.parentElement.style.overflow="hidden"),-1===["relative","absolute","fixed"].indexOf(s.parentElement.style.position)&&(s.parentElement.style.position="relative"),t(),this.update=t}