/g, '>').replace(/"/g, '"').replace(/&/g, '&') html += ' ' return html }, '')) $('.functionList').html(functions.reduce(function(html, value){ var value = value.replace(//g, '>').replace(/"/g, '"').replace(/&/g, '&') html += ' ' return html }, '')) var updateCheckbox = function(container, span, def) { $(container + ' input[type=checkbox]').each(function() { var $this = $(this); $this.on("change", function(e) { if ($(this).hasClass('all')) { var c = $(this).is(':checked'); if (c) { $(this).closest('div.checkbox').find('label.enabled input[type="checkbox"]').prop('checked', true); } else { $(this).closest('div.checkbox').find('label.enabled input[type="checkbox"]').prop('checked', false); } } var d=$.map($(container + ' input[type=checkbox]:checked'), function(i){ return i.value }).join(', ') $(span).html(d.length>0?d:def) window.location.hash = updateSearchHash() }) }) } updateCheckbox('.departmentsList', '.selectedDepartements', 'Departments') updateCheckbox('.functionList', '.selectedFunctions', 'Specialization') var channel = isMobileTablet ? dtmChannelMobile : dtmChannel; mcDataLayer.pagename = channel + ':view job'; mcDataLayer.channel = channel; $('form.keywordSearch').submit(function(e) { e.preventDefault() window.location.hash = updateSearchHash() }) $('#keyword').on('keyup', function() { var $this = $(this), timer = $this.data('timer') if (timer) clearTimeout(timer) timer = setTimeout(function(){ window.nooverlay=true window.location.hash = updateSearchHash() },250) $this.data('timer', timer) }) var pagedJobs = getPagedJobs(jobs) doPagination(pagedJobs.length, 1) render(decodeURI(window.location.hash)) $(window).on('hashchange', function() { render(decodeURI(window.location.hash)) }) //setup all anchors with .back class to call history.back $('#results-container').on('click', 'a.back', function(e) { e.preventDefault(); window.history.back(); }); //attach a click event to all view-details links $('#results-container').on('click', '.view-details a.job', function(e) { e.preventDefault() var j = $(this).data('job-id') window.location.hash = 'job/' + j; }); //attach a click event to all apply-now links $('#results-container').on('click', 'a.apply-now', function(e) { e.preventDefault(); var j = $(this).data('job-id'); //remove the #search/page=x from the hash window.location.hash = 'apply/' + j; var channel = isMobileTablet ? dtmChannelMobile : dtmChannel; mcDataLayer.pagename = channel + ':apply job'; mcDataLayer.channel = channel; }); //a.clear-filters event, prevent page jump $('#results-container').on('click', 'a.clear-filters', function(e) { e.preventDefault(); window.location.hash = '#clear'; }); //attach an event listener to the pagination links, just updates the curent Page $('#results-container').on('click', '#results-pagination li a', function(e) { e.preventDefault(); var p = $(this).data('page'); //remove the #search/page=x from the hash var hash = window.location.hash; if (hash.indexOf('&') != -1) { var h = 'search/page=' + p + hash.substring(hash.indexOf('&')); } else { var h = 'search/page=' + p; } window.location.hash = h; }); // click to link, not checkbox $('#searchpageSearch').on('click', 'div.panel-body a', function() { clearFilters() }); }) //routing function render(url) { //avoid double rendering if (window.currentHash && window.currentHash === url) return; window.currentHash=url /* urls # #search/page1of18&location=ireland&department= #job/34af2 #apply/34af2 */ var temp = url.split('/')[0]; var map = { //empty - show all jobs, clear all filters '#clear': function() { placeOverlay(); var pagedJobs = getPagedJobs(jobs); var data = pagedJobs[0]; showJobs(data); $('#vacancies-found').html(jobs.length); doPagination(pagedJobs.length, 1); clearFilters(); removeOverlay(); return true; }, //empty - show all jobs, clear all filters '': function() { placeOverlay(); var pagedJobs = getPagedJobs(jobs); var data = pagedJobs[0]; showJobs(data); $('#vacancies-found').html(jobs.length); doPagination(pagedJobs.length, 1); clearFilters(); removeOverlay(); return true; }, //search - initiates a search based on the passed filters '#search': function() { if (!window.nooverlay) placeOverlay(); var hash = decodeURI(window.location.hash).split('/',2)[1] var query = hash.split('&').map(function(segment){ var segment = segment.split('=',2) var key = segment[0] var value = decodeURIComponent(segment[1]).split(/,/) return {key:key, value:value} }).reduce(function(query, item){ if (item.value && item.value.join('').length>0) query[item.key]=item.value return query }, {}) //filter based on the values passed in the hash window.filteredJobs = jobs if (query.departements && query.departements.length>0) { filteredJobs = filteredJobs.filter(function(job){ return query.departements.find(function(item){ return job.department === item }) }) query.departements.map(function(dep){ $(".departmentsList input[value='"+dep+"']").attr('checked', true) }) $('span.selectedDepartements').text( query.departements.length ? query.departements.join(',') : 'Departments' ) } if (query.functions && query.functions.length>0) { filteredJobs = filteredJobs.filter(function(job){ return query.functions.find(function(item){ return job.function === item }) }) query.functions.map(function(dep){ $(".functionList input[value='"+dep+"']").attr('checked', true) }) $('span.selectedFunctions').text( query.functions.length ? query.functions.join(',') : 'Specialization' ) } if (query.keyword && query.keyword.length>0) { var keywords = query.keyword[0] console.log('keywords=', keywords) if (keywords.length>0) { filteredJobs = filterJobsByKeyword(keywords, filteredJobs) } $("#keyword").val(keywords) } if (query.page) { query.page = parseInt(query.page[0]) if (isNaN(query.page)) query.page=1 } else { query.page=1 } //no job found, show the no vacancies template if (filteredJobs.length === 0) { placeOverlay(); } else { var pagedJobs = getPagedJobs(filteredJobs) var data = pagedJobs[query.page - 1] showJobs(data) doPagination(pagedJobs.length, query.page) } if (!window.nooverlay) removeOverlay(); window.nooverlay=false; }, //job details page '#job': function() { //get the job id var jobId = url.split('#job/')[1].trim(); var j = viewDetails(jobId) }, ///apply page, with iframe '#apply': function() { //get the job id var jobId = url.split('#apply/')[1].trim(); applyNow(jobId) }, '#no-jobs': function() { noResults(); } } //Execute the selected function var func = map[temp] ? map[temp] : map['']; console.log('rendering ', temp) func() } //strip unwanted elements from the hash wehn conducting a new search function newSearchHash() { //decode the hash/uri for processing var h = decodeURI(window.location.hash); //remove the '#'' h = h.substring(1, h.length); //remove the search and page h = h.replace(/search\/page=[\d]{1,2}/g, ''); h = encodeURI(h); h = 'search/page=1' + h; return h; } //show the job function viewDetails(jobId) { $('.search-job').parent().hide() placeOverlay(); var data = getJobById(jobId) var year = new Date(data. date); var n = year.getMonth()+1; if (n<10) { bulan = '0'+n; } else { bulan = n; } var m = year.getDate(); if (m<10) { date = '0'+m; } else { date = m; } var newdate = year.getFullYear()+''+bulan+''+date; var channel = isMobileTablet ? dtmChannelMobile : dtmChannel; mcDataLayer.pagename = channel + ':jobdetails:'+newdate+':'+data.id+' '+data.title; mcDataLayer.channel = channel; mcDataLayer.contentid = data.id; mcDataLayer.contentname = data.title; mcDataLayer.contentpublishdate = newdate; mcDataLayer.contentlength = data.full_description.length; console.log(data) if (data) { var source = $('#job-details-template').html(); var template = Handlebars.compile(source); $('#results-container').html(template(data)); } else { console.log('viewDetails() 404 Error - job not found'); } removeOverlay(); return data; } function loadImageFileAsURL() { var filesSelected = document.getElementById("resumefile").files; if (filesSelected.length > 0) { var fileToLoad = filesSelected[0]; $('.fake-file input').attr('value', fileToLoad.name) var size = fileToLoad.size var type = fileToLoad.type.split('/') var extensions = fileToLoad.name.split('.') var extension = extensions.pop() var maxSize = parseInt(document.getElementById("resumefile").getAttribute('data-max-size')) var types = document.getElementById("resumefile").getAttribute('data-types').split(',') var validTypes = types.find(function(type) { return type === extension}) if (!validTypes) { alert("File type invalid") return false; } if (size > maxSize) { alert("File size too large") return false; } var fileReader = new FileReader(); fileReader.onload = function(fileLoadedEvent) { document.getElementById ("resumedata").value = fileLoadedEvent.target.result.split(/,/, 2)[1] } fileReader.readAsDataURL(fileToLoad) } } function thanksPage() { $('.search-job').parent().hide() placeOverlay(); var jobId = url.split('#apply/')[1].trim(); var data = getJobById(jobId) var source = $('#job-thanks-template').html(); var template = Handlebars.compile(source); $('#results-container').html(template(data)); removeOverlay() } function applyNow(jobId) { $('.search-job').parent().hide() placeOverlay(); var data = getJobById(jobId) var source = $('#job-apply-template').html(); var template = Handlebars.compile(source); $('#results-container').html(template(data)); $("#loading").show() $("#iframe").hide() $("#iframe").on('load', function(){ $("#loading").hide(); $("#iframe").show(); $('#global-nav').css('background',"rgba(255,255,255,1)"); removeOverlay() }) return data; } function noResults() { var source = $('#no-results-template').html(); var template = Handlebars.compile(source); $('#results-container').html(template('')); doPagination(0, 0); return true; } //place semi-transparent overlay function placeOverlay() { var overlay = '
'; $('#results-container').append(overlay); return true; } //scrolls to the top of the results div and removes the overlay function removeOverlay() { //scroll to the top of the results div var offset = $('.results').offset().top - 80; $('html, body').animate({ scrollTop: offset }, 700, 'swing'); setTimeout(function() { $('#results-overlay').remove(); }, 700); return true; } function getJobById(jobId) { var data = false; for (var i = 0; i < jobs.length; i++) { if (jobs[i].id === jobId) { var data = jobs[i]; break; } } return data; } /** * doPagination * build a function to output pagination - http://getbootstrap.com/components/#pagination */ function doPagination(numPages, page) { //only show it is numPages > 1 if (2 > numPages) { $('#results-pagination').html(''); return false; } var items = ''; var prev = page - 1; var next = page + 1; var items = ''; for (var i = 1; i <= numPages; i++) { items += ''; } $('#results-pagination').html(items); return true; } /** * getPagedJobs * takes an array of jobs, returns jobs in sets of six */ function getPagedJobs(jobsArray) { var numPages = Math.ceil(jobsArray.length / 6); var pagedJobs = []; //pagedjobs needs to be an array of objects... for (var i = 0; i < numPages; i++) { var slice = jobsArray.slice(i * 6, i * 6 + 6); var jobs = { 'jobs': slice, 'total': jobsArray.length }; pagedJobs[i] = jobs; } return pagedJobs; } /** * clearFilters * pass data into a function to show jobs, this will be triggered by pagination and form updates */ function clearFilters() { $('.searchpageSearch input[type="checkbox"]').prop('checked', false) document.getElementById('keyword').value = '' return true; } /** * showJobs * pass data into a function to show jobs, this will be triggered by pagination and form updates */ function showJobs(data) { var pageTitle = 'Current Job Openings'; if ($("#keyword").val() || $('.departmentsList input[type="checkbox"]:checked,.functionList input[type="checkbox"]:checked').length>0) { pageTitle = (filteredJobs.length) + ' results' } data.pagetitle = pageTitle var source = $('#job-template').html() var template = Handlebars.compile(source) var context = template(data) $('#results-container').html(context) $('.search-job').attr('id', location.hash.substring(1)) $('.search-job').parent().show() return true } /** * filterJobsByKeyword * takes a keyword and an array of jobs */ function filterJobsByKeyword(keyword, jobs) { var keywordJobs = []; var keywordJobsFull = []; var keywordJobsPart = []; var keywordJobsFullPart = []; var keywordFields = ["full_title", "department", "requirements", "search_location", "description"]; var fullKeyword = keyword keyword = keyword.replace(/[^a-zA-Z0-9 -]+/g, ' ') //check if keyword contains spaces if (keyword.indexOf(' ') >= 0) { //multiple keyword search //if contains spaces, split into individual words var dirtyKeywords = keyword.split(" ").filter(function(r) { return r.trim() ? true:false }) //remove empty elements (caused by adjacent spaces in the string) var keywords = []; for (var i = 0; i < dirtyKeywords.length; i++) { if (dirtyKeywords[i]) { keywords.push(dirtyKeywords[i]); } } console.log(keywords) var totalKeywords = keywords.length; var keywordMatches = 0; //loop through each of the jobs and match jobs that have ALL of the keywords somewhere for (var i = 0; i < jobs.length; i++) { if (jobs[i][keywordFields[0]] && jobs[i][keywordFields[0]].toLowerCase().indexOf(fullKeyword.toLowerCase()) != -1) { keywordJobsFull.push(jobs[i]); } var counter = 0; for (var r = 0; r < keywords.length; r++) { key = keywords[r].toLowerCase(); if (jobs[i][keywordFields[0]] && jobs[i][keywordFields[0]].toLowerCase().indexOf(key.toLowerCase()) != -1) { counter++; } } if (counter == keywords.length) { keywordJobsFullPart.push(jobs[i]); } if (keywords.length > 2 && counter == keywords.length - 1) { keywordJobsFullPart.push(jobs[i]); } for (var c = 0; c < keywords.length; c++) { keyword = keywords[c].toLowerCase(); prev_keyword = ""; for (var j = 0; j < keywordFields.length; j++) { //if( jobs[i][keywordFields[j]] !== null && jobs[i][keywordFields[j]].indexOf(keyword) != -1){ if (jobs[i][keywordFields[0]] && jobs[i][keywordFields[0]].toLowerCase().indexOf(keyword.toLowerCase()) != -1) { keywordJobsPart.push(jobs[i]) break; } if (jobs[i][keywordFields[j]] && jobs[i][keywordFields[j]].toLowerCase().indexOf(keyword.toLowerCase()) != -1) { if (prev_keyword !== keyword) { prev_keyword = keyword; keywordMatches = keywordMatches + 1; if (keywordMatches == totalKeywords) { keywordJobs.push(jobs[i]); keywordMatches = 0; break; } } } } } keywordMatches = 0; } } else { //single keyword search for (var i = 0; i < jobs.length; i++) { if (jobs[i][keywordFields[0]] && jobs[i][keywordFields[0]].toLowerCase().indexOf(keyword.toLowerCase()) != -1) { keywordJobsFull.push(jobs[i]) //break; } for (var j = 0; j < keywordFields.length; j++) { //if( jobs[i][keywordFields[j]] !== null && jobs[i][keywordFields[j]].indexOf(keyword) != -1){ if (jobs[i][keywordFields[j]] && jobs[i][keywordFields[j]].toLowerCase().indexOf(keyword.toLowerCase()) != -1) { keywordJobs.push(jobs[i]) //keywordJobsFull.push(jobs[i]) //break; } } } } var uniqueArray = function(arrArg) { return arrArg.filter(function(elem, pos,arr) { return arr.indexOf(elem) == pos; }); }; var resultJobs = uniqueArray(keywordJobsFull.concat(keywordJobsFullPart).concat(keywordJobsPart).concat(keywordJobs)); return resultJobs; } function receiveMessage(e) { // only use messages coming in from workable if (e.origin.indexOf('workable') == -1) { return; } var key = e.data.split(':')[0]; var val = e.data.split(':')[1]; switch (key) { case 'height': console.debug("key is height"); //resize the iframe to remove scrollbars $('iframe').attr("height", val); break; case 'submit': console.debug("key is submit"); // scroll to top of #iframe div /*$('html, body').animate({ scrollTop: $(".iframe").offset().top }, 400); */ thanksPage() break; default: console.log('unexpected postMessage', e); } } window.addEventListener("message", receiveMessage, false);
青青精品国产自在线拍