Skip to content

Instantly share code, notes, and snippets.

@nkmdk-007
Created April 6, 2016 16:34
Show Gist options
  • Save nkmdk-007/472bfaebd09e0ea03fbecd31be413f36 to your computer and use it in GitHub Desktop.
Save nkmdk-007/472bfaebd09e0ea03fbecd31be413f36 to your computer and use it in GitHub Desktop.
(function() {
"use strict";
// Reduce version of jQuery (1.6.4) is loaded at this point in the JSVM.
var _$,
$form,
VERSION = '24',
timer,
$selectRegion = $('select[name="region"]'),
dataFilterHandler = function(data, dataType) {
if (this.url.indexOf('/organisations?') >= 0) {
return data.replace(/flexslider--fixed-height/g, 'flexslider--fixed-height flexslider--inactive');
}
},
updateMetaLinks = function() {
var $orgDetails = $('.organisation__details'),
loop,
$org,
$webSiteLink,
$telLink,
domain;
for (loop = 0; loop < $orgDetails.length; loop++) {
$org = $($orgDetails[loop]);
$webSiteLink = $org.find('.meta__website a');
domain = $webSiteLink[0].hostname.replace(/www\./i, '');
$webSiteLink.attr('data-test38-domain', domain);
$telLink = $org.find('.meta__tel a');
if ($telLink.length) {
$telLink.attr('data-test38-domain', domain);
}
}
},
ajaxFormCompleteHandler = function(evt, xhr, settings) {
$form.off('ajax:complete', ajaxFormCompleteHandler); // Remove Handler to prevent duplicates
timer = window.setInterval(postAjaxIntervalHandler, 50);
},
postAjaxIntervalHandler = function(evt) {
if ($('.organisation__details a[data-test38-domain]').length > 0) {
return;
}
window.clearInterval(timer);
timer = null;
updateMetaLinks();// Copy over some meta data for use in the Goals.
},
orgLinkClickHandler = function(evt) {
var goal = 'test38-',
$link = $(this);
if (!$link.attr('data-test38-domain')) {
return;
}
if ($link.parents('.js-section-online').length > 0) {
goal = goal + 'www-';
}
else {
goal = goal + 'tel-';
}
goal = goal + $link.attr('data-test38-domain');
window.optimizely.push(['trackEvent', goal]);
};
// ensures the optimizely object is defined globally using
window['optimizely'] = window['optimizely'] || [];
if (optimizely.variationNamesMap['5270531233'] !== 'dal-carousel--original') {
// Prevent flexslider from being initialised first time round if we're not in the original variant
$('.flexslider').addClass('flexslider--inactive');
}
updateMetaLinks();// Copy over some meta data for use in the Goals.
$('.js-section-online').parent().delegate('.js-section-online a, .js-section-phone a', 'mousedown', orgLinkClickHandler);
// NOTE: live() is valid in the optimizely jQuery version.
$selectRegion.live('change', function(evt) {
_$ = window.$; // Use our version of jQuery now it's available.
$form = _$(this).parent('form');
$form.on('ajax:complete', ajaxFormCompleteHandler);
if (optimizely.variationNamesMap['5270531233'] !== 'dal-carousel--original') {
_$.ajaxSetup({
dataFilter: dataFilterHandler
});
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment