var UNIQLONAV = function () {
this.init();
}
UNIQLONAV.CONSTANTS = {
SEC_NAV_ID_SELECTOR: '#secondary',
SEARCH_SELECTOR: '#search',
PRIMARY_NAV_SELECTOR: '#primary',
HOVER_CLS: 'hover',
CURRENT_CLS: 'current',
EASEMETHOD: 'easeOutQuint',
SEARCHSELECTED: 'searchselected',
SEARCHHOVER: 'searchhover',
CURRENT_SUBNAV_CLS: 'currentNav',
CUSTOMER_MENU: 'customerMenu',
SHOPPING_MENU: 'shoppingMenu'
}
UNIQLONAV.prototype = {
secondaryNav: null,
primaryNav: null,
primaryHeader: null,
subNavArry: new Array(),
currentNav: null,
cInx: null,
navOpenTimer: null,
navCloseTimer: null,
pageDoneLoaded: false,
navBar: null,
search: null,
_c: UNIQLONAV.CONSTANTS,
mainSection: null,
init: function () {
this.secondaryNav = $(this._c.SEC_NAV_ID_SELECTOR); //secondary and tertiary nav container
this.primaryNav = $(this._c.PRIMARY_NAV_SELECTOR + ' nav'); //primary nav
this.navBar = $('#navBar'); //3px subnav top border
this.primaryHeader = $('#primaryHeader'); //global nav container
this.mainSection = $("header").next();
this.attachEvtPrimary(); //attach hover event to primary nav
this.attachEvtSearch(); //attach mouse event to search container, mouseenter, mouseleave, focus, blur and clear
this.searchFilterActions(); // search filter functions
this.attachEvtSecondaryNav(); //attach mouse event to secondary and tertiary nav
this.attachEvtShoppingBag(); //attach mouse event to user name and shopping bag area
//this.attachEvtWindow(); //attach scroll event
this.attachEvtBody(); //attach click event to document body
this.getSubNav(); //create an array of sub nav
this.secondaryNav.height(0);
this.ie9Check(); /// adds ie-9 class if browser is IE verison 9
this.pageDoneLoaded = true;
},
getSubNav: function () {
var _self = this;
$(this._c.SEC_NAV_ID_SELECTOR + ' .secondaryNav').each(function (inx) {
if ($(this).hasClass(UNIQLONAV.CONSTANTS.CURRENT_SUBNAV_CLS)) {
_self.cInx = inx; //index of initial open nav if there's one
_self.initalShowNavBorder(); //show sub nav border if it is open on page load
}
_self.subNavArry.push($(this));
_self.subNavArry[inx].tertiary = _self.subNavArry[inx].find('ul');
_self.subNavArry[inx].secondary = _self.subNavArry[inx].find('th a');
});
},
initalShowNavBorder: function () {
if (this.secondaryNav.height()) {
//window.scrollTo(0, 0);
this.showNavBorder();
}
},
attachEvtPrimary: function () {
var _self = this;
this.primaryNav.on('mouseover', 'a', function (e) {
var el = $(this);
_self.unSelectPrimaryNav(el);
el.addClass(_self._c.HOVER_CLS);
_self.setOpenTimer(el.parent());
}).on('mouseleave', 'a', function (e) {
_self.setCloseTimer();
});
},
setCloseTimer: function () {
var _self = this;
clearTimeout(this.navOpenTimer);
this.navCloseTimer = setTimeout(function () {
_self.hideNav();
}, 150);
},
setOpenTimer: function (el) {
var _self = this;
clearTimeout(this.navCloseTimer);
this.navOpenTimer = setTimeout(function () {
_self.showNav(el);
}, 150);
},
attachEvtSearch: function () {
this.search = $(this._c.SEARCH_SELECTOR);
var input = this.search.find('input'),
_self = this;
this.search.on('mouseenter', function () {
if (!_self.search.hasClass(_self._c.SEARCHSELECTED)) {
_self.search.addClass(_self._c.SEARCHHOVER);
}
}).on('mouseleave', function () {
if (!input.is(':focus')) {
_self.search.removeClass(_self._c.SEARCHHOVER).removeClass(_self._c.SEARCHSELECTED);
}
})
input.on('focus', function (e) {
_self.search.removeClass(_self._c.SEARCHHOVER).addClass(_self._c.SEARCHSELECTED);
});
this.search.find('a.reset').on('click', function (e) {
e.preventDefault();
input.val('');
});
},
attachEvtSecondaryNav: function () {
var _self = this;
this.secondaryNav.on('mouseenter', function (e) {
clearTimeout(_self.navCloseTimer);
}).on('mouseleave', function () {
_self.setCloseTimer();
}).on('mouseover', 'a', function (e) {
$(this).addClass('hover').removeClass('out');
}).on('mouseout', 'a', function (e) {
$(this).switchClass(UNIQLONAV.CONSTANTS.HOVER_CLS, 'out', 150);
});
},
attachEvtShoppingBag: function () {
var obj = $(".shoppingbag");
$('.customername').on('click', function () {
hideDiv('customerItems');
obj.addClass('shoppingbaghover');
showDiv('customerMenu');
});
$('.bagcount').on('click', function () {
$(this).addClass('open');
hideDiv('customerMenu');
obj.addClass('shoppingbaghover');
showDiv('customerItems');
});
$('#customerItems').on('mouseleave', function () {
hideDiv('customerItems');
});
$('#customerMenu').on('mouseleave', function () {
hideDiv('customerMenu');
})
$('#primary nav a').on('mouseenter', function (e) {
$('#customerItems, #customerMenu').slideUp('normal', function () {
$('.bagcount').removeClass('open');
$(".shoppingbag").removeClass('shoppingbaghover');
});
});
},
attachEvtWindow: function () {
var _self = this;
$(window).on('scroll', function () {
clearTimeout(_self.navCloseTimer);
var subnavHeight = _self.secondaryNav.height();
var hideGutter = false;
if (subnavHeight) {
var currentNav = _self.subNavArry[_self.cInx],
links = currentNav.tertiary,
scrollTop = $(this).scrollTop(),
maxScroll = subnavHeight;
if (scrollTop <= maxScroll) {
// links.css({'margin-top': (scrollTop * -1 + 20) + 'px'});
// currentNav.find('th').css({'top': scrollTop + 'px'});
//_self.secondaryNav.css({'height' : 'auto'});
_self.showNavBorder();
hideGutter = true;
if (scrollTop == 0) {
$('.scrollNav').addClass(UNIQLONAV.CONSTANTS.HOVER_CLS);
}
} else if (scrollTop > maxScroll) {
_self.navBar.css({
'display': 'none'
});
$('#primary nav a.hover').addClass('scrollNav').removeClass(UNIQLONAV.CONSTANTS.HOVER_CLS);
hideGutter = false;
}
}
_self.toggleGutter(hideGutter);
});
},
toggleGutter: function (hide) { //hide gutter below the primary header
if (hide) {
this.primaryHeader.removeClass('gutter');
} else {
this.primaryHeader.addClass('gutter');
}
},
attachEvtBody: function () {
$('body').on('click', 'div', function (e) {
var clickedElm = $(e.target);
if (clickedElm.attr('href')) {
clickedElm.attr('href') != "#";
return;
}
if (!$(UNIQLONAV.CONSTANTS.SEARCH_SELECTOR).find('input').is(':focus')) {
$(UNIQLONAV.CONSTANTS.SEARCH_SELECTOR).removeClass(UNIQLONAV.CONSTANTS.SEARCHSELECTED);
return false;
}
});
},
unSelectPrimaryNav: function (el) {
var hoverNav = this.primaryNav.find('.' + this._c.HOVER_CLS);
if (el != null && hoverNav.html() == el.html()) {
return 1;
}
if (hoverNav.hasClass(this._c.CURRENT_CLS)) {
hoverNav.removeClass(this._c.HOVER_CLS);
} else {
hoverNav.animate({
opacity: 0.1
}, {
duration: 150,
easing: 'linear',
complete: function () {
$(this).removeClass(UNIQLONAV.CONSTANTS.HOVER_CLS).css({
'opacity': 1
});
}
});
}
},
hideNav: function () {
var _self = this,
sn = this.secondaryNav;
if (sn.height()) {
this.subNavArry[this.cInx].tertiary.animate({
top: '-500px'
}, 200);
sn.animate({
height: '33px'
}, 200, function () {
_self.subNavArry[_self.cInx].secondary.animate({
top: '-40px'
}, 150);
_self.subNavArry[_self.cInx].animate({
marginTop: '-33px'
}, 150);
sn.animate({
height: 0
}, 150, function () {
_self.subNavArry[_self.cInx].removeClass(_self._c.CURRENT_SUBNAV_CLS);
_self.unSelectPrimaryNav();
});
_self.animateShrinkNavBar(_self.search.outerWidth());
});
//this.animateContent(0, 100);
this.mainSection.animate({
marginTop: 0
}, {
duration: 100
});
}
},
animateShrinkNavBar: function (searchWidth) {
var _self = this;
this.navBar.animate({
backgroundColor: '#000000',
width: (searchWidth + 20),
marginLeft: '60px'
}, {
duration: 250,
easing: 'linear',
complete: function () {
_self.navBar.animate({
width: searchWidth
}, 200, function () {
_self.navBar.css({
'display': 'none'
});
});
}
});
},
showNav: function (el) {
var prevNav = this.subNavArry[this.cInx],
new_cInx = el.index();
this.stopAnimate();
if (prevNav != null && this.cInx == new_cInx) {
clearTimeout(this.navCloseTimer);
if (this.secondaryNav.height() == prevNav.height()) {
return 1;
}
} else {
this.cInx = new_cInx;
$("#primary li a").removeClass('scrollNav');
}
if ($(window).scrollTop() > 0) {
//window.scrollTo(0, 0);
}
var _self = this,
currentNavHeight = this.secondaryNav.height(),
newNavHeight = this.subNavArry[this.cInx].height(),
links = this.subNavArry[this.cInx].find('a'),
duration = 300;
if (currentNavHeight) {
duration = (Math.abs(currentNavHeight - newNavHeight) * 2);
prevNav.removeClass(this._c.CURRENT_SUBNAV_CLS);
}
this.resetSubNav();
links.css({
'opacity': 0
});
this.subNavArry[this.cInx].addClass(this._c.CURRENT_SUBNAV_CLS);
this.animateSubNav(links, newNavHeight, duration);
this.animateContent(newNavHeight, duration)
},
animateSubNav: function (links, newNavHeight, duration) {
var _self = this;
this.secondaryNav.animate({
height: newNavHeight + 'px'
}, {
duration: duration,
easing: UNIQLONAV.CONSTANTS.EASEMETHOD,
complete: function () {
links.each(function (inx) {
$(this).delay(5 * inx).animate({
opacity: 1
}, {
duration: 150,
easing: 'linear'
});
});
_self.showNavBorder();
}
});
},
animateContent: function (offSet, duration) {
this.mainSection.animate({
marginTop: offSet
}, {
duration: duration,
easing: UNIQLONAV.CONSTANTS.EASEMETHOD
});
//this.mainSection
},
resetSubNav: function () {
this.showNavBorder();
this.toggleGutter(true);
this.subNavArry[this.cInx].css({
'margin-top': 0
});
this.subNavArry[this.cInx].secondary.css({
'top': 0
});
this.subNavArry[this.cInx].tertiary.css({
'top': 0,
'margin-top': '20px'
});
this.secondaryNav.css({
'opacity': 1,
'margin-top': 0
});
},
showNavBorder: function () {
this.navBar.css({
'display': 'block',
'background-color': '#ff0000',
'width': '100%',
'opacity': 1,
'margin-left': 0
});
},
stopAnimate: function () {
if (this.subNavArry[this.cInxx]) {
this.subNavArry[this.cInx].tertiary.stop(true, true);
this.subNavArry[this.cInx].secondary.stop(true, true);
this.secondaryNav.stop();
//this.navBar.stop();
}
},
animateCustomerMenus: function () {},
searchFilterActions: function () {
$('.searchColors ul li span').click(function (e) {
$('.searchColors ul li span').removeClass('current');
$(this).addClass('current');
});
$('.sortBy').click(function (e) {
if (!$(this).hasClass('open')) {
e.preventDefault();
$(this).toggleClass('open');
}
}).on('mouseleave', function (e) {
$(this).removeClass('open');
});
$('#searchWrapper .searchGender label, #searchWrapper .searchCategories label, #searchWrapper .searchSizes label, #searchWrapper .searchPrice label').click(function (e) {
var name = $(this).attr('for');
var isChecked = $(this).hasClass('checked');
if (!isChecked) {
$(this).addClass('checked');
$(this).parent().find('input').attr('checked', true);
} else {
$(this).removeClass('checked');
$(this).parent().find('input').attr('checked', false);
}
});
$('#searchWrapper .searchColors label').click(function (e) {
var name = $(this).attr('for');
var isChecked = $(this).hasClass('checked');
if (!isChecked) {
$(this).addClass('checked');
$(this).parent().find('input').attr('checked', true);
} else {
$(this).removeClass('checked');
$(this).parent().find('input').attr('checked', false);
}
});
$('.clearAllBtn').click(function (e) {
$('#searchWrapper label').parent().find('label').removeClass('checked');
$('#searchWrapper input').attr('checked', false);
});
$('#searchWrapper').click(function (e) {
/* var nodeType = e.target.nodeName;
if($(this).hasClass('open') && nodeType == 'DIV'){ }
else if(!$(this).hasClass('open') && nodeType == 'DIV'){ $(this).addClass('open'); $(this).transition({ height: '310px' }, 250, function() { $('#searchWrapper #searchColumnWrapper').show(); }); }
*/
});
/*$('#searchWrapper').on('mouseleave', function(e){
var nodeType = e.target.nodeName;
$('#searchWrapper #searchColumnWrapper').hide();
$(this).removeClass('open');
$(this).transition({ height: '70px' }, 250, function() { });
}); */
},
ie9Check: function () {
if ($.browser.msie && $.browser.version == "9.0") {
$('html').addClass('ie-9');
};
}
};
$(function () {
var uNav = new UNIQLONAV(); /** footer should be refactored **/
var footer = $('#gFooter'),
footerBar = $('#footerBar');
footerBar.on('click', function (e) {
footer.toggleClass('expand');
$('#gFooter .content').slideToggle('fast');
if (footer.hasClass('expand')) {
footerBar.removeClass('hover');
}
});
footer.on('mouseleave', function (e) {
if (footer.hasClass('expand')) {
footer.removeClass('expand');
$('#gFooter .content').hide('fast');
} else if (footerBar.hasClass('hover')) {
footerBar.switchClass('hover', '', 400);
}
}).on('mouseenter', function (e) {
if (!footer.hasClass('expand')) {
footerBar.addClass('hover');
} else {
footerBar.removeClass('hover');
}
});
$('.region').on('click', 'a', function (e) {
if (!$(e.delegateTarget).hasClass('open')) {
e.preventDefault();
$(e.delegateTarget).toggleClass('open');
} else {
document.location = $(this).attr('href');
}
}).on('mouseleave', function (e) {
$(this).removeClass('open');
});
$(document).on('keyup', function (e) {
// show footer hotkey F7
if ((e.keyCode || e.which) == 118) {
footerBar.trigger('click');
}
if ((e.keyCode || e.which) == 119) {
$('#primary li.play').trigger('hover');
}
});
});
function showDiv(div) {
$('#' + div).slideDown('normal', function () {
$(".shoppingbag").addClass('shoppingbaghover');
});
}
function hideDiv(div) {
$('#' + div).slideUp('normal', function () {
if (div == 'customerItems') {
$('.bagcount').removeClass('open');
}
$(".shoppingbag").removeClass('shoppingbaghover');
});
}