css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

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.

  .default Share Your Location to Get The Local&nbsp;Weather!
      span.button#button-f.activated °F
      span.button#button-c °C
  pre This App Is Powered 
      | by 
      a(href="http://forcast.io" target="_blank") Forcast.io
      | , 
      a(href="http://geocoder.ca" target="_blank") Geocoder.ca 
      = "\n"
      | and 
      a(href="https://erikflowers.github.io/weather-icons/" target="_blank") Weather Icons

              $blue: rgba(51, 153, 255, .6)
  background-color: $blue
    width: 60%
    min-width: 200px 
    margin: 0 auto
      family: 'Open Sans', sans-serif
      weight: 300
    padding: 2em
    border-radius: 2.5em
    margin-top: 5em
    text-align: center
    display: flex
    justify-content: center
    flex-wrap: wrap
      display: none
      color: white
      font-size: 2.2em
      @media(max-width: 400px)
        font-size: 1.5em
      color: white
      margin: .5em
      display: none
      color: white
      min-width: 100%
        size: 3em
      @media(max-width: 600px)
        font-size: 2em
      @media(max-width: 400px)
        font-size: 1.5em
      display: none
      min-width: 250px
        size: 8em
      @media(max-width: 600px)
        font-size: 5em
      @media(max-width: 400px)
        font-size: 3em
      margin-top: .5em
      display: none
        color: white
        padding: .2em 1em
          size: 1em
          weight: 700
        border: 2px solid white
        border-radius: 1.5em
        margin: 0 .25em
        transition: all ease-in-out .5s 
          background-color: white
          border: 2x solid white
          color: $blue
          cursor: pointer
          background-color: white
          color: $blue
          border: 2px solid white
      display: none
      margin-top: 3em
        font-size: 7em
        @media(max-width: 600px)
          font-size: 5em
        @media(max-width: 400px)
          font-size: 3em
      display: none
      color: white
        size: 2em
      text-transform: capitalize
      @media(max-width: 400px)
        font-size: 1.5em
    margin: auto
    position: absolute
    top: 0 
    left: 0 
    bottom: 100
    right: 0
    border: none
    background: none
    font-family: Open Sans
    color: white
        text-decoration: none
              $(document).ready ->
  lat = undefined
  lon = undefined
  temp = undefined
  getLocationAndWeather = ->
    # If brwoser supports HTML5 geolocation then execute the getWeather function
    getWeather = (position) ->
      # Locate nearest city using Geocoder.ca API
      geocodeAPI = 'http://geocoder.ca/?latt=' + lat + '&longt=' + lon + '&reverse=1&allna=1&geoit=xml&corner=1&json=1'
      $.getJSON geocodeAPI, (data) ->
        $('#name').html 'The current weather in ' + data.city + ',&nbsp;' + data.prov
      # Using forcast api to get the current weather.
      Forcast_API_KEY = '464271a84e193070f9a5d159c9574296'
      forcastAPI = 'https://api.forecast.io/forecast/' + Forcast_API_KEY + '/' + lat + ',' + lon + '?callback=?'
      # Could only use an ajax request because the getJSON request was causing a cross domain error
        url: forcastAPI
        dataType: 'jsonp'
        crossDomain: true
        success: (data) ->
          # Return summary
          $('#summary').html data.currently.summary
          # Return temperature
          temp = Math.floor(data.currently.temperature)
          $('#temp').html temp + '&deg;F'
          #Switch up the weather icons based on the current condition
          switch data.currently.icon
            when 'clear-day'
              $('#icon').html '<i class="wi wi-day-sunny"></i>'
            when 'clear-night'
              $('#icon').html '<i class="wi wi-night-clear"></i>'
            when 'rain'
              $('#icon').html '<i class="wi wi-day-rain-mix"></i>'
            when 'snow'
              $('#icon').html '<i class="wi wi-day-snow"></i>'
            when 'sleet'
              $('#icon').html '<i class="wi wi-day-sleet"></i>'
            when 'wind'
              $('#icon').html '<i class="wi wi-day-windy"></i>'
            when 'fog'
              $('#icon').html '<i class="wi wi-day-fog"></i>'
            when 'cloudy'
              $('#icon').html '<i class="wi wi-day-cloudy"></i>'
            when 'partly-cloudy-day'
              $('#icon').html '<i class="wi wi-day-cloudy"></i>'
            when 'partly-cloudy-night'
              $('#icon').html '<i class="wi wi-night-cloudy"></i>'
              $('#icon').html '<i class="wi wi-day-sunny"></i>'
          $('.loader').fadeOut 500, ->
            $('#name').fadeIn 500
            $('#icon').fadeIn 500
            $('#temp').fadeIn 500
            $('#summary').fadeIn 500
            $('#button-box').fadeIn 500

    # Throw errors if location is not defined

    showError = (error) ->
      switch error.code
        when error.PERMISSION_DENIED
          $('.error').html 'User denied the request for Geolocation.'
        when error.POSITION_UNAVAILABLE
          $('.error').html 'Location information is unavailable.'
        when error.TIMEOUT
          $('.error').html 'The request to get user location times out.'
        when error.UNKNOWN_ERROR
          $('.error').html 'An unknown error occurred.'

    if navigator.geolocation
      navigator.geolocation.getCurrentPosition ((position) ->
        # Log the latitude and longitude 
        lat = position.coords.latitude
        lon = position.coords.longitude
        # Only call this function 6 times a day when the browser is open
        setInterval getWeather(), 144000000
      ), showError
      $('.default').html 'Geolocation is not supported by this browser.'

  # Toggle the temperature between Fahrenheit and Celsius

  changeTemp = ->
    $('#button-c').click ->
      $('#button-c').addClass 'activated'
      $('#button-f').removeClass 'activated'
      $('#temp').html Math.floor((temp - 32) * .5555555) + '&deg;C'
    $('#button-f').click ->
      $('#button-f').addClass 'activated'
      $('#button-c').removeClass 'activated'
      $('#temp').html temp + '&deg;F'


# ---
# generated by js2coffee 2.1.0
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................