diff --git a/facile.js b/facile.js index ba2a5b0..f1aa96e 100755 --- a/facile.js +++ b/facile.js @@ -1,293 +1,293 @@ var map; var euros = 40; var errortooresults = true; var trovalatuazona = true; var nessunfornitore = true; var impianti = []; var ZOOM_OPENING_SEARCH_RESULT = 17; var Overworld = { $el: undefined, $action: undefined, visible: true, running: false, hide: function() { if(Overworld.running) { return; } Overworld.running = true; Overworld.$el.hide("drop", {direction: "up"}, "slow", function() { Overworld.$action.show("drop", {direction: "up"}, "fast", function() { Overworld.running = false; }); }); }, show: function() { if(Overworld.running) { return; } Overworld.running = true; map.closePopup(); Overworld.$el.find("input").val(""); Overworld.$action.hide("drop", {direction: "up"}, "slow", function() { Overworld.$el.show("drop", {direction: "up"}, "fast", function() { Overworld.$el.find("input").focus(); Overworld.running = false; }); }); } }; $(document).ready(function() { Overworld.$action = $("#overworld-buttons"); Overworld.$el = $("#overworld"); Overworld.$action.hide().click(function() { Overworld.show(); }); $("form").submit(function(event) { suggest_nominatim_addresses( $("input[name=search_address]").val() ); event.preventDefault(); }); map = L.map('map'); // create the tile layer with correct attribution var osmUrl='http://{s}.tile.osm.org/{z}/{x}/{y}.png'; var osmAttrib='Map data Facile.it © OpenStreetMap contributors'; var osm = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 17, attribution: osmAttrib}); map.addLayer(osm); - map.setView([42.5, 12.9], 7); + map.setView([45.49, 9.21], 15); map.on("moveend", function() { getMarkersInBounds(); return true; }); map.on("popupopen", function() { Overworld.hide(); }); fitDocument(); map.locate({setView: true, enableHighAccuracy: true, maxZoom: 16}); map.on("locationfound", function(e) { var radius = e.accuracy / 2; enfatizeLatLng(e.latlng, 2000); }); map.on("locationerror", function(e) { Materialize.toast("Posizione non disponibile. Zomma!", 3000); }); getMarkersInBounds(); }); function getMarkersInBounds(preCallback, postCallback) { var zoom = map.getZoom(); if(zoom < 13) { trovalatuazona && Materialize.toast("Trova la tua zona, zomma!", 3000); trovalatuazona = false; return; } trovalatuazona = true; var bounds = map.getBounds(); var data = {}; data.lat_n = bounds.getNorth(); data.lat_s = bounds.getSouth(); data.lng_w = bounds.getWest(); data.lng_e = bounds.getEast(); $.getJSON( "/api/bounds.php", data, function(json) { if(json.error) { errortooresults && Materialize.toast("Vedo molte stazioni. Zomma per scoprirle!", 2000); errortooresults = false; return; } errortooresults = true; if(json.length === 0) { nessunfornitore && Materialize.toast("Nessun fornitore in questa zona", 2000); nessunfornitore = false; return; } nessunfornitore = true; if(json.length > 90) { Materialize.toast("Vedo " + json.length + " risultati! Zooma per scoprirli", 2000); return; } if(preCallback) { var r = preCallback(bounds, json); if(r === false) { return; } } for(var i=0; i" + json[i].gestore + ":
"; for(var j=0; j"; } else { txt += ""; } txt += ""; txt += ""; txt += ""; } txt += "
" + litres + " Lper il " + json[i].prezzi[j].descCarburante + ""; if(json[i].prezzi[j].isSelf === "1") { txt += "(self)"; } else { txt += ""; } txt += "
"; txt += "

+ PREFERITI"; txt += "segnala errore

"; L.marker( [json[i].latitudine, json[i].longitudine], { bounceOnAdd: true, bounceOnAddOptions: {duration: 500, height: 100}, bounceOnAddCallback: function() {} } ) .bindPopup(txt) .addTo(map); } if(postCallback) { postCallback(bounds, json); } } ); } function suggest_nominatim_addresses(query) { $.ajax({ url: "https://nominatim.openstreetmap.org/search", jsonp: "nominatimJsonp", dataType: "jsonp", data: { q: query, format: "json", json_callback: "nominatimJsonp" } }); } function nominatimJsonp(json) { var $searchResults = $("#modal-search-addr-results"); var $list = $searchResults.find("ol").empty(); if(json.length > 0) { for(i=0; i") .append( $('') .text(json[i].display_name) .data("latLng", {lat: json[i].lat, lng: json[i].lon}) .data("bounds", json[i].boundingbox) .click(function(event) { $searchResults.closeModal(); var latLng = $(this).data("latLng"); var bounds = $(this).data("bounds"); var adaptedBounds = [ [bounds[0], bounds[3]], [bounds[1], bounds[2]] ]; map.fitBounds( adaptedBounds ); getMarkersInBounds(); Overworld.hide(); event.preventDefault(); }) ) .append( $("
") ) .append( $("") .text(json[i].licence) ) ); } // Result links $searchResults.find("a").click(function() { $searchResults.closeModal(); }); } else { $list.append( $("
  • ").text( "Nessun indirizzo trovato" ) ); } $searchResults.openModal(); } function enfatizeLatLng(latLng, duration) { duration = duration || 2000; var circle = L.circle(latLng, 100).addTo(map); window.setTimeout(function () { map.removeLayer(circle); }, duration); } function fitDocument() { var w = $("body").width(); var h = $("body").height(); $("#map").width( w ).height( h ); } $(window).resize(function() { setTimeout(fitDocument, 500); setTimeout(fitDocument, 2000); setTimeout(fitDocument, 4000); }); $(document).on("click", ".add-favorites", function() { Materialize.toast("Aggiunto ai tuoi preferiti. Facile!", 3000); }); $(document).on("click", ".segnala-errore", function() { Materialize.toast("La tua segnalazione è preziosa. Grazie!", 3000); }); function impiantoExists(idImpianto) { for(var i=0; i. */ // Lasciate questo file intonso per ora define('INCLUDES', 'includes'); define('MATERIALIZE', INCLUDES . _ . 'materialize'); define('JQUERY', INCLUDES . _ . 'jquery'); define('LEAFLET', INCLUDES . _ . 'leaflet'); -define('SITE_NAME', 'Facile.it'); +define('SITE_NAME', 'Facile Carburanti'); register_js( 'jquery', URL . _ . JQUERY . '/jquery-2.1.4.min.js' ); register_js( 'jquery.ui', URL . _ . INCLUDES . '/jquery-ui/jquery-ui.min.js' ); register_js( 'materialize', URL . _ . MATERIALIZE . '/js/materialize.min.js' ); register_js( 'leaflet', URL . _ . LEAFLET . '/leaflet.js' ); register_js( 'leaflet.bouncemarker', URL . _ . INCLUDES . '/leaflet.bouncemarker/bouncemarker.js' ); register_js( 'my-facile', URL . '/facile.js' ); register_css( 'materialize', URL . _ . MATERIALIZE . '/css/materialize.min.css' ); register_css( 'leaflet', URL . _ . LEAFLET . '/leaflet.css' ); register_css( 'my-facile', URL . '/facile.css' ); register_css( 'materialize.icons', 'https://fonts.googleapis.com/icon?family=Material+Icons' ); add_menu_entries([ new MenuEntry( 'home', URL, _("Home"), null, [ - 'title' => sprintf( - _("%s carburanti"), - SITE_NAME - ), + 'title' => SITE_NAME, 'desc' => _("Confronta e scegli il miglior prezzo") ] ) ]); require ABSPATH . _ . INCLUDES . _ . '/header.php'; require ABSPATH . _ . INCLUDES . _ . '/footer.php'; require ABSPATH . _ . INCLUDES . _ . '/functions.php';