SKIP TO CONTENT
`; }, // We are returning the same thing as footer but empty only get called when there is no suggestion empty: () => null, } }, { name: 'popular_search', source: popularSearchSource(popularSearchArray), display: 'display', templates: { header: '

Popular Searches

', suggestion: function (data) { return `

${data.display}

`; }, footer: function() { return ` Browse the entire Learning Library `; } } } ); // Custom submission method when user search const submitForm = function (termUrl) { // EDENG-3785: convert ampersand to ' and ' word to avoid missing info in URL // TODO: if we DO run into some other character for which we need to do something like escaping, // then we need to update to use escape/encode&decode way. const updatedTerm = typeof(termUrl) === 'string' ? termUrl.replaceAll('&', ' and ') : termUrl; window.location.href = '/resources/?q=' + updatedTerm; } //Add tracking for new taxonomy const trackSearchTerm = function(searchTerm) { if (searchTerm !== null && searchTerm !== ""){ let xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", `https://${window.location.hostname}/api/search-analytics/trackSearchTerm`); xmlhttp.setRequestHeader("Content-Type", "application/json"); // Prepare request body let requestBody = JSON.stringify({ searchTerm: searchTerm }); // Send request xmlhttp.send(requestBody); } }; typeAheadInput.bind('keydown', function (e) { // Typing should only be on letter keys if (/^[A-Za-z0-9]$/.test(e.key)) { clearTimeout(typingTimer); } if (e.key === "Enter") { e.preventDefault(); var termFound = false; $.each($('.tt-dataset-dataList p.tt-suggestion'), function (i, el) { if (typeAheadInput.val() === $(el).data().display) { submitForm($(el).data().term); termFound = true; } }); $.each($('.tt-dataset-popular_search p.tt-suggestion'), function (i, el) { // Don't ask me what is ttSelectebleObject, I don't know why but I saw it using console.log const popularSuggestionObject = $(el).data().ttSelectableObject; if (typeAheadInput.val() === popularSuggestionObject.display) { submitForm(popularSuggestionObject.term); termFound = true; } }); if (!termFound) { // EDENG-3785: convert ampersand to ' and ' word to avoid missing info in URL // TODO: if we DO run into some other character for which we need to do something like escaping, // then we need to update to use escape/encode&decode way. const updatedTerm = typeAheadInput.val().replaceAll('&', ' and '); typeAheadInput.val(updatedTerm); form.submit(); } trackSearchTerm(typeAheadInput.val()); } }); typeAheadInput.bind('typeahead:select', function (e, suggestion) { submitForm(suggestion.term); trackSearchTerm(suggestion.term); }); typeAheadInput.on('focus', function (e) { cancelButton.css('display', 'block'); }); header.on('click', function (e) { /** VERY hacky way for "Search all resources" and "Browse entire Learning Library" links to work */ // When clicking on the searchAllBox div or its child, submit search let parent = e.target.closest('.tt-suggestion.tt-selectable.searchAllBox'); if ($(e.target).hasClass('searchAllBox') || parent !== null) { form.submit(); } // When clicking on the browseAllLink div or its child, submit search parent = e.target.closest('.tt-suggestion.tt-selectable.browseAllLink'); if ($(e.target).hasClass('browseAllLink') || parent !== null) { form.submit(); } }); //Prevent click event from bubbling up to search bar container and make it active searchButton.on('click', function (e) { e.stopPropagation(); }); // On keyup, start the countdown typeAheadInput.on('keyup', function (e) { // Typing should only be on letter keys if (/^[A-Za-z0-9]$/.test(e.key)) { clearTimeout(typingTimer); typingTimer = setTimeout(doneTyping, doneTypingInterval); } }); // User is "finished typing," do something function doneTyping () { // Send request to api when no suggestion matched if($('.tt-dataset-dataList p.tt-suggestion').size() === 0 && typeAheadInput.val().length !== 0){ let xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", `https://${window.location.hostname}/api/auto-complete/misspelled`); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(); } } }; if($.fn.typeahead) { onTypeaheadLoad(); } else { $(document).on('typeaheadLoaded', onTypeaheadLoad); } })(window.jQuery); (function($) { $(document).ready(function() { var accountInfo = JSON.parse(window.localStorage.getItem('accountInfo') || '[]'); if (accountInfo.length > 1) { $('li.my-accounts', '.user-menu').removeClass('hidden'); var my_accounts_modal = $("#my-accounts-modal").modal({ email: null, showMyAccounts: function() { this.populateAccounts(); this.show(); }, populateAccounts: function() { var self = this; var accounts = $('.accounts',this.el); if (!$('.account').length) { var userAccounts = JSON.parse(window.localStorage.getItem('accountInfo')); var googleAccounts = []; var facebookAccounts = []; // Only show the first 5 accounts userAccounts = userAccounts.slice(0, 5); userAccounts.forEach(function(account) { if(!('socialSignupTypes' in account)) { account.socialSignupTypes = []; } if ('socialSignupType' in account && account.socialSignupTypes.indexOf(account.socialSignupType) === -1) { account.socialSignupTypes.push(account.socialSignupType) } var accountContainer = $('