/************************************************
* evaluate hashes from the url
************************************************/
if(window.location.hash) {
hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
//hash found
console.log(hash);
searchWords = hash.split("&")[0]; //suchbegriffe
country = hash.split("&")[1];
loc = hash.split("&")[2]; //ort
radius = parseInt(hash.split("&")[3]); //radius
buttonColor = hash.split("&")[4]; //button farbe
buttonTypeColor = hash.split("&")[5];
language = hash.split("&")[1];
} else {
//place defaults here
searchWords = "Maler;Handwerker"; //suchbegriffe
country = "de";
loc = ""; //ort
radius = 100; //radius
buttonColor = '#3bade2'; //
buttonTypeColor = '#ffffff';
language = "de";
}
//now populate fields with the hashed values
searchstring = searchWords.replace(/;/g," ");
Input = $('#SuchInputBegriff').val(searchstring);
c = $('#SuchInputOrt').val(loc);
dist = $('#RangeInput').val(radius);
country = $('#LandInput').val(country);
/************************************************
* Layout and design
************************************************/
$('#toggle-menu').sideNav({menuWidth: 310});
$(document).ready(function(){
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('.modal').modal();
$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
$('').appendTo('head');
$('.value').css("color", buttonTypeColor);
$('.input-field label').css("color", buttonColor);
$('label').css("color", buttonColor);
$('").appendTo('head');
$('").appendTo('head');
$('.validate').keypress(function (e){
if (e.which == 13) {
//alert("enter");
$('.hidewithenter').slideUp();
$('.buttonafterhide').append('
Neue Suche
');
$('#newSearch').click(function(){
$('.hidewithenter').fadeIn();
$('.buttonafterhide').html("");
});
}
});
$('#newSearch').css('background-color', buttonColor);
$('#newSearch').css('color',buttonTypeColor);
});
/********************************
* Map *
********************************/
var map = L.map('map', {zoomControl:false, maxZoom:18});
//map.fitBounds([[60.7931936169,-180],[-60.7572606169,180.4588028203]]);
additional_attrib = 'webmap © Geolicious
';
basemap_0 = L.tileLayer('https://a.tile.thunderforest.com/landscape/{z}/{x}/{y}.png', {
attribution: additional_attrib + 'Maps © Thunderforest, Data © OpenStreetMap contributors'
});
basemap_0.addTo(map);
L.control.zoom({
position:'topright'
}).addTo(map);
/*******************
* now call the api *
********************/
var searchstring = $("#SuchInputBegriff").val();
searchstring = searchstring.replace(/ /g,"+or+");
var dist = $('#RangeInput').val(); //distance
var startEntry = 0; //result startEntry number
days = 28; //days old
var c = $('#SuchInputOrt').val(); //city
var country = $('#LandInput').val();
var myip;
$.get("http://ipinfo.io", function(response) {
myip = response.ip;
},"jsonp");
useragent = encodeURI(navigator.userAgent); //useragent like Firefox , IE or chrome and stuff.
url= "http://api.indeed.com/ads/apisearch?publisher=7392943220713551&format=JSON&q=" + searchstring + "&l=" + c + "&sort=date&radius="+ dist + "&st=&jt=&start="+String(startEntry) +"&limit=25&fromage=28&filter=&latlong=1&co=" + country + "&chnl=&userip=" + myip + "&useragent=" + useragent + "&v=2";
url2= "http://api.indeed.com/ads/apisearch?publisher=7392943220713551&format=JSON&q=" + searchstring + "&l=" + c + "&sort=date&radius="+ dist + "&st=&jt=&start="+String(startEntry+25) +"&limit=25&fromage=28&filter=&latlong=1&co=" + country + "&chnl=&userip=" + myip + "&useragent=" + useragent + "&v=2";
//create beautiful buttons from links
function replaceURLWithHTMLLinks(text) {
var exp = /(\b(http?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(exp,"");
}
//call the API
var data=[], numberResult;
var geojson = {};
geojson['type'] = 'FeatureCollection';
function parseXML(data) {
geojson['features'] = [];
for (i in data){
old = JSON.stringify(data[i]);
old2 = old.replace(',"url":',',"link":');
old3 = replaceURLWithHTMLLinks(old2);
data[i] = JSON.parse(old3);
}
for (var k in data) {
if (!data[k].longitude || !data[k].latitude){
}
if (data[k].longitude != "" && data[k].latitude != "" && data[k].longitude != null && data[k].latitude != null){
y= new Date;
y = Date.parse(data[k].date);
var date = new Date(y);
//console.log(date.getDate());
var newFeature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [parseFloat(data[k].longitude), parseFloat(data[k].latitude)]
},
"properties": {
"title": data[k].jobtitle,
"company": data[k].company,
"date": String(date.getDate()) +"."+ String(date.getMonth()+1) +"."+ String(date.getYear()+1900),
"linksex": data[k].link,
"place": data[k].city,
"snippet": data[k].snippet
}
}
geojson['features'].push(newFeature);
}
}
console.log(geojson.features.length);
}
function popup(feature, layer) {
var popupContent ='' + String(feature.properties['title']) + '
' + String(feature.properties['snippet']) + '
' + String(feature.properties['company']) + '
Angebot vom: ' + String(feature.properties['date']) + "
"+String(feature.properties['linksex']);
layer.bindPopup(popupContent);
}
function addDataMap(geojson){
try {
map.removeLayer(markers);
} catch(err){
//console.log("initial view");
}
markers = L.markerClusterGroup({
showCoverageOnHover: false,
maxClusterRadius: 30,
spiderfyDistanceMultiplier: 2
});
jobs = L.geoJson(geojson,{
onEachFeature: popup,
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: L.icon({
iconUrl: "plugins/leaflet1/images/marker-icon.png",
shadowUrl: 'plugins/leaflet1/images/marker-shadow.png',
iconSize: [26,42], // size of the icon change this to scale your icon (first coordinate is x, second y from the upper left corner of the icon)
iconAnchor: [13,42], // point of the icon which will correspond to marker's location (first coordinate is x, second y from the upper left corner of the icon)
popupAnchor: [0, -42] // point from which the popup should open relative to the iconAnchor (first coordinate is x, second y from the upper left corner of the icon)
})
})
}
});
jobs.addTo(markers);
markers.addTo(map);
map.fitBounds(jobs.getBounds());
}
var numberResult;
var currentPage = 0;
function fillList(data, numberResult, currentPage){
if (data.length>0){
var textContent = "";
var number = currentPage*50;
//putting null latitude data to the back!
console.log(data.length);
good=[];
bad=[];
for (l in data){
if (data[l].city==""){
bad.push(data[l]);
}else{
good.push(data[l]);
}
}
//console.log(entry);
data = [];
for (i in good){
data.push(good[i]);
}
for (i in bad){
data.push(bad[i]);
}
for (var k in data){
//console.log(number);
number = parseInt(number) + 1;
textContent += '' + String(number) + ".) " + data[k].jobtitle + "
";
if (data[k].latitude){
textContent += "bei " + data[k].company + " in:
" + data[k].city + " ";
} else {
textContent += "bei " + data[k].company + " in:
Unbekannt";
}
textContent += "
" + data[k].snippet + "
";
textContent += data[k].link
}
numberpages=Math.ceil(numberResult/50);
if (currentPage > 0){
pagesText = "<< vorherige | nächste >>
"
} else {
pagesText = "| nächste >>
"
}
console.log(number, numberResult)
if (number == numberResult && numberResult <= 50){
pagesText = "";
}
if (number == numberResult && numberResult > 50){
pagesText = "<< vorherige |
";
}
$("#list").html( textContent + "
" + pagesText);
$("#listHead").html("" + String(currentPage*50 +1) + " - " + String(number) + " von " + String(numberResult) + " Suchergebnissen
" + pagesText);
//console.log(data[k].link);
$('#list').fadeIn("fast");
$('.preloader-wrapper').fadeOut("fast");
//for new result pages, we need to translate again:
$('.tr').each(function(i){
$(this).text(aLangKeys[country][ $(this).attr('key') ]);
});
} else {
textContent = "";
pagesText = "";
$("#list").html( textContent + "
" + pagesText);
$("#listHead").html("keine Suchergebnisse
" + pagesText);
$('.tr').each(function(i){
$(this).text(aLangKeys[country][ $(this).attr('key') ]);
});
}
}
function jumpto(lat, lon) {
position = new L.latLng(lat, lon);
if ($("#SuchInputOrt").val() != ""){
map.flyTo(position, 13);
} else {
map.flyTo(position, 10);
}
}
function nextPage(jumpParameter){
if (jumpParameter==1){
$('#list').fadeOut("fast");
$('.preloader-wrapper').fadeIn("fast");
currentPage += 1;
startResult = currentPage *50;
useInputs(startResult);
} else {
$('#list').fadeOut("fast");
$('.preloader-wrapper').fadeIn("fast");
currentPage += -1;
startResult = currentPage *50;
useInputs(startResult);
}
}
function useInputs(startResult){
Input = $('#SuchInputBegriff').val();
searchstring = Input.replace(/ /g,"+or+");
dist = $('#RangeInput').val(); //distance
console.log(dist);
startEntry = startResult; //start with number xxx
days = 28; //days old
c = $('#SuchInputOrt').val(); //city
country = $('#LandInput').val();
//get userIP:
var myip;
$.get("http://ipinfo.io", function(response) {
myip = response.ip;
},"jsonp");
useragent = encodeURI(navigator.userAgent); //useragent like Firefox , IE or chrome and stuff.
url= "http://api.indeed.com/ads/apisearch?publisher=7392943220713551&format=JSON&q=" + searchstring + "&l=" + c + "&sort=date&radius="+ dist + "&st=&jt=&start="+String(startEntry) +"&limit=25&fromage="+ String(days) + "&filter=&latlong=1&co=" + country + "&chnl=&userip=" + myip + "&useragent=" + useragent + "&v=2";
url2= "http://api.indeed.com/ads/apisearch?publisher=7392943220713551&format=JSON&q=" + searchstring + "&l=" + c + "&sort=date&radius="+ dist + "&st=&jt=&start="+String(startEntry+25) +"&limit=25&fromage="+ String(days) + "&filter=&latlong=1&co=" + country + "&chnl=&userip=" + myip + "&useragent=" + useragent + "&v=2";
getDataShowData(url,url2,data,numberResult);
}
function getDataShowData(url,url2,data,numberResult){
$.ajax({
url: url,
jsonp: "callback",
dataType: "JSONP",
success: function( response ) {
if(response.totalResults==0){
$('.preloader-wrapper').fadeOut("fast");
try {
map.removeLayer(markers);
} catch(err){
console.log("initial view");
}
var data = [];
numberResult = 0;
currentPage = 0;
listText = fillList(data, numberResult, currentPage);
} else {
numberResult = response.totalResults;
//console.log(numberResult)
data = response.results;
if (numberResult>25){
$.ajax({
url: url2,
jsonp: "callback",
dataType: "JSONP",
success: function( response ) {
numberResult = response.totalResults;
console.log(numberResult);
//console.log(response.results)
for (i in response.results){
data.push(response.results[i]);
}
parseXML(data);
addDataMap(geojson)
listText = fillList(data, numberResult, currentPage);
}
});
} else {
parseXML(data);
addDataMap(geojson)
listText = fillList(data, numberResult, currentPage);
}
}
}
});
}
$('#SuchInputBegriff').on('change', function(e) {
$('.preloader-wrapper').fadeIn("fast");
currentPage = 0;
startResult = 0;
useInputs(0);
})
$('#LandInput').on('change' ,function(e) {
$('#SuchInputOrt').val("");
$('.preloader-wrapper').fadeIn("fast");
currentPage = 0;
startResult = 0;
useInputs(0);
})
$('#RangeInput').on('change' ,function(e) {
$('.preloader-wrapper').fadeIn("fast");
currentPage = 0;
startResult = 0;
useInputs(0);
})
$('#SuchInputOrt').on('change' ,function(e) {
$('.preloader-wrapper').fadeIn("fast");
currentPage = 0;
startResult = 0;
useInputs(0);
})
var attributionIndeed = L.control({position: 'bottomright'});
attributionIndeed.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info');
div.innerHTML='jobs by ';
return div;
};
attributionIndeed.addTo(map);
var attributionGeolicious = L.control({position: 'bottomright'});
attributionGeolicious.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info2');
div.innerHTML='';
map.attributionGeolicious = this
return div;
};
attributionGeolicious.addTo(map);
map.on("load", function(e) {
dim = map.getSize();
if (dim.x<993){
$("#menuClose").fadeIn();
$('.tr').each(function(i){
$(this).text(aLangKeys[country][ $(this).attr('key') ]);
});
attributionGeolicious.remove();
}
});
map.on("resize", function(e) {
$('.tr').each(function(i){
$(this).text(aLangKeys[country][ $(this).attr('key') ]);
});
if(e.newSize.x<993) {
$("#menuClose").css("display","");
attributionGeolicious.remove(); // e is an event object (MouseEvent in this case)
} else {
$("#menuClose").css("display","none");
attributionGeolicious.addTo(map);
}
});
getDataShowData(url,url2,data,numberResult);
map.on("popupopen", function(){
$('.tr').each(function(i){
$(this).text(aLangKeys[country][ $(this).attr('key') ]);
});
})
//getDataShowData(url2);