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

              
                
<!--This block is "main page" -->
<div id="main">
<div class="container">    
  <div class="row">
      <div class="col-md-12"><img src="//res.cloudinary.com/dzjiv8sye/image/upload/v1469558705/logo.png" alt="logo"></div>
  </div>
  <div class="row">
      <div class="col-md-12"><h1>Weather App</h1></div>
  </div>
  <div class="row">
     <div class="col-md-3">
     </div>
     <div class="col-md-6">
      <div class="custom-search-input">
        <div class="input-group col-md-12 ">                  
          <input type="text" class="form-control input-lg" id="textbox-main" placeholder="Enter city name" />
          <span class="input-group-btn">
              <button class="btn btn-info btn-lg search-btn" type="button" id="search-btn-main">
                  <i class="glyphicon glyphicon-search"></i>
              </button>
          </span>                  
        </div>
      </div>  
    </div>  
    <div class="col-md-3">
     </div>
  </div>
  <div class="row">
      <div class="col-md-12"><span class="city">Kurumkan</span><span class="region">Buryatia</span></div>
  </div>
  <div class="row">
    <div class="col-md-12">
      <span class="temperature">20</span> 
      <span class="fahrenheit second-color cursor-finger">&deg;F</span>|<span class="celsium cursor-finger">&deg;C</span>
    </div>
  </div>
  <div class="row">
      <div class="col-md-12">
          <span class="weather-status">Cloudy</span>
      </div>
  </div>
  <div class="row">
      <div class="col-md-12">
          <img class="weather-status-image" src="//res.cloudinary.com/dzjiv8sye/image/upload/v1469558705/cloudy.png" alt="partly-cloudy-day">
      </div>
  </div>
  <div class="row">
      <div class="col-md-12">
          <div class="winddiv">
              <span class="wind-direction">NW</span> <span class="wind-speed">7</span> 
              <span class="mph second-color cursor-finger">mph</span>|<span class="mps cursor-finger">mps</span> 
          </div>
      </div>
  </div>
  <div class="row">
      <div class="col-md-12">by <a href="https://www.linkedin.com/in/artur-arsalanov-ab3a6895" target="_blank" title="Find me in  LinkedIn!">ArturArsalanov</a></div>
  </div>
  </div>
</div>



<!--This block is searchpage. Initially hidden" -->
<div id="search-component"  class="hidden">
 <div class="container">
   <div class="row">
      <div class="col-md-1">                       
        <img src="//res.cloudinary.com/dzjiv8sye/image/upload/v1469558705/logo.png" id="search-logo" alt="logo">
      </div>       
      <div class="col-md-8">        
        <div class="row">
          <div class="col-md-12">
            <div class="custom-search-input">
              <div class="input-group col-md-12 ">                  
                <input type="text" class="form-control input-lg" id="textbox" placeholder="Enter city name" required="" />
                <span class="input-group-btn">
                    <button class="btn btn-info btn-lg" id="search-btn" type="button">
                        <i class="glyphicon glyphicon-search"></i>
                    </button>
                </span>                  
              </div>
            </div>  
          </div>  
        </div>
        <div class="row">    
          <div class="col-md-12">    
            <div class="list-group" id="citylist">        
            </div>
          </div>      
        </div>
      </div>
      <div class="col-md-3">
        <div class="row">
          <div class="col-md-12">
            <span class="city">Kurumkan</span><span class="region">Buryatia</span>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <span class="temperature">20</span> 
            <span class="fahrenheit second-color cursor-finger">&deg;F</span>|<span class="celsium cursor-finger">&deg;C</span>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <span class="weather-status">
            Cloudy</span>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <img class="weather-status-image" src="//res.cloudinary.com/dzjiv8sye/image/upload/v1469558705/cloudy.png" alt="partly-cloudy-day">
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <div class="winddiv">
              <span class="wind-direction">NW</span> <span class="wind-speed">7</span> 
              <span class="mph second-color cursor-finger">mph</span>|<span class="mps cursor-finger">mps</span> 
            </div>
          </div>
        </div>
      </div> 
   </div>
   <div class="row">
       <div class="col-md-1"></div>
      <div class="col-md-8">by <a href="https://www.linkedin.com/in/artur-arsalanov-ab3a6895" target="_blank" title="Find me in  LinkedIn!">ArturArsalanov</a></div>
      <div class="col-md-3"></div>
  </div>
</div>
</div>

              
            
!

CSS

              
                body{
	background-color: #263238!important;
	color: #ffb700!important;
	font-family: 'Roboto', sans-serif!important;
	text-align: center;
	padding: 50px 0;
}
#main h1{
	font-size: 75px;
}
#main{
	font-size: 25px;
}

.cursor-finger{
	cursor: pointer; cursor: hand;
}
#city{
	text-transform: uppercase;
}
.second-color{    
    color:white;
}

#search-component{
	margin-top: 20px;
}
.custom-search-input{
    padding: 3px;
    border: solid 2px #ffb700;
    border-radius: 6px;
    background-color: #fff;
    margin: 20px 0;
}

.custom-search-input input{
    border: 0;
    box-shadow: none;
}

.custom-search-input button{
    margin: 2px 0 0 0;
    background: none;
    box-shadow: none;
    border: 0;
    color: #ffb700;
    padding: 0 8px 0 10px;
    border-left: solid 1px #ffb700;
}

.custom-search-input button:hover{
    border: 0;
    box-shadow: none;
    border-left: solid 1px #ffb700;
}

.custom-search-input .glyphicon-search{
    font-size: 23px;    
}
.form-control{
	color:#263238!important;
}
.list-group-item{
	text-align: left;	
	color: #263238!important;
    cursor:pointer;
}
.list-group-item.active, .list-group-item.active:focus, .list-group-item.active:hover{
	background-color: #ffb700!important;
	border-color: #ffb700!important;

}
#search-logo{
	cursor: pointer; cursor: hand;
}
              
            
!

JS

              
                //in this table we will store information about each city from listitem (in searchbox)
  var weatherParams={};
    
  //convert miles per hour to meters per second
  function mphtomps(mph){
    return  (0.44704*mph).toFixed(2); 
  }
  //convert farenheit to celsium
  function ftoc(f){
    return ((f-32)/1.8).toFixed(2);
  }
  //the function creates geocoder object
  function initialize() {
      return new google.maps.Geocoder();
    }
    //updating current location info
  function updateAddress(city, prov){
    $(".city").html(city);
    $(".region").html(prov);
  }
  //update info about weather params
  function updateWeatherDisplay(lt,lg){
      var url = 'https://api.forecast.io/forecast/';            
      var lati=lt;
      var longi=lg;
      var data;
      var apiKey="ee61150ab79ab0338e81f5bf05244b32";
      var tempf=0;
      var tempc=0;
      var mph=0;
      var mps=0;

      $.getJSON(url + apiKey + "/" + lati + "," + longi + "?callback=?", function(data) {              
        tempf=data.currently.temperature;
        tempc=ftoc(tempf);
        $(".temperature").html(tempf);  
        //getting icon value(for example:  partly-cloudy-day)
        var icon=data.currently.icon;             
        //changing icon image source
        $(".weather-status-image").attr("src","//res.cloudinary.com/dzjiv8sye/image/upload/v1469558705/"+icon+".png");   
        //Title the icon    partly-cloudy-day=>Partly Cloudy Day
        icon=icon.split("-").map(i => i[0].toUpperCase() + i.substring(1)).join(' ');
        $(".weather-status").html(icon);
        mph=data.currently.windSpeed;
        mps=mphtomps(mph);

        $(".wind-speed").html(mph);
        //getting wind direction
        var windBearing=data.currently.windBearing;
        var windDir="";
        if((windBearing>=348.75||windBearing<11.25)&&windBearing>0)
          windDir="N";
        else if(windBearing>=11.25&&windBearing<33.75) 
          windDir="NNE";
        else if(windBearing>=33.75&&windBearing<56.25) 
          windDir="NE";
        else if(windBearing>=56.25&&windBearing<78.75) 
          windDir="ENE";
        else if(windBearing>=78.75&&windBearing<101.25) 
          windDir="E";
        else if(windBearing>=101.25&&windBearing<123.75) 
          windDir="ESE";
        else if(windBearing>=123.75&&windBearing<146.25) 
          windDir="SE";
        else if(windBearing>=146.25&&windBearing<168.75) 
          windDir="SSE";
        else if(windBearing>=168.75&&windBearing<191.25) 
          windDir="S";
        else if(windBearing>=191.25&&windBearing<213.75) 
          windDir="SSW";
        else if(windBearing>=213.75&&windBearing<236.25) 
          windDir="SW";
        else if(windBearing>=236.25&&windBearing<258.75) 
          windDir="WSW";
        else if(windBearing>=258.75&&windBearing<281.25)
          windDir="W";
        else if(windBearing>=281.25&&windBearing<303.75)
          windDir="WNW";
        else if(windBearing>=303.75&&windBearing<326.25)
          windDir="NW";
        else if(windBearing>=326.25&&windBearing<348.75)
          windDir="NNW";

        $(".wind-direction").html(windDir);
      });

      //listeners 
      $(".fahrenheit").click(function(){
        $(".temperature").html(tempf);    
        $(".celsium").removeClass("second-color");  
        $(".fahrenheit").addClass("second-color");
      });
      $(".celsium").click(function(){
        $(".temperature").html(tempc);    
        $(".fahrenheit").removeClass("second-color"); 
        $(".celsium").addClass("second-color");
      });

      $(".mph").click(function(){
        $(".wind-speed").html(mph);   
        $(".mps").removeClass("second-color");  
        $(".mph").addClass("second-color");
      });
      $(".mps").click(function(){
        $(".wind-speed").html(mps);   
        $(".mph").removeClass("second-color");  
        $(".mps").addClass("second-color");
      });           
  }
//this function is to update weather info in search box
function updateWeatherSearch(listId){      
  var formaddr = weatherParams[listId]["formaddr"];
  var lat=weatherParams[listId]["lat"];
  var lng=weatherParams[listId]["lng"];      
  var cityname=weatherParams[listId]["cityname"];
  var shortname=weatherParams[listId]["shortname"];  
  $("#textbox").val(formaddr);
  updateWeatherDisplay(lat,lng);  
  updateAddress(cityname,shortname);    
  $(".active").removeClass("active");
  $("#list"+listId).addClass("active");
  $(".fahrenheit").click();
  $(".mph").click();
}
//getting current location weather info
function getCurrentWeather(){
  $.getJSON("http://ip-api.com/json/?callback=?", function(data) {
      var lat=data["lat"];
      var lon=data["lon"];
      updateWeatherDisplay(lat,lon);         
      updateAddress(data["city"],", "+data["region"]);
    });
}

$(document).ready(function(){
  //getting current location weather info
  getCurrentWeather();
  $("#textbox-main").val("");
  //getting to search view
  $("#search-btn-main").click(function(){
    var input = $("#textbox-main").val();
    if(input){
      $("#main").hide(1000); 
      $("#search-component").show();
      $("#search-component").removeClass("hidden");    
      handleSearch(input);
      $("#textbox").val(input);
      $(".fahrenheit").click();
      $(".mph").click();
    }       
  });
  $("#search-btn").click(function(){
    var input=$("#textbox").val();
    if(input){
      handleSearch(input);
      $(".fahrenheit").click();
      $(".mph").click();
    }
  });  
  //getting to main view
  $("#search-logo").click(function(){
    $("#search-component").hide(1000);
    $("#main").show(1000);    
    $("#textbox-main").val("")

    getCurrentWeather();

    $(".fahrenheit").click();
    $(".mph").click();
  });  
  $("#textbox").keyup(function(event){
    if(event.keyCode == 13){
        $("#search-btn").click();
    }
  });
  $("#textbox-main").keyup(function(event){
    if(event.keyCode == 13){
        $("#search-btn-main").click();
    }
  });
  
});

function handleSearch(c){  
    var geocoder = new google.maps.Geocoder();
    var cityinput=c;
    geocoder.geocode( { 'address': cityinput}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      var formaddr=results[0]["formatted_address"];
      var lat = results[0].geometry.location.lat();
      var lng=results[0].geometry.location.lng()
      var cityname="";
      var shortname="";
      
      //discplay first cities weather data
      updateWeatherDisplay(lat, lng);         
      try{
        cityname=results[0].address_components[0].long_name+", ";
        shortname=results[0].address_components[2].short_name;        
      }catch(e)
      {
        cityname=results[0].address_components[0].long_name;
        shortname="";        
      }      
      updateAddress(cityname,shortname);

      //this var stores all list items from list group
      var citylist="";     
      for(var i=0; i<results.length;i++){
        var formaddr=results[i]["formatted_address"];
        var lat = results[i].geometry.location.lat();
        var lng=results[i].geometry.location.lng()
        var cityname="";
        var shortname="";
        try{
          cityname=results[i].address_components[0].long_name+", ";
          shortname=results[i].address_components[2].short_name;
        }catch(e)
        {
          cityname=results[i].address_components[0].long_name;
        }        
        
        citylist+="<div onclick=\"updateWeatherSearch("+i+");\" id=\"list"+i+"\""+" class=\"list-group-item\">"+formaddr+"</div>";
        weatherParams[""+i]={
        "formaddr": formaddr,
        "lat": lat,
        "lng": lng,
        "cityname": cityname,
        "shortname": shortname
        };
      }
      $("#citylist").html(citylist);      
      $("#list0").addClass("active");
    } else {
      console.log("Something got wrong " + status);
    }
  });
}


              
            
!
999px

Console