diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 0000000..b1f7ef2
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1,2 @@
+node_modules
+dist
diff --git a/.prettierrc b/.prettierrc
new file mode 100755
index 0000000..51727a1
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,7 @@
+{
+ "printWidth": 80,
+ "singleQuote": true,
+ "quote-props": "consistent",
+ "trailingComma": "es5",
+ "arrowParens": "always"
+}
diff --git a/README.md b/README.md
index 59b0b41..3195e8d 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
# object-fit-polyfill
+
A polyfill for browsers that don't support the `object-fit` CSS property. Unsure of what the `object-fit` does? Essentially `object-fit` is to `` tags what `background-size` is to `background-image`. You can check out the [MDN page](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) for more details.
## Features
@@ -38,20 +39,25 @@ Initialization:
```html
-
+
@@ -61,15 +67,33 @@ Customized object-fit/object-position:
```html
-
+
-
+
-
+
```
@@ -77,7 +101,12 @@ If you're only interested in using the basic polyfill (which assumes `object-fit
```html
-
+
diff --git a/demo/style.css b/demo/style.css
index 84a3914..4f3d7d7 100644
--- a/demo/style.css
+++ b/demo/style.css
@@ -1,7 +1,9 @@
-html, body {
+html,
+body {
margin: 0;
height: 100%;
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
+ Arial, sans-serif;
line-height: 1.5;
background-color: #111;
color: #fff;
@@ -9,7 +11,8 @@ html, body {
a {
color: inherit;
}
-h1, h2 {
+h1,
+h2 {
margin: 0;
}
@@ -20,7 +23,7 @@ h1, h2 {
.heading-intro {
position: relative;
top: 50%;
- background-color: rgba(0,0,0, 0.8);
+ background-color: rgba(0, 0, 0, 0.8);
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
@@ -31,7 +34,7 @@ h1, h2 {
*/
.clearfix::after {
- content: "";
+ content: '';
display: table;
clear: both;
}
diff --git a/dist/objectFitPolyfill.basic.min.js b/dist/objectFitPolyfill.basic.min.js
index d47e597..37aa0c8 100644
--- a/dist/objectFitPolyfill.basic.min.js
+++ b/dist/objectFitPolyfill.basic.min.js
@@ -1 +1 @@
-!function(){"use strict";if("undefined"!=typeof window){var t=window.navigator.userAgent.match(/Edge\/(\d{2})\./),n=!!t&&16<=parseInt(t[1],10);if("objectFit"in document.documentElement.style==!1||n){var o=function(t){var e=t.parentNode;!function(t){var e=window.getComputedStyle(t,null),i=e.getPropertyValue("position"),n=e.getPropertyValue("overflow"),o=e.getPropertyValue("display");i&&"static"!==i||(t.style.position="relative"),"hidden"!==n&&(t.style.overflow="hidden"),o&&"inline"!==o||(t.style.display="block"),0===t.clientHeight&&(t.style.height="100%"),-1===t.className.indexOf("object-fit-polyfill")&&(t.className=t.className+" object-fit-polyfill")}(e),function(t){var e=window.getComputedStyle(t,null),i={"max-width":"none","max-height":"none","min-width":"0px","min-height":"0px",top:"auto",right:"auto",bottom:"auto",left:"auto","margin-top":"0px","margin-right":"0px","margin-bottom":"0px","margin-left":"0px"};for(var n in i)e.getPropertyValue(n)!==i[n]&&(t.style[n]=i[n])}(t),t.style.position="absolute",t.style.height="100%",t.style.width="auto",t.clientWidth>e.clientWidth?(t.style.top="0",t.style.marginTop="0",t.style.left="50%",t.style.marginLeft=t.clientWidth/-2+"px"):(t.style.width="100%",t.style.height="auto",t.style.left="0",t.style.marginLeft="0",t.style.top="50%",t.style.marginTop=t.clientHeight/-2+"px")},e=function(t){if(void 0===t)t=document.querySelectorAll("[data-object-fit]");else if(t&&t.nodeName)t=[t];else{if("object"!=typeof t||!t.length||!t[0].nodeName)return!1;t=t}for(var e=0;ee.clientWidth?(t.style.top="0",t.style.marginTop="0",t.style.left="50%",t.style.marginLeft=t.clientWidth/-2+"px"):(t.style.width="100%",t.style.height="auto",t.style.left="0",t.style.marginLeft="0",t.style.top="50%",t.style.marginTop=t.clientHeight/-2+"px")},e=function(t){if(void 0===t)t=document.querySelectorAll("[data-object-fit]");else if(t&&t.nodeName)t=[t];else{if("object"!=typeof t||!t.length||!t[0].nodeName)return!1;t=t}for(var e=0;en.clientWidth||"contain"===e&&t.clientWidthn.clientWidth||"contain"===e&&t.clientWidth tags
// TODO: Keep an eye on Edge to determine which version has full final support
var edgeVersion = window.navigator.userAgent.match(/Edge\/(\d{2})\./);
- var edgePartialSupport = (edgeVersion) ? (parseInt(edgeVersion[1], 10) >= 16) : false;
+ var edgePartialSupport = edgeVersion
+ ? parseInt(edgeVersion[1], 10) >= 16
+ : false;
// If the browser does support object-fit, we don't need to continue
- if ("objectFit" in document.documentElement.style !== false && !edgePartialSupport) {
- window.objectFitPolyfill = function() { return false };
+ var hasSupport = 'objectFit' in document.documentElement.style !== false;
+ if (hasSupport && !edgePartialSupport) {
+ window.objectFitPolyfill = function() {
+ return false;
+ };
return;
}
@@ -37,28 +40,28 @@
*/
var checkParentContainer = function($container) {
var styles = window.getComputedStyle($container, null);
- var position = styles.getPropertyValue("position");
- var overflow = styles.getPropertyValue("overflow");
- var display = styles.getPropertyValue("display");
+ var position = styles.getPropertyValue('position');
+ var overflow = styles.getPropertyValue('overflow');
+ var display = styles.getPropertyValue('display');
- if (!position || position === "static") {
- $container.style.position = "relative";
+ if (!position || position === 'static') {
+ $container.style.position = 'relative';
}
- if (overflow !== "hidden") {
- $container.style.overflow = "hidden";
+ if (overflow !== 'hidden') {
+ $container.style.overflow = 'hidden';
}
// Guesstimating that people want the parent to act like full width/height wrapper here.
// Mostly attempts to target