in media/js/careers/listings/filters.es6.js [36:114]
onFilterChange: function () {
// collection of tr.position elements
const positions = this.positionTable.getElementsByClassName('position');
let positionsVisible = false;
let querystring = '';
const filters = {
position_type: this.typeInput.value,
team: this.teamInput.value,
location: this.locationInput.value
};
// Hide table and show all positions.
this.positionTable.classList.add('hidden');
this.emptyFilterMessage.classList.add('hidden');
for (let i = 0; i < positions.length; i++) {
positions.item(i).classList.remove('hidden');
}
// Hide positions that don't match the current filters.
this.filterPositions('type', filters['position_type']);
this.filterPositions('team', filters['team']);
this.filterLocations(filters['location']);
// If there aren't any positions being shown, show the no-results message.
for (let j = 0; j < positions.length; j++) {
if (!positions.item(j).classList.contains('hidden')) {
positionsVisible = true;
break;
}
}
if (!positionsVisible) {
this.emptyFilterMessage.classList.remove('hidden');
}
// Get rid of unset filters.
for (const k in filters) {
if (
Object.prototype.hasOwnProperty.call(filters, k) &&
!filters[k]
) {
delete filters[k];
}
}
// Build a querystring from populated filters.
for (const prop in filters) {
querystring += prop + '=' + filters[prop];
}
// Preserve Google Analytics parameters.
const ga_parameters = window.location.search
.substr(1)
.split('&')
.filter(function (parameter) {
return parameter.indexOf('utm_') === 0;
});
if (querystring.length && ga_parameters.length) {
querystring += '&';
}
querystring += ga_parameters.join('&');
if (querystring.length) {
querystring = '?' + querystring;
}
// Replace history state with this filtered state.
window.history.replaceState(
filters,
'Filtered',
location.pathname + querystring
);
this.positionTable.classList.remove('hidden');
},