Welcome to your new lab, here's the instructions for each exercise :
You must try to find documentation and solution by yourself. The course contains links to references and a lot of other interesting websites. Don't forget : the web is your friend ;-)
Bon courage...
In this exercise, we'll try to display an empty calendar for the next 6 months. The result should look like 2-tickets-please-calendar.html.
We'll use both direct DOM manipulation and using jQuery. If you're still wondering which one is better, have look at this jsperf.
2-tickets-please-calendar.js
..calendar
div with this structure :<div class="calendar">
<div class="cal-month" data-month="9" data-year="2012">
<h2 class="cal-month-name">October 2012</h2>
</div>
<div class="cal-month" data-month="10" data-year="2012">
<h2 class="cal-month-name">November 2012</h2>
</div>
<div class="cal-month" data-month="11" data-year="2012">
<h2 class="cal-month-name">December 2012</h2>
</div>
<div class="cal-month" data-month="0" data-year="2013">
<h2 class="cal-month-name">January 2013</h2>
</div>
<div class="cal-month" data-month="1" data-year="2013">
<h2 class="cal-month-name">February 2013</h2>
</div>
<div class="cal-month" data-month="2" data-year="2013">
<h2 class="cal-month-name">March 2013</h2>
</div>
</div>
.months
unordered list with this structure :<ul class="months">
<li class="month-name">October 2012</li>
<li class="month-name">November 2012</li>
<li class="month-name">December 2012</li>
<li class="month-name">January 2013</li>
<li class="month-name">February 2013</li>
<li class="month-name">March 2013</li>
</ul>
<div class="cal-month" data-month="9" data-year="2012">
<h2 class="cal-month-name">October 2012</h2>
<div class="day-names">
<div class="day-name">Monday</div>
<div class="day-name">Tuesday</div>
<div class="day-name">Wednesday</div>
<div class="day-name">Thursday</div>
<div class="day-name">Friday</div>
<div class="day-name">Saturday</div>
<div class="day-name">Sunday</div>
</div>
</div>
.cal-month
div. Use this structure :<div class="cal-month" data-month="9" data-year="2012">
<h2 class="cal-month-name">October 2012</h2>
<div class="day-names"><!-- day names... --></div>
<div class="days">
<div class="day" data-day="1">
<div class="day-number">1</div>
</div>
<div class="day" data-day="2">
<div class="day-number">2</div>
</div>
<!-- and so on... -->
</div>
</div>
/* Thursday */
[data-day-start="2"] .day:first-child {
margin-left: 14.47%;
}
/* Wednesday */
[data-day-start="3"] .day:first-child {
margin-left: 28.74%;
}
/* Tuesday */
[data-day-start="4"] .day:first-child {
margin-left: 43.01%;
}
/* Friday */
[data-day-start="5"] .day:first-child {
margin-left: 57.28%;
}
/* Saturday */
[data-day-start="6"] .day:first-child {
margin-left: 71.55%;
}
/* Sunday */
[data-day-start="0"] .day:first-child {
margin-left: 85.82%;
}
data-day-start
value correspond to the result of getDay()
from Date
: 0 => "Sunday"
, 1 => "Monday"
....cal-month
div has this particular attribute with the correct value. Here's an example :<div class="cal-month" data-day-start="4" data-month="10" data-year="2012">
<h2 class="cal-month-name">November 2012</h2>
</div>
innerHTML
for the no-jQuery parts.Now that we have our beautiful empty calendar, it's time to fill it with some events such as concerts, one-man-show, plays...
The result should look like 2-tickets-please-events.html.
In real life, these events would be retrieved from a server or something. We haven't covered that in the lessons, we'll see more about that next week.
The 2-tickets-please-events.js script provides a JSON strings that contains venues and events.
venues
and try to figure out how it is structured. Use console.log
and/or the JavaScript debugger..venues
div like this :<ul class="venues">
<li class="venue-name zenith">Le Zénith</li>
<li class="venue-name aeronef">L'Aéronef</li>
<!-- and so on... -->
</ul>
.day
div corresponding to the date of the event..day
element, insert a new element into it like this example :<div class="day" data-day="23">
<div class="day-number">23</div>
<div class="event" data-venue="zenith" title="CARAVAN PALACE">CARAVAN PALACE</div>
</div>
.day-number
div was already a child of .day
, you just have to append your .event
div after.data-venue
will be useful for adding colors to each venue.This is a "be awesome" exercise!
Our "2 Tickets Please!" application works fine, let's try to improve it. In the following steps, you'll find easy stuffs you can add, more complex ones and resources to learn new features...
It's your app, do what you want and be awesome.
There's a way to implement selector/filter without JavaScript. Using that, you could :
This "hack" crosses the line of what you "should" do with CSS and introduces some bad semantics. However, it's fun to play with it and you'll realize how much CSS is powerful. Don't use it on real websites unless you have a very good reason.
Try to add some responsivity with media queries. Have some different CSS for phone, tablet... resolutions.
2-tickets-please.css
and 2-tickets-please.html
. If you wanna modify the CSS, use 2-tickets-please-custom.css
. If you wanna add some HTML, use the DOM.