1/** 2 * @file 3 * The Lazy-load behavior. 4 */ 5 6(function (Drupal) { 7 8 'use strict'; 9 10 Drupal.behaviors.lazy = { 11 attach: function (context, settings) { 12 var utils = { 13 extend: function (obj, src) { 14 Object.keys(src).forEach(function (key) { 15 obj[key] = src[key]; 16 }); 17 return obj; 18 }, 19 once: function (selector, context) { 20 return (context || document).querySelector(selector); 21 }, 22 loadScript: function (url) { 23 if (document.querySelectorAll('script[src="' + url + '"]').length == 0) { 24 var script = document.createElement('script'), 25 scripts = document.getElementsByTagName('script')[0]; 26 script.src = url; 27 script.async = true; 28 scripts.parentNode.insertBefore(script, scripts); 29 } 30 } 31 }; 32 33 if (utils.once('body', context)) { 34 var lazysizes = settings.lazy.lazysizes || {}; 35 36 if (!settings.lazy.preferNative) { 37 // 1. Lazysizes configuration. 38 window.lazySizesConfig = window.lazySizesConfig || {}; 39 window.lazySizesConfig = utils.extend(window.lazySizesConfig, lazysizes); 40 // 2. Load all selected lazysizes plugins. 41 if (!Object.entries) { 42 Object.entries = function (obj) { 43 var ownProps = Object.keys(obj), 44 i = ownProps.length, 45 resArray = new Array(i); 46 while (i--) { 47 resArray[i] = [ownProps[i], obj[ownProps[i]]]; 48 } 49 return resArray; 50 }; 51 } 52 var min = settings.lazy.minified ? '.min' : ''; 53 Object.entries(lazysizes.plugins).forEach(function (path) { 54 utils.loadScript(settings.lazy.libraryPath + '/plugins/' + path[1] + min + '.js'); 55 }); 56 // 3. Load the lazysizes library. 57 utils.loadScript(settings.lazy.libraryPath + '/lazysizes' + min + '.js'); 58 } 59 } 60 } 61 }; 62 63})(Drupal);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.