//Author : Francis Bolaji
//Modified and Extn: Lewis Leighton
//http://javascript.nwbox.com/CSSSupport/
//https://gist.github.com/441842
function selectorSupported(selector) {
var support, link, sheet, doc = document,
root = doc.documentElement,
head = root
.getElementsByTagName('head')[0],
impl = doc.implementation || {
hasFeature: function () {
return false;
}
},
link = doc.createElement("style");
link.type = 'text/css';
(head || root).insertBefore(link, (head || root).firstChild);
sheet = link.sheet || link.styleSheet;
if (!(sheet && selector))
return false;
support = impl.hasFeature('CSS2', '') ?
function (selector) {
try {
sheet.insertRule(selector + '{ }', 0);
sheet.deleteRule(sheet.cssRules.length - 1);
} catch (e) {
return false;
}
return true;
} : function (selector) {
sheet.cssText = selector + ' { }';
return sheet.cssText.length !== 0 && !(/unknown/i).test(sheet.cssText) && sheet.cssText.indexOf(selector) === 0;
};
return support(selector);
};
Modernizr.addTest('targetselector', function () {
return selectorSupported(':target');
});
// introduce a bind fallback for older browsers
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable
// function
throw new TypeError(
"Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {}, fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
var debug = {};
var EP2 = EP2 || {};
EP2.Utils = {
objectHasProperties: function (obj) {
for (var prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
return true;
}
}
return false;
}
};
EP2.searchBox = function () {
var pub = {
init: function () {
var srchBox = $('#s');
srchBox.css('width', 'auto');
var checkIEbrowser = $('.lt-ie9');
var compareTxt = srchBox.attr('placeholder');
var w = 91;
srchBox.removeAttr('placeholder');
if (checkIEbrowser.length) { // Fix for IE -
// placeholder attribute
srchBox.val(srchBox.attr('placeholder'));
}
var callback = function (ele) {
if (srchBox.val() == "") {
setTimeout(function () {
$(ele).closest('form')
.removeClass('expand');
if (checkIEbrowser.length && compareTxt == srchBox.val()) {
srchBox.val('');
}
srchBox.blur();
}, 7000);
}
};
srchBox.bind({
focus: function () {
var $this = $(this);
$this.attr('placeholder', compareTxt)
if (checkIEbrowser.length) {
srchBox.val(compareTxt);
}
$this.closest('form').addClass('expand');
$this.animate({
width: 299
}, 250);
},
blur: function () {
var $this = $(this);
$this.closest('form').removeClass('expand');
$this.animate({
width: w
}, 250);
$this.closest('form').removeClass(
'expand, notEmpty');
$this.removeAttr('placeholder');
$this.removeAttr('style');
$this.val('');
},
keyup: function () {
var $this = $(this);
if (checkIEbrowser.length) {
if ($this.val().match(compareTxt)) {
$this.val($this.val().replace(compareTxt, ''));
}
}
}
});
}
};
return pub;
}();
EP2.equalizer = function () {
var pub = {
init: function (ele) {
$(ele).maxHeight();
}
};
return pub;
}();
EP2.extendFooterBackground = function () {
var pub = {
init: function () {
var winHeight = $(window).height(),
wrapperHeight = $('#wrapper').height(),
footerOriginalHeight = $('#wrapper footer').height();
var newFooterHeight = parseInt(footerOriginalHeight + (winHeight - wrapperHeight));
if (footerOriginalHeight > newFooterHeight) {
//do nothing
$('#wrapper footer').removeAttr('style');
} else {
$('#wrapper footer').css('height', newFooterHeight + 'px');
}
}
};
return pub;
}();
EP2.toggleFooterSubLinks = function () {
var pub = {
init: function (ele) {
var expandSelector = $(ele);
expandSelector.next('dl.flyout').hide('fast');
expandSelector.click(function (e) {
e.preventDefault();
var $this = $(this);
if ($('dl.flyout').is(':visible')) {
$('dl.flyout').slideUp('fast');
}
if ($('dl.flyout').not(':visible')) {
$('dl.flyout').prev().removeClass("active");
$('dl.flyout').parent().removeClass("active");
$(this).find('span').css('background-position',
'0 -15px');
}
$this.addClass("active");
$this.parent().addClass("active");
$this.next('dl.flyout').toggle();
});
expandSelector.hover(function () {
$(this).find('span').css('background-position',
'0 -15px');
}, function () {
$(this).find('span').css('background-position',
'0 0');
});
}
};
return pub;
}();
jQuery(function ($) {
(function () { //inject a css class for specific site font issue
var fordsite = function () {
this.hostName = location.hostname;
this.matchdomain = this.hostName.match(/cz/g) || this.hostName.match(/CZ/g);
if (this.matchdomain) {
// console.log(this.hostName +":"+ this.matchdomain);
$('html').addClass('cz-font-render');
$('head').append('');
}
};
return fordsite();
})();
/* beginsOf Fn(s) */
//I don't know hwy this is DIV is there but ...adjust div width to stop hovering issue in the top section of the EP2 nav.
$('.pv-endpoint').css({
width: 'auto'
});
$('ul.skip').html(
'
Skip to vehicle content');
/* $('#sbe div.flyout dt:eq(1)').css({
marginTop: '10px',
paddingTop: '5px'
});*/
// move the breadcrumb list into the ".topContainer" in the header section
$('nav.breadCrumb').insertBefore('div.topContainer > .fr');
$('nav.breadCrumb').removeClass('visuallyhidden');
EP2.equalizer.init('.carModels > li');
EP2.toggleFooterSubLinks.init($('.expand'));
EP2.extendFooterBackground.init();
$(window).bind('resize', EP2.extendFooterBackground.init());
EP2.applyCssToFooterSBE = function(){
var expandable = $('dd > .expand');
var ordinaryLink = $('.listColumn > dl > dd > .sbe');
expandable.each(function(i,v){
var findSpan = $(this).find('> span');
console.log();
if(!findSpan.length){
$(this).append('');
}
});
ordinaryLink.each(function(i,v){
var findLink = $(this).find('> span');
if(!findLink.length){
$(this).append('');
}
});
}();
});
/** ***************** PLUGINS **************** */
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function f() {
log.history = log.history || [];
log.history.push(arguments);
if (this.console) {
var args = arguments,
newarr;
args.callee = args.callee.caller;
newarr = [].slice.call(args);
if (typeof console.log === 'object')
log.apply.call(console.log, console, newarr);
else
console.log.apply(console, newarr);
}
};
// make it safe to use console.log always
(function (a) {
function b() {}
for (var c = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn"
.split(","), d; !! (d = c.pop());) {
a[d] = a[d] || b;
}
})(function () {
try {
console.log();
return window.console;
} catch (a) {
return (window.console = {});
}
}());
//Plugin EQUALIZER
;
(function ($) {
$.fn.maxHeight = function () {
var max = 0;
// check for the tallest element(height)
this.each(function (ele, index) {
max = Math.max(max, $(this).height());
});
// apply the tallest element's height to all the siblings
$(this).each(function () {
if (max) {
$(this).css({
'height': max
});
}
});
return max;
};
})(jQuery);
//FBolaji - specially designed for topNavigation and other EP2 tabs
(function($, window, document, undefined) {
$.tabbifiedContent = function(element, options) {
var defaults = {
navEle : 'ul.subMenu a', // links to turn to tab selector
tabPanelWrapperSelector : '', // tab content wrapper selector
// ids/class
tabPanelSelector : '', // turn a group of content element to tab
// content
tabNavEvent : 'mouseover', // types of events to use; mouseover,
// mouseenter, click and focusin
selectedTabLink:null, // specify tab content to display on
// loading. default : 1
hiAjax : false, // ajax call to load content, "true" is to enable
afterTabSelected : function(){} // do stuff after tab a sepcific tab is selected.
};
var plugin = this;
plugin.settings = {};
var $element = $(element);
// element = element;
plugin.init = function() {
plugin.settings = $.extend({}, defaults, options);
// tab content starts here
var navSelector = $(element).find(plugin.settings.navEle);
var tabBlock = plugin.settings.tabPanelWrapperSelector != "" ? $(plugin.settings.tabPanelWrapperSelector).children() : $(plugin.settings.tabPanelSelector);
var tabEvent = plugin.settings.tabNavEvent;
var selectedTab = parseInt (plugin.settings.selectedTabLink);
// $(element).find()navSelector.hasClass('selected');
// plugin.settings.selectedTabLink -1; // using array count method
var myArray = [];
var tabContentNav = function() {
if ($element != undefined) {
var tabContainers = $(tabBlock);
var tabNavLinkSelected = navSelector;
// tabNavLinkSelected.removeClass('selected');
tabContainers.hide('fast');
// tabNavLinkSelected.eq(selectedTab).addClass('selected');
// collect tabcontent as array
tabContainers.each(function() {
var addAttr = $element.attr('id') + $(this).index() || $element.attr('class') + $(this).index();
$(this).attr('id', addAttr);
myArray.push({
'id' : $(this).attr('id')
});
});
// show and apply the tabcontent array index and populate in
// tabNav as rel
$.each(myArray, function(i, v) {
var relAttr = v.id;
tabNavLinkSelected.eq(i).attr({
rel : v.id,
id : 'link' + v.id
});
});
var linkSelected = tabNavLinkSelected.hasClass('selected');
var linkSelectedId = $(element).find('.selected').index();
var getSelectedRel = $(element).find('.selected').attr(
'rel');
// show the first tab content or specified tab content.
if(selectedTab!==null){
tabContainers.eq(selectedTab).show('fast');
tabNavLinkSelected.parent('li').removeClass('selected');
tabNavLinkSelected.eq(selectedTab).addClass('selected');
tabNavLinkSelected.eq(selectedTab).parent('li').addClass('selected');
}
// var getRel = navSelector.attr('rel');
if (linkSelected === true) {
// console.log(getSelectedRel);
$('#' + getSelectedRel).show('fast');
}
// event behaviour
tabNavLinkSelected.each(function(i, v) {
var $this = $(this);
var setLinkHash = $this.attr('rel');
var getRelatedLink = $this.attr('href');
if (tabEvent == "mouseover"
|| tabEvent == "mouseenter"
|| tabEvent == "focusin") {
$this
.bind({
'focusin mouseover mouseenter' : function(e) {
tabContainers.stop(true,true).hide('fast');
var getId = tabContainers.hide().filter(this.hash).attr('id');
$this.attr('href', '#'+ setLinkHash);
tabContainers.hide().filter(this.hash).stop(true, true).show();
tabNavLinkSelected.removeClass('selected');
$this.addClass('selected');
if (plugin.settings.hiAjax === true) {
hiAjaxbehaviour(
getRelatedLink,
getId);
}
$this.attr('href',getRelatedLink);
},
'focusout mouseout mouseleave' : function() {
$this.attr('href',
getRelatedLink);
},
'click' : function(e) {
e.preventDefault();
$this.attr('href',
getRelatedLink);
window.location.href = getRelatedLink;
},
'mousedown' : function(e) {
e.preventDefault();
$this.attr('href',
getRelatedLink);
// console.log(getRelatedLink);
// window.location.href =
// getRelatedLink;
}
});
}
if (tabEvent == "click") {
$this
.on({
'click' : function() {
var getId = tabContainers
.hide().filter(
this.hash)
.attr('id');
$this.attr('href', '#'
+ setLinkHash);
tabContainers.hide()
.filter(this.hash)
.stop(true, true)
.show('fast');
tabNavLinkSelected
.removeClass('selected');
$this.addClass('selected');
if (plugin.settings.hiAjax == true) {
hiAjaxbehaviour(
getRelatedLink,
getId);
}
}
});
}
});
if(typeof(plugin.settings.afterTabSelected) == "function"){
plugin.settings.afterTabSelected(navSelector); //callback
}
}
};
var hiAjaxbehaviour = function(url, id) {
var contentURL = url;
$.ajax({
url : contentURL,
dataType : 'html',
success : function(html) {
$('#' + id).html(html);
}
});
};
tabContentNav();
};
plugin.init();
};
$.fn.tabbifiedContent = function(options) {
return this.each(function() {
if (undefined == $(this).data('tabbifiedContent')) {
var plugin = new $.tabbifiedContent(this, options);
$(this).data('tabbifiedContent', plugin);
}
});
};
})(jQuery, window, document);