IT Berufe - Jobanzeigen
const targetContainer = document.getElementById("jobContentContainer")
let totalPages = 0, pageNumber = document.querySelector('#pageNumber') getTags(1)
function getTags(page) {
let tagURL = `https://it-berufe.eu/wp-json/wp/v2/job-listings/?search=informatik&per_page=80&page=${page}`;
// $loader.style.display = "block"; fetch(tagURL) .then(async (response) => { let dataTag = await response.json() // get json
totalPages = response.headers.get('x-wp-totalpages') if (!pageNumber.textContent) { createPage(); // create page number }
// on response received, empty it document.querySelector('#jobContentContainer').innerHTML = '' dataTag.forEach(data => { // not map generateBlock(data); })
}).catch(err => { console.log(err); let message = err.statusText || "Es ist ein Fehler aufgetreten..."; $posts.innerHTML = `
Error ${err.status}: ${message}
`; $loader.style.display = "none"; }); }
function generateBlock(job) {
const targetContainer = document.getElementById("jobContentContainer")
const jobArticle = document.createElement("article") jobArticle.classList.add("job-listing")
const imgBlock = document.createElement("div") imgBlock.classList.add("img-block")
const imgCompanyLink = document.createElement("a") imgCompanyLink.setAttribute("href", `${job.meta._application}`) imgCompanyLink.setAttribute("target", "_blank") imgCompanyLink.setAttribute("rel", "nofollow")
const img = document.createElement("img") img.setAttribute("src", `${job.meta._company_video}`)
imgBlock.appendChild(imgCompanyLink) imgCompanyLink.appendChild(img)
const contentBlock = document.createElement("div") contentBlock.classList.add("content-block")
const title = document.createElement("h5") title.classList.add("content-block")
const titleLink = document.createElement("a") titleLink.setAttribute("href", `${job.meta._application}`) titleLink.setAttribute("target", "_blank") titleLink.setAttribute("rel", "nofollow") titleLink.innerText = `${job.title.rendered}`
const contentBlockInfo = document.createElement("div") contentBlockInfo.classList.add("content-block-info")
const company = document.createElement("h5") company.classList.add("company") company.innerText = `${job.meta._company_name}`
const location = document.createElement("span") location.classList.add("location") location.innerText = `${job.meta. _company_twitter}`
const jobDate = document.createElement("span") jobDate.classList.add("job-date") jobDate.innerText = `${job.meta._company_tagline}`
contentBlock.appendChild(title) title.appendChild(titleLink)
contentBlock.appendChild(contentBlockInfo) contentBlockInfo.appendChild(company) contentBlockInfo.appendChild(location) contentBlockInfo.appendChild(jobDate)
jobArticle.appendChild(imgBlock) jobArticle.appendChild(contentBlock)
targetContainer.appendChild(jobArticle)
}
function removeActivePage() { let liElement = document.getElementsByClassName("pageNumber")
for (var i = 0; i < liElement.length; i++) { liElement[i].classList.remove('activePage') } } function smoothscroll() { var currentScroll = document.documentElement.scrollTop || document.body.scrollTop; if (currentScroll > 500) { window.requestAnimationFrame(smoothscroll); window.scrollTo(0, currentScroll - (currentScroll / 5)); } }
function createPage() { for (var i = 0; i < totalPages; i++) { let li = document.createElement('li') li.classList.add("pageNumber") li.textContent = i + 1 li.onclick = function() { smoothscroll() removeActivePage() getTags(this.textContent) this.classList.add("activePage") } pageNumber.appendChild(li) } }