Ho questo codice JS che vorrei rendere più fluido e funzionale. Il codice funziona ma volevo sapere se esiste un modo diverso per scrivere la stessa cosa con più professionalità:
codice:
$(document).ready(function () {function pad(n) {
return (n < 10 ? '0' + n : n);
}
var data = new Date();
var giorno, mese, anno, ore, minuti, secondi;
giorno = pad(data.getDate());
mese = pad(data.getMonth() + 1);
anno = data.getFullYear();
ore = pad(data.getHours());
minuti = pad(data.getMinutes());
secondi = pad(data.getSeconds());
var data_formattata = giorno + "/" + mese + "/" + anno + " " + ore + ":" + minuti + ":" + secondi;if (!$('p').hasClass('errore1') & !$('p').hasClass('errore2')) {
$("div.respform [name='Tempo']").val(data_formattata);
}
var href = jQuery(location).attr('href');
var protocollo = href.substr(0,5);
if (protocollo == "https") {
(function(){ document.getElementById("noSupporto").style.display = "none";
if (navigator.geolocation) {
if((document.getElementById("Latitudine").value == "") ||
(document.getElementById("Longitudine").value == "")){
navigator.geolocation.getCurrentPosition(mia_posizione, posizione_sconosciuta,
{enableHighAccuracy: false, timeout: 1000, maximumAge: 1001});
}
} else {
document.getElementById("noSupporto").style.display = "block";
}
setTimeout(arguments.callee, 1000);
})();function mia_posizione(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
document.getElementById("Latitudine").value = lat.toFixed(7);
document.getElementById("Longitudine").value = lon.toFixed(7);
}
function posizione_sconosciuta() {
}
}
});
Grazie