1/** 2 * Yofla360 Client script 3 */ 4 5/** 6 * Resizes an element on page resize, maintaining its defiend aspect ratio and max-sizes 7 * 8 */ 9(function () { 10 11 // resizes element to match required aspect-ratio 12 var elements = document.getElementsByClassName('auto-aspect-ratio'); 13 14 if (elements.length) { 15 for (var i = 0; i < elements.length; i++) { 16 var element = elements[i] 17 18 19 var resizeElement = function () { 20 21 22 var modifyHeight = false; // force setting of width of image (keep height) 23 var maxHeight = null; 24 var maxWidth = null; 25 26 var matches = this.className.match(/auto-aspect-ratio__(\d+)x(\d+)/); 27 28 if (!matches[1] || !matches[2]) { 29 return; 30 } 31 var ratio = matches[1] / matches[2]; 32 maxWidth = matches[1] 33 maxHeight = matches[2] 34 35 // w/h 36 var matches_2 = this.className.match(/auto-aspect-ratio__modify-(\w+)-(\d+)/); 37 if (matches_2 && matches_2[1] == 'height') { 38 modifyHeight = true; 39 maxHeight = matches_2[2] 40 } 41 42 if (modifyHeight) { 43 // modify height on width change 44 var width = Math.min(maxWidth,this.offsetWidth); 45 var newHeight = Math.round(width / ratio); 46 newHeight = maxHeight ? Math.min(newHeight, maxHeight) : newHeight; 47 this.style.height = newHeight + 'px'; 48 this.style.maxHeight = newHeight + 'px'; 49 this.style.maxWidth = maxWidth + 'px'; 50 } else { 51 // modify width 52 var height = this.offsetHeight; 53 var newWidth = Math.round(height * ratio); 54 if (newWidth > 10) { 55 this.style.width = newWidth + 'px'; 56 } 57 } 58 } 59 60 var resizeFn = resizeElement.bind(element); 61 resizeFn(); 62 window.addEventListener('resize', resizeFn) 63 } 64 } 65})(); 66
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.