/*eslint-disable */ //thanks http://stackoverflow.com/a/2091331 const componentList = { "queryVariables": [ { "name": "room", "elements": [ { "elementById": "pex-enquiry-room-form" }, { "elementById": "pex-arrange-room-viewing-form" } ] }, { "name": "building", "elements": [ { "elementById": "building-form" }, { "elementById": "contact-form" } ] }, { "name": "location", "elements": [ { "elementById": "building-form" }, { "elementById": "contact-form" }, { "elementById": "city-results" } ] }, { "name": "roomTypeSearch", "elements": [ { "elementById": "building-form" } ] }, { "name": "book", "elements": [ { "elementById": "building-form" }, { "elementById": "contact-form" } ] }, { "name": "viewing", "elements": [ { "elementById": "building-form" }, { "elementById": "contact-form" } ] }, { "name": "enquire", "elements": [ { "elementById": "building-form" }, { "elementById": "contact-form" } ] } ] }; function getQueryVariable (variable) { var query = window.location.search.substring(1); var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); if (decodeURIComponent(pair[0]) == variable) { return decodeURIComponent(pair[1]); } } } var otherAttributes = ["book", "viewing", "enquire"]; for (let queryVariable of componentList.queryVariables) { let theQueryVariable = getQueryVariable(queryVariable.name); for (let element of queryVariable.elements) { for (let attribute of otherAttributes) { if (document.getElementById(element.elementById) && document.getElementById(element.elementById).getAttribute(attribute)) { let current = document.getElementById(element.elementById).getAttribute(attribute); document.getElementById(element.elementById).setAttribute(attribute, current.replace("", theQueryVariable)); } } if (theQueryVariable && document.getElementById(element.elementById)) document.getElementById(element.elementById).setAttribute(queryVariable.name, theQueryVariable); } } /*eslint-enable */