(function ($) { // Get the page title var pageTitle = document.title; // Check if the page title contains the string "Example" if (pageTitle.includes("Aviation Employment Opportunities")) { // create a link element for the stylesheet var link = document.createElement("link"); link.rel = "stylesheet"; link.href = "https://www.jsfirm.com/resources/asa.css"; // append the link element to the document head document.head.appendChild(link); ("use strict"); // initial pagination options var pageNum = 1, pageSize = 10; var _showJobCount = false; // a function to limit the size (word count) of results function truncate(str, no_words) { return str.split(" ").splice(0, no_words).join(" "); } // a function to strip HTML out of the job description previews function strip(html) { var doc = new DOMParser().parseFromString(html, "text/html"); return doc.body.textContent || ""; } // the main (ajax) results call function loadPostings(showJobCount) { _showJobCount = showJobCount; // debug tools // console.log("LoadPostings is executing:") // console.log("PageNum: " + pageNum + " / PageSize: " + pageSize); // clear out the current results list, hide pagination, show the spinner $("#jobsListing").empty(); $("#preloader").show(); // create empty placeholders for the new content var jobData = [], listingHtml = ""; var filterData = {}, filterKeyword = $(".filterInputs #keyword").val(), company = $(".filterInputs #company").val(), location = $(".filterInputs #location").val(), jobType = $(".filterInputs #jobType").val(); filterData.page = pageNum; filterData.pagesize = pageSize; filterData.keyword = filterKeyword; filterData.company_name = company; if (location) { filterData.locations = [location]; } filterData.position = jobType; filterData.priority_group = ""; //console.dir(filterData); // tbe main ajax call // pageSize and pageNum are passed as the value of the current global variables $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "https://jobsearch.jsfirm.com/integration/api/feed/getfeedadvanced/ASA-JDN/", data: JSON.stringify(filterData), success: function (data) { var jobData = data.Listing, resultsData = data.Results[0]; // month names in the required format const monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; // make sure that the listingHtml placeholder is emptied out after any previous update listingHtml = ""; // create a result entry for each job that is returned $.each(jobData, function (key, value) { if (value.PriorityGroup == 1) { listingHtml += '
  • "; } listingHtml += '

  • ' + value.JobTitle + "" + value.CoName + " | " + value.NearestCity + ", " + value.State + "

    "; listingHtml += truncate(strip(value.Description), 20); listingHtml += '... Read More

    '; var jobDate = new Date(value.job_search_date); listingHtml += '
    ' + monthNames[jobDate.getMonth()] + '' + jobDate.getDate() + "
  • "; }); // hide the spinner, show pagination and add the new results listing to the content area $("#preloader").hide(); $("#jobsListing").append(listingHtml); // calculate updated pagination data var thisPage = resultsData.Page || 0, pageSize = resultsData.PageSize || 0, startPoint = thisPage * pageSize - (pageSize - 1) || 0, endPoint = thisPage * pageSize || 0, totalCount = resultsData.TotalCount || 0, resultsHtml = ""; if (endPoint > totalCount) { endPoint = totalCount; } console.log("thisPage: " + thisPage); console.log("pageSize: " + pageSize); console.log("startPoint: " + startPoint); console.log("endPoint: " + endPoint); console.log("totalCount: " + totalCount); console.log("resultsHtml: " + resultsHtml); if (parseInt(totalCount) > parseInt(pageSize)) { resultsHtml = "Showing " + startPoint + " to " + endPoint + " of " + totalCount + " results."; } else { resultsHtml = "Showing " + totalCount + " result"; if (totalCount > 1 || totalCount == 0) { resultsHtml += "s"; } resultsHtml += "."; } $(".resultsSummary").html(resultsHtml); //
  • First
  • // //
  • 1
  • //
  • 2
  • //
  • 3
  • //
  • 4
  • //
  • 5
  • // //
  • Last
  • $(".pagination ul").empty(); if (parseInt(thisPage) > 1) { //$('.pagination ul').append("
  • First
  • "); var prev = parseInt(thisPage) - 1; $(".pagination ul").append( "" ); } else { $(".pagination ul").append(""); } var pageCount = Math.ceil(totalCount / pageSize); if (pageCount > 1) { var start = 1; if (parseInt(thisPage) > 3 && parseInt(thisPage) < pageCount - 3) { start = parseInt(thisPage) - 2; } else if (parseInt(thisPage) > 3) { start = pageCount - 4; } var pages = 5; if (pageCount < pages) pages = pageCount; var i = 0; while (i < pages) { if (start + i == parseInt(thisPage)) { $(".pagination ul").append( "
  • " + parseInt(start + i) + "
  • " ); } else { $(".pagination ul").append( "
  • " + parseInt(start + i) + "
  • " ); } i++; } if (parseInt(thisPage) < pageCount) { var next = parseInt(thisPage) + 1; $(".pagination ul").append( "" ); //$('.pagination ul').append("
  • Last
  • "); } else { $(".pagination ul").append(""); } $(".page-link").click(function (e) { pageNum = this.getAttribute("data-page"); loadPostings(); e.preventDefault(); }); } } }); } } $(document).ready(function () { /* Only run if not in Sitecore */ if (!$("body.in-sitecore").length && pageTitle.includes("Aviation Employment Opportunities")) { let head = document.getElementsByTagName("HEAD")[0]; let JSFirmJS = document.createElement("script"); JSFirmJS.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"; head.appendChild(JSFirmJS); // initialize results loadPostings(false); // handle changes in 'results per page' option $("#resultsCount").change(function () { pageSize = $(this).val(); pageNum = 1; loadPostings(); }); // handle click of filter search button $("#filterBtn").click(function () { pageNum = 1; loadPostings(true); }); } }); })(jQuery);