85 lines
2.8 KiB
JavaScript
85 lines
2.8 KiB
JavaScript
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",
|
|
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);
|
|
if(onLoad) {
|
|
$('#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');
|
|
offset += 1;
|
|
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(); |