Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* NOTES: Purpose of .off() jquery native function
- is to prevent multiple fired event during orientation change */
- /* version="9sssssssssss" */
- if (ComponentRegistry.GlobalHeaderSettings) {
- /* Adjust Header in Preview */
- function adjustHeaderForPreview() {
- if ($('#scCrossPiece').length > 0 && $('#scFieldValues').length <= 0) {
- $('.navbar-fixed-top').css('top', $('#scCrossPiece').height());
- }
- else { setTimeout(adjustHeaderForPreview, 2500); }
- }
- $(window).load(function () {
- tertiaryNav.css('display', 'none');
- var frameParent = $('#scWebEditRibbon');
- if (frameParent.length > 0 && $('#scFieldValues').length <= 0) {
- adjustHeaderForPreview();
- //add event handler
- var siteCoreButton = $("a[data-sc-id='QuickRibbon']", frameParent.contents());
- siteCoreButton.on('click dblclick', function () {
- setTimeout(adjustHeaderForPreview, 50);
- });
- }
- if (isMobile() && !isTablet()) {
- if (isLandscape()) {
- tertiaryNav.css('margin-top', '-100%');
- menuFooter.css('position', 'static');
- }
- else {
- tertiaryNav.css('margin-top', '-200%');
- }
- }
- });
- /* GLOBAL VARIABLES */
- var viewPortWidth, deviceHeight;
- var backDropTablet = $(".back-drop-tablet");
- var countrySelectorCont = $('.utility-nav .country-form');
- var mobileShowToggle = 'show-sub-menu';
- var nav = $(".nav-content .nav-submenu");
- var navContainer = $('.nav-content');
- var navIcon = $('#nav-icon');
- var navLabel = $(".nav-content .nav-submenu-label");
- var toggleCountryList = 'show-country-list';
- var varSearchBody = $('#search-body .search-body-wrapper');
- var divContainer = $(".secondary-navs");
- var acnLogoContainer = $('.acn-logo-container');
- var documentClick = $(document);
- var navMenu = $('#navigation-menu');
- var menuFooter = $('#menuFooter');
- var tertiaryContainer = $('.secondary-item');
- var tertiaryClose = $('.nav-submenu-label-L3');
- var tertiaryNav = $('#tertiaryNav');
- var primaryNav = $('.primary-nav');
- var secondContactLink = $('#second-contact-link');
- var tertiaryListContainer = $('#tertiaryListContainer')
- var subMenuLabel = $('.nav-submenu-label');
- $(document).ready(function () {
- viewPortWidth = $(document).width();
- deviceHeight = $(window).height();
- globalHeader.init();
- });
- window.addEventListener("orientationchange", function () {
- setTimeout(function () {
- viewPortWidth = $(document).width();
- deviceHeight = $(window).height();
- globalHeader.init();
- }, 100);
- if (isLandscape()) {
- secondContactLink.css('position', 'static');
- }
- }, false);
- /* GLOBAL HEADER CONTROL */
- var globalHeader = (function () {
- var init = function () {
- globalHeaderNavigation();
- if ($('.search-icon-container.search-trigger').length == 0) {
- globalHeaderSearch();
- }
- globalCountrySelector();
- setNavigationHeightOnChangeOrientation();
- }
- /* NAVIGATION LINKS */
- var globalHeaderNavigation = function () {
- var prevSubmenu = null;
- var countrySelect = $('.country-select-cont');
- if (isTablet() && !isMobile()) {
- tertiaryNav.css('margin-top', '-304%');
- divContainer.removeClass('hidden');
- navContainer.addClass('hidden');
- if (navIcon.hasClass("open")) {
- navIcon.removeClass("open");
- showHideSecondaryNav.hideBackDrop();
- navContainer.removeClass('crawl-right');
- }
- backDropTablet.click(function () {
- showHideSecondaryNav.hideBackDropOnClick();
- });
- } else {
- divContainer.addClass('hidden');
- navContainer.removeClass('hidden');
- }
- if (isMobile()) {
- divContainer.removeClass('hidden');
- $(window).on('orientationchange', function (event) {
- if (isLandscape()) {
- tertiaryNav.css('margin-top', '-100%');
- menuFooter.css('position', 'static');
- }
- else {
- tertiaryNav.css('margin-top', '-200%');
- menuFooter.css('position', 'fixed');
- }
- });
- }
- navIcon.off('click').click(function () {
- $('body').toggleClass('o-hidden');
- if (!isTablet()) {
- $(this).toggleClass('open');
- }
- if (isTablet() || isMobile()) {
- if (isPrimaryOverflow()) {
- menuFooter.css('position', 'static');
- } else {
- menuFooter.css('position', 'fixed');
- }
- closeL3();
- }
- if (isTablet() && !isMobile()) {
- if (hasClass(backDropTablet, 'hidden')) {
- showHideSecondaryNav.showBackDrop();
- navContainer.removeClass('hidden');
- setTimeout(function () {
- navIcon.addClass("open");
- navContainer.addClass('crawl-right');
- }, 100);
- } else {
- showHideSecondaryNav.hideBackDrop();
- navContainer.removeClass('crawl-right');
- setTimeout(function () {
- navIcon.removeClass("open");
- navContainer.addClass('hidden');
- }, 210);
- }
- } else {
- navContainer.toggleClass('crawl-down');
- if (tertiaryNav.css('display') == 'block') {
- tertiaryNav.css('display', 'none');
- }
- }
- nav.removeClass(mobileShowToggle);
- if (isMobile()) {
- acnLogoContainer.toggleClass('hidden');
- countrySelect.toggleClass('absolute-fade');
- }
- divContainer.removeClass('in').addClass('collapse');
- setNavigationHeightOnChangeOrientation();
- countrySelectorControl.closeCountrySelector();
- prevSubmenu = null;
- });
- navLabel.click(function (event) {
- event.preventDefault();
- var $this = $(this);
- var newNav = $this.closest('.nav-submenu');
- var subMenu = $(this).next();
- var newDivContainer = $this.siblings('.secondary-navs');
- if (isMobile() || isTablet()) {
- if (newNav.hasClass(mobileShowToggle)) {
- setTimeout(function () {
- newNav.removeClass(mobileShowToggle);
- }, 10);
- } else {
- if (newNav.attr('id') != 'tertiary-block') {
- nav.delay(1400).removeClass(mobileShowToggle);
- }
- setTimeout(function () {
- newNav.delay(2800).addClass(mobileShowToggle);
- }, 10);
- }
- if (isSecondaryOverflow(subMenu) || isPrimaryOverflow()) {
- menuFooter.css('position', 'static');
- } else {
- menuFooter.css('position', 'fixed');
- }
- } else {
- if (hasClass(newDivContainer, 'hidden')) {
- divContainer.addClass('hidden');
- setTimeout(function () {
- showHideSecondaryNav.showNav(newNav);
- }, 100);
- } else {
- showHideSecondaryNav.clickHideNav(newNav);
- }
- if (!$this.hasClass('active')) {
- navLabel.removeClass('active').closest('.nav-submenu').removeClass('border-bottom');
- $this.addClass('active').closest('.nav-submenu').addClass('border-bottom');
- }
- else {
- $this.removeClass('active').closest('.nav-submenu').removeClass('border-bottom');
- }
- }
- });
- if (isMobile() || isTablet()) {
- if (!hasClass(divContainer, 'collapse')) {
- divContainer.addClass('collapse');
- navLabel.attr('data-toggle', 'collapse');
- }
- tertiaryClose.click(function() {
- closeL3()
- });
- //open tertiary menu
- tertiaryContainer.click(function L3() {
- if ($(this).parent().attr('id') != 'no-l3') {
- navMenu.children().addClass('hidden');
- var tertiary = $(this).data("tertiary");
- $('#' + tertiary).removeClass('hidden');
- tertiaryNav.css({ 'opacity': '0', 'right': '-530px' });
- tertiaryNav.css("display", "block").animate({
- opacity: '1',
- right: '0px',
- }, 100);
- $('.tertiary-title').html($(this).parents('.secondary-navs').attr('id'));
- subMenuLabel.addClass('tertiaryLevel3');
- tertiaryListContainer.html($(this).children('ul').clone());
- tertiaryListContainer.children('ul').removeClass('hidden-xs hidden-sm');
- if (isTertiaryOverflow($(this))) {
- secondContactLink.css("position", "static");
- } else {
- $("#second-contact-link").css("position", "fixed");
- }
- }
- });
- } else {
- divContainer.removeClass('collapse');
- navLabel.removeAttr('data-toggle');
- }
- if (!isMobile() && !isTablet()) {
- documentClick.off('click').click(function (event) {
- if (!$(event.target).closest(navMenu).length && !navLabel.is(event.target)) {
- showHideSecondaryNav.hideSubNav();
- }
- });
- }
- }
- /* SEARCH */
- var globalHeaderSearch = function () {
- var headerId = '#header-topnav';
- var searchBody = $('#search-body');
- var searchIcon = $(headerId + ' .search-icon-container');
- var searchInput = $(headerId + ' .search-textbox');
- var clearInput = $(headerId + ' .ion-ios-close');
- var countrySelector = $('.utility-nav .country-select-cont');
- var showSearchClass = 'show-search';
- var signInCont = $('.utility-nav .signin-container');
- var textboxSearchIcon = $(headerId + ' .ion-ios-search');
- searchIcon.off('click').click(function () {
- $(this).toggleClass(showSearchClass);
- varSearchBody.css('height', deviceHeight + 'px');
- $('body').toggleClass('modal-open');
- acnLogoContainer.toggleClass('hidden');
- navIcon.toggleClass('hidden-xs hidden-sm');
- countrySelector.css('visibility','hidden');
- searchBody.toggleClass('slide-down');
- signInCont.css('visibility', 'hidden');
- navLabel.css('visibility', 'hidden');
- searchInput.val('');
- clearInput.addClass('hidden');
- if (!hasClass($(this), showSearchClass)) {
- varSearchBody.css('height', 0);
- countrySelector.removeAttr('style');
- signInCont.removeAttr('style');
- navLabel.removeAttr('style');
- }
- });
- searchInput.keyup(function () {
- if (viewPortWidth <= 999) {
- if ($(this).val() != '') {
- clearInput.removeClass('hidden');
- } else {
- clearInput.addClass('hidden');
- }
- }
- });
- clearInput.click(function (e) {
- e.preventDefault();
- searchInput.val('');
- clearInput.addClass('hidden');
- $('#search-recommendation').removeClass('in')
- .addClass('collapse');
- });
- }
- /* COUNTRY SELECTOR */
- var globalCountrySelector = function () {
- var countries = GetCountrySelectorData();
- var countryIcon = $('.country-select-cont');
- CountrySelectorTemplate(countries);
- countryIcon.off('click').click(function () {
- countrySelectorCont.toggleClass(toggleCountryList);
- })
- $(document).on("mouseup touchend", function (e) {
- if (!e) e = window.event;
- var targetElement = e.target || e.srcElement;
- if ($('.show-country-list').length && $(targetElement).attr('class') !== 'country-select-cont' && $(targetElement).attr('class') !== 'show-country-list'
- && !$(targetElement).closest('.country-select-cont').length && !$(targetElement).closest('.show-country-list').length) {
- countrySelectorCont.toggleClass(toggleCountryList);
- }
- });
- }
- var geoGroupStoredData = "";
- var ACN_COUNTRY_SELECTOR_CAREERS = "CountryLanguageSelectorData_Careers";
- var ACN_COUNTRY_SELECTOR_DOTCOM = "CountryLanguageSelectorData_Dotcom";
- function GetCountrySelectorData() {
- var geoGroupStoredData = CheckCountrySelectorLocalStorage();
- var pageLocation = document.location.href.toLowerCase();
- var countries = [];
- if (geoGroupStoredData != 'null' && geoGroupStoredData != null && typeof geoGroupStoredData != 'undefined' && geoGroupStoredData.length > 0) { //check value condition for different type of browser.
- var geoObj = JSON.parse(geoGroupStoredData);
- //If local Storage is more than 1 day, remove localStorage.
- if (geoObj.DateCreated < 86400000) {
- if (pageLocation.indexOf("/careers") >= 0) {
- localStorage.removeItem(ACN_COUNTRY_SELECTOR_CAREERS);
- }
- else {
- localStorage.removeItem(ACN_COUNTRY_SELECTOR_DOTCOM);
- }
- }
- for (var i = 0; i < geoObj.GeoGroup.length; i++) {
- for (var j = 0; j < geoObj.GeoGroup[i].CountryGroup.length; j++) {
- for (var k = 0; k < geoObj.GeoGroup[i].CountryGroup[j].CountryList.length; k++) {
- countries.push(geoObj.GeoGroup[i].CountryGroup[j].CountryList[k]);
- }
- }
- }
- countries.sort(function (a, b) { var a1 = a.CountryName, b1 = b.CountryName; if (a1 == b1) return 0; return a1 > b1 ? 1 : -1; });
- return countries;
- } else {
- var serviceURL = '/api/sitecore/CountrySelectorModule/GetCountrySelectorData';
- $.ajax({
- type: 'GET',
- url: serviceURL,
- contentType: "application/json; charset=utf-8",
- data: { pageContext: pageContext }, //pulled from the country selector view variable.
- dataType: "json",
- async: true,
- cache: true,
- error: function () {
- console.error("Error while trying to get Geo Group List.");
- },
- success: function (data, status) {
- if (data.GeoGroup != null && data.GeoGroup != "") {
- if (data.GeoGroup.length > 0) {
- if (typeof (Storage) !== "undefined") {
- var dataObject = { GeoGroup: data.GeoGroup, DateCreated: new Date().getTime() }
- if (pageLocation.indexOf("/careers") >= 0) {
- localStorage.setItem(ACN_COUNTRY_SELECTOR_CAREERS, JSON.stringify(dataObject));
- }
- else {
- localStorage.setItem(ACN_COUNTRY_SELECTOR_DOTCOM, JSON.stringify(dataObject));
- }
- }
- for (var i = 0; i < data.GeoGroup.length; i++) {
- for (var j = 0; j < data.GeoGroup[i].CountryGroup.length; j++) {
- for (var k = 0; k < data.GeoGroup[i].CountryGroup[j].CountryList.length; k++) {
- countries.push(data.GeoGroup[i].CountryGroup[j].CountryList[k]);
- }
- }
- }
- countries.sort(function (a, b) { var a1 = a.CountryName, b1 = b.CountryName; if (a1 == b1) return 0; return a1 > b1 ? 1 : -1; });
- }
- } else {
- console.error("Page Context is not set.");
- }
- }
- })
- return countries;
- }
- }
- function CheckCountrySelectorLocalStorage() {
- var pageLocation = document.location.href.toLowerCase();
- if (typeof (Storage) !== "undefined") {
- if (pageLocation.indexOf("/careers") >= 0) {
- geoGroupStoredData = localStorage.getItem(ACN_COUNTRY_SELECTOR_CAREERS);
- }
- else {
- geoGroupStoredData = localStorage.getItem(ACN_COUNTRY_SELECTOR_DOTCOM);
- }
- }
- return geoGroupStoredData;
- }
- function CountrySelectorTemplate(countries) {
- var locationContainerId = "#location-recommendation";
- var locationSelectorMarkup = "";
- var countrySite = "/" + window.location.pathname.split("/")[1];
- var defaultHeader = "";
- var languageContainer = $('.language-container.ucase');
- //Compare countrysite of the URL to the list of countries displayed in the Language Selector
- for (var i = 0; i < countries.length; i++) {
- //var countryUrl = countries[i].CountryList[0].CountryDotcomUrl;
- //var countryLanguage = RetrieveCountryLanguageName(countries[i].CountryList[0].LanguageName);
- // var countryAbbr = countries[i].CountryList[0].LanguageAbbr;
- var countryUrl = countries[i].CountryDotcomUrl;
- var countryLanguage = countries[i].LanguageTitle;
- var countryAbbr = countries[i].LanguageAbbr;
- //If countrysite is the same as the URL of the country, End the comparison
- //Display the corresponding language of the country as Default Language
- if (countrySite == countryUrl) {
- defaultHeader = '<li class="default">Default (' + countryLanguage + ') </li > ';
- languageContainer.text(countryAbbr);
- break;
- }
- //Else, if countrysite is not among the list, set "English" as default
- else {
- defaultHeader = '<li class="default">Default (English) </li > ';
- languageContainer.text('ENG');
- }
- }
- var allCountriesHeader = '<li class="dropdown-header ucase">All COUNTRIES & LANGUAGES</li>';
- locationSelectorMarkup = '<ul type="none" role="menu">';
- locationSelectorMarkup += defaultHeader;
- locationSelectorMarkup += allCountriesHeader;
- for (var i = 0; i < countries.length; i++) {
- var countryName = countries[i].CountryName;
- var countryUrl = countries[i].CountryDotcomUrl;
- var countryLanguage = countries[i].LanguageTitle;
- locationSelectorMarkup += '<li><a href="' + countryUrl + '" role="list">' + countryName + " (" + countryLanguage + ")" + '</a></li>';
- }
- locationSelectorMarkup += '</ul>';
- $(locationContainerId).html(locationSelectorMarkup);
- }
- var setNavigationHeightOnChangeOrientation = function () {
- if (isTablet()) {
- navContainer.css('height', (deviceHeight - 49) + 'px');
- } else {
- navContainer.css({ 'height': (deviceHeight - 49) + 'px', 'overflow': 'auto' });
- }
- }
- return {
- init: init,
- setNavigationHeightOnChangeOrientation: setNavigationHeightOnChangeOrientation
- }
- })();
- /* HIDE OR SHOW SECONDARY NAVIGATION CONTROL */
- var showHideSecondaryNav = {
- showNav: function (navlinks) {
- var $this = navlinks;
- var subMenu = $("#" + $this.data("id"));
- subMenu.css({ 'opacity': '0', 'top': '-530px' });
- subMenu.removeClass("hidden").animate({
- opacity: '1',
- top: '70px'
- }, 400);
- },
- hideNav: function (navlinks) {
- var $this = navlinks;
- var subMenu = $("#" + $this.data("id"));
- subMenu.css({ 'opacity': '1' });
- subMenu.animate({ opacity: '0' }, 400);
- setTimeout(function () {
- subMenu.addClass("hidden")
- }, 450);
- },
- hideAllNav: function () {
- //var $this = divContainer;
- var subMenu = divContainer;
- subMenu.css({ 'opacity': '1' });
- subMenu.animate({ opacity: '0' }, 400);
- //setTimeout(function () {
- subMenu.addClass("hidden")
- //}, 450);
- },
- hideSubNav: function () {
- var subMenu = divContainer;
- navLabel.removeClass('active');
- subMenu.css({ 'top': '0', 'opacity': '1' });
- subMenu.animate({
- top: '-530px',
- opacity: '0'
- }, 400);
- setTimeout(function () {
- subMenu.addClass("hidden")
- }, 450);
- },
- clickHideNav: function (navlinks) {
- var $this = navlinks;
- var subMenu = $("#" + $this.data("id"));
- subMenu.css({ 'top': '0', 'opacity': '1' });
- subMenu.animate({
- top: '-530px',
- opacity: '0'
- }, 300);
- setTimeout(function () {
- subMenu.addClass("hidden");
- }, 700);
- },
- showBackDrop: function () {
- backDropTablet.css({ 'opacity': '0.6', 'z-index': '-1', 'top': '0' });
- backDropTablet.removeClass("hidden").animate({
- opacity: '0.6',
- zIndex: '1'
- }, 300);
- },
- hideBackDrop: function () {
- backDropTablet.css({ 'opacity': '1', 'z-index': '1' });
- backDropTablet.animate({
- opacity: '0',
- zIndex: '0'
- }, 300);
- setTimeout(function () { backDropTablet.addClass('hidden') }, 1000);
- },
- hideBackDropOnClick: function () {
- var primaryNav = $('.primary-nav');
- primaryNav.css({ 'margin-top': '0' });
- primaryNav.animate({
- marginTop: '-200%'
- }, 300);
- backDropTablet.css({ 'top': '', 'margin-top': '0%' });
- backDropTablet.animate({
- maringTop: '-200%',
- opacity: '0',
- zIndex: '0'
- }, 100);
- setTimeout(function () {
- navIcon.toggleClass('open');
- backDropTablet.addClass('hidden');
- navContainer.addClass('hidden')
- .removeClass('crawl-right');
- primaryNav.removeAttr('style');
- }, 400);
- closeL3();
- }
- }
- /* COUNTRY SELECTOR CONTROL */
- var countrySelectorControl = {
- closeCountrySelector: function () {
- if (hasClass(countrySelectorCont, toggleCountryList)) {
- countrySelectorCont.removeClass(toggleCountryList);
- }
- }
- }
- /* GLOBAL FUNCTIONS */
- /* Overrides native jquery function isMobile() */
- function isMobile() {
- if (viewPortWidth < 768) {
- return true;
- } else {
- return false;
- }
- }
- function isTablet() {
- if (viewPortWidth >= 768 && viewPortWidth < 1000) {
- return true;
- } else {
- return false;
- }
- }
- /* Overrides native jquery function hasClass() */
- function hasClass($thisElement, $class) {
- var classArray = $thisElement.attr('class');
- if (classArray) {
- classArray = classArray.split(" ");
- }
- if ($.inArray($class, classArray) > 0) {
- return true;
- } else {
- return false;
- }
- }
- /* Landscape && Portrait Functions */
- function isLandscape() {
- if ($(window).width() > $(window).height()) {
- return true;
- }
- else {
- return false;
- }
- }
- function isTertiaryOverflow(tertiary) {
- //sets footer to fix if overflow is false
- var tertiaryBaseHeight = $('#tertiaryListContainer').children('ul').height();
- if ((tertiaryBaseHeight + secondContactLink.height() + primaryNav.height()) > $(window).height()) {
- // scrollbar
- return true;
- }
- //sets footer to static if overflow is true
- else {
- return false;
- }
- }
- function isSecondaryOverflow(subMenu) {
- //sets footer to fix if overflow is false
- var linkCount = subMenu.find('ul.secondaryCounter').first().data('secondarylinkcount');
- var linkHeight = subMenu.find('li').outerHeight();
- var secondaryLinkHeight = $('.nav-submenu-label').outerHeight();
- var secondaryLinkCount = $('.nav-submenu.panel').length;
- var menuFooterHeight = $('.nav-contact-link').height();
- var headerHeight = $('#header-topnav').height();
- var contentHeight = ((secondaryLinkHeight * secondaryLinkCount) + (linkCount * linkHeight));
- var contentSpace = ($(window).height() - menuFooterHeight - headerHeight);
- if (contentHeight > contentSpace) {
- return true;
- }
- else {
- return false;
- }
- }
- function isPrimaryOverflow() {
- var contentHeight = $('.nav-submenu-label.collapsed').length;
- var primaryLinkHeight = $('.nav-submenu-label.collapsed').height();
- if ((contentHeight * primaryLinkHeight) > (navMenu.outerHeight() - menuFooter.height())) {
- return true;
- } else {
- return false;
- }
- }
- function closeL3() {
- navMenu.children().removeClass('hidden');
- tertiaryNav.css("display", "none");
- tertiaryListContainer.html("");
- subMenuLabel.removeClass('tertiaryLevel3');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement