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=501',
applicationURI: 'https://job-boards.greenhouse.io/embed/job_app?for=501',
baseURI: '',
iFrameWidth: '100%',
useEmbeddedInternalBoard: false,
trustedAutofillUrl: 'https://job-boards.greenhouse.io',
trustedJobSeekersUrl: 'https://my.greenhouse.io',
};
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);
window.addEventListener('message', handleAutofillMessage, 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);
}
}
function handleAutofillMessage(e) {
if (e.origin !== Grnhse.Settings.trustedAutofillUrl) {
return;
}
if (e.data.type === 'autofill') {
if (document.getElementById("autofill-toast")) {
return;
}
const container = document.getElementById("grnhse_app");
const checkMark = document.createElement("span");
checkMark.innerHTML = ``;
const autoFillNotice = document.createElement("p");
const profileLink = document.createElement("a");
if (e.data.editProfileLink.startsWith(Grnhse.Settings.trustedJobSeekersUrl)) {
profileLink.href = e.data.editProfileLink;
profileLink.target = "_blank";
} else {
profileLink.href = "#";
}
profileLink.href = e.data.editProfileLink;
profileLink.setAttribute("style", "font-weight: 400;line-height: 1.5rem;text-decoration: underline;cursor: pointer;color: #047957;");
profileLink.innerText = "MyGreenhouse";
autoFillNotice.setAttribute("style", "font-weight: 400;font-size: 1rem;line-height: 1.5rem;margin: 0;padding: 0;padding-inline-end: 0;padding-inline-start: 0;color: #15372c;");
autoFillNotice.appendChild(document.createTextNode("Autofilled from "));
autoFillNotice.appendChild(profileLink);
const closeButton = document.createElement("button");
closeButton.id = "clear-toast";
closeButton.type = "button";
closeButton["aria-label"] = "Close flash";
closeButton.setAttribute("style", "padding: 0;font-family: inherit;display: inline-flex;flex-direction: row;justify-content: center;align-items: center;border-radius: 50%;cursor: pointer;border: 0;background: transparent;height: 24px;width: 24px;");
closeButton.innerHTML = ``
const innerToast = document.createElement("div");
innerToast.setAttribute("style", "position: sticky;padding: 12px 16px;box-shadow: 0 2px 6px #00000021;border-radius: 5px;background: #f9faf9;max-width: calc(100% - 32px);display: flex;flex-direction: row;align-items: flex-start;gap: 16px;");
innerToast.appendChild(checkMark);
innerToast.appendChild(autoFillNotice);
innerToast.appendChild(closeButton);
const toast = document.createElement("div");
toast.id = "autofill-toast";
toast.setAttribute("style", "top: 25px;left: 50%;transform: translate(-50%);position: fixed;z-index: 9999;width: auto;font-family:sans-serif;letter-spacing:0.5px;");
toast.appendChild(innerToast);
container.appendChild(toast);
document.getElementById('clear-toast').addEventListener('click', function () {
if (toast) {
toast.remove();
}
});
setTimeout(function() {
if (toast) {
toast.remove();
}
}, 12000);
}
}
};
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);
}
})();