-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjectFitPolyfill.basic.min.js
executable file
·1 lines (1 loc) · 1.92 KB
/
objectFitPolyfill.basic.min.js
1
!function(){"use strict";if("undefined"!=typeof window){var t=-1!==window.navigator.userAgent.indexOf("Edge/16.");if("objectFit"in document.documentElement.style!=!1&&!t)return void(window.objectFitPolyfill=function(){return!1});var e=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")},i=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])}},n=function(t){var n=t.parentNode;e(n),i(t),t.style.position="absolute",t.style.height="100%",t.style.width="auto",t.clientWidth>n.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")},o=function(e){if(void 0===e)e=document.querySelectorAll("[data-object-fit]");else if(e&&e.nodeName)e=[e];else{if("object"!=typeof e||!e.length||!e[0].nodeName)return!1;e=e}for(var i=0;i<e.length;i++)if(e[i].nodeName){var o=e[i].nodeName.toLowerCase();"img"!==o||t?"video"===o&&(e[i].readyState>0?n(e[i]):e[i].addEventListener("loadedmetadata",function(){n(this)})):e[i].complete?n(e[i]):e[i].addEventListener("load",function(){n(this)})}return!0};document.addEventListener("DOMContentLoaded",function(){o()}),window.addEventListener("resize",function(){o()}),window.objectFitPolyfill=o}}();