JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<div class="back">
<h1 class="head center groove">A WEATHER APP</h1>
<div id="city">
<p class="center">Click the button to get your local weather.</p></div>
<div id="temp"></div>
<div class="center-div">
<button class="buttonone"id="getWeather" >Get Current Weather</button>
</div>
</div>
h1{border-style:groove;
display:block;
border-width:2px;
background-color:DodgerBlue;
border-color:white;}
.back{background-color:Lightseagreen;
padding:10px;
}
.head{color:white;
font-family:Raleway, Arial;
font-size:60px;
}
.center{text-align:center;
font-family:Raleway
;
}
#city {
text-align: center;
font-size: 30px;
font-family:Raleway;}
#temp {
text-align:left;
font-size:30px;
font-family:Raleway;
}
.buttonone {
margin: 30px auto;
padding: 20px 30px;
font-family:Arial;
font-size:20px;
color:Azure;
background-color:Lawngreen;
border-color:#00FA9A;
border-width:5px;
border-radius:30px;
;
}
.myclass{font-family:Raleway;
}
.center-div { text-align: center; width: 500px; margin: 20px auto; }
.button{
margin:5px;
padding:5px;
}
$(document).ready(function() {
$( "#getWeather" ).click(function() {
tryToGetLocation();
});
var APP_ID = "3abdc25e06a9753f60cafd4efa793ba3";
var API_DATA={};
var Celsius_Result=0;
$('body').on('click', '#getTemp', function() {
convertFtoC();
});
$('body').on('click', '#getMoreTemp', function() {
convertCtoF();
});
function success(position) {
console.log('position',position);
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
getData( latitude, longitude );
};
function error(error) {
console.log('error',error);
alert(error.message);
};
var options = {
maximumAge: 50000,
enableHighAccuracy: true
}
var tryToGetLocation = function() {
if ( navigator.geolocation ) {
navigator.geolocation.getCurrentPosition( success, error, options);
} else {
alert("Geolocation is disabled, please enable it");
}
};
function getData( latitude, longitude ) {
$.getJSON("https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon="+ longitude + "&APPID=" + APP_ID + "&callback=", callbackFuncWithData);
}
function callbackFuncWithData(data) {
API_DATA=data;
console.log("data",data);
$("#city").html("<span class='myclass'>City:" + data.name+"</span>"
);
$("#temp").html("Temperature: "+data.main.temp);
$("#temp").append('<button class="button" id="getTemp"> °F</button>');
$("#weather").html("<span class='myclass'>Weather: " + data.main.weather +"</span");
}
//Update Weather animation based on the returned weather description
var convertFtoC=function(){
var Celsius=(API_DATA.main.temp-32)/(9/5);Celsius_Result=Celsius.toFixed(2);
$("#temp").html("Temperature: "+Celsius.toFixed(2)+'<button class="button" id="getMoreTemp"> °C</button>')};
var convertCtoF=function(){
var Fahrenheit=(Celsius_Result*(9/5))+32;
$("#temp").html("Temperature: "+Fahrenheit.toFixed(2)+'<button class="button" id="getTemp"> °F</button>');}
});
Also see: Tab Triggers