forked from redhat-developer/developers.redhat.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlatest.js
More file actions
49 lines (42 loc) · 1.2 KB
/
Copy pathlatest.js
File metadata and controls
49 lines (42 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
Latest Component
Shows up on the home page
*/
app = window.app || {};
app.latest = {};
app.latest.fetch = function() {
$.getJSON(app.dcp.url.search + '/resources?newFirst=true&size10=true',function(data){
if(data.hits && data.hits.hits) {
app.latest.render(data.hits.hits);
}
});
}
app.latest.render = function(materials) {
materials = materials.slice(0,6);
var html = [];
materials.forEach(function(material){
var type = material.fields.sys_type[0];
var timeStamp = new Date(material.fields.sys_created[0]);
var formattedDate = moment(timeStamp).format('ll')
var item = [
'<li>',
'<i class="icon-RHDev_-resources_icons_'+ type +'"></i>',
'<a href="' + material.fields.sys_url_view[0] + '" class="title">',
material.fields.sys_title[0],
'<p class="date">',
formattedDate,
'</p>',
'</a>',
'</li>'
].join('');
html.push(item);
});
$('.homepage-resources-latest').html(html.join(''));
}
$(function() {
var $latestResourceList = $('.homepage-resources-latest');
// check if we are on a page that needs this to run
if($latestResourceList.length) {
app.latest.fetch();
}
});