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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <div class="container-fluid all">
  <div id="dialog" class="noselect" title="Welcome!">
  <p>Thank you for using my weather app. <br/><br/> Click on the temperature label to toggle between F&deg and  C&deg.<br/><br/> The application refreshes every 5 minutes for accurate reporting.<br/><br/> <strong>Please allow this application to know your location for accurate weather reporting.</strong><br/><br/> Enjoy!</p>
</div>
  <div class="jumbotron">
    <h1 class="text-center">Weather App</h1>
  </div>
  <div class="row">
    <div class="col-md-12 well" id="city">
      <h2 class="text-center">Weather for</h2>
      <h2 class="text-center data-item" id="city-text"></h2>


      <div class="row">
        <div class="col-md-4" id="weather">
          <img src="" id="weatherImg" class="center-block">
          <h3 class="text-center data-item" id="weather-text"></h3>
        </div>
        <div class="col-md-4" id="temp">
          <h3 class="text-center">Temperature</h3>
          <h3 class="text-center data-item noselect"><span id="temp-text"></span> <span id="tempMode">F&deg</span></h3>
        </div>
        <div class="col-md-4" id="wind">
          <h3 class="text-center">Wind Speed</h3>
          <h3 class="text-center data-item" id="wind-text"></h3>
        </div>
      </div>
    </div>
  </div>
  <div class="footer">
    <div class="container">
      <p class="copyright">Copyright © Brandon Gottschling 2016. All Rights Reserved. Made with the <a href="http://www.openweathermap.com">openweathermap</a> API.</p>
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  background-color: #404576;
}

.data-item {
  color: #444;
}

.jumbotron,
.well {
  background: #888;
  color: white;
}

.copyright {
  color: #222;
}

.noselect {
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none;   /* Chrome/Safari/Opera */
  -khtml-user-select: none;    /* Konqueror */
  -moz-user-select: none;      /* Firefox */
  -ms-user-select: none;       /* IE/Edge */
  user-select: none;           /* non-prefixed version, currently
                                  not supported by any browser */
}

#tempMode {
  cursor: pointer;
}
              
            
!

JS

              
                //necessary global variables for selector caching.
var $tempMode = $("#tempMode");
var $tempText = $("#temp-text");
var $windText = $("#wind-text");
//$(document).ready(function() {
  // this function takes the temperature from the dataHandler and displays the temperature according to the correct temperature unit, and colors the temperature hot or cold.

//function for instruction dialog
  $(function() {
    $( "#dialog" ).dialog();
  });

  function formatTemperature(kelvin) {
    
    
    var clicked = false;
    var fahr = ((kelvin * 9 / 5) - 459.67).toFixed(0);
    var cels = (kelvin - 273.15).toFixed(1);
    //initial temperature display
    $tempText.html(fahr);

    var firstClick = false;
    //click handler to update the temperature unit of measurement.
    $tempMode.off("click").on("click", function() {
      firstClick = true;
      console.log(clicked);
      clicked === false ? clicked = true : clicked = false;
      clicked === true ? $tempMode.html("C&deg") : $tempMode.html("F&deg");
      if (clicked) {
        $tempText.html(cels);
      } else
        $tempText.html(fahr);
    });

    if (cels > 24) {
      $("#temp-text").css("color", "red");
    } else if (cels < 18) {
      $("#temp-text").css("color", "blue");
    }
  }
  //handles response data and formats it accordingly since it is an asynchronous response object all data handling and formatting must be done within this function.
  function dataHandler(data) {

    formatTemperature(data.main.temp);

    if (data.main.temp && data.name && data.sys) {
      // display location name
      $("#city-text").html(data.name + ", " + data.sys.country);
      // display icon
      if (data.weather) {
        var imgURL = "http://openweathermap.org/img/w/" + data.weather[0].icon + ".png";
        $("#weatherImg").attr("src", imgURL);
        $("#weather-text").html(data.weather[0].description);
      }
      // display wind speed
      if (data.wind) {
        var knots = data.wind.speed * 1.9438445;
        $windText.html(knots.toFixed(1) + " Knots");
      }
    }
  }
  //This calls the api with the correct coordinates provided by the getLocation function
  function getWeather(lat, lon) {
    var apiURI = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=06170c100199dbae1e223cc3dfad960b";

    return $.ajax({
      url: apiURI,
      dataType: "json",
      type: "GET",
      async: "true",
    });
  }

  //Passes the browser's geolocation into the getWeather function once its done the response from the getWeather call will be passed to the data handler for formatting.
  var counter = 0;

  function getLocation() {
    console.log("Update# " + counter++);
    if ("geolocation" in navigator) {
      navigator.geolocation.getCurrentPosition(function(position) {
        getWeather(position.coords.latitude, position.coords.longitude).done(dataHandler);
      })
    } else {
      alert("geolocation not available");
    }
  }
  var updateInterval = setInterval(getLocation(), 300000);
//});
              
            
!
999px

Console