Skip to content
This repository was archived by the owner on Mar 2, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/jquery.stackview.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
color: #fff;
}

.stack-item-empty {
padding: 10px 10px 15px 5px;
}

.spine-text {
position: absolute;
z-index: 2;
Expand Down
2 changes: 1 addition & 1 deletion lib/jquery.stackview.min.js

Large diffs are not rendered by default.

31 changes: 29 additions & 2 deletions src/js/jquery.stackview.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,22 @@
if ($placeholder) {
$placeholder.remove();
}

};

/*
#check_empty(StackView, number) - Private

If count is 0, check_empty renders the empty message to the stack
passed in.
*/
var check_empty = function(stack, count) {
if (count) return;

stack.$element.find(stack.options.selectors.item_list).append(
tmpl(StackView.templates.empty, {
message: stack.options.emptyMessage
})
);
};

/*
Expand Down Expand Up @@ -195,6 +210,9 @@
An alternative to URL, used for static data. Accepts a typical
URL response object or a simple array of item objects.

emptyMessage
Text shown to users when the stack contains no items.

id
When using a search type of loc_sort_order, this is the id of
the item that the search centers around.
Expand Down Expand Up @@ -236,6 +254,7 @@
defaults: {
cache_ttl: 60,
data: '',
emptyMessage: 'No items found.',
id: null,
items_per_page: 10,
jsonp: false,
Expand Down Expand Up @@ -354,7 +373,14 @@

this.direction = 'down';
if (opts.data) {
render_items(this, opts.data.docs ? opts.data.docs : opts.data);
if (opts.data.docs) {
render_items(this, opts.data.docs);
check_empty(this, opts.data.num_found);
}
else {
render_items(this, opts.data);
check_empty(this, opts.data.length);
}
this.finished.down = true;
this.$element.trigger(events.page_load, [opts.data]);
}
Expand All @@ -363,6 +389,7 @@
.find(opts.selectors.item_list)
.append($placeholder);
fetch_page(this, function(data) {
check_empty(that, data.num_found);
render_items(that, data.docs, $placeholder);
if (parseInt(data.start, 10) === -1) {
that.finished.down = true;
Expand Down
2 changes: 1 addition & 1 deletion src/js/jquery.stackview.navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}).delegate('.stackview', 'stackview.pageload', function(event, data) {
var $stack = $(event.target),
stack = $stack.data('stackviewObject'),
num_found = data.num_found ? parseInt(data.num_found, 10) : data.length,
num_found = data.num_found != null ? parseInt(data.num_found, 10) : data.length,
num;

stack.num_found = num_found;
Expand Down
2 changes: 2 additions & 0 deletions src/js/jquery.stackview.templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<span class="stack-cover" />\
</a>\
</li>',

empty: '<li class="stack-item-empty"><%= message %></li>',

placeholder: '<li class="stackview-placeholder"></li>'
}
Expand Down
4 changes: 4 additions & 0 deletions src/scss/jquery.stackview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
}
}

.stack-item-empty {
padding:10px 10px 15px 5px;
}

.spine-text {
position:absolute;
z-index:2;
Expand Down