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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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 id="wrap">
        <div id="main" class="container clear-top text-center">

            <div class="jumbotron">

                <!-- city -->
                <div id="idCity" class="lw-city">
                </div>
                <!-- end city -->

                <!-- date -->
                <div id="idDateTime" class="lw-date">
                    Retrieving Position...
                </div>
                <!-- end date -->

                <!-- more info -->
                <div class="lw-moreinfo inline">
                    <i id="idLocationIcon" class="fa fa-location-arrow" aria-hidden="true"></i>
                    <span id="idLocation">(unk)</span>
                    <span>&nbsp;</span>
                    <span>&nbsp;</span>
                    <i class="wi wi-barometer" alt="pressure" title="pressure"></i>
                    <span id="idPressure">-</span>
                    <span>&nbsp;</span>
                    <span>&nbsp;</span>
                    <i class="wi wi-humidity" alt="humidity" title="humidity"></i>
                    <span id="idHumidity">-</span>
                </div>
                <!-- end more info -->

                <!-- temp -->
                <div class="lw-temp inline">
                    <div style="display:inline-block;">
                        <div style="display:inline-block;"><i id="idIcon" class="wi wi-cloud" title="cloudy"></i></div>
                        <div style="display:inline-block;">
                            <div style="display:inline-block;" id="idTemp">--</div>
                            <div style="display:inline-block;"><i id="idUnits" class="wi wi-fahrenheit"></i></div>
                        </div>
                    </div>
                </div>
                <!-- end temp -->

                <div class="lw-commands inline">
                    <!-- warning icon -->
                    <a id="warningIcon" href="#" title="There seem to be a problem loading the data. Try again, or come back after a break." class="invisible">
                        <span><i class="fa fa-exclamation-triangle fa-1x" aria-hidden="true"></i></span>
                    </a>
                    <!-- refresh button -->
                    <a id="refreshButton" href="#" title="Refresh">
                        <span><i id="spinButton" class="fa fa-refresh fa-1x"></i></span>
                    </a>
                    <!-- refresh button -->
                    <span>&nbsp;</span>
                    <span>&nbsp;</span>
                    <!-- units button -->
                    <a id="unitsFahrenheit" href="#" title="Toggle to Fahrenheit" class="hidden">
                        <span class="units-toggle"><i class="wi wi-degrees"></i>F</span>
                    </a>
                    <a id="unitsCelsius" href="#" title="Toggle to Celsius">
                        <span class="units-toggle"><i class="wi wi-degrees"></i>C</span>
                    </a>
                    <!-- end units button -->
                </div>

            </div>
            <!-- jumbotron -->

            <!-- container-fluid -->
        </div>
        <!-- container -->
    </div>
    <!--   wrap -->

    <!-- footer -->
    <footer class="bg-footer footer-app-colophon text-gray-light text-sm text-center">
        <p>Bootstrap theme designed and coded with &nbsp;<i class="fa fa-coffee fa-1" title="coffee" aria-hidden="true"></i>&nbsp; by
            <a href="https://codepen.io/lorepirri/full/WpBJKO/" title="lorepirri" target="_blank">me</a> :)
        </p>
    </footer>

              
            
!

CSS

              
                $widget-bg-color: #0095FF;
$widget-color: white;
$widget-greyed-color: grey;

$body-bg-color: white;
$body-color: #435071;

.container {
  padding: 70px 0px 70px 0px;
}

.jumbotron {
  background-color: $widget-bg-color;
  color: $widget-color;
  margin-left: 2%;
  margin-right: 2%;
  padding: 20px 0px 20px 0px;
  margin-bottom: 20px;
  font-size: 21px;
}

.lw-city {
  font-weight: 400;
  font-size: 32px;
}

.lw-date {
  font-size: 18px;
}

.lw-temp {
  padding: 0px 10px 10px 10px;
  font-weight: 400;
  font-size: 64px;
}

.lw-moreinfo {
  padding-top: 15px;
  font-size: 14px;
}

.lw-commands {
  font-size: 14px;
  font-weight: 300;
  color: $widget-greyed-color;
}

.units-toggle {
  font-size: 14px;
  font-weight: 400;
}

body {
  background-color: $body-bg-color;
  color: $body-color;
  font-size: 14px;
  font-weight: 300;
  font-family: RobotoDraft, Roboto, sans-serif;
}

a {
  //color: #435071;
  text-decoration: none;
}

a.disabled {
   pointer-events: none;
   cursor: default;
}

a:hover {
  color: $widget-color;
  text-decoration: none;
}

.fa-exclamation-triangle {
  color: $body-color;
  text-decoration: none;
}

a:-webkit-any-link{
text-decoration:none !important;
/* https://www.google.com/support/forum/p/Chrome/thread?tid=44100701f93d5951&hl=en */
}

footer {
  font-size: 14px;
  font-weight: 300;
  padding-top: 30px;
  padding-bottom: 30px;
  color: grey;
  position: relative;
  margin-top: -60px; /* negative value of footer height */
  height: 60px;
  clear:both;
  padding-top:20px;
}

/* this makes the footer stays always down */
html, body {
  height: 100%;
}

#wrap {
  min-height: 100%;
}

#main {
  overflow:auto;
  padding-bottom:150px; /* this needs to be bigger than footer height*/
}

              
            
!

JS

              
                
function fixedEncodeURIComponent(str) {
  return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
    return '%' + c.charCodeAt(0).toString(16);
  });
}

var defaultResponse = {"coord":{"lon":13.41,"lat":52.52},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":287.64,"pressure":1021,"humidity":51,"temp_min":287.15,"temp_max":288.15},"visibility":10000,"wind":{"speed":1},"clouds":{"all":0},"dt":1491762000,"sys":{"type":1,"id":4892,"message":0.0029,"country":"DE","sunrise":1491711616,"sunset":1491760572},"id":2950159,"name":"Berlin","cod":200};
var currentParams = { units: "metric", lon: defaultResponse.coord.lon, lat: defaultResponse.coord.lat };

function showWarning() {
    $("#warningIcon").toggleClass("invisible"); // show warning
}
function hideWarning() {
    $("#warningIcon").addClass("invisible"); // hide warning
}

function disableUIinteraction() {
  $("#refreshButton").addClass('disabled'); // enable
  $("#unitsFahrenheit").addClass('disabled'); // enable
  $("#unitsCelsius").addClass('disabled'); // enable
  $("#spinButton").addClass('fa-spin'); // stop spin
  hideWarning();
  console.log("disable UI interaction");
}

function enableUIinteraction(thereWasAnError) {
  $("#refreshButton").removeClass('disabled'); // enable
  $("#unitsFahrenheit").removeClass('disabled'); // enable
  $("#unitsCelsius").removeClass('disabled'); // enable
  $("#spinButton").removeClass('fa-spin'); // stop spin
  if (thereWasAnError === true) {
    showWarning();
    console.log("data ready, an error occurred, enable UI interaction");
  } else {
    hideWarning();
    console.log("data ready, no err, enable UI interaction");
  }
}

function updateWeatherUI(owm) {

  // update the weather widget with the owm data

  var coords = "(" + owm.coord.lat + ", " + owm.coord.lon + ")";
  $("#idCity").html(owm.city);
  $("#idDateTime").html(owm.dateTimeString);
  $("#idLocation").html(coords);
  $("#idLocationIcon").prop('title', coords);
  $("#idPressure").html(owm.pressure);
  $("#idHumidity").html(owm.humidity);

  $("#idIcon").attr("class", "wi " + owm.icon);
  $("#idIcon").prop('title', owm.description);

  $("#idTemp").html(owm.temp);

  if (owm.units === "imperial") {
    $("#idUnits").attr("class", "wi wi-fahrenheit");
    $("#unitsFahrenheit").addClass("hidden");
    $("#unitsCelsius").removeClass("hidden");
  } else {
    $("#idUnits").attr("class", "wi wi-celsius");
    $("#unitsFahrenheit").removeClass("hidden");
    $("#unitsCelsius").addClass("hidden");
  }
  console.log("update weather UI");
}

function getDateTimeFromUnixTimestamp(unixTimestamp) {
  var newDate = new Date();
  newDate.setTime(unixTimestamp * 1000);
  return newDate.toUTCString();
}

function formatWeatherData(response, params) {

  // convert OWM response into UIParams

  if (response.count && response.count > 0) {
    response = response.list[0];
  }

  var city = response.name + ", " + response.sys.country;

  var ownicon = "wi-owm-";
  ownicon += response.weather[0].icon[2] === "d" ? "day":"night";
  ownicon += "-" + response.weather[0].id;
  // ownicon = "wi-owm-day-800"
  var dateTimeString = getDateTimeFromUnixTimestamp(response.dt);

  // from current paramrs
  var units = params.units;

  console.log("format data" );
  console.log("ownicon: " + ownicon);
  return {
    coord: response.coord,
    city: city,
    temp: response.main.temp,
    title: response.weather[0].main,
    description: response.weather[0].description,
    pressure: response.main.pressure,
    humidity: response.main.humidity,
    icon: ownicon,
    dateTimeString: dateTimeString,
    units: units
  };
}

function fetchWeatherData(userParams) {

  disableUIinteraction(); // update UI

  // fetch the data from OpenWeatherMapProxy: a proxy that I wrote for the purpose
  // (see https://github.com/lorepirri/OpenWeatherMapProxy)
  // in case of error, notify with an icon
  // and return the default quote

  var owmURLapi = "https://script.google.com/macros/s/AKfycbybFVtS_EurDJJwccfyyFiw7_h2ggh8Ubd3LbNzLrwyJj_mnuc/exec";
  var owmURLquery = "?nomockupme=1&nodebugme=1";
  owmURLquery += "&units=" + userParams.units;
  owmURLquery += "&lon=" + userParams.lon;
  owmURLquery += "&lat=" + userParams.lat;
  var owmURLrequest = owmURLapi + owmURLquery;
  console.log(owmURLquery);
  // fetch the quote
  // in case of error, notify with an icon
  // and return the default quote
  $.ajax({
    url: owmURLrequest,
    datatype: 'json',
    error: function(err){
      console.log('error');
      enableUIinteraction(true); // update UI
      //updateWeatherUI(formatWeatherData(defaultResponse, currentParams)); // update UI
    },//error
    success: function(response){
      if (response.cod === 200) {
        console.log('success!');
        enableUIinteraction(false); // update UI
        console.log(response);
        //consolidate the requested params as actual
        currentParams.units = userParams.units;
        currentParams.lon = userParams.lon;
        currentParams.lat = userParams.lat;
        updateWeatherUI(formatWeatherData(response, currentParams)); // update UI
      } else {
        console.log('OWM querystring has an error!');
        enableUIinteraction(true); // update UI
        //updateWeatherUI(formatWeatherData(defaultResponse, currentParams)); // update UI
      }
    }//success
  });
}

function fetchWeatherDataUsingGeoIP() {
  disableUIinteraction(); // disable UI
  $.ajax({
    url: "https://freegeoip.net/json/",
    datatype: 'json',
    error: function(err){
      console.log("error, can't fetch geo location from IP address!");
      console.log(err);
    },//error
    success: function(response){
      console.log('success!');
      console.log(response);
      currentParams.lat = response.latitude;
      currentParams.lon = response.longitude;
      console.log("ip: " + response.ip + ", latitude: " + response.latitude + ", longitude: " + response.longitude);
      fetchWeatherData(currentParams);
    }//succes
  });
}

$(document).ready(function() {

  fetchWeatherDataUsingGeoIP();

  if (navigator.geolocation) {
      // uses the ones from the browser
      disableUIinteraction(); // disable UI
      console.log("geolocation service available");
      navigator.geolocation.getCurrentPosition(function(position) {
      currentParams.lat = position.coords.latitude;
      currentParams.lon = position.coords.longitude;
      console.log("latitude: " + position.coords.latitude + ", longitude: " + position.coords.longitude);
      fetchWeatherData(currentParams);
    });

  } else {
    // no geo location
    console.log("no geo location for browser.");
  }

  $("#refreshButton").on("click", function() {
    // get lon/lat
    //userParams.lon = 0;
    //userParams.lat = 0;
    var params = { units : currentParams.units, lon: currentParams.lon, lat: currentParams.lat};
    fetchWeatherData(params); // fetch and update UI
  });

  $("#unitsCelsius").on("click", function() {
    var params = { units : "metric", lon: currentParams.lon, lat: currentParams.lat};
    fetchWeatherData(params); // fetch and update UI
  });
  $("#unitsFahrenheit").on("click", function() {
    var params = { units : "imperial", lon: currentParams.lon, lat: currentParams.lat};
    fetchWeatherData(params); // fetch and update UI
  });


});

              
            
!
999px

Console