From ae68564e883f78fbd7987d03af6c5895b7ec512c Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Thu, 2 Jul 2015 11:41:37 -0400 Subject: [PATCH] Use an array comparison to check for a valid parent position rather than three separate comparisons --- contain-element.js | 2 +- contain-element.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contain-element.js b/contain-element.js index 30df6fe..6f4d7ae 100644 --- a/contain-element.js +++ b/contain-element.js @@ -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() { diff --git a/contain-element.min.js b/contain-element.min.js index 5ed52f3..aa43655 100644 --- a/contain-element.min.js +++ b/contain-element.min.js @@ -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} \ No newline at end of file +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} \ No newline at end of file