From 7a59f6bc3cd4e9d1981edd722d52ab4b9506a36e Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Fri, 4 Sep 2015 14:26:56 -0400 Subject: [PATCH] Add a function to return the current scale factor of the contained element --- README.md | 6 +++++- contain-element.js | 3 +++ contain-element.min.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fde8291..c4a1021 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ The plugin scales an element to the minimum size required for it to be completel * Pure JavaScript with no dependencies * Configures the horizontal and vertical alignment of the contained element * Can detect the native size or have it specified at runtime -* Includes function to update the size and position ## Usage @@ -35,6 +34,11 @@ window.onload = function() { }; ``` +## Functions + +* `update()`: Update the size and position of the contained element. +* `getScale()`: Return the current scale factor being applied to the contained element. + ## Credits Written by [Williams New York](http://williamsnewyork.com) diff --git a/contain-element.js b/contain-element.js index 31d0771..331e30e 100644 --- a/contain-element.js +++ b/contain-element.js @@ -74,5 +74,8 @@ function ContainElement(options) { // Add an external scale and anchor update function this.update = updateContain; + + // Add function to return the current scale factor + this.getScale = function() { return scaleFactor; }; } diff --git a/contain-element.min.js b/contain-element.min.js index c9073f6..ff0aa91 100644 --- a/contain-element.min.js +++ b/contain-element.min.js @@ -1 +1 @@ -function ContainElement(e){function t(){var n=i.parentElement.offsetWidth,a=i.parentElement.offsetHeight;if(n&&a){if(l=n>a/(o*l)*s*l?n/s:a/o,i.style.width=s*l+"px",i.style.height=o*l+"px",s*l>n)switch(e.halign){case"left":i.style.left="0px";break;case"right":i.style.left=0-(s*l-n)+"px";break;default:i.style.left=0-(s*l-n)/2+"px"}else i.style.left="0px";if(o*l>a)switch(e.valign){case"top":i.style.top="0px";break;case"bottom":i.style.top=0-(o*l-a)+"px";break;default:i.style.top=0-(o*l-a)/2+"px"}else i.style.top="0px"}else window.setTimeout(t,30)}var l=1,i=document.getElementById(e.id),s=e.width||i.offsetWidth,o=e.height||i.offsetHeight;i.style.position="absolute",i.parentElement.style.overflow="hidden",-1===["relative","absolute","fixed"].indexOf(window.getComputedStyle(i.parentElement,null).getPropertyValue("position"))&&(i.parentElement.style.position="relative"),t(),this.update=t} \ No newline at end of file +function ContainElement(e){function t(){var o=i.parentElement.offsetWidth,a=i.parentElement.offsetHeight;if(o&&a){if(l=o>a/(n*l)*s*l?o/s:a/n,i.style.width=s*l+"px",i.style.height=n*l+"px",s*l>o)switch(e.halign){case"left":i.style.left="0px";break;case"right":i.style.left=0-(s*l-o)+"px";break;default:i.style.left=0-(s*l-o)/2+"px"}else i.style.left="0px";if(n*l>a)switch(e.valign){case"top":i.style.top="0px";break;case"bottom":i.style.top=0-(n*l-a)+"px";break;default:i.style.top=0-(n*l-a)/2+"px"}else i.style.top="0px"}else window.setTimeout(t,30)}var l=1,i=document.getElementById(e.id),s=e.width||i.offsetWidth,n=e.height||i.offsetHeight;i.style.position="absolute",i.parentElement.style.overflow="hidden",-1===["relative","absolute","fixed"].indexOf(window.getComputedStyle(i.parentElement,null).getPropertyValue("position"))&&(i.parentElement.style.position="relative"),t(),this.update=t,this.getScale=function(){return l}} \ No newline at end of file