' + 'Platform: ' + navigator.platform + '
' + 'User agent: ' + navigator.userAgent + '
' + 'Window width: ' + window.innerWidth + '
' + 'Window height: ' + window.innerHeight + '
' + 'Is high density: ' + service.helpers().isHighDensity() + '
' + 'Is retina: ' + service.helpers().isRetina() + '
'; } } if (typeof sizes[i+1] !== 'undefined' && currentWidth < parseInt(sizes[i+1])){ var data = getUrl(sizes[i]); imageUrl = data.url; type = data.typeOfDevise; break; } else { var data = getUrl(sizes[sizes.length - 1]); imageUrl = data.url; type = data.typeOfDevise; width = sizes[sizes.length - 1]; } } return {'url': imageUrl, 'width': width, 'type': type, 'currentWidth' : currentWidth}; }, isRetina: function () { return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min--moz-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)').matches)) || (window.devicePixelRatio && window.devicePixelRatio >= 2)) && /(iPad|iPhone|iPod|Mac)/g.test(navigator.userAgent); } } }; service.settings = service.helpers().extendSettings(defaultOptions, customOptions); service.init = function () { if (service.helpers().allowedBreakpointsModes.indexOf(service.settings.breakpointsMode) === -1){ service.settings.breakpointsMode = service.helpers().defaultBreakpointsMode; } itemsToLoad = document.querySelectorAll(service.settings.selector); service.runProcessing(); window.onresize = function () { service.runProcessing(); }; if (service.settings.lazyLoad) { window.onscroll = function () { service.runProcessing(); } } if (service.settings.lazyLoadAllAfterTimeout !== false) { setTimeout(function () { service.settings.lazyLoad = false; service.runProcessing(); }, service.settings.lazyLoadAllAfterTimeout); } }; service.researchItems = function () { itemsToLoad = document.querySelectorAll(service.settings.selector); }; service.runProcessing = function () { if (itemsToLoad.length > 0) { for (var i = 0; i < itemsToLoad.length; i++) { var element = itemsToLoad[i]; if (service.settings.lazyLoad){ if ((window.pageYOffset + window.innerHeight) >= element.getBoundingClientRect().top + window.scrollY - service.settings.lazyLoadRunOffset) { service.setImage(element); element.style.opacity = 1; } } else { service.setImage(element); element.style.opacity = 1; } } } }; service.setImage = function (element) { var options = JSON.parse(element.getAttribute('data-performance-load')); var info = service.helpers().getCurrentBreakpointImage(element, options); if (element.nodeName === 'IMG'){ element.src = info.url; } else { element.style.backgroundImage = "url('" + info.url + "')"; } element.setAttribute('data-debug', 'URL: ' + info.url + '|Breakpoint: ' + info.width + '|Type: ' + info.type + '|Current Width: ' + info.currentWidth); }; service.init(); }; }()); window.performanceLoad = new performanceLoadService();