1
/*! npm.im/object-fit-images 3.2.4 */
2
var objectFitImages=function(){"use strict";var OFI="bfred-it:object-fit-images",propRegex=/(object-fit|object-position)\s*:\s*([-.\w\s%]+)/g,testImg="undefined"==typeof Image?{style:{"object-position":1}
3
}
4
:new Image,supportsObjectFit="object-fit"in testImg.style,supportsObjectPosition="object-position"in testImg.style,supportsOFI="background-size"in testImg.style,supportsCurrentSrc="string"==typeof testImg.currentSrc,nativeGetAttribute=testImg.getAttribute,nativeSetAttribute=testImg.setAttribute,autoModeEnabled=!1;function setPlaceholder(img,width,height){var placeholder="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='"+(width||1)+"' height='"+(height||0)+"'%3E%3C/svg%3E";nativeGetAttribute.call(img,"src")!==placeholder&&nativeSetAttribute.call(img,"src",placeholder)}
5
function onImageReady(img,callback){img.naturalWidth?callback(img):setTimeout(onImageReady,100,img,callback)}
6
function fixOne(el){var style=function(el){for(var parsed,style=getComputedStyle(el).fontFamily,props={}
7
;null!==(parsed=propRegex.exec(style));)props[parsed[1]]=parsed[2];return props}
8
(el),ofi=el[OFI];if(style["object-fit"]=style["object-fit"]||"fill",!ofi.img){if("fill"===style["object-fit"])return;if(!ofi.skipTest&&supportsObjectFit&&!style["object-position"])return}
9
if(!ofi.img){ofi.img=new Image(el.width,el.height),ofi.img.srcset=nativeGetAttribute.call(el,"data-ofi-srcset")||el.srcset,ofi.img.src=nativeGetAttribute.call(el,"data-ofi-src")||el.src,nativeSetAttribute.call(el,"data-ofi-src",el.src),el.srcset&&nativeSetAttribute.call(el,"data-ofi-srcset",el.srcset),setPlaceholder(el,el.naturalWidth||el.width,el.naturalHeight||el.height),el.srcset&&(el.srcset="");try{!function(el){var descriptors={get:function(prop){return el[OFI].img[prop||"src"]}
10
,set:function(value,prop){return el[OFI].img[prop||"src"]=value,nativeSetAttribute.call(el,"data-ofi-"+prop,value),fixOne(el),value}
11
}
12
;Object.defineProperty(el,"src",descriptors),Object.defineProperty(el,"currentSrc",{get:function(){return descriptors.get("currentSrc")}
13
}
14
),Object.defineProperty(el,"srcset",{get:function(){return descriptors.get("srcset")}
15
,set:function(ss){return descriptors.set(ss,"srcset")}
16
}
17
)}
18
(el)}
19
catch(err){window.console&&console.warn("https://bit.ly/ofi-old-browser")}
20
}
21
!function(el){if(el.srcset&&!supportsCurrentSrc&&window.picturefill){var pf=window.picturefill._;el[pf.ns]&&el[pf.ns].evaled||pf.fillImg(el,{reselect:!0}
22
),el[pf.ns].curSrc||(el[pf.ns].supported=!1,pf.fillImg(el,{reselect:!0}
23
)),el.currentSrc=el[pf.ns].curSrc||el.src}
24
}
25
(ofi.img),el.style.backgroundImage='url("'+(ofi.img.currentSrc||ofi.img.src).replace(/"/g,'\\"')+'")',el.style.backgroundPosition=style["object-position"]||"center",el.style.backgroundRepeat="no-repeat",el.style.backgroundOrigin="content-box",/scale-down/.test(style["object-fit"])?onImageReady(ofi.img,(function(){ofi.img.naturalWidth>el.width||ofi.img.naturalHeight>el.height?el.style.backgroundSize="contain":el.style.backgroundSize="auto"}
26
)):el.style.backgroundSize=style["object-fit"].replace("none","auto").replace("fill","100% 100%"),onImageReady(ofi.img,(function(img){setPlaceholder(el,img.naturalWidth,img.naturalHeight)}
27
))}
28
function fix(imgs,opts){var startAutoMode=!autoModeEnabled&&!imgs;if(opts=opts||{}
29
,imgs=imgs||"img",supportsObjectPosition&&!opts.skipTest||!supportsOFI)return!1;"img"===imgs?imgs=document.getElementsByTagName("img"):"string"==typeof imgs?imgs=document.querySelectorAll(imgs):"length"in imgs||(imgs=[imgs]);for(var i=0;i<imgs.length;i++)imgs[i][OFI]=imgs[i][OFI]||{skipTest:opts.skipTest}
30
,fixOne(imgs[i]);startAutoMode&&(document.body.addEventListener("load",(function(e){"IMG"===e.target.tagName&&fix(e.target,{skipTest:opts.skipTest}
31
)}
32
),!0),autoModeEnabled=!0,imgs="img"),opts.watchMQ&&window.addEventListener("resize",fix.bind(null,imgs,{skipTest:opts.skipTest}
33
))}
34
return fix.supportsObjectFit=supportsObjectFit,fix.supportsObjectPosition=supportsObjectPosition,function(){function getOfiImageMaybe(el,name){return el[OFI]&&el[OFI].img&&("src"===name||"srcset"===name)?el[OFI].img:el}
35
supportsObjectPosition||(HTMLImageElement.prototype.getAttribute=function(name){return nativeGetAttribute.call(getOfiImageMaybe(this,name),name)}
36
,HTMLImageElement.prototype.setAttribute=function(name,value){return nativeSetAttribute.call(getOfiImageMaybe(this,name),name,String(value))}
37
)}
38
(),fix}
39
();
40
//# sourceURL=https://cdn2.hubspot.net/hub/20293962/hub_generated/template_assets/50308538530/1644250293096/DD_Theme/assets/js/object-fit-polyfill.js