Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

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.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <div id="smtw"></div>
            
          
!

CSS

            
              body {
  background-color: #333;
  font: 100% 'Open Sans', "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
}

/*
Weather icon font from: 
http://fonts.artill.de/collection/artill-weather-icons
*/
@font-face {
    font-family: 'weather';
    src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/93/artill_clean_icons-webfont.eot');
    src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/93/artill_clean_icons-webfont.eot?#iefix') format('embedded-opentype'),
         url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/93/artill_clean_icons-webfont.woff') format('woff'),
         url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/93/artill_clean_icons-webfont.ttf') format('truetype'),
         url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/93/artill_clean_icons-webfont.svg#artill_clean_weather_iconsRg') format('svg');
    font-weight: normal;
    font-style: normal;
}

#smtw {
    background-color: #333;
    color: #fff;
    width: 100%;
    margin: 0;
    text-align: center;
    text-transform: uppercase;
}
    #smtw h2 {
        margin: 0;
        padding-top: 20px;
        color: #fff;
        font-size: 250%;
        font-weight: 300;
        text-align: center;
        text-shadow: 0px 1px 3px rgba(0, 0, 0, 0.15);
    }
    #smtw i {
        color: #fff;
        font-family: weather;
        font-size: 300%;
        font-weight: normal;
        font-style: normal !important;
        line-height: .8;
    }
    #smtw p {
        font-size: 68%;
    }

.icon-0:before  { content: ":"; }
.icon-1:before  { content: "p"; }
.icon-2:before  { content: "S"; }
.icon-3:before  { content: "Q"; }
.icon-4:before  { content: "S"; }
.icon-5:before  { content: "W"; }
.icon-6:before  { content: "W"; }
.icon-7:before  { content: "W"; }
.icon-8:before  { content: "W"; }
.icon-9:before  { content: "I"; }
.icon-10:before { content: "W"; }
.icon-11:before { content: "I"; }
.icon-12:before { content: "I"; }
.icon-13:before { content: "I"; }
.icon-14:before { content: "I"; }
.icon-15:before { content: "W"; }
.icon-16:before { content: "I"; }
.icon-17:before { content: "W"; }
.icon-18:before { content: "U"; }
.icon-19:before { content: "Z"; }
.icon-20:before { content: "Z"; }
.icon-21:before { content: "Z"; }
.icon-22:before { content: "Z"; }
.icon-23:before { content: "Z"; }
.icon-24:before { content: "E"; }
.icon-25:before { content: "E"; }
.icon-26:before { content: "3"; }
.icon-27:before { content: "a"; }
.icon-28:before { content: "A"; }
.icon-29:before { content: "a"; }
.icon-30:before { content: "A"; }
.icon-31:before { content: "6"; }
.icon-32:before { content: "1"; }
.icon-33:before { content: "6"; }
.icon-34:before { content: "1"; }
.icon-35:before { content: "W"; }
.icon-36:before { content: "1"; }
.icon-37:before { content: "S"; }
.icon-38:before { content: "S"; }
.icon-39:before { content: "S"; }
.icon-40:before { content: "M"; }
.icon-41:before { content: "W"; }
.icon-42:before { content: "I"; }
.icon-43:before { content: "W"; }
.icon-44:before { content: "a"; }
.icon-45:before { content: "S"; }
.icon-46:before { content: "U"; }
.icon-47:before { content: "S"; }
            
          
!

JS

            
              /**
 * Show Me The Weather, constructor.
 */
function ShowMeTheWeather(options) {
    this.options = {
        location: options.location || '',
        woeid: options.woeid || '',
        unit: options.unit || 'c',
        success: options.success || function(){},
        error: options.error || function(){}
    };
    this.query = 'select * from weather.forecast where woeid';
    
    if (this.options.location) {
        this.query += ' in (select woeid from geo.placefinder where text="'+this.options.location+'" and gflags="R" limit 1) and u="'+this.options.unit+'"';
    } else if (this.options.woeid) {
        this.query += '='+this.options.woeid+' and u="'+this.options.unit+'"';
    } else {
        this.options.error({
            message: 'No weather information could be retrieved. Please provide a location.'
        });
    }
}

/**
 * Fetches data using JSONP from the Yahoo! query API.
 */
ShowMeTheWeather.prototype.fetch = function(callback) {
    var script = document.createElement('script'),
        uid = 'smtw' + new Date().getTime(),
        encodedQuery = encodeURIComponent(this.query.toLowerCase());

    ShowMeTheWeather[uid] = function(data) {
        delete ShowMeTheWeather[uid];
        document.body.removeChild(script);
        callback(data);
    };

    script.src = 'https://query.yahooapis.com/v1/public/yql?q=' 
        + encodedQuery + '&format=json&callback=ShowMeTheWeather.' + uid;
    document.body.appendChild(script);
};

/**
 * Get weather information.
 */
ShowMeTheWeather.prototype.now = function() {
    var instance = this;
    this.fetch(function(data) {
        if (data !== null && data.query !== null && data.query.results !== null || data.query.results.channel.description !== 'Yahoo! Weather Error') {
            var result = data.query.results.channel,
                weather = {};

            // I´ve choosen to expose only the data needed.
            // There´s a lot of more data to play with here =)
            weather.temp = result.item.condition.temp;
            weather.code = result.item.condition.code;
            weather.city = result.location.city;
            weather.units = {
                temp: result.units.temperature, 
                distance: result.units.distance, 
                pressure: result.units.pressure, 
                speed: result.units.speed
            };
            
            instance.options.success(weather);
        } else {
            this.options.error({
                message: 'Error retrieving the latest weather information.'
            });
        }
    });
};

// This is how to use the widget above on your page
var smtw = new ShowMeTheWeather({
    woeid: '906057',
    success: function(weather) {
        var html = '<h2><i class="icon-'+weather.code+'"></i><br>'+weather.temp+'&deg;'+weather.units.temp+'</h2>';
            html += '<p>'+weather.city+'</p>';
        document.getElementById('smtw').innerHTML = html;  
    },
    error: function(error) {
        div.innerHTML = '<p>'+error.message+'</p>';
    }
}).now();
            
          
!
999px

Console