/*! MAP - v0.0.1 - ]init[ Katharina Kappis - 2014-04-11 */ var MAPP = window.MAPP || {}; /************************************************************************************************************* Adressenermittlung mit hilfe einer GAZETTEER Template **************************************************************************************************************/ function printAddress(latitude, longitude) { $('#btn-address-refresh, #btn-address-change').show(); $('#address').attr('value', 'Position erfolgreich ermittelt.'); var latadrtxt = ""+latitude+""; var latadrtxt = latadrtxt.substr(0,8) var longadrtxt = ""+longitude+""; var longadrtxt = longadrtxt.substr(0,8) $('#address-txt').html("Position erfolgreich ermittelt.
GPS: " + latadrtxt + " " +longadrtxt); $('#latitude-txt').val(latitude); $('#longitude-txt').val(longitude); $('#_gemeinde').val(''); $('#_str').val(''); $('#_hnr').val(''); $('#koordinaten').val(''); var getrequest = "/sixcms/detail.php?template=00_m_app_gazetteer_request_test&latitude="+latadrtxt.substr(0,8)+ "&longitude="+longadrtxt.substr(0,8); console.log(getrequest); $.ajax( getrequest, { type: "GET", cache: false, dataType: 'json', success: function(data){ if("gemeindename" in data){ let gewaehlteGemeinde = document.getElementById("gemeindename").innerHTML; if(gewaehlteGemeinde.search(data.gemeindename) == -1 ){ console.log(data.gemeindename); console.log( document.getElementById("gemeindename").innerHTML ); $("#plz").val(''); $("#ortsteil").val(''); $("#strassenname").val(''); $("#hausnummer").val(''); $('#address-txt').append("   Die ermittelten Koordinaten befinden sich nicht in der ausgewählten Gemeinde."); $('#address-txt').append(" \""+ gewaehlteGemeinde +"\" gewählt aber \""+ data.gemeindename +"\" ermittelt."); $('#address-txt').append(" Bitte ändern Sie die Gemeinde oder geben Sie den Standort des Misstandes manuell ein"); return; } } $("#plz").val(data.postleitzahl); $("#ortsteil").val(data.ortsteilname); $("#strassenname").val(data.strassenname); $("#hausnummer").val(data.hausnummer); if("strassenname" in data && "hausnummer" in data){ $('#address-txt').append(" (" + data.strassenname + " " + data.hausnummer + ")"); }else{ $('#address-txt').append("   Die Koordinaten konnten keiner Adresse zugeordnet werden. Bitte beschreiben Sie im Text den genauen Ort des Missstandes."); } }, error: function(data){ $('#address-txt').append("   Die Koordinaten konnten keiner Adresse zugeordnet werden. Bitte beschreiben Sie im Text den genauen Ort des Missstandes."); console.log("could not fetch gazetteer data"); } } ); } /********************************************************************************************************************* === DOCUMENT READY === **********************************************************************************************************************/ $(document).ready(function() { "use strict"; MAPP.toggle(); MAPP.scollToTop(); MAPP.scrollToAnswer(); MAPP.initPlaceholderFix(); MAPP.initGeolocation(); MAPP.handleOpenSelect(); MAPP.scrollToField(); MAPP.preload(); }); /********************************************************************************************************************* === WINDOW REZIZE === **********************************************************************************************************************/ $(window).resize(function() { "use strict"; }); /********************************************************************************************************************** === INIT camera support detection === **********************************************************************************************************************/ // Detect file input support var isFileInputSupported = (function () { // Handle devices which falsely report support if (navigator.userAgent.match(/(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Windows Phone (OS 7|8.0))|(XBLWP)|(ZuneWP)|(w(eb)?OSBrowser)|(webOS)|(Kindle\/(1.0|2.0|2.5|3.0))/)) { return false; } // Create test element var el = document.createElement("input"); el.type = "file"; return !el.disabled; })(); // Add 'fileinput' class to html element if supported if (isFileInputSupported) { $('input[type="file"]').show(); } /********************************************************************************************************************** === INIT geoloacation === **********************************************************************************************************************/ MAPP.initGeolocation = function() { var btnFindLocation = $('#addressFind'); var btnAddressChange = $('#btn-address-change'); function findAddress() { $('#address-txt').show(); $('.location-change-content').attr('style','display:none;') //check if geolocation is supported if (navigator && navigator.geolocation) { //alert('Geolocation is supported!'); // Geolocation is supported! $('#address-txt').text('Standort ermitteln…'); $('#address').attr('value', ' '); // make the request for the user's position navigator.geolocation.getCurrentPosition(geo_success, geo_error); } else { // alert('Geolocation is not supported for this Browser/OS version yet.'); // Geolocation is not supported for this Browser/OS version yet. handleLocationErr(); } }; function geo_success(position) { printAddress(position.coords.latitude, position.coords.longitude); } function geo_error(error) { // alert('Fehler aufgetreten'); //Fehlercode prüfen und entsprechende Meldung ausgeben switch(error.code) { case error.PERMISSION_DENIED: msg("Keine Erlaubnis zur Standort-Ermittlung."); break; case error.POSITION_UNAVAILABLE: msg("Keine Daten vorhanden."); break; case error.TIMEOUT: msg("Timeout"); break; case error.UNKNOWN_ERROR: msg("Unbekannter Fehler"); break; default: break; } // (instead of displaying an error), show alternative form elements handleGeo_error(); } function handleGeo_error() { $('#address-txt').hide().text('Standort'); $('.location .toggle-head').trigger( "click" ); } function msg(msg) { alert(msg); } function hideAddress() { $('#address-txt').hide(); } // btn for refresh address btnFindLocation.on('click',function () { findAddress(); }); // btn for cange address btnAddressChange.on('click',function(){ hideAddress(); }) // trigger event to get address automatically when page is loaded btnFindLocation.trigger( "click" ); }; /********************************************************************************************************************** === INIT placeholder fix === (http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html) **********************************************************************************************************************/ MAPP.initPlaceholderFix = function() { $('[placeholder]').focus(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); input.removeClass('placeholder'); } }).blur(function() { var input = $(this); if (input.val() == '' || input.val() == input.attr('placeholder')) { input.addClass('placeholder'); input.val(input.attr('placeholder')); } }).blur().parents('form').submit(function() { $(this).find('[placeholder]').each(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); } }) }); }; /********************************************************************************************************************** === INIT toggle === **********************************************************************************************************************/ MAPP.toggle = function() { $('.toggle-body').hide(); function toggleIt(head) { var body = head.parent().find('.toggle-body'); body.is(':hidden') ? open() : close(); function open() { body.slideDown('200').addClass('opened'); head.addClass('opened'); switchIcon('icon-down','icon-up'); $('html,body').animate({ scrollTop: head.offset().top},'slow'); } function close() { body.slideUp('200', function() { head.removeClass('opened'); body.removeClass('opened'); switchIcon('icon-up','icon-down'); }); } function switchIcon(remIcon, addIcon) { head.find($('.'+remIcon)) .removeClass(remIcon) .addClass(addIcon); } } $('.toggle-head').click(function (e) { e.preventDefault(); toggleIt($(this)); }); //toggleIt($('.accordion .toggle-item:first-child .toggle-head')); }; /********************************************************************************************************************** === INIT scroll to answer === **********************************************************************************************************************/ MAPP.scrollToAnswer = function() { $('.hint-content .answer').each(function(index, value){ var elem = ''; $(value).parents('.hint-content').prepend(elem); }); $('.navToAnswer').on('click', function(){ var answer = $(this).parent('.hint-content').find('.answer'); if(answer) { var pos = answer.offset().top - 65; if(pos > 0) $("html, body").animate({ scrollTop: pos }, 800); } return false; }); } /********************************************************************************************************************** === INIT scroll to field === **********************************************************************************************************************/ MAPP.scrollToField = function() { /* $('.hint-content .answer').each(function(index, value){ var elem = ''; $(value).parents('.hint-content').prepend(elem); }); */ $('.navToField').on('focus', function(){ $('#hoehe').css( "padding", "0 0 250px 0" ) var pos = $(this).offset().top - 65; if(pos > 0) $("html, body").animate({ scrollTop: pos }, 800); return false; }); } /********************************************************************************************************************** === INIT scroll to top === **********************************************************************************************************************/ MAPP.scollToTop = function() { $('.navToTop').hide(); $(window).scroll(function(){ if ($(this).scrollTop() > $('#header').height()) { $('#topline').addClass('fixed').fadeIn(); $('.navToTop').fadeIn('slow'); } else { $('#topline').removeClass('fixed'); $('.navToTop').hide(); } }); $('.navToTop').click(function(){ $("html, body").animate({ scrollTop: 0 }, 800); return false; }); }; /********************************************************************************************************************** === INIT open selcetbox === **********************************************************************************************************************/ MAPP.openSelect = function(elem) { if (document.createEvent) { var e = document.createEvent("MouseEvents"); e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); elem[0].dispatchEvent(e); } else if (element.fireEvent) { elem[0].fireEvent("onmousedown"); } }; MAPP.handleOpenSelect = function() { $('.form-select.has-icon .icon.icon-down-open').click(function() { var item = $(this).parent('.form-select').find('select'); MAPP.openSelect(item); }); }; /****************************************************** ==== Preloader **************************************/ $(window).load(function() { // makes sure the whole site is loaded $('#status').fadeOut(); // will first fade out the loading animation $('#preloader').delay(350).fadeOut('slow'); // will fade out the white DIV that covers the website. $('body').delay(350).css({'overflow':'visible'}); }) /********************************************************************************************************************** === INIT scroll to top === **********************************************************************************************************************/ MAPP.preload = function() { $('.preload').click(function(){ $('#status').fadeIn(); // will first fade out the loading animation $('#preloader').fadeIn('slow'); // will fade out the white DIV that covers the website. }); $('form[name="m_form"]').submit(function(){ $('#status').fadeIn(); // will first fade out the loading animation $('#preloader').fadeIn('slow'); // will fade out the white DIV that covers the website. }); $('.eingabeform').submit(function(){ var fehler = ""; if ($('#select1 :selected').val() == ""){ alert("Bitte einen Eintrag auswählen. Danke."); return false; } $('#status').fadeIn(); // will first fade out the loading animation $('#preloader').fadeIn('slow'); // will fade out the white DIV that covers the website. }) };