From 970d0e5ca774bcec5cf8226a6672b2d576fbac53 Mon Sep 17 00:00:00 2001 From: Matt Olson Date: Thu, 8 Mar 2018 21:07:46 -0800 Subject: [PATCH 1/8] STRF-4599: Remove Modernizr * Modernizr is a blocking script that has very little benefit for us. Removing this script improves page responsiveness. * We used Modernizr via the css classes `csscolumns`, `flexbox`, `objectfit`, and `js`. * The `csscolumns` class was used for productMasonry for older browsers, but since then all of our supported browsers support css columns. There is one small problem with Firefox: it does not support break-inside, but it does support page-break-inside, which does the same thing. See https://caniuse.com/#feat=multicolumn * The `flexbox` class is unused * The `objectfit` class is used by carousel. Reimplmented without using Modernizer. The previous implmentation put a background image on the wrapper div and then hid it if object-fit is supported. The new implementation does not put the background image on the wrapper div by default, but instead assumes that your browser supports object-fit (all ours do except for IE). For IE, we use javascript to copy the image source from the image tag to the background image of the wrapper div and then hide the image. * The `js` class is used for a few things in css, so mimic this behavior with a simple inline script. --- assets/js/theme/common/carousel.js | 12 +++++ assets/modernizr-custom.js | 3 -- .../stencil/heroCarousel/_heroCarousel.scss | 50 +++++++++---------- .../scss/layouts/products/_productGrid.scss | 20 +------- templates/components/carousel.html | 3 +- templates/layout/amp-iframe.html | 6 ++- templates/layout/base.html | 6 ++- 7 files changed, 47 insertions(+), 53 deletions(-) delete mode 100644 assets/modernizr-custom.js diff --git a/assets/js/theme/common/carousel.js b/assets/js/theme/common/carousel.js index 7844286858..05048ea415 100644 --- a/assets/js/theme/common/carousel.js +++ b/assets/js/theme/common/carousel.js @@ -7,4 +7,16 @@ export default function () { if ($carousel.length) { $carousel.slick(); } + + // Alternative image styling for IE, which doesn't support objectfit + if (typeof document.documentElement.style.objectFit === 'undefined') { + $('.heroCarousel-slide').each(() => { + const $container = $(this); + const imgUrl = $container.find('img').data('lazy'); + + if (imgUrl) { + $container.css('backgroundImage', `url(${imgUrl})`).addClass('compat-object-fit'); + } + }); + } } diff --git a/assets/modernizr-custom.js b/assets/modernizr-custom.js deleted file mode 100644 index 06718abbb6..0000000000 --- a/assets/modernizr-custom.js +++ /dev/null @@ -1,3 +0,0 @@ -/*! modernizr 3.5.0 (Custom Build) | MIT * - * https://modernizr.com/download/?-csscolumns-flexbox-objectfit-setclasses !*/ - !function(e,n,t){function r(e,n){return typeof e===n}function o(){var e,n,t,o,s,i,a;for(var l in x)if(x.hasOwnProperty(l)){if(e=[],n=x[l],n.name&&(e.push(n.name.toLowerCase()),n.options&&n.options.aliases&&n.options.aliases.length))for(t=0;td;d++)if(m=e[d],y=j.style[m],a(m,"-")&&(m=i(m)),j.style[m]!==t){if(s||r(o,"undefined"))return f(),"pfx"==n?m:!0;try{j.style[m]=o}catch(g){}if(j.style[m]!=y)return f(),"pfx"==n?m:!0}return f(),!1}function h(e,n,t,o,s){var i=e.charAt(0).toUpperCase()+e.slice(1),a=(e+" "+k.join(i+" ")+i).split(" ");return r(n,"string")||r(n,"undefined")?y(a,n,o,s):(a=(e+" "+P.join(i+" ")+i).split(" "),u(a,n,t))}function g(e,n,r){return h(e,t,t,n,r)}var C=[],x=[],S={_version:"3.5.0",_config:{classPrefix:"",enableClasses:!0,enableJSClass:!0,usePrefixes:!0},_q:[],on:function(e,n){var t=this;setTimeout(function(){n(t[e])},0)},addTest:function(e,n,t){x.push({name:e,fn:n,options:t})},addAsyncTest:function(e){x.push({name:null,fn:e})}},Modernizr=function(){};Modernizr.prototype=S,Modernizr=new Modernizr;var w=n.documentElement,b="svg"===w.nodeName.toLowerCase(),_="Moz O ms Webkit",k=S._config.usePrefixes?_.split(" "):[];S._cssomPrefixes=k;var E=function(n){var r,o=prefixes.length,s=e.CSSRule;if("undefined"==typeof s)return t;if(!n)return!1;if(n=n.replace(/^@/,""),r=n.replace(/-/g,"_").toUpperCase()+"_RULE",r in s)return"@"+n;for(var i=0;o>i;i++){var a=prefixes[i],l=a.toUpperCase()+"_"+r;if(l in s)return"@-"+a.toLowerCase()+"-"+n}return!1};S.atRule=E;var P=S._config.usePrefixes?_.toLowerCase().split(" "):[];S._domPrefixes=P;var T={elem:l("modernizr")};Modernizr._q.push(function(){delete T.elem});var j={style:T.elem.style};Modernizr._q.unshift(function(){delete j.style}),S.testAllProps=h,S.testAllProps=g,function(){Modernizr.addTest("csscolumns",function(){var e=!1,n=g("columnCount");try{e=!!n,e&&(e=new Boolean(e))}catch(t){}return e});for(var e,n,t=["Width","Span","Fill","Gap","Rule","RuleColor","RuleStyle","RuleWidth","BreakBefore","BreakAfter","BreakInside"],r=0;r {{#each carousel.slides}} -