Crafting our Rain-or-Not app

This is our root page.

1<div data-role='page' id='root'>
2  <div data-role='header'>
3    <h1>Rain or Not?</h1>
4    <a class='ui-btn-right' data-role='button' data-transition='customslide' href='#about'>關於</a>
5  </div>
6  <div data-role='content' id='rain-content' class='loading'>
7  </div>
8</div>

The very basic yet working logic.

 1;(function($){
 2  $.getJSON('http://api.openweathermap.org/data/2.5/weather?q=Macao,MO&callback=?', function(data){
 3    console.log(data);
 4    var code = data.weather[0].id + ""; // force to string
 5    if (code[0] === '5') { // rainy code all start at 5
 6      $('#rain-content').removeClass().addClass('rain');
 7    } else {
 8      $('#rain-content').removeClass().addClass('sunny');
 9    }
10  });
11}).call(this, jQuery);

Note: the rainy code information is from the API documentation.

And the style.

 1.sunny {
 2  background: #ade1f9 url(../images/sunny.png) no-repeat center center;
 3}
 4.rain {
 5  background: #ade1f9 url(../images/rain.png) no-repeat center center;
 6}
 7.loading {
 8 background: #ade1f9 url(../images/loading.png) no-repeat center center;
 9}
10
11#root {
12  background: #ade1f9;
13}
14
15#rain-content {
16  height: 400px;
17}

What’s next? We’re going to take a look at “Refactoring”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content