Auto collapse news items after a week

This commit is contained in:
JonnyWong16 2020-05-31 14:47:08 -07:00
parent e14457da58
commit d95afa990d
No known key found for this signature in database
GPG key ID: B1F1F9807184697A

View file

@ -3007,21 +3007,23 @@ $(document).ready(function() {
async: true, async: true,
success: function (data) { success: function (data) {
if (data) { if (data) {
var now = moment().endOf('day');
var news = $('<ul/>').addClass('accordion list-unstyled') var news = $('<ul/>').addClass('accordion list-unstyled')
$.each(data, function (index, news_item) { $.each(data, function (index, news_item) {
var date = moment(news_item.date, "YYYY-MM-DD");
if (index >= 5) { return false; } if (index >= 5) { return false; }
var header = $('<div/>').addClass('link').html( var header = $('<div/>').addClass('link').html(
'<span class="toggle-left"><i class="fa fa-newspaper fa-fw"></i></span>' + '<span class="toggle-left"><i class="fa fa-newspaper fa-fw"></i></span>' +
'<span class="news-title">' + news_item.title + '</span>' + '<span class="news-title">' + news_item.title + '</span>' +
'<span class="toggle-right"><i class="fa fa-chevron-down fa-fw"></i></span>' + '<span class="toggle-right"><i class="fa fa-chevron-down fa-fw"></i></span>' +
'<span class="news-date toggle-right">' + moment(news_item.date, "YYYY-MM-DD").format($('#date_format').val()) + '</span>'); '<span class="news-date toggle-right">' + date.format($('#date_format').val()) + '</span>');
var subtitle = $('<span/>').addClass('news-subtitle').html(news_item.subtitle); var subtitle = $('<span/>').addClass('news-subtitle').html(news_item.subtitle);
var body = $('<span/>').addClass('news-body').html(news_item.body); var body = $('<span/>').addClass('news-body').html(news_item.body);
var content = $('<div/>').addClass('submenu'); var content = $('<div/>').addClass('submenu');
if (news_item.subtitle) { content.append(subtitle); } if (news_item.subtitle) { content.append(subtitle); }
content.append(body); content.append(body);
var li = $('<li/>').append(header).append(content) var li = $('<li/>').append(header).append(content)
if (index === 0) { if (index === 0 && Math.abs(now.diff(date, 'days')) < 7) {
li.addClass('open'); li.addClass('open');
content.css('display', 'block'); content.css('display', 'block');
} }