gd-bs 6.9.1 → 6.9.2

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.
@@ -17,6 +17,10 @@ var __extends = (this && this.__extends) || (function () {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.Pagination = exports.PaginationAlignment = void 0;
19
19
  var base_1 = require("../base");
20
+ var skipBackward_1 = require("../../icons/svgs/skipBackward");
21
+ var skipForward_1 = require("../../icons/svgs/skipForward");
22
+ var skipEnd_1 = require("../../icons/svgs/skipEnd");
23
+ var skipStart_1 = require("../../icons/svgs/skipStart");
20
24
  var templates_1 = require("./templates");
21
25
  /**
22
26
  * Pagination Alignment
@@ -37,8 +41,14 @@ var _Pagination = /** @class */ (function (_super) {
37
41
  if (template === void 0) { template = templates_1.HTML; }
38
42
  if (itemTemplate === void 0) { itemTemplate = templates_1.HTMLItem; }
39
43
  var _this = _super.call(this, template, props) || this;
44
+ _this._activePage = null;
40
45
  _this._elList = null;
41
46
  _this._items = null;
47
+ _this._showDefault = true;
48
+ // Buttons
49
+ _this._buttons = null;
50
+ // Create the default buttons
51
+ _this.createButtons(itemTemplate);
42
52
  // Configure the collapse
43
53
  _this.configure(itemTemplate);
44
54
  // Configure the parent
@@ -66,104 +76,208 @@ var _Pagination = /** @class */ (function (_super) {
66
76
  break;
67
77
  }
68
78
  // Render the page numbers
69
- this.renderPageNumbers(1, itemTemplate);
79
+ this.renderPageNumbers(itemTemplate);
70
80
  }
71
81
  };
72
- // Configures the next/previous buttons, based on the active index
73
- _Pagination.prototype.configureNextPrevButtons = function (activePage) {
82
+ // Configures the default buttons, based on the active index
83
+ _Pagination.prototype.configureDefaultButtons = function () {
74
84
  // Update the previous button
75
- var prevItem = this._items[0];
76
- if (activePage == 1) {
77
- // Ensure the previous item is disabled
78
- prevItem.classList.add("disabled");
85
+ if (this._activePage == 1) {
86
+ // Ensure the first/previous item is disabled
87
+ this._buttons.First.classList.add("disabled");
88
+ this._buttons.Previous.classList.add("disabled");
79
89
  }
80
90
  else {
81
- // Ensure the previous item is enabled
82
- prevItem.classList.remove("disabled");
91
+ // Ensure the first/previous item is enabled
92
+ this._buttons.First.classList.remove("disabled");
93
+ this._buttons.Previous.classList.remove("disabled");
83
94
  }
84
- // Update the next button
85
- var nextItem = this._items[this._items.length - 1];
86
- if (activePage == this._items.length - 2) {
87
- // Ensure the previous item is disabled
88
- nextItem.classList.add("disabled");
95
+ // Update the next/last button
96
+ if (this._activePage == this._items.length) {
97
+ // Ensure the next/last item is disabled
98
+ this._buttons.Next.classList.add("disabled");
99
+ this._buttons.Last.classList.add("disabled");
89
100
  }
90
101
  else {
91
- // Ensure the previous item is enabled
92
- nextItem.classList.remove("disabled");
102
+ // Ensure the next/last item is enabled
103
+ this._buttons.Next.classList.remove("disabled");
104
+ this._buttons.Last.classList.remove("disabled");
93
105
  }
94
106
  };
95
107
  // Configure the events
96
- _Pagination.prototype.configureEvents = function (item) {
108
+ _Pagination.prototype.configureEvents = function (item, itemTemplate) {
97
109
  var _this = this;
98
- // See if this is the next or previous item and skip it
110
+ // See if this is a spacer
99
111
  var link = item.querySelector("a").getAttribute("aria-label");
112
+ if (link == "...") {
113
+ // Do nothing
114
+ return;
115
+ }
116
+ // See if this is the next or previous item and skip it
100
117
  if (link == "Previous" || link == "Next") {
101
118
  var isPrevious_1 = link == "Previous";
102
119
  // Add a click event
103
120
  item.addEventListener("click", function (ev) {
121
+ var _a;
104
122
  // Prevent the page from moving to the top
105
123
  ev.preventDefault();
106
124
  // Do nothing if it's disabled
107
125
  if (item.classList.contains("disabled")) {
108
126
  return;
109
127
  }
110
- // Parse the items, excluding the next/previous items
111
- for (var i = 1; i < _this._items.length - 1; i++) {
112
- var item_1 = _this._items[i];
113
- // See if this item is active
114
- if (item_1.classList.contains("active")) {
115
- // See if the previous button was clicked
116
- if (isPrevious_1) {
117
- // Click the previous item if it's available
118
- i - 1 > 0 ? _this._items[i - 1].click() : null;
119
- }
120
- else {
121
- // Click the next item if it's available
122
- i < _this._items.length - 2 ? _this._items[i + 1].click() : null;
123
- }
124
- // Break from the loop
125
- break;
128
+ // Update the active page
129
+ isPrevious_1 ? _this._activePage-- : _this._activePage++;
130
+ // See if we are rendering the default
131
+ if (_this._showDefault) {
132
+ // Click the item
133
+ (_a = _this._items[_this._activePage]) === null || _a === void 0 ? void 0 : _a.click();
134
+ }
135
+ else {
136
+ // Render the active buttons
137
+ _this.renderActivePageNumbers(itemTemplate);
138
+ // Call the click event
139
+ _this.props.onClick ? _this.props.onClick(_this._activePage) : null;
140
+ }
141
+ });
142
+ }
143
+ else if (link == "First" || link == "Last") {
144
+ var isLast_1 = link == "Last";
145
+ // Add a click event
146
+ item.addEventListener("click", function (ev) {
147
+ var _a, _b;
148
+ // Prevent the page from moving to the top
149
+ ev.preventDefault();
150
+ // Do nothing if it's disabled
151
+ if (item.classList.contains("disabled")) {
152
+ return;
153
+ }
154
+ // See if we are rendering the default
155
+ if (_this._showDefault) {
156
+ // See if this is the last item
157
+ if (isLast_1) {
158
+ // Click on the last item
159
+ (_a = _this._items[_this._items.length - 1]) === null || _a === void 0 ? void 0 : _a.click();
126
160
  }
161
+ else {
162
+ // Click on the first item
163
+ (_b = _this._items[0]) === null || _b === void 0 ? void 0 : _b.click();
164
+ }
165
+ }
166
+ else {
167
+ // Update the active page
168
+ _this._activePage = isLast_1 ? _this.props.numberOfPages : 1;
169
+ // Render the active buttons
170
+ _this.renderActivePageNumbers(itemTemplate);
171
+ // Call the click event
172
+ _this.props.onClick ? _this.props.onClick(_this._activePage) : null;
127
173
  }
128
174
  });
129
175
  }
176
+ else if (link == "&lt;&lt;" || link == "&lt;" || link == "&gt;" || link == "&gt;&gt;") {
177
+ // Add a click event
178
+ item.addEventListener("click", function (ev) {
179
+ // Prevent the page from moving to the top
180
+ ev.preventDefault();
181
+ // Update the active page
182
+ switch (link) {
183
+ case "&lt;&lt;":
184
+ _this._activePage -= 10;
185
+ break;
186
+ case "&lt;":
187
+ _this._activePage -= 5;
188
+ break;
189
+ case "&gt;":
190
+ _this._activePage += 5;
191
+ break;
192
+ case "&gt;&gt;":
193
+ _this._activePage += 10;
194
+ break;
195
+ }
196
+ // Validate the page number
197
+ if (_this._activePage <= 0) {
198
+ _this._activePage = 1;
199
+ }
200
+ else if (_this._activePage > _this.props.numberOfPages) {
201
+ _this._activePage = _this.props.numberOfPages;
202
+ }
203
+ // Render the active buttons
204
+ _this.renderActivePageNumbers(itemTemplate);
205
+ // Call the click event
206
+ _this.props.onClick ? _this.props.onClick(_this._activePage) : null;
207
+ });
208
+ }
130
209
  else {
131
210
  var pageNumber_1 = parseInt(link);
132
211
  // Add a click event
133
212
  item.addEventListener("click", function (ev) {
134
213
  // Prevent the page from moving to the top
135
214
  ev.preventDefault();
136
- // Parse the active items
137
- var activeItems = _this.el.querySelectorAll(".page-item.active");
138
- for (var i = 0; i < activeItems.length; i++) {
139
- var item_2 = activeItems[i];
140
- // Clear the active class
141
- item_2.classList.remove("active");
142
- // Remove the active span
143
- var span_1 = item_2.querySelector("span");
144
- span_1 ? span_1.parentNode.removeChild(span_1) : null;
215
+ // Set the active index
216
+ _this._activePage = pageNumber_1;
217
+ // See if we are showing the default
218
+ if (_this._showDefault) {
219
+ // Clear the active item
220
+ var activeItem = _this._items[_this._activePage - 1];
221
+ if (activeItem) {
222
+ // Clear the active class
223
+ activeItem.classList.remove("active");
224
+ // Remove the active span
225
+ var span_1 = activeItem.querySelector("span");
226
+ span_1 ? span_1.parentNode.removeChild(span_1) : null;
227
+ }
228
+ // Show the active item
229
+ _this._items[_this._activePage - 1].classList.add("active");
230
+ // Add the span
231
+ var span = document.createElement("span");
232
+ span.classList.add("visually-hidden");
233
+ span.innerHTML = "(current)";
234
+ _this._items[_this._activePage - 1].appendChild(span);
235
+ // Configure the default buttons
236
+ _this.configureDefaultButtons();
145
237
  }
146
- // Make this item active
147
- item.classList.add("active");
148
- // Add the span
149
- var span = document.createElement("span");
150
- span.classList.add("visually-hidden");
151
- span.innerHTML = "(current)";
152
- item.appendChild(span);
153
- // Configure the next/previous buttons
154
- _this.configureNextPrevButtons(pageNumber_1);
155
- // Class the click event
156
- _this.props.onClick ? _this.props.onClick(pageNumber_1, ev) : null;
238
+ else {
239
+ // Render the active buttons
240
+ _this.renderActivePageNumbers(itemTemplate);
241
+ }
242
+ // Call the click event
243
+ _this.props.onClick ? _this.props.onClick(pageNumber_1) : null;
157
244
  });
158
245
  }
159
246
  };
247
+ // Creates the default buttons
248
+ _Pagination.prototype.createButtons = function (itemTemplate) {
249
+ this._buttons = {
250
+ First: this.createItem("First", itemTemplate, true),
251
+ Last: this.createItem("Last", itemTemplate, true),
252
+ Next: this.createItem("Next", itemTemplate, true),
253
+ Previous: this.createItem("Previous", itemTemplate, true),
254
+ SkipBack10: this.createItem("<<", itemTemplate, true),
255
+ SkipBack5: this.createItem("<", itemTemplate, true),
256
+ SkipForward5: this.createItem(">", itemTemplate, true),
257
+ SkipForward10: this.createItem(">>", itemTemplate, true)
258
+ };
259
+ // Set the default classes
260
+ this._buttons.First.classList.add("first");
261
+ this._buttons.Last.classList.add("last");
262
+ this._buttons.Next.classList.add("next");
263
+ this._buttons.Previous.classList.add("previous");
264
+ // Disable the first and previous buttons by default
265
+ this._buttons.First.classList.add("disabled");
266
+ this._buttons.Previous.classList.add("disabled");
267
+ // Set the icons
268
+ this._buttons.SkipBack10.querySelector("a").innerHTML = (0, skipBackward_1.skipBackward)(15, 15).outerHTML;
269
+ this._buttons.SkipBack5.querySelector("a").innerHTML = (0, skipStart_1.skipStart)(15, 15).outerHTML;
270
+ this._buttons.SkipForward5.querySelector("a").innerHTML = (0, skipEnd_1.skipEnd)(15, 15).outerHTML;
271
+ this._buttons.SkipForward10.querySelector("a").innerHTML = (0, skipForward_1.skipForward)(15, 15).outerHTML;
272
+ };
160
273
  // Creates an page number item
161
- _Pagination.prototype.createItem = function (text, itemTemplate) {
274
+ _Pagination.prototype.createItem = function (text, itemTemplate, isDefault) {
275
+ if (isDefault === void 0) { isDefault = false; }
162
276
  // Create the item
163
277
  var el = document.createElement("div");
164
278
  el.innerHTML = itemTemplate;
165
279
  var item = el.firstChild;
166
- this._items.push(item);
280
+ isDefault ? null : this._items.push(item);
167
281
  // Update the link
168
282
  var link = item.querySelector("a");
169
283
  if (link) {
@@ -171,42 +285,131 @@ var _Pagination = /** @class */ (function (_super) {
171
285
  link.setAttribute("aria-label", link.innerHTML);
172
286
  }
173
287
  // Configure the events
174
- this.configureEvents(item);
288
+ this.configureEvents(item, itemTemplate);
175
289
  // Return the item
176
290
  return item;
177
291
  };
178
292
  // Renders the page numbers
179
- _Pagination.prototype.renderPageNumbers = function (activeItem, itemTemplate) {
293
+ _Pagination.prototype.renderPageNumbers = function (itemTemplate) {
180
294
  // Clear the items
295
+ this._activePage = 1;
181
296
  this._items = [];
182
297
  // Determine if there are > 10 pages
183
298
  var pages = this.props.numberOfPages || 1;
184
- var showFirstLast = pages > 10;
185
- // Create the previous link
186
- var item = this.createItem("Previous", itemTemplate);
187
- item.classList.add("disabled");
188
- item.classList.add("previous");
189
- this._elList.appendChild(item);
190
- // See if we are showing the first/last links
191
- if (showFirstLast) {
192
- item = this.createItem("1", itemTemplate);
193
- activeItem == 1 ? item.classList.add("active") : null;
194
- item.classList.add("next");
299
+ var maxPages = typeof (this.props.maxPages) === "number" ? this.props.maxPages : 10;
300
+ this._showDefault = pages < maxPages;
301
+ // See if we are rendering the default
302
+ if (this._showDefault) {
303
+ // Append the first/previous link
304
+ this._elList.appendChild(this._buttons.First);
305
+ this._elList.appendChild(this._buttons.Previous);
306
+ // Loop for the number of pages to create
307
+ for (var i = 1; i <= pages; i++) {
308
+ // Create a link
309
+ var item = this.createItem(i.toString(), itemTemplate);
310
+ i == this._activePage ? item.classList.add("active") : null;
311
+ this._elList.appendChild(item);
312
+ }
313
+ // Append the next/last link
314
+ this._elList.appendChild(this._buttons.Next);
315
+ this._elList.appendChild(this._buttons.Last);
316
+ if (pages == 1) {
317
+ this._buttons.Next.classList.add("disabled");
318
+ this._buttons.Last.classList.add("disabled");
319
+ }
320
+ }
321
+ else {
322
+ // Render the active page numbers
323
+ this.renderActivePageNumbers(itemTemplate);
324
+ }
325
+ };
326
+ // Renders the active page numbers
327
+ _Pagination.prototype.renderActivePageNumbers = function (itemTemplate) {
328
+ // Clear the items and list element
329
+ this._items = [];
330
+ while (this._elList.firstChild) {
331
+ this._elList.removeChild(this._elList.firstChild);
332
+ }
333
+ // Append the first/previous link
334
+ this._elList.appendChild(this._buttons.First);
335
+ this._elList.appendChild(this._buttons.Previous);
336
+ if (this._activePage == 1) {
337
+ this._buttons.First.classList.add("disabled");
338
+ this._buttons.Previous.classList.add("disabled");
339
+ }
340
+ else {
341
+ this._buttons.First.classList.remove("disabled");
342
+ this._buttons.Previous.classList.remove("disabled");
343
+ }
344
+ // See if we are at the beginning
345
+ if (this._activePage < 5) {
346
+ // Render the first five
347
+ for (var i = 1; i <= 5; i++) {
348
+ // Create a link
349
+ var item_1 = this.createItem(i.toString(), itemTemplate);
350
+ i == this._activePage ? item_1.classList.add("active") : null;
351
+ this._elList.appendChild(item_1);
352
+ }
353
+ // Render a spacer
354
+ var item = this.createItem("...", itemTemplate, true);
195
355
  this._elList.appendChild(item);
356
+ // Render the last 3
357
+ var diff = Math.round((this.props.numberOfPages - 5) / 3);
358
+ for (var i = 2; i >= 0; i--) {
359
+ // Create a link
360
+ var idx = this.props.numberOfPages - i * diff;
361
+ var item_2 = this.createItem((idx).toString(), itemTemplate);
362
+ this._elList.appendChild(item_2);
363
+ }
196
364
  }
197
- // Loop for the number of pages to create
198
- // Parse the number of pages
199
- for (var i = 2; i <= pages; i++) {
200
- // Create a link
201
- item = this.createItem(i.toString(), itemTemplate);
202
- i == activeItem ? item.classList.add("active") : null;
365
+ // Else, see if we are at the end
366
+ else if (this._activePage > this.props.numberOfPages - 5) {
367
+ // Render the first 3
368
+ var diff = Math.round((this.props.numberOfPages - 5) / 3);
369
+ for (var i = 0; i <= 2; i++) {
370
+ // Create a link
371
+ var idx = i == 0 ? 1 : i * diff;
372
+ var item_3 = this.createItem((idx).toString(), itemTemplate);
373
+ this._elList.appendChild(item_3);
374
+ }
375
+ // Render a spacer
376
+ var item = this.createItem("...", itemTemplate, true);
203
377
  this._elList.appendChild(item);
378
+ // Render the last five
379
+ for (var i = this.props.numberOfPages - 5; i <= this.props.numberOfPages; i++) {
380
+ // Create a link
381
+ var item_4 = this.createItem(i.toString(), itemTemplate);
382
+ i == this._activePage ? item_4.classList.add("active") : null;
383
+ this._elList.appendChild(item_4);
384
+ }
385
+ }
386
+ // Else, render the skip buttons
387
+ else {
388
+ // Render the skip buttons
389
+ this._elList.appendChild(this._buttons.SkipBack10);
390
+ this._elList.appendChild(this._buttons.SkipBack5);
391
+ // Render +/- 2 from the active index
392
+ for (var i = this._activePage - 2; i <= this._activePage + 2; i++) {
393
+ // Create a link
394
+ var item = this.createItem(i.toString(), itemTemplate);
395
+ i == this._activePage ? item.classList.add("active") : null;
396
+ this._elList.appendChild(item);
397
+ }
398
+ // Render the skip buttons
399
+ this._elList.appendChild(this._buttons.SkipForward5);
400
+ this._elList.appendChild(this._buttons.SkipForward10);
401
+ }
402
+ // Append the next/last link
403
+ this._elList.appendChild(this._buttons.Next);
404
+ this._elList.appendChild(this._buttons.Last);
405
+ if (this._activePage == this.props.numberOfPages) {
406
+ this._buttons.Next.classList.add("disabled");
407
+ this._buttons.Last.classList.add("disabled");
408
+ }
409
+ else {
410
+ this._buttons.Next.classList.remove("disabled");
411
+ this._buttons.Last.classList.remove("disabled");
204
412
  }
205
- // Create the next link
206
- item = this.createItem("Next", itemTemplate);
207
- pages > 1 ? null : item.classList.add("disabled");
208
- item.classList.add("next");
209
- this._elList.appendChild(item);
210
413
  };
211
414
  return _Pagination;
212
415
  }(base_1.Base));