var Grnhse = Grnhse || {}; Grnhse.Settings = { targetDomain: 'https://job-boards.greenhouse.io', scrollOnLoad: true, autoLoad: true, boardURI: 'https://job-boards.greenhouse.io/embed/job_board?for=globalenergyallianceforpeopleandplanetgeappllc', applicationURI: 'https://job-boards.greenhouse.io/embed/job_app?for=globalenergyallianceforpeopleandplanetgeappllc', baseURI: 'https://energyalliance.org/jobs/', iFrameWidth: '100%', useEmbeddedInternalBoard: false }; Grnhse.Const = { JOB_ID: 'gh_jid', SOURCE_TOKEN: 'gh_src', PROGRAMMATIC_SOURCING_TRACKING: 'ccuid' }; Grnhse.Config = { IframeDefault: { id: 'grnhse_iframe', width: Grnhse.Settings.iFrameWidth, frameborder: '0', scrolling: 'no', allow: 'geolocation', onload: undefined, title: 'Greenhouse Job Board' } }; Grnhse.UriHelper = { base: function() { var uriHelper = Grnhse.UriHelper, location = uriHelper.currentLocation(), settings = Grnhse.Settings; return window && location ? uriHelper.pathFromLocation(location) : settings.boardURI; }, currentLocation: function() { return window.top.location; }, getParam: function(name) { var location = Grnhse.UriHelper.currentLocation(), uri = location.href, start = uri.indexOf(name), end; if (start === -1) { return null; } start += name.length + 1; end = uri.substr(start).search(/(&|#|$|;)/); return uri.substr(start, end); }, appendParams: function(url, params) { params.push('b=' + Grnhse.UriHelper.base()); url += (url.indexOf('?') === -1) ? '?' : '&'; return url + params.join('&'); }, pathFromLocation: function(location) { return encodeURIComponent(location.protocol + '//' + location.host + location.pathname); } }; var Grnhse = Grnhse || {}; Grnhse.Iframe = function(jobId, source, ccuid) { this.jobId = jobId || Grnhse.UriHelper.getParam(Grnhse.Const.JOB_ID) || ""; this.source = source || Grnhse.UriHelper.getParam(Grnhse.Const.SOURCE_TOKEN) || ""; this.ccuid = ccuid || Grnhse.UriHelper.getParam(Grnhse.Const.PROGRAMMATIC_SOURCING_TRACKING) || ""; this.queryParams = { token: this.jobId, t: this.source, ccuid: this.ccuid, }; this.iframeElement = null; this.registerEventHandlers(); // iframe src this.pathToLoad = !!this.jobId ? this.applicationUrl() : this.boardUrl(); this.iframeElement = this.render(); }; Grnhse.Iframe.prototype.boardUrl = function() { const boardUri = Grnhse.Settings.boardURI; const url = new URL(boardUri); if (this.source) { url.searchParams.set("t", this.source); } if (Grnhse.Settings.useEmbeddedInternalBoard) { url.searchParams.set("internal", "true"); } return url.href; }; Grnhse.Iframe.prototype.applicationUrl = function() { const applicationUri = Grnhse.Settings.applicationURI; const url = new URL(applicationUri); for (const [key, value] of Object.entries(this.queryParams)) { if (value) { url.searchParams.set(key, value); } } if (Grnhse.Settings.useEmbeddedInternalBoard) { url.searchParams.set("internal", "true"); } return url.href; }; Grnhse.Iframe.prototype.build = function() { const iframe = document.createElement("iframe"); const attributes = Grnhse.Config.IframeDefault; for (const [attribute, value] of Object.entries(attributes)) { if (attributes.hasOwnProperty(attribute)) { iframe.setAttribute(attribute, value); } } iframe.setAttribute("src", this.pathToLoad); return iframe; }; Grnhse.Iframe.prototype.render = function() { const container = document.getElementById("grnhse_app"); const iframeElement = this.build(); container.innerHTML = ""; container.appendChild(iframeElement); return iframeElement; }; Grnhse.Iframe.prototype.registerEventHandlers = function() { let resizeEvent = null; let instance = this; window.addEventListener('message', resize, false); window.addEventListener('resize', windowResize, false); function windowResize(e) { // Pass resize event from parent window to iframe clearTimeout(resizeEvent); resizeEvent = setTimeout(triggerResize, 200); } function triggerResize() { if (window.postMessage && instance.iframeElement) { instance.iframeElement.contentWindow.postMessage('resize', '*'); } } function resize(e) { if (instance.iframeElement && e.origin === Grnhse.Settings.targetDomain && e.data > 0) { instance.iframeElement.setAttribute('height', e.data); } } }; Grnhse.Iframe.load = function(jobId, source, ccuid) { return new Grnhse.Iframe(jobId, source, ccuid); }; Grnhse.Iframe.autoLoad = function() { Grnhse.Iframe.load(); }; (function() { if (Grnhse.Settings.autoLoad) { addEventListener("load", Grnhse.Iframe.autoLoad); } })();