forked from wezm/wezm.net
Start implementing JS pagination of articles
This commit is contained in:
parent
19be2ada2e
commit
ed7c6183be
4 changed files with 46 additions and 19 deletions
|
@ -7,18 +7,7 @@
|
||||||
<link rel="stylesheet" href="/css/reset.css" type="text/css" media="screen,projector" />
|
<link rel="stylesheet" href="/css/reset.css" type="text/css" media="screen,projector" />
|
||||||
<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen,projector" />
|
<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen,projector" />
|
||||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
|
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
|
||||||
<script src="/js/script.js" type="text/javascript"></script>
|
<script src="/js/articles.js" type="text/javascript"></script>
|
||||||
<script type="text/javascript">
|
|
||||||
var articles;
|
|
||||||
jQuery(function() {
|
|
||||||
// load JSON
|
|
||||||
// get( url, [data], [callback], [type] )
|
|
||||||
jQuery.get('/articles/index.json', {}, function(data) {
|
|
||||||
articles = data;
|
|
||||||
console.log(data);
|
|
||||||
}, 'json');
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%= render 'header' %>
|
<%= render 'header' %>
|
||||||
|
@ -39,9 +28,9 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
<a href="">« Newer</a>
|
<a href="/articles/#page-0" class="older">« Older</a>
|
||||||
|
|
|
|
||||||
<a href="">Older »</a>
|
<a href="/articles/#page-2" class="newer">Newer »</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<%= render 'footer' %>
|
<%= render 'footer' %>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<title><%= @item[:title] %></title>
|
<title><%= @item[:title] %></title>
|
||||||
<link rel="stylesheet" href="/css/reset.css" type="text/css" media="screen,projector" />
|
<link rel="stylesheet" href="/css/reset.css" type="text/css" media="screen,projector" />
|
||||||
<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen,projector" />
|
<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen,projector" />
|
||||||
<script src="/js/script.js" type="text/javascript"></script>
|
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%= render 'header' %>
|
<%= render 'header' %>
|
||||||
|
@ -19,16 +19,16 @@
|
||||||
<span class="day"><%= post_date.day %></span>
|
<span class="day"><%= post_date.day %></span>
|
||||||
<span class="month"><%= post_date.strftime('%b') %></span>
|
<span class="month"><%= post_date.strftime('%b') %></span>
|
||||||
<span class="year"><%= post_date.year %></span>
|
<span class="year"><%= post_date.year %></span>
|
||||||
</span>
|
</abbr>
|
||||||
<a href="<%= article.reps.first.path %>"><%= article[:title] %></a>
|
<a href="<%= article.reps.first.path %>"><%= article[:title] %></a>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
<a href="">« Newer</a>
|
<a href="#newer">« Newer</a>
|
||||||
|
|
|
|
||||||
<a href="">Older »</a>
|
<a href="#older">Older »</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<%= render 'footer' %>
|
<%= render 'footer' %>
|
||||||
|
|
|
@ -143,3 +143,8 @@ ul#menu li {
|
||||||
display: block;
|
display: block;
|
||||||
font-weight: 200;
|
font-weight: 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
display: none;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
33
output/js/articles.js
Normal file
33
output/js/articles.js
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
var articles;
|
||||||
|
|
||||||
|
function articles_loaded(data) {
|
||||||
|
articles = data;
|
||||||
|
console.log(data);
|
||||||
|
$('.pagination').slideDown('fast');
|
||||||
|
};
|
||||||
|
|
||||||
|
jQuery(function() {
|
||||||
|
$('.newer, .older').click(function() {
|
||||||
|
var elem = $(this);
|
||||||
|
|
||||||
|
var page;
|
||||||
|
var matches;
|
||||||
|
if(matches = elem.attr('href').match(/(\d+)$/)) {
|
||||||
|
page = new Number(matches[1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var per_page = 10;
|
||||||
|
|
||||||
|
var i = (page - 1) * per_page;
|
||||||
|
for(; i < page * per_page; i++) {
|
||||||
|
console.log(articles[i].title);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
jQuery.get('/articles/index.json', {}, articles_loaded, 'json');
|
||||||
|
});
|
Loading…
Reference in a new issue