Last active
September 30, 2016 13:18
-
-
Save franklin-like-the-turtle/1d59c944ecb74d6831092eec52c37ec0 to your computer and use it in GitHub Desktop.
Fixes for GTM Events in CMP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The Per Diem tool reports custom events using Google Analytics ga() methods, and Google Tag Manager dataLayer objects. | |
It seems that some of these have been removed from the script, and others refactored in a way that prevents them from firing: | |
1. var "ga" returns undefined, preventing Google Analytics ga() methods from firing. | |
2. tests for the object "dataLayer" seem to be confused with other if statements. This is difficult to discern post-compression, but is clearly preventing event objects from reaching the GTM dataLayer. | |
*/ | |
var perDiemSwiper, | |
perDiemSearch = { | |
rates: {}, | |
query: {}, | |
}, | |
gaConsoleCSS = 'background: green; color: white', | |
apiRoot = window.location.protocol + '//' + window.location.host; | |
//doc ready | |
(function($) { | |
$(document).ready(function() { | |
//homepage travel tabs collapse in mobile | |
$('#homepage-travel-tabs').tabCollapse(); | |
jQuery.ajax({ | |
type: 'GET', | |
url: '/perdiems/Get_Valid_Date', | |
success: function(result) { | |
if (result != '') { | |
var datearray = result.split('||'); | |
var RatestartDate = datearray[0]; | |
var RateEndDate = datearray[1]; | |
var startdateObj = new Date(RatestartDate * 1000); | |
start_year = startdateObj.getFullYear(); | |
start_month = startdateObj.getMonth() + 1; | |
start_day = startdateObj.getDate(); | |
validDatesBegin_from_CMP = start_month + '/' + start_day + '/' + start_year; | |
validDatesBegin_from_CMP = validDatesBegin_from_CMP.toString(); | |
// get rate end date | |
var enddateObj = new Date(RateEndDate * 1000); | |
end_year = enddateObj.getFullYear(); | |
end_month = enddateObj.getMonth() + 1; | |
end_day = enddateObj.getDate(); | |
validDatesEnd_from_CMP = end_month + '/' + end_day + '/' + end_year; | |
validDatesEnd_from_CMP = validDatesEnd_from_CMP.toString() | |
SetUp_Perdiem_Tool(validDatesBegin_from_CMP, validDatesEnd_from_CMP) | |
} | |
}, | |
error: function() { | |
jQuery('#perdiem-swiper').text('An error occurred while seting up rate start date and rate end date'); | |
} | |
}); | |
}); | |
function SetUp_Perdiem_Tool(validDatesBegin_from_CMP, validDatesEnd_from_CMP) { | |
//apiRoot = 'https://gsa-stage.ctacdev.com', | |
validDatesBegin = validDatesBegin_from_CMP, | |
//must be updated when API is updated | |
validDatesEnd = validDatesEnd_from_CMP; | |
//set valid search dates to moment objs | |
validDatesBegin = moment(validDatesBegin, 'MM/DD/YYYY'); | |
validDatesEnd = moment(validDatesEnd, 'MM/DD/YYYY'); | |
//init swiper | |
perDiemSwiper = new Swiper('#perdiem-swiper', { | |
onlyExternal: true, | |
a11y: true, | |
widgetPositioning: { | |
horizontal: 'auto', | |
vertical: 'bottom' | |
} | |
}); | |
perDiemSwiper.on('slideChangeStart', function() { | |
$('html, body').animate({ | |
scrollTop: $("#perdiem-swiper").offset().top - 120 | |
}, 0); | |
}); | |
//global ajax settings | |
$.ajaxSetup({ | |
timeout: 10000 | |
}); | |
//test for IE11, print userAgent | |
var isIE11 = !!navigator.userAgent.match(/Trident\/7.0;(.*)rv(:*)11/); | |
if (!navigator.geolocation) { | |
$('#perdiem-current-location').hide(); | |
} | |
//init date pickers | |
$('#perdiem-start-date-group').datetimepicker({ | |
format: 'MM/DD/YYYY', | |
keepInvalid: true, | |
useCurrent: false, | |
minDate: validDatesBegin, | |
maxDate: validDatesEnd, | |
//debug: isIE11 | |
debug: true | |
}); | |
$('#perdiem-end-date-group').datetimepicker({ | |
format: 'MM/DD/YYYY', | |
keepInvalid: true, | |
useCurrent: false, | |
minDate: validDatesBegin, | |
maxDate: validDatesEnd, | |
debug: isIE11 | |
}); | |
//enable/disable functionality | |
$('#perdiem-swiper').on('click', '#next:not(.disabled)', function() { | |
perDiemSwiper.slideNext() | |
}) | |
$('#perdiem-swiper').on('click', '#prev:not(.disabled)', function() { | |
perDiemSwiper.slidePrev() | |
}) | |
//geolocation | |
$('#perdiem-current-location').on('click', useMyCurrentLocation); | |
//clear location form | |
$('#perdiem-clear-location-form').on('click', clearLocationForm); | |
//reset search, back to first screen | |
$('#perdiem-new-search').on('click', newSearch); | |
//perform ajax calls, check for multiple rates | |
$('#perdiem-multiple-rates-check').on('click', checkForMultipleRates); | |
//validate multiple rate selection | |
$('#perdiem-swiper').on('change', '#perdiem-fiscal-year-1,#perdiem-fiscal-year-2', validateMultipleRates); | |
//perform calculation with selected rates | |
$('#perdiem-swiper').on('click', '#perdiem-rates-selected', ratesSelected); | |
//validate location | |
$('#perdiem-city,#perdiem-zip').on('keyup', validateLocationParams) | |
$('#perdiem-state').on('change', validateLocationParams) | |
validateLocationParams(); | |
//validate dates | |
$('#perdiem-start-date,#perdiem-end-date').on('keyup', validateDates) | |
$('#perdiem-slide-dates:not(input)').on('click', validateDates) | |
$('#perdiem-start-date-group').on('dp.change', validateDates) | |
$('#perdiem-end-date-group').on('dp.change', validateDates) | |
validateDates(); | |
//to date selection | |
$('#perdiem-look-up-rates').on('click', function() { | |
perDiemSwiper.slideTo(3) | |
perDiemSearch.searchType = 'Look Up'; | |
}) | |
$('#perdiem-calculate-expenses').on('click', function() { | |
perDiemSwiper.slideTo(2) | |
perDiemSearch.searchType = 'Calculator'; | |
}) | |
//to calculate/lookup selection | |
$('#perdiem-to-step-2').on('click', function() { | |
perDiemSwiper.slideTo(1) | |
}) | |
$('#perdiem-tool-intent').on('click', function() { | |
perDiemSwiper.slideTo(1) | |
if (typeof(ga) != "undefined") { | |
ga('send', 'event', 'Per Diem Tool Intent', perDiemSearch.locationType); | |
} | |
console.log('%cGA SEND EVENT: CATEGORY: Per Diem Tool Intent ACTION: ' + perDiemSearch.locationType, gaConsoleCSS) | |
}) | |
//on to date select | |
$('#perdiem-swiper').on('click', '#perdiem-to-date-range', function() { | |
perDiemSwiper.slideTo(2) | |
}) | |
$('#perdiem-swiper').on('click', '#perdiem-result-print', perDiemResultPrint) | |
//launch gsa.gov rate lookup | |
$('#perdiem-look-up-rates-submit').on('click', lookUpRatesSubmit); | |
//overflow fix | |
setTimeout(function() { | |
perDiemSwiper.onResize(); | |
}, 250) | |
} | |
function newSearch() { | |
clearLocationForm() | |
clearDateForm() | |
perDiemSwiper.slideTo(0) | |
} | |
function resetErrors() { | |
$('.perdiem-error').hide(); | |
} | |
function clearLocationForm() { | |
$('#perdiem-state').val(''); | |
$('#perdiem-zip').val(''); | |
$('#perdiem-city').val(''); | |
validateLocationParams(); | |
$('#perdiem-current-location').focus(); | |
} | |
function clearDateForm() { | |
$('#perdiem-start-date-group').data("DateTimePicker").clear() | |
$('#perdiem-end-date-group').data("DateTimePicker").clear() | |
validateDates(); | |
} | |
function validateMultipleRates() { | |
if ($('#perdiem-fiscal-year-1').val() === '' && $('#perdiem-fiscal-year-2').val()) { | |
$('#perdiem-rates-selected').addClass('disabled').attr('disabled', 'disabled'); | |
} else { | |
$('#perdiem-rates-selected').removeClass('disabled').removeAttr('disabled'); | |
} | |
} | |
function validateDates() { | |
perDiemSearch.locationType = 'Custom Location' | |
resetErrors(); | |
var valid = /\d{1,2}\/\d{1,2}\/\d{2,4}/; | |
var startDateVal = $('#perdiem-start-date').val(); | |
var endDateVal = $('#perdiem-end-date').val(); | |
var startDate = moment(startDateVal, 'MM/DD/YYYY'); | |
var endDate = moment(endDateVal, 'MM/DD/YYYY'); | |
//text is valid and dates are valid | |
if (startDateVal.match(valid) && endDateVal.match(valid) && startDate.isValid() && endDate.isValid()) { | |
//dates are in acceptable range (THIS IS NOT INCLUSIVE) | |
if ((startDate.isSame(validDatesBegin) || startDate.isBetween(validDatesBegin, validDatesEnd)) && (endDate.isBetween(validDatesBegin, validDatesEnd) || endDate.isSame(validDatesEnd))) { | |
//start is before or equal to end | |
if (startDate.isBefore(endDate) || startDate.isSame(endDate)) { | |
enableNext() | |
$('#perdiem-start-date').removeClass('perdiem-invalid') | |
$('#perdiem-end-date').removeClass('perdiem-invalid') | |
} else { | |
$('#perdiem-end-before-start').show(); | |
disableNext() | |
} | |
} else { | |
disableNext() | |
} | |
} else { | |
disableNext() | |
if (!startDateVal.match(valid) || !startDate.isValid()) { | |
if (startDateVal !== '') { | |
$('#perdiem-start-date').addClass('perdiem-invalid') | |
} | |
} | |
if (!endDateVal.match(valid) || !endDate.isValid()) { | |
if (endDateVal !== '') { | |
$('#perdiem-end-date').addClass('perdiem-invalid') | |
} | |
} | |
} | |
function disableNext() { | |
$('#perdiem-multiple-rates-check').addClass('disabled').attr('disabled', 'disabled'); | |
} | |
function enableNext() { | |
$('#perdiem-multiple-rates-check').removeClass('disabled').removeAttr('disabled'); | |
resetErrors() | |
} | |
} | |
function validateLocationParams() { | |
resetErrors(); | |
perDiemSearch.locationType = 'Custom Location'; | |
var validZIP = /\d{5}/; | |
//if everything is blank | |
if ($('#perdiem-city').val() === '' && $('#perdiem-state').val() === '' && $('#perdiem-zip').val().length < 5) { | |
//disabled | |
$('#perdiem-tool-intent').addClass('disabled').attr('disabled', 'disabled'); | |
//if not everything is blank | |
} else { | |
//but zip and state are blank (city only) | |
if (!$('#perdiem-zip').val().match(validZIP) && $('#perdiem-state').val() === '') { | |
//disabled | |
$('#perdiem-tool-intent').addClass('disabled').attr('disabled', 'disabled'); | |
} | |
//otherwise | |
else { | |
//enabled | |
$('#perdiem-tool-intent').removeClass('disabled').removeAttr('disabled'); | |
} | |
} | |
} | |
function checkForMultipleRates() { | |
function e(e) { | |
if (perDiemSearch.query.zip = $("#perdiem-zip").val(), perDiemSearch.query.state = $("#perdiem-state").val(), perDiemSearch.query.city = $("#perdiem-city").val(), "" !== perDiemSearch.query.zip) var a = apiRoot + "/api/rs/perdiem/zip/" + perDiemSearch.query.zip, | |
t = "zip"; | |
else if ("" === perDiemSearch.query.city || e) { | |
var a = apiRoot + "/api/rs/perdiem/state/" + perDiemSearch.query.state; | |
varreqType = "state" | |
} else var a = apiRoot + "/api/rs/perdiem/city/" + perDiemSearch.query.city + "/state/" + perDiemSearch.query.state, | |
t = "city-state"; | |
r(a, t) | |
} | |
function r(r, t) { | |
function o() { | |
return $.ajax({ | |
url: s | |
}).done(function(r) { | |
if (r.rates && 0 !== r.rates.length) { | |
a = !1; | |
var o = r.rates[0].rate; | |
if (o.length > 1) { | |
for (i in o) " " === o[i].county && (o[i].county = "Standard Rate"); | |
perDiemSearch.rates.fy1 = { | |
year: perDiemSearch.startFY, | |
multiple: !0, | |
rates: o | |
} | |
} else perDiemSearch.rates.fy1 = { | |
year: perDiemSearch.startFY, | |
multiple: !1, | |
rate: o[0] | |
} | |
} else "city-state" === t ? e(!0) : locationError(), a = !0 | |
}).fail(function() { | |
$("#perdiem-multiple-rates-check").html("Next"), a = !0, $("#perdiem-api-error").show() | |
}) | |
} | |
function n() { | |
if (perDiemSearch.startFY !== perDiemSearch.endFY) { | |
var o = r + "/year/" + perDiemSearch.endFY; | |
return $.ajax({ | |
url: o | |
}).done(function(r) { | |
if (r.rates && 0 !== r.rates.length) { | |
a = !1; | |
var o = r.rates[0].rate; | |
if (o.length > 1) { | |
for (i in o) " " === o[i].county && (o[i].county = "Standard Rate"); | |
perDiemSearch.rates.fy2 = { | |
year: perDiemSearch.endFY, | |
multiple: !0, | |
rates: o | |
} | |
} else perDiemSearch.rates.fy2 = { | |
year: perDiemSearch.endFY, | |
multiple: !1, | |
rate: o[0] | |
} | |
} else "city-state" === t ? e(!0) : locationError(), a = !0 | |
}).fail(function() { | |
$("#perdiem-multiple-rates-check").html("Next"), $("#perdiem-api-error").show(), a = !0 | |
}) | |
} | |
return !0 | |
} | |
var s = r + "/year/" + perDiemSearch.startFY; | |
$.when(o(), n()).done(function() { | |
function e() { | |
function e(e, r) { | |
return e.county > r.county | |
} | |
perDiemSearch.rates.fy1.multiple && (perDiemSearch.rates.fy1.rates = perDiemSearch.rates.fy1.rates.sort(e)), perDiemSearch.rates.fy2 && perDiemSearch.rates.fy2.multiple && (perDiemSearch.rates.fy2.rates = perDiemSearch.rates.fy2.rates.sort(e)); | |
var r = template_multiple_rates, | |
a = Mustache.render(r, { | |
rates: perDiemSearch.rates | |
}); | |
$(".perdiem-choose-rates").html(a), perDiemSwiper.slideTo(4), $("#perdiem-multiple-rates-check").html("Next") | |
} | |
a === !0 || (perDiemSearch.rates.fy2 ? perDiemSearch.rates.fy1.multiple || perDiemSearch.rates.fy2.multiple ? e() : calculateRates() : perDiemSearch.rates.fy1.multiple ? e() : calculateRates()) | |
}) | |
} | |
$("#perdiem-multiple-rates-check").html('Next <span class="glyphicon glyphicon-refresh spinning"></span>'), resetErrors(), perDiemSearch.startDate = moment($("#perdiem-start-date").val(), "MM/DD/YYYY"), perDiemSearch.startDate.month() > 8 ? perDiemSearch.startFY = perDiemSearch.startDate.year() + 1 : perDiemSearch.startFY = perDiemSearch.startDate.year(), perDiemSearch.endDate = moment($("#perdiem-end-date").val(), "MM/DD/YYYY"), perDiemSearch.endDate.month() > 8 ? perDiemSearch.endFY = perDiemSearch.endDate.year() + 1 : perDiemSearch.endFY = perDiemSearch.endDate.year(), e(); | |
var a = !1 | |
} | |
function useMyCurrentLocation() { | |
var $btn = $(this).button('loading') | |
var geocodeResult = { | |
city: '', | |
state: '', | |
zip: '' | |
}; | |
//get location | |
navigator.geolocation.getCurrentPosition(reverseGeocode, currentPositionError); | |
geocoder = new google.maps.Geocoder(); | |
function reverseGeocode(position) { | |
var latitude = position.coords.latitude, | |
longitude = position.coords.longitude; | |
var latlong = new google.maps.LatLng(latitude, longitude); | |
geocoder.geocode({ | |
'latLng': latlong | |
}, function(results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
var addressComponents = results[0].address_components; | |
//ZIP, use postal_code | |
for (i in addressComponents) { | |
if (addressComponents[i].types[0] === 'postal_code') { | |
geocodeResult.zip = addressComponents[i].long_name; | |
} | |
} | |
//CITY, use locality | |
for (i in addressComponents) { | |
if (addressComponents[i].types.indexOf('locality') > -1) { | |
geocodeResult.city = addressComponents[i].long_name; | |
} | |
} | |
//if no locality, use sublocality | |
if (geocodeResult.city === '') { | |
for (i in addressComponents) { | |
if (addressComponents[i].types.indexOf('sublocality') > -1) { | |
geocodeResult.city = addressComponents[i].long_name; | |
} | |
} | |
} | |
//STATE, use administrative_area_level_1 | |
for (i in addressComponents) { | |
if (addressComponents[i].types.indexOf('administrative_area_level_1') > -1) { | |
geocodeResult.state = addressComponents[i].short_name; | |
} | |
} | |
populateForm(); | |
$btn.button('reset') | |
} else { | |
//error | |
} | |
}); | |
} | |
function populateForm() { | |
$('#perdiem-zip').val(geocodeResult.zip) | |
$('#perdiem-city').val(geocodeResult.city) | |
$('#perdiem-state option').each(function() { | |
if ($(this).val() === geocodeResult.state) { | |
//$(this).attr('selected', 'selected'); | |
$(this).prop('selected', true); | |
} | |
}) | |
setTimeout(function() { | |
validateLocationParams(); | |
perDiemSearch.locationType = 'Geolocation' | |
}, 250) | |
$('#perdiem-zip,#perdiem-city,#perdiem-state').addClass('animated flash'); | |
setTimeout(function() { | |
$('#perdiem-zip,#perdiem-city,#perdiem-state').removeClass('animated flash'); | |
}, 2000) | |
} | |
function currentPositionError() { | |
} | |
} | |
function locationError() { | |
$('#perdiem-location-error').show() | |
$('#perdiem-multiple-rates-check').html('Next') | |
perDiemSwiper.slideTo(0) | |
} | |
function calculateRates() { | |
$("#perdiem-multiple-rates-check").html('Next <span class="glyphicon glyphicon-refresh spinning"></span>'), $("#perdiem-multiple-rates-check,#perdiem-rates-selected").html("Next"), perDiemSearch.results = { | |
breakdown: [], | |
rateInfo: [], | |
total: 0 | |
}; | |
var e = moment(perDiemSearch.startDate, "MM/DD/YYYY"), | |
r = moment(perDiemSearch.endDate, "MM/DD/YYYY"); | |
moment(perDiemSearch.startDate, "MM/DD/YYYY"), moment(perDiemSearch.endDate, "MM/DD/YYYY"); | |
if (perDiemSearch.startDate === perDiemSearch.endDate) var a = .75 * perDiemCalculator.rates.fy1.rate.meals; | |
else | |
for (var a = 0, t = moment(perDiemSearch.startDate).format("MM-DD-YYYY"), o = moment(perDiemSearch.endDate).format("MM-DD-YYYY"), n = e; !n.isAfter(r); n.add(1, "days")) { | |
var s = n.format("M") - 1, | |
m = n.format("YYYY"); | |
if (s > 8) var c = parseFloat(m) + 1; | |
else var c = parseFloat(m); | |
var l = Object.keys(perDiemSearch.rates); | |
for (i in l) | |
if (perDiemSearch.rates[l[i]].year === c) var p = perDiemSearch.rates[l[i]].rate; | |
for (i in p.months.month) | |
if (p.months.month[i].number === s + 1) var d = p.months.month[i].value; | |
var u = n.format("MMMM"), | |
h = perDiemSearch.results.rateInfo; | |
for (i in h) | |
if (h[i].date === u) var D = !0; | |
else var D = !1; | |
if (0 === h.length) var D = !1; | |
if (D === !1 && perDiemSearch.results.rateInfo.push({ | |
date: u, | |
lodging: formatCurrency(d), | |
mie: formatCurrency(p.meals) | |
}), n.format("MM-DD-YYYY") === t && t !== o) { | |
var f = .75 * p.meals; | |
a += f, a += d; | |
var v = d + f; | |
perDiemSearch.results.breakdown.push({ | |
date: "First Day", | |
fullDate: n.format("MM/DD/YY"), | |
lodging: formatCurrency(d), | |
mie: formatCurrency(f), | |
isFirstLast: !0, | |
total: formatCurrency(v) | |
}) | |
} else if (n.format("MM-DD-YYYY") === o) { | |
if (t === o) var y = "Single Day"; | |
else var y = "Last Day"; | |
var f = .75 * p.meals; | |
a += f, perDiemSearch.results.breakdown.push({ | |
date: y, | |
fullDate: n.format("MM/DD/YY"), | |
mie: formatCurrency(f), | |
lodging: 0, | |
isFirstLast: !0, | |
total: formatCurrency(f) | |
}) | |
} else { | |
var f = p.meals; | |
a += d, a += f; | |
var S = perDiemSearch.results.breakdown; | |
for (i in S) | |
if (S[i].date === u) var D = !0; | |
else var D = !1; | |
if (!D) { | |
var v = d + f; | |
perDiemSearch.results.breakdown.push({ | |
isRate: !0, | |
date: u, | |
lodging: formatCurrency(d), | |
mie: formatCurrency(f), | |
total: formatCurrency(v) | |
}) | |
} | |
} | |
} | |
perDiemSearch.results.total = a, perDiemSearch.rates.fy2 && perDiemSearch.rates.fy1.rate.county === perDiemSearch.rates.fy2.rate.county && (perDiemSearch.ratesAreSame = !0), perDiemSearch.query.stateFormatted = USStates[perDiemSearch.query.state.toLowerCase()], perDiemSearch.results.totalFormatted = formatCurrency(perDiemSearch.results.total); | |
var g = template_calculator_results, | |
Y = Mustache.render(g, { | |
perDiemSearch: perDiemSearch, | |
sameRate: perDiemSearch.ratesAreSame | |
}); | |
if ($("#perdiem-results").html(Y), perDiemSwiper.slideTo(5), "undefined" != typeof dataLayer) { | |
var w = { | |
event: "virtualEvent" | |
}; | |
w.eventCategory = "Per Diem Tool Success", w.eventAction = perDiemSearch.searchType, "Look Up" === perDiemSearch.searchType && (w.eventLabel = perDiemSearch.endFY), dataLayer.push(w) | |
} | |
}; | |
function formatCurrency(n) { | |
if (n % 1 != 0) { | |
var formatted = n.toFixed(2) | |
} else { | |
var formatted = n | |
} | |
return formatted; | |
} | |
function ratesSelected() { | |
if (perDiemSearch.rates.fy1.multiple) { | |
var e = $("#perdiem-fiscal-year-1 option:selected").index() - 1; | |
perDiemSearch.rates.fy1.rate = perDiemSearch.rates.fy1.rates[e] | |
} | |
if (perDiemSearch.rates.fy2 && perDiemSearch.rates.fy2.multiple) { | |
var r = $("#perdiem-fiscal-year-2 option:selected").index() - 1; | |
perDiemSearch.rates.fy2.rate = perDiemSearch.rates.fy2.rates[r] | |
} | |
calculateRates() | |
} | |
function updateProgress(n) { | |
$('.progress-bar').attr('aria-valuenow', n).css('width', n + '%') | |
} | |
function lookUpRatesSubmit() { | |
var lookUpYear = $('#perdiem-rate-lookup-fiscal-year').val() | |
var url = apiRoot + "/travel/plan-book/per-diem-rates/per-diem-rates-look-up/?action=perdiems_report&fiscal_year=" + lookUpYear + "&city=" + $('#perdiem-city').val() + "&state=" + $('#perdiem-state').val() + "&zip=" + $('#perdiem-zip').val(); | |
if (typeof(ga) != "undefined") { | |
ga('send', 'event', 'Per Diem Tool Success', 'Look Up'); | |
} | |
console.log('%cGA SEND EVENT: CATEGORY: Per Diem Tool Success ACTION: Look Up LABEL: ' + lookUpYear, gaConsoleCSS) | |
window.open(url) | |
} | |
function perDiemResultPrint() { | |
var w = window.open(); | |
w.document.title = 'Per Diem Rates'; | |
var template = template_calculator_results_print; | |
var rendered = Mustache.render(template, { | |
perDiemSearch: perDiemSearch, | |
sameRate: perDiemSearch.ratesAreSame | |
}); | |
$(w.document.body).html(rendered + $('#per-diem-terms-conditions-accordion-content').html()); | |
setTimeout(function() { | |
w.focus(); | |
w.print(); | |
}, 1000) | |
} | |
})(jQuery); | |
var USStates = { | |
"al": "Alabama", | |
"ak": "Alaska", | |
"az": "Arizona", | |
"ar": "Arkansas", | |
"ca": "California", | |
"co": "Colorado", | |
"ct": "Connecticut", | |
"dc": "District of Columbia", | |
"de": "Delaware", | |
"fl": "Florida", | |
"ga": "Georgia", | |
"hi": "Hawaii", | |
"id": "Idaho", | |
"il": "Illinois", | |
"in": "Indiana", | |
"ia": "Iowa", | |
"ks": "Kansas", | |
"ky": "Kentucky", | |
"la": "Louisiana", | |
"me": "Maine", | |
"md": "Maryland", | |
"ma": "Massachusetts", | |
"mi": "Michigan", | |
"mn": "Montana", | |
"ms": "Mississippi", | |
"mo": "Missouri", | |
"ne": "Nebraska", | |
"nv": "Nevada", | |
"nh": "New Hampshire", | |
"nj": "New Jersey", | |
"nm": "New Mexico", | |
"ny": "New York", | |
"nc": "North Carolina", | |
"nd": "North Dakota", | |
"oh": "Ohio", | |
"ok": "Oklahoma", | |
"or": "Oregon", | |
"pa": "Pennsylvania", | |
"ri": "Rhode Island", | |
"sc": "South Carolina", | |
"sd": "South Dakota", | |
"tn": "Tennessee", | |
"tx": "Texas", | |
"ut": "Utah", | |
"vt": "Vermont", | |
"va": "Virginia", | |
"wa": "Washington", | |
"wv": "West Virginia", | |
"wi": "Wisconsin", | |
"wy": "Wyoming" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
$ = jQuery; | |
/* if(!GSA){ | |
var GSA = {} | |
} | |
var staticGACrumb = '/sustainability'; | |
var gaDimensions = {}; | |
var router = new Grapnel({root : '/sustainability/' }); | |
^^Ogilvy used a JS router to two-way bind Sustainability's "virtual pages" with hash URLS. | |
We have custom JS leveraged via GTM which detects hash changes, and reports "virtual page views" to GTM. | |
With these router directives factored out, analytics on page interactions are no longer reported | |
*/ | |
blockHover(); | |
toggleActiveBlocks(); | |
hoverThumbs(); | |
$(".popup").fancybox(); | |
if($(window).width <= 768) { | |
$('.blocks-container').css('height', 'auto!important'); | |
} | |
jQuery('#landing').on('click', '.block', function (e) { | |
$('#second-level').fadeOut(500); | |
var header = $(this).find('aside').text(); | |
var indexValue = $(this).parent('div').index() + 1; | |
if ($(this).parent('div').index() === 0) { | |
e.preventDefault(); | |
} else { | |
e.preventDefault(); | |
//maintain height of display area and get index number of clicked block | |
var wrapper = $('.blocks-container'); | |
wrapper.height(wrapper.height()); | |
GSA.indexTracker = $(this).parent('div').index(); | |
//assign the active block and create some variables | |
var activeBlock = $(this).parent('.block-wrap'), | |
offsetLeft = activeBlock.position().left, | |
offsetTop = activeBlock.position().top; | |
// position the ACTIVE block | |
activeBlock.addClass('current'); | |
activeBlock.css({position: 'absolute', display: 'block', left: offsetLeft, top: offsetTop}); | |
activeBlock.animate({left: 0, top: 0, width: '100%', height: '100%'}, 500, function () { | |
// display the thumb navigation | |
displayThumbs(); | |
$("html, body").animate({scrollTop: $('#thumb-nav').offset().top - 125}, 500); | |
// display left/right navigation | |
$('.slide-section').fadeIn(500); | |
}); | |
// apply template and style to each of the blocks hidden behind the active block | |
$('.block-wrap').each(function () { | |
var title = $(this).find('header').text(), | |
label = $(this).find('aside').text(), | |
text = $(this).find('.full-display-content').html(); | |
image = $(this).children('.block').css('background-image'); | |
$(this).removeClass('block-wrap col-sm-3 col-sm-6').addClass('slide').html("<div class='inner-block' style='background: #f6f6f6;'><header>" + title + "</header><article>" + text + "</article></div>").css({height: '100%'}); | |
}); | |
setTimeout(function () { | |
var heightofActiveBlock = parseInt($('.current .inner-block > article').height() + 75); | |
wrapper.height(heightofActiveBlock); | |
}, 200); | |
// router | |
//router.navigate('#/'+GSA.CIDs[indexValue]); | |
} | |
}); | |
function blockHover () { | |
$("#landing").on({ | |
mouseenter: function () { | |
$(this).find('.rollover').stop().fadeIn(500); | |
}, | |
mouseleave: function () { | |
$(this).find('.rollover').stop().fadeOut(300); | |
} | |
},'.block-wrap:not(:first-child)'); | |
}; | |
function hoverThumbs() { | |
$("#landing").on({ | |
mouseenter: function () { | |
$(this).find('.thumb').stop().animate({opacity: 1}, 200); | |
}, | |
mouseleave: function () { | |
$(this).find('.thumb').stop().animate({opacity: 0.7}, 200); | |
} | |
}, '#thumb-nav > div:not(:first-child)'); | |
} | |
function displayThumbs() { | |
var wrapperWidth = $('.blocks-container').width(), | |
thumbBlocks = wrapperWidth / 8, | |
spacePadding = 6; | |
sortDivs('#thumb-nav', '.thumb-wrap'); | |
$('#thumb-nav > div:first-child').css('width', (thumbBlocks*2)-spacePadding); | |
$('#thumb-nav').children('div').each(function(i) { | |
if(i == GSA.indexTracker) { | |
$(this).addClass('active-thumb'); | |
} | |
$(this).delay(i * 100).slideDown(600); | |
}); | |
}; | |
function sortDivs(wrapper,item) { | |
var $wrapper = $(wrapper); | |
$wrapper.find(item).sort(function (a, b) { | |
return +a.getAttribute('data-sort') - +b.getAttribute('data-sort'); | |
}).appendTo( $wrapper ); | |
}; | |
function toggleActiveBlocks() { | |
var thumbBlock = '#thumb-nav > div'; | |
var wrapper = $('.blocks-container'); | |
$('#landing').on('click',thumbBlock,function(e) { | |
var thumbIndex = $(this).index(); | |
if(thumbIndex == 0) { | |
//router.navigate(''); | |
} else { | |
e.preventDefault(); | |
$(thumbBlock).removeClass('active-thumb'); | |
$(this).addClass('active-thumb'); | |
var currentSlide = $('.blocks-container > div').eq(thumbIndex); | |
currentSlide.addClass('current').fadeIn(500,function() { | |
$('.current').not(currentSlide).fadeOut(300).delay(300).removeClass('current'); | |
var heightofActiveBlock = parseInt($('.current .inner-block > article').height() + 175); | |
wrapper.height(heightofActiveBlock); | |
}); | |
GSA.indexTracker = thumbIndex; | |
//router | |
//router.navigate('#/'+GSA.CIDs[thumbIndex+1]); | |
} | |
}) | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment