mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 14:18:27 +01:00
People / Spaces: Endless Scrolling (#5211)
This commit is contained in:
parent
671a98bee4
commit
bb14db9c69
@ -5,3 +5,4 @@
|
|||||||
- Enh #5197: Default .htaccess - Remove Options +FollowSymLinks
|
- Enh #5197: Default .htaccess - Remove Options +FollowSymLinks
|
||||||
- Enh #4495: Allow to lock comments per content
|
- Enh #4495: Allow to lock comments per content
|
||||||
- Enh #3688: Use Image widget in user list
|
- Enh #3688: Use Image widget in user list
|
||||||
|
- Enh #5188: People / Spaces: Endless Scrolling
|
||||||
|
@ -6,11 +6,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use humhub\assets\DirectoryAsset;
|
use humhub\assets\DirectoryAsset;
|
||||||
|
use humhub\libs\Html;
|
||||||
use humhub\modules\space\components\SpaceDirectoryQuery;
|
use humhub\modules\space\components\SpaceDirectoryQuery;
|
||||||
use humhub\modules\space\widgets\SpaceDirectoryCard;
|
use humhub\modules\space\widgets\SpaceDirectoryCard;
|
||||||
use humhub\modules\space\widgets\SpaceDirectoryFilters;
|
use humhub\modules\space\widgets\SpaceDirectoryFilters;
|
||||||
use humhub\widgets\Button;
|
|
||||||
use humhub\widgets\LinkPager;
|
|
||||||
use yii\web\View;
|
use yii\web\View;
|
||||||
|
|
||||||
/* @var $this View */
|
/* @var $this View */
|
||||||
@ -48,13 +47,9 @@ DirectoryAsset::register($this);
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if (!$spaces->isLastPage()) : ?>
|
<?php if (!$spaces->isLastPage()) : ?>
|
||||||
<div class="directory-load-more">
|
<?= Html::tag('div', '', [
|
||||||
<?= Button::primary(Yii::t('SpaceModule.base', 'Load more'))
|
'class' => 'directory-end',
|
||||||
->icon('fa-angle-down')
|
'data-current-page' => $spaces->pagination->getPage() + 1,
|
||||||
->action('directory.loadMore')
|
'data-total-pages' => $spaces->pagination->getPageCount(),
|
||||||
->options([
|
]) ?>
|
||||||
'data-current-page' => $spaces->pagination->getPage() + 1,
|
|
||||||
'data-total-pages' => $spaces->pagination->getPageCount(),
|
|
||||||
]) ?>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
@ -5,7 +5,6 @@ use humhub\libs\Html;
|
|||||||
use humhub\modules\user\components\PeopleQuery;
|
use humhub\modules\user\components\PeopleQuery;
|
||||||
use humhub\modules\user\widgets\PeopleCard;
|
use humhub\modules\user\widgets\PeopleCard;
|
||||||
use humhub\modules\user\widgets\PeopleFilters;
|
use humhub\modules\user\widgets\PeopleFilters;
|
||||||
use humhub\widgets\Button;
|
|
||||||
use humhub\widgets\ModalButton;
|
use humhub\widgets\ModalButton;
|
||||||
|
|
||||||
/* @var $this \yii\web\View */
|
/* @var $this \yii\web\View */
|
||||||
@ -53,13 +52,10 @@ DirectoryAsset::register($this);
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if (!$people->isLastPage()) : ?>
|
<?php if (!$people->isLastPage()) : ?>
|
||||||
<div class="directory-load-more">
|
<?= Html::tag('div', '', [
|
||||||
<?= Button::primary(Yii::t('UserModule.base', 'Load more'))
|
'class' => 'directory-end',
|
||||||
->icon('fa-angle-down')
|
'data-current-page' => $people->pagination->getPage() + 1,
|
||||||
->action('directory.loadMore')
|
'data-total-pages' => $people->pagination->getPageCount(),
|
||||||
->options([
|
'data-ui-loader' => '',
|
||||||
'data-current-page' => $people->pagination->getPage() + 1,
|
]) ?>
|
||||||
'data-total-pages' => $people->pagination->getPageCount(),
|
|
||||||
]) ?>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
@ -6,24 +6,27 @@ humhub.module('directory', function(module, require, $) {
|
|||||||
$(evt.$trigger).closest('form').submit();
|
$(evt.$trigger).closest('form').submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadMore = function(evt) {
|
const loadMore = function(directoryEndIndicator) {
|
||||||
const urlParams = {page: $(evt.$trigger).data('current-page') + 1};
|
const urlParams = {page: directoryEndIndicator.data('current-page') + 1};
|
||||||
|
|
||||||
|
$('.directory-end').data('isLoading', true);
|
||||||
|
loader.append(directoryEndIndicator);
|
||||||
client.get(module.config.loadMoreUrl, {data: urlParams}).then(function (response) {
|
client.get(module.config.loadMoreUrl, {data: urlParams}).then(function (response) {
|
||||||
$('.container-directory .card:hidden').show();
|
$('.container-directory .card:hidden').show();
|
||||||
$('.container-directory .cards').append(response.response);
|
$('.container-directory .cards').append(response.response);
|
||||||
if (urlParams.page == $(evt.$trigger).data('total-pages')) {
|
if (urlParams.page == directoryEndIndicator.data('total-pages')) {
|
||||||
// Remove button "Load more" because the last page was loaded
|
// Remove the directory end indicator because the last page was loaded
|
||||||
$(evt.$trigger).parent().remove();
|
directoryEndIndicator.remove();
|
||||||
} else {
|
} else {
|
||||||
$(evt.$trigger).data('current-page', urlParams.page);
|
directoryEndIndicator.data('current-page', urlParams.page);
|
||||||
hideLastNotCompletedRow();
|
hideLastNotCompletedRow();
|
||||||
}
|
}
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
module.log.error(err, true);
|
module.log.error(err, true);
|
||||||
reject();
|
reject();
|
||||||
}).finally(function() {
|
}).finally(function() {
|
||||||
loader.reset(evt.$trigger);
|
loader.reset(directoryEndIndicator);
|
||||||
|
$('.directory-end').data('isLoading', false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,15 +36,12 @@ humhub.module('directory', function(module, require, $) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadMoreButton = $('.directory-load-more button');
|
const directoryEndIndicator = $('.directory-end');
|
||||||
if (loadMoreButton.data('current-page') === loadMoreButton.data('total-pages')) {
|
if (directoryEndIndicator.data('current-page') === directoryEndIndicator.data('total-pages')) {
|
||||||
// No reason to hide a not completed row if current page is last
|
// No reason to hide a not completed row if current page is last
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display button to load more cards
|
|
||||||
loadMoreButton.parent().show();
|
|
||||||
|
|
||||||
const cardsPerRow = Math.floor($('.container-directory .row').outerWidth() / $('.container-directory .card:first').width());
|
const cardsPerRow = Math.floor($('.container-directory .row').outerWidth() / $('.container-directory .card:first').width());
|
||||||
const hideLastCardsNum = cardsNum % cardsPerRow;
|
const hideLastCardsNum = cardsNum % cardsPerRow;
|
||||||
if (hideLastCardsNum > 0 && cardsNum > cardsPerRow) {
|
if (hideLastCardsNum > 0 && cardsNum > cardsPerRow) {
|
||||||
@ -50,15 +50,40 @@ humhub.module('directory', function(module, require, $) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const preventScrollLoading = function () {
|
||||||
|
return $('.directory-end').data('isLoading');
|
||||||
|
};
|
||||||
|
|
||||||
|
const initScroll = function () {
|
||||||
|
if (!window.IntersectionObserver) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $directoryEndIndicator = $('.directory-end');
|
||||||
|
|
||||||
|
const observer = new IntersectionObserver(function (entries) {
|
||||||
|
if (preventScrollLoading()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entries.length && entries[0].isIntersecting) {
|
||||||
|
loadMore($directoryEndIndicator);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe($directoryEndIndicator[0]);
|
||||||
|
}
|
||||||
|
|
||||||
const init = function() {
|
const init = function() {
|
||||||
hideLastNotCompletedRow();
|
hideLastNotCompletedRow();
|
||||||
$('input.form-search-filter[name=keyword]').focus();
|
$('input.form-search-filter[name=keyword]').focus();
|
||||||
|
initScroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.export({
|
module.export({
|
||||||
initOnPjaxLoad: true,
|
initOnPjaxLoad: true,
|
||||||
init,
|
init,
|
||||||
applyFilters,
|
applyFilters,
|
||||||
loadMore,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -175,10 +175,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.directory-load-more {
|
|
||||||
display: none;
|
|
||||||
text-align: center;
|
|
||||||
padding: 12px 0 15px;
|
|
||||||
}
|
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user