Tagged Assets: Support passing arguments
Pass LOAD_INITIAL_COUNT and LOAD_NEXT_COUNT Also only show 'Load more' if LOAD_NEXT_COUNT is not set to 0
This commit is contained in:
@@ -108,7 +108,7 @@
|
|||||||
load_next.remove();
|
load_next.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
$.fn.loadTaggedAssets = function() {
|
$.fn.loadTaggedAssets = function(LOAD_INITIAL_COUNT, LOAD_NEXT_COUNT) {
|
||||||
this.each(function(index, card_deck_element) {
|
this.each(function(index, card_deck_element) {
|
||||||
// TODO(Sybren): show a 'loading' animation.
|
// TODO(Sybren): show a 'loading' animation.
|
||||||
$.get('/api/nodes/tagged/' + card_deck_element.dataset.assetTag)
|
$.get('/api/nodes/tagged/' + card_deck_element.dataset.assetTag)
|
||||||
@@ -130,13 +130,15 @@
|
|||||||
// Don't bother with a 'load next' link if there is no more.
|
// Don't bother with a 'load next' link if there is no more.
|
||||||
if (resp.length <= LOAD_INITIAL_COUNT) return;
|
if (resp.length <= LOAD_INITIAL_COUNT) return;
|
||||||
|
|
||||||
// Construct the 'load next' link.
|
if (LOAD_NEXT_COUNT > 0) {
|
||||||
let link = $('<a class="btn btn-link px-5 my-auto">')
|
// Construct the 'load next' link.
|
||||||
.addClass('js-load-next')
|
let link = $('<a class="btn btn-link px-5 my-auto">')
|
||||||
.attr('href', 'javascript:void(0);')
|
.addClass('js-load-next')
|
||||||
.click(function() { loadNext(card_deck_element); return false; })
|
.attr('href', 'javascript:void(0);')
|
||||||
.text('Load more items');
|
.click(function() { loadNext(card_deck_element); return false; })
|
||||||
link.appendTo(card_deck_element);
|
.text('Load more items');
|
||||||
|
link.appendTo(card_deck_element);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@@ -7,7 +7,7 @@ script(src="{{ url_for('static_cloud', filename='assets/js/tagged_assets.min.js'
|
|||||||
|
|
||||||
script.
|
script.
|
||||||
$(function() {
|
$(function() {
|
||||||
$('.js-asset-list').loadTaggedAssets();
|
$('.js-asset-list').loadTaggedAssets(5, 3);
|
||||||
})
|
})
|
||||||
| {% endblock %}
|
| {% endblock %}
|
||||||
| {% block body %}
|
| {% block body %}
|
||||||
|
Reference in New Issue
Block a user