@teipublisher/pb-components 1.32.2 → 1.34.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/pb-load.js CHANGED
@@ -288,13 +288,12 @@ export class PbLoad extends pbMixin(LitElement) {
288
288
  }
289
289
 
290
290
  _handleContent(ev) {
291
- this._parseHeaders(ev.detail.xhr);
292
-
293
291
  const resp = this.shadowRoot.getElementById('loadContent').lastResponse;
294
292
  if (this.container) {
295
293
  this.style.display = 'none';
296
294
  document.querySelectorAll(this.container).forEach((elem) => {
297
- elem.innerHTML = resp
295
+ elem.innerHTML = resp;
296
+ this._parseHeaders(ev.detail.xhr, elem);
298
297
  this._fixLinks(elem);
299
298
  this._onLoad(elem);
300
299
  });
@@ -304,6 +303,7 @@ export class PbLoad extends pbMixin(LitElement) {
304
303
 
305
304
  const div = document.createElement('div');
306
305
  div.innerHTML = resp;
306
+ this._parseHeaders(ev.detail.xhr, div);
307
307
  div.slot = '';
308
308
  this.appendChild(div);
309
309
  this._fixLinks(div);
@@ -338,9 +338,20 @@ export class PbLoad extends pbMixin(LitElement) {
338
338
  dialog.open();
339
339
  }
340
340
 
341
- _parseHeaders(xhr) {
342
- const total = xhr.getResponseHeader('pb-total');
343
- const start = xhr.getResponseHeader('pb-start');
341
+ _parseHeaders(xhr, content) {
342
+ // Try to determine number of pages and current position
343
+ // Search for data-pagination-* attributes first and if they
344
+ // can't be found, check HTTP headers
345
+ function getPaginationParam(type) {
346
+ const elem = content.querySelector(`[data-pagination-${type}]`);
347
+ if (elem) {
348
+ return elem.getAttribute(`data-pagination-${type}`);
349
+ }
350
+ return xhr.getResponseHeader(`pb-${type}`);
351
+ }
352
+
353
+ const total = getPaginationParam('total');
354
+ const start = getPaginationParam('start');
344
355
 
345
356
  if (this.start !== start) {
346
357
  this.start = parseInt(start);