1/*! SiOrganiseImagesV4 - v0.1.4 */ 2(function () { 3 //Closest-Polyfill 4 !function (e) { var t = e.Element.prototype; "function" != typeof t.matches && (t.matches = t.msMatchesSelector || t.mozMatchesSelector || t.webkitMatchesSelector || function (e) { for (var t = (this.document || this.ownerDocument).querySelectorAll(e), o = 0; t[o] && t[o] !== this;)++o; return Boolean(t[o]) }), "function" != typeof t.closest && (t.closest = function (e) { for (var t = this; t && 1 === t.nodeType;) { if (t.matches(e)) return t; t = t.parentNode } return null }) }(window); 5 6 document.addEventListener("DOMContentLoaded", function () { 7 init(); 8 }); 9 init(); 10 11 window.addEventListener("load", function () { 12 if (!window.$) return; 13 $(document).ajaxComplete(function () { 14 init(); 15 }); 16 }); 17 18 window.siOrganiseImages = { 19 run: init, 20 svgPlaceholder: function (image) { svgPlaceholder(image) }, 21 lazySizesAttributes: function (image) { lazySizesAttributes(image) }, 22 lightCaseAttributes: function (image) { lightCaseAttributes(image) }, 23 lightCaseHrefAttributes: function (link) { lightCaseHrefAttributes(link) } 24 } 25 26 function init() { 27 var dynamicImages = document.querySelectorAll("img[dynamicimageloading=true]"); 28 for (var i = 0; i < dynamicImages.length; i++) { 29 var image = dynamicImages[i]; 30 svgPlaceholder(image); 31 lazySizesAttributes(image); 32 lightCaseAttributes(image); 33 } 34 35 var imageLinks = document.querySelectorAll("a[href*='/Images/']"); 36 for (var i = 0; i < imageLinks.length; i++){ 37 var link = imageLinks[i]; 38 lightCaseHrefAttributes(link) 39 } 40 } 41 42 function svgPlaceholder(img) { 43 var width = img.style.width.replace("px", ""); 44 var height = img.style.height.replace("px", ""); 45 var placeHolderWidth = 1; 46 var placeHolderHeight = 1; 47 48 if (img.matches('.sc-slideshow-slide')) { 49 var tmp = img.closest(".sc-slideshow"); 50 if (tmp) { 51 tmp = tmp.parentNode; 52 if (tmp) { 53 var ratio = tmp.getAttribute("data-imgratio"); 54 if (ratio) { 55 ratio = ratio.split(":"); 56 if (ratio.length === 2) { 57 width = ratio[0]; 58 height = ratio[1]; 59 } 60 } 61 } 62 } 63 } 64 65 if (typeof width === "undefined" || width === null || width === "0" || width === "" || isNaN(width)) { 66 img.removeAttribute("width"); 67 } else { 68 img.width = width; 69 placeHolderWidth = width 70 img.style.width = null; 71 } 72 if (typeof height === "undefined" || height === null || height === "0" || height === "" || isNaN(height)) { 73 img.removeAttribute("height"); 74 } else { 75 img.height = height; 76 placeHolderHeight = height; 77 img.style.height = null; 78 } 79 80 img.src = "data:image/svg+xml;charset=utf8,%3Csvg%20width='" + placeHolderWidth + "'%20height='" + placeHolderHeight + "'%20xmlns='http://www.w3.org/2000/svg'%3E%3C/svg%3E"; 81 } 82 83 function lazySizesAttributes(img) { 84 img.classList.add("lazyload"); 85 img.removeAttribute("dynamicimageloading"); 86 87 var path = img.getAttribute("data-src"); 88 if (!path) path = img.src; 89 90 if (path.indexOf("/CustomerData/") !== 0) { 91 return; 92 } 93 94 var notRes = img.getAttribute("data-notres"); 95 if (typeof notRes === "string" && notRes.length >= 0) { 96 return; 97 } 98 99 var fileExtension = path.split(".").pop().toLowerCase(); 100 if (fileExtension !== "jpg" && fileExtension !== "jpeg" && fileExtension !== "png" && fileExtension !== "gif") { 101 return; 102 } 103 104 var version = SiCenter && SiCenter.AssetsKey ? "?" + SiCenter.AssetsKey : ""; 105 var sizes = [400, 600, 900, 1200, 1500, 1800, 2100]; 106 var service = "https://images.simedia.cloud/cms-v2"; 107 var imagePath = path + "/" 108 109 var value = ""; 110 for (var i = 0; i < sizes.length; i++) { 111 var size = sizes[i]; 112 value += service + imagePath + size + "x0/image." + fileExtension + version + " " + size + "w"; 113 if (i < sizes.length - 1) { 114 value += ", "; 115 } 116 } 117 118 if (img.getAttribute("data-nosrcset") === null) { 119 img.setAttribute("data-sizes", "auto"); 120 img.setAttribute("data-srcset", value); 121 } 122 img.setAttribute("data-src", service + imagePath + "image." + fileExtension + version); 123 } 124 125 function lightCaseAttributes(image) { 126 if (!image || image.getAttribute("data-sigallery") === "none") return; 127 128 var parent = image.parentElement; 129 var dataSrc = image.getAttribute("data-src"); 130 131 var collection = image.closest("[data-sigallery]"); 132 133 var collectionName = ""; 134 if (collection && collection.getAttribute("data-sigallery")) { 135 collectionName = ":" + collection.getAttribute("data-sigallery"); 136 } 137 138 if (parent && parent.tagName === "A" && parent.href && parent.href.indexOf("/Images/") > 0) { 139 var anchorCollectionName = parent.getAttribute("data-sigallery"); 140 collectionName = anchorCollectionName && anchorCollectionName.length ? ":" + anchorCollectionName : collectionName; 141 parent.setAttribute("data-rel", "lightcase" + collectionName); 142 } else if (image.src && image.src.indexOf("/Images/") > 0 && collection) { 143 image.setAttribute("data-rel", "lightcase" + collectionName); 144 image.setAttribute("data-lc-href", image.src); 145 } else if (dataSrc && dataSrc.indexOf("/Images/") > 0 && collection) { 146 image.setAttribute("data-rel", "lightcase" + collectionName); 147 image.setAttribute("data-lc-href", dataSrc); 148 } 149 } 150 151 function lightCaseHrefAttributes(link) { 152 if (!link || link.getAttribute("data-sigallery") === "none") return; 153 if(link.getAttribute("data-rel")) return; 154 155 var dataSrc = link.href; 156 var collection = link.closest("[data-sigallery]"); 157 158 var collectionName = ""; 159 if (collection && collection.getAttribute("data-sigallery")) { 160 collectionName = ":" + collection.getAttribute("data-sigallery"); 161 } 162 if (dataSrc && dataSrc.indexOf("/Images/") > 0){ 163 link.setAttribute("data-rel", "lightcase" + collectionName); 164 } 165 } 166})();
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.