/* Template Name: Grenviro Monitoring Author: Themesbrand Website: https://Themesbrand.com/ Contact: Themesbrand@gmail.com File: job companies list init js */ var url = "build/json/"; var allCompaniesList = ''; var prevButton = document.getElementById('page-prev'); var nextButton = document.getElementById('page-next'); // configuration variables var currentPage = 1; var itemsPerPage = 16; // getJSON var getJSON = function (jsonurl, callback) { var xhr = new XMLHttpRequest(); xhr.open("GET", url + jsonurl, true); xhr.responseType = "json"; xhr.onload = function () { var status = xhr.status; if (status === 200) { callback(null, xhr.response); } else { callback(status, xhr.response); } }; xhr.send(); }; // get json getJSON("job-companies-list.json", function (err, data) { if (err !== null) { console.log("Something went wrong: " + err); } else { allCompaniesList = data; loadCompaniesListData(allCompaniesList, currentPage); paginationEvents(); } }); function loadCompaniesListData(datas, page) { var pages = Math.ceil(datas.length / itemsPerPage) if (page < 1) page = 1 if (page > pages) page = pages document.querySelector("#companies-list").innerHTML = ''; for (var i = (page - 1) * itemsPerPage; i < (page * itemsPerPage) && i < datas.length; i++) { // Array.from(datas).forEach(function (listData, index) { if (datas[i]) { document.querySelector("#companies-list").innerHTML += '
'+ datas[i].industryType + '
\