Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/assets/js/home.js

91 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-10-16 16:28:42 +00:00
const amount = 18;
let offset = 0;
let category = $('#social-post-container .sort-list-filter > li > a.active').attr('data-filter');
$(window).load(function () {
$portfolio_selectors = $('#social-post-container .sort-list-filter >li>a');
if ($portfolio_selectors != 'undefined') {
$portfolio = $('.sort-list-items');
$portfolio.isotope({
itemSelector: 'li',
layoutMode: 'masonry'
});
$portfolio_selectors.on('click', function () {
$portfolio_selectors.removeClass('active');
$(this).addClass('active');
const selector = $(this).attr('data-filter');
// if(selector === '*') {
offset = 0;
$('#load-more-button').fadeOut();
$portfolio.isotope('remove', $('#social-posts > li'));
category = selector;
loadPosts(true);
// autoHeight();
// } else if(selector === 'twitter') {
//
// }
$portfolio.isotope({filter: selector}).isotope('layout');
return false;
});
}
loadPosts(true);
});
$(document).ready(function () {
});
function loadPosts(onLoad) {
// const category = $('#social-post-container .sort-list-filter > li > a.active').attr('data-filter');
$.ajax({
url: "/main/getPosts",
2018-10-16 16:28:42 +00:00
data: {
amount: amount,
offset: offset,
category: category
},
beforeSend: function () {
$('#load-more-button').html($('#load-more-button').attr('data-loading'));
},
success: function (data) {
const $items = $(data);
console.log(data);
if(onLoad) {
// $('#social-posts').isotope('insert', $items);
$('#social-posts').append($items)
.isotope('appended', $items);
$('#load-more-button').fadeIn();
} else {
$('#social-posts').append($items)
.isotope('appended', $items);
}
$('#load-more-button').html($('#load-more-button').attr('data-load'));
autoHeight();
$('#social-posts').isotope({filter: '*'}).isotope('layout');
// $('#social-posts-list .social-post-item').each(function () {
// $(this).css('height', $(this).outerHeight());
// });
offset += 1;
// data = ' ';
if(data === ' ') {
$('#load-more-button').fadeOut().delay(1000).remove();
$('#social-post-container').parent().append('<div class="alert alert-warning">' + $('#social-post-container').attr('data-error-msg') + '</div>');
}
}
});
}
function autoHeight() {
$('.sort-list-item').each(function () {
$(this).css('height', $('.item-inner', this).outerHeight() + 40);
});
}
$('#main-slider').on('swiperight', function () {
$('#main-slider').carousel('prev');
});
$('#main-slider').on('swipeleft', function () {
$('#main-slider').carousel('next');
});
addReadMoreBtns();