1// Auto-sizes the hub opportunity feed iframe to its content. 2// 3// The feed is cross-origin, so the parent cannot read its content height - the 4// embed has to post it out. Until the hub does that, nothing arrives here and the 5// iframe keeps the CSS fallback height. Nothing to undo if the hub never changes. 6// 7// Expected message from https://hub.thetalentpeople.co.uk, any of: 8// { type: 'cif-height', height: 1234 } | { height: 1234 } | 1234 9window.opportunityFeed = (function () { 10 var HUB_ORIGIN = 'https://hub.thetalentpeople.co.uk'; 11 var MIN_PX = 200; 12 var MAX_PX = 20000; 13 14 var wrappers = []; 15 var listening = false; 16 17 function readHeight(data) { 18 if (typeof data === 'number') return isFinite(data) ? data : null; 19 20 if (typeof data === 'string') { 21 var s = parseFloat(data); 22 return isFinite(s) ? s : null; 23 } 24 25 if (data && typeof data === 'object') { 26 var raw = data.height != null ? data.height 27 : data.h != null ? data.h 28 : data.value; 29 var n = parseFloat(raw); 30 return isFinite(n) ? n : null; 31 } 32 33 return null; 34 } 35 36 function onMessage(e) { 37 if (e.origin !== HUB_ORIGIN) return; 38 39 var height = readHeight(e.data); 40 if (height === null || height < MIN_PX || height > MAX_PX) return; 41 42 for (var i = 0; i < wrappers.length; i++) { 43 var wrap = document.getElementById(wrappers[i]); 44 if (!wrap) continue; 45 46 // Only resize the frame that actually sent the message, so several 47 // feeds on one page cannot fight over the height. 48 var frame = wrap.querySelector('iframe'); 49 if (!frame || (e.source && frame.contentWindow !== e.source)) continue; 50 51 wrap.style.height = Math.ceil(height) + 'px'; 52 wrap.setAttribute('data-auto-height', 'true'); 53 } 54 } 55 56 return { 57 autoHeight: function (wrapperId) { 58 if (wrappers.indexOf(wrapperId) === -1) wrappers.push(wrapperId); 59 if (!listening) { 60 window.addEventListener('message', onMessage); 61 listening = true; 62 } 63 } 64 }; 65})();
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.