Skip to content

Commit 91021ac

Browse files
author
Michael Lancaster
committed
added filter to the list of books by beginner, intermediate, advanced and some js improvements
1 parent 62e1926 commit 91021ac

File tree

2 files changed

+105
-15
lines changed

2 files changed

+105
-15
lines changed

css/index.css

+21-1
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,7 @@ footer {
13561356
.booksection {
13571357
margin-bottom: 30px;
13581358
}
1359+
13591360
.booksection #cover {
13601361
float: left;
13611362
position: relative;
@@ -1552,12 +1553,31 @@ a#infos:hover {
15521553
}
15531554
.pythonbooks {
15541555
background-color: transparent;
1555-
margin: 0 0 30px;
1556+
margin: 0;
15561557
}
15571558
.pythonbooks > * {
15581559
display: inline;
15591560
margin-right: 10px;
15601561
}
1562+
#filterBy {
1563+
float: left;
1564+
overflow: hidden;
1565+
margin: 0 0 30px;
1566+
}
1567+
#filterBy li {
1568+
float: left;
1569+
margin: 0 0 0 10px;
1570+
list-style: none;
1571+
}
1572+
#filterBy li:first-child {
1573+
margin-left: 0;
1574+
}
1575+
#filterBy a {
1576+
color: #eedb59;
1577+
}
1578+
#filterBy .active {
1579+
color: #fff;
1580+
}
15611581
/*!
15621582
* Bootstrap Responsive v2.0.4
15631583
*

index.html

+84-14
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,22 @@ <h4>About us :</h4>
8989
=========================== -->
9090
<div class="container">
9191
<div class="row">
92-
<a class="recrutement span12" href="http://www.revolunet.com/recrutement-developpeur-web" target="_blank"> We're hiring talented web developers in Paris, France </a>
9392
<div class="pythonbooks span12">
9493
<p>See also :</p>
9594
<a href="http://pythonbooks.revolunet.com/" target="_blank">
9695
<img src="./img/logo_pythonbooks.png" alt="Python Books" title="Learn Python for free !" width="100" height="16">
9796
</a>
9897
</div>
98+
<a class="recrutement span12" href="http://www.revolunet.com/recrutement-developpeur-web" target="_blank"> We're hiring talented web developers in Paris, France </a>
99+
<div class="span12 row-fluid">
100+
<p class="span1">Filter by :</p>
101+
<ul id="filterBy">
102+
<li><a href="#" class="active all" title="filter books by All">All</a></li>
103+
<li><a href="#" class="beginner" title="filter books by Beginner">Beginner</a></li>
104+
<li><a href="#" class="intermediate" title="filter books by Intermediate">Intermediate</a></li>
105+
<li><a href="#" class="advanced" title="filter books by Advanced">Advanced</a></li>
106+
</ul>
107+
</div>
99108
</div>
100109

101110
<!-- ////////// WRAPPER BOOKS -->
@@ -123,23 +132,86 @@ <h4>About us :</h4>
123132
return (Math.round(Math.random())-0.5);
124133
}
125134

135+
function filterBy() {
136+
var // var's sort by
137+
active = 'active',
138+
btFilterBy = $('#filterBy').find('a'),
139+
elBeginner = $('.Beginner'),
140+
elIntermediate = $('.Intermediate'),
141+
elAdvanced = $('.Advanced'),
142+
booksection = $('.booksection');
143+
144+
// interaction filter by level
145+
btFilterBy.on('click', function(e) {
146+
e.preventDefault();
147+
148+
booksection.each(function() {
149+
$(this).show();
150+
});
151+
152+
if ( $(this).hasClass('all') ) {
153+
booksection.each(function() {
154+
$(this).show();
155+
});
156+
}
157+
158+
if ( $(this).hasClass('beginner') ) {
159+
booksection.each(function() {
160+
if ( ! $(this).hasClass('Beginner') ) {
161+
$(this).fadeOut('fast');
162+
}
163+
});
164+
}
165+
166+
if ( $(this).hasClass('intermediate') ) {
167+
booksection.each(function() {
168+
if ( ! $(this).hasClass('Intermediate') ) {
169+
$(this).fadeOut('fast');
170+
}
171+
});
172+
}
173+
174+
if ( $(this).hasClass('advanced') ) {
175+
booksection.each(function() {
176+
if ( ! $(this).hasClass('Advanced') ) {
177+
$(this).fadeOut('fast');
178+
}
179+
});
180+
}
181+
182+
btFilterBy.removeClass(active);
183+
$(this).addClass(active);
184+
});
185+
}
186+
126187
$(document).ready(function() {
127-
$.getJSON('./issues.json?' + Math.random(), function(data) {
128-
var template = $('#booktpl').html();
129-
data.books.sort(randOrd);
130-
var html = Mustache.to_html(template, data);
131-
$('#issueswrap').html(html);
132-
});
133-
$('#jsinfos').hide();
134-
$('a.#infos').on('click', function(){
135-
$('#jsinfos').slideToggle();
136-
});
188+
// get the data and compile into the html template
189+
$.getJSON('./issues.json?' + Math.random(), function(data) {
190+
var template = $('#booktpl').html(),
191+
html = Mustache.to_html(template, data),
192+
issuesWrap = $('#issueswrap');
193+
194+
data.books.sort(randOrd);
195+
issuesWrap.html(html);
196+
197+
filterBy();
198+
});
199+
200+
var // var's info
201+
jsInfos = $('#jsinfos'),
202+
btInfo = $('a.#infos');
203+
204+
// interaction show more info about it
205+
jsInfos.hide();
206+
btInfo.on('click', function(){
207+
jsInfos.slideToggle();
208+
});
137209
});
138210
</script>
139211

140212
<script id="booktpl" type="text/template">
141213
{{#books}}
142-
<div class="span4 booksection">
214+
<div class="span4 booksection {{level}}">
143215
<a target="_blank" href="{{url}}">
144216
<div class="view"> READ </div>
145217
<div id="cover" style="background:black url('{{cover}}') no-repeat center;-webkit-background-size:cover;-moz-background-size:cover;background-size:cover;">
@@ -153,8 +225,6 @@ <h3><a href="{{authorUrl}}" target="_blank">{{author}}</a></h3>
153225
{{/books}}
154226
</script>
155227

156-
157-
158228
<script type="text/javascript">
159229
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
160230
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

0 commit comments

Comments
 (0)