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.
div#app
header: h1 {{ appTitle }}
display(v-bind:res="weatherRes")
actions(v-bind:location="cityName" @search="searchcity")
// FONTS
@import url('https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700');
$main-font: 'Open Sans Condensed', sans-serif;
// COLORS
$white: #fff;
$black: #000;
$palette: #96A8BE, #738BA8, #506E92, #3F6083, #344F70;
// GENERAL
*, *::before, *::after{
box-sizing: border-box;
}
body{
font-family: $main-font;
font-size: 16px;
font-weight: 300;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: rgba(nth($palette, 1), .40);
}
h1,h2,h3,h4,h5,h6{
font-weight: normal;
}
// APP STYLES
#app{
width: 270px;
margin: 3rem 0;
background: nth($palette, 3);
box-shadow: 0 15px 10px -10px rgba(nth($palette, 5), .75);
overflow: hidden;
h1{
margin: 0;
padding: .3rem 1rem;
font-size: .75em;
font-weight: bold;
text-align: center;
color: nth($palette, 4);
background: rgba($white, .2);
}
}
.display{
text-align: center;
color: $white;
h2{
margin: 2rem 1rem .5rem;
}
h5{
position: relative;
margin: .7rem 1rem 4rem;
font-size: .85em;
color: nth($palette, 1);
&::after{
content: '';
position: absolute;
bottom: -1.5rem;
left: 50%;
transform: translateX(-50%);
width: 3rem;
height: 1px;
background: rgba($white, .65);
}
}
.temp{
padding: 0 1rem;
font-size: 2em;
}
img{
width: auto;
height: 128px;
display: inline-block;
}
.text{
margin: 0 0 1.5rem;
padding: 0 1rem;
text-transform: uppercase;
color: $white;
}
}
.actions{
position: relative;
margin-top: 3rem;
.togglSearch{
height: 35px;
line-height: 35px;
padding: 0 1rem;
font-family: $main-font;
text-align: center;
color: rgba(nth($palette, 1), .6);
background: nth($palette, 4);
transform: translateY(0);
transition: color .4s, transform .4s;
cursor: pointer;
&.active{
transform: translateY(-100%);
}
&:hover, &:focus{
color: nth($palette, 1);
}
}
.panel{
position: absolute;
bottom: 0;
left: 0;
display: flex;
width: 100%;
background: nth($palette, 5);
transform: translateY(100%);
transition: transform .4s;
&.active{
transform: translateY(0);
}
input, button{
height: 35px;
line-height: 35px;
padding: 0 1rem;
font-family: $main-font;
outline: none;
background: transparent;
border: none;
transition: color .4s;
color: rgba(nth($palette, 1), .4);
&:hover, &:focus{
color: nth($palette, 1);
}
}
input{
flex-grow: 2;
}
button{
border-left: 1px solid rgba(nth($palette, 1), .4);
cursor: pointer;
i{
vertical-align: middle;
}
}
}
}
/**
* This pen uses OpenWeatherMap weather API
* https://openweathermap.org/
*/
/*******************************************
* GLOBAL COMPONENTS
*******************************************/
// DISPLAY
Vue.component('display', {
props: ['res'],
template: `
<section class="display">
<h2>{{ res.name }}, {{ res.sys.country }}</h2>
<h5>
<span>Lat:</span> {{ res.coord.lat }}
<span>Lon: {{ res.coord.lon }}</span>
</h5>
<div class="condition">
<div class="temp">{{ temperature }}°C</div>
<img v-bind:src="'https://openweathermap.org/themes/openweathermap/assets/vendor/owm/img/widgets/' + res.weather[0].icon + '.png'"
v-bind:alt="'Weather in ' + res.name"
width="128" height="128">
<p class="text">{{ res.weather[0].description }}</p>
</div>
</section>
`,
computed: {
temperature(){
//Remove decimals on temperature value
var temp = this.res.main.temp,
noDecimals = temp.toFixed();
return noDecimals;
}
}
});
// ACTIONS
Vue.component('actions', {
props: ['location'],
data(){
return{
isSearching: false
}
},
template: `
<section class="actions">
<div class="togglSearch" v-bind:class="{'active': isSearching}" @click="isSearching = ! isSearching">
<span v-if="!isSearching">Search</span>
<span v-else>Close</span>
</div>
<div v-bind:class="{'active': isSearching}" class="panel">
<input type="text" v-model="location">
<button @click="search"><i class="material-icons">search</i></button>
</div>
</section>
`,
methods: {
search(){
this.$emit('search', this.location);
this.isSearching = false;
}
}
});
/*******************************************
* ROOT COMPONENT
*******************************************/
var app = new Vue({
el: '#app',
data: {
appTitle: 'Vue Weather App',
dataApi: 'aae97860de78632108ecc73036d6d17c',
cityName: 'milano',
lang: 'en',
weatherRes: null
},
// GET DATA WHEN MOUNTED
mounted(){
this.performAJAX();
},
// METHODS
methods: {
// SEARCH A NEW CITY
searchcity(city){
this.cityName = city;
var ctx = this;
ctx.performAJAX();
},
// GET WEATHER DATA
performAJAX(){
var ctx = this;
axios.get('https://api.openweathermap.org/data/2.5/weather?q=' +
ctx.cityName + '&units=metric&lang=' +
ctx.lang + '&APPID=' + ctx.dataApi )
.then(function (response) {
ctx.weatherRes = response.data;
})
.catch(function (error) {
console.log(error);
});
}
}
});
Also see: Tab Triggers