/// /// /// $(document).ready(function () { // set dropdown if ($('#client-profiles-month-dropdown').length > 0) { var clientProfilesMonthDropdown = new Menubutton(document.getElementById('client-profiles-month-dropdown')); clientProfilesMonthDropdown.init(); } if ($('#client-profiles-region-dropdown').length > 0) { var clientProfilesRegionDropdown = new Menubutton(document.getElementById('client-profiles-region-dropdown')); clientProfilesRegionDropdown.init(); } if ($('#client-profiles-industry-dropdown').length > 0) { var clientProfilessIndustryDropdown = new Menubutton(document.getElementById('client-profiles-industry-dropdown')); clientProfilessIndustryDropdown.init(); } var month = getUrlParameter('month'); var region = getUrlParameter('region'); var industry = getUrlParameter('industry'); var isSearching = false; // get json data for cards var clientProfilesCardJSON; var hastagJSON; var isLoading = false; var nextPage = ''; var clientProfilesCardApi = apiDomain + "/api/client-profiles?language=" + htmlLang; var totalItemCount; // get templates var clientCardHashTag = $('script[data-template="tags"]').text().split(/\$\{(.+?)\}/g); var clientCard = $('script[data-template="clientProfilesCard"]').text().split(/\$\{(.+?)\}/g); // Search client profiles $('.client-profiles__top__button').click(function (e) { clientProfilesTopButtonClick(e); }); $('.client-profiles__top__button').keydown(function (e) { if (e.keyCode == 13) { clientProfilesTopButtonClick(e); isKeyboardUser = true; } }); function clientProfilesTopButtonClick(e) { e.preventDefault(); // init load more button // $('.client-profiles__moreContainer').hide(0) $('.loadMoreButton').addClass('hidden'); // add loading and clear all cards $('.client-profiles__content__cards').html(''); $('
').appendTo($('.client-profiles__content__cards')); var formData = $('#searchClientProfiles').serialize(); getJsonCards(clientProfilesCardApi + '&' + formData); isSearching = true; } //first load if (typeof month == 'undefined') { month = ''; } if (typeof region == 'undefined') { region = ''; } if (typeof industry == 'undefined') { industry = ''; } setDropdownAndSearch(); getJsonCards(clientProfilesCardApi + '&month=' + month + '®ion=' + region + '&industry=' + industry); //load more news $('.loadMoreButton').click(function () { getJsonCards(nextPage); }); // get cards via JSON function getJsonCards(currentPage) { if (!isLoading) { isLoading = true; currentPage = currentPage; $.ajax({ url: currentPage }).done(function (data) { // get data clientProfilesCardJSON = data._items; hastagJSON = data.items; nextPage = data._metadata.next; totalItemCount = data._metadata.total_count; // bind data to templates if (totalItemCount <= 0 || typeof nextPage == 'undefined' || typeof clientProfilesCardJSON == 'undefined') { $('.result_not_found').addClass('active'); $('.loadMoreButton').addClass('hidden'); $('.client-profiles__content__cards .loader').remove(); } else { $('.result_not_found').removeClass('active'); $('.client-profiles__content__cards').append(clientProfilesCardJSON.map(function (item, index) { var finalHashTag = item.hashtag.map(function (item, index) { return clientCardHashTag.map(render(item)).join(''); }).join(''); item["hashtagFinal"] = finalHashTag; return clientCard.map(render(item)).join(''); })); } templateReplaceAttribute(); // display cards loadJSONCards({ cardsToDisplay: 9, cardClass: 'clientProfilesCard', loadMoreButtonClass: 'client-profiles__more', cardParent: 'client-profiles__content__cards', totalCards: totalItemCount }); isLoading = false; if (isSearching) { isSearching = false; setTimeout(function () { scrollToResults(); }, 100); } }); } } function setDropdownAndSearch() { if (month != '') { month = decodeURIComponent(month); var obj_1 = $('.client-profiles__top__item input[name="month"]').parents('.client-profiles__top__item').find('ul li'); obj_1.each(function (index) { if (month == $(this).find('a').attr('data-value')) { obj_1.eq(index).click(); } }); } if (region != '') { region = decodeURIComponent(region); var obj_2 = $('.client-profiles__top__item input[name="region"]').parents('.client-profiles__top__item').find('ul li'); obj_2.each(function (index) { if (region == $(this).find('a').attr('data-value')) { obj_2.eq(index).click(); } }); } if (industry != '') { industry = decodeURIComponent(industry); var obj_3 = $('.client-profiles__top__item input[name="industry"]').parents('.client-profiles__top__item').find('ul li'); obj_3.each(function (index) { if (industry == $(this).find('a').attr('data-value')) { obj_3.eq(index).click(); } }); } if (month != '' || region != '' || industry != '') { // search setTimeout(function () { $('.client-profiles__top__button').click(); }, 600); } else { setDefaultRegionAndSearch(); } } $(document).on('keydown', ".client-profiles__cover > a", function (e) { if (e.keyCode == 13) { window.location.href = $(this).attr('href'); } }); }); function scrollToResults() { var headerHeight = $('#header').outerHeight(true); var breadcrumbsHeight = $('.breadcrumbs').outerHeight(true); var clientProfilesHeader = $('.client-profiles__header').outerHeight(true); var elementAboveTop = headerHeight + breadcrumbsHeight + clientProfilesHeader; var bufferHeight; var cardsTop = $('.client-profiles__content__cards').offset().top; var toPosTop; if ($(window).width() > 1200) { bufferHeight = 60; } else if ($(window).width() > 580 && $(window).width() <= 1200) { bufferHeight = 90; } else if ($(window).width() <= 580) { bufferHeight = 70; } toPosTop = elementAboveTop - bufferHeight; $('html,body').animate({ scrollTop: toPosTop + 'px' }, 800, function () { // set focus to first item if (isKeyboardUser) { isKeyboardUser = false; setTimeout(function () { $('.clientProfilesCard:first a:first').focus(); }, 30); } }); } function setDefaultRegionAndSearch() { // for japan and france if (lang == 'ja' || lang == 'fr') { var currentLang = $('html').attr('lang'); var showname_1; if (lang == 'ja') { showname_1 = 'Japan'; } else if (lang == 'fr') { showname_1 = 'France'; } var obj_4 = $('.client-profiles__top__item input[name="region"]').parents('.client-profiles__top__item').find('ul ul li'); obj_4.each(function (index) { if (showname_1 == $(this).attr('data-value')) { obj_4.eq(index).click(); } }); // search setTimeout(function () { $('.client-profiles__top__button').click(); }, 600); } } var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } };