PageSourceSearch

https://simpleyyt.com/assets/js/src/paginator.js

js simpleyyt.com collected 2026-10-03 23:20:28 UTC 3,346 bytes, 109 lines download raw bytes

1'use strict';
2
3function paginatorHelper(options) {
4  options = options || {};
5
6  var current = options.current || 0;
7  var total = options.total || 1;
8  var endSize = options.hasOwnProperty('end_size') ? +options.end_size : 1;
9  var midSize = options.hasOwnProperty('mid_size') ? +options.mid_size : 2;
10  var space = options.hasOwnProperty('space') ? options.space : '…';
11  var base = options.base || '';
12  var format = options.format || '/%d/';
13  var prevText = options.prev_text || 'Prev';
14  var nextText = options.next_text || 'Next';
15  var prevNext = options.hasOwnProperty('prev_next') ? options.prev_next : true;
16  var transform = options.transform;
17  var self = this;
18  var result = '';
19  var i;
20
21  if (!current) return '';
22
23  var currentPage = '<span class="page-number current">' +
24    (transform ? transform(current) : current) +
25    '</span>';
26
27  function link(i) {
28    return i === 1 ? base : base + format.replace('%d', i);
29  }
30
31  function pageLink(i) {
32    return '<a class="page-number" href="' + link(i) + '">' +
33      (transform ? transform(i) : i) +
34      '</a>';
35  }
36
37  // Display the link to the previous page
38  if (prevNext && current > 1) {
39    result += '<a class="extend prev" rel="prev" href="' + link(current - 1) + '">' + prevText + '</a>';
40  }
41
42  if (options.show_all) {
43    // Display pages on the left side of the current page
44    for (i = 1; i < current; i++) {
45      result += pageLink(i);
46    }
47
48    // Display the current page
49    result += currentPage;
50
51    // Display pages on the right side of the current page
52    for (i = current + 1; i <= total; i++) {
53      result += pageLink(i);
54    }
55  } else {
56    // It's too complicated. May need refactor.
57    var leftEnd = current <= endSize ? current - 1 : endSize;
58    var rightEnd = total - current <= endSize ? current + 1 : total - endSize + 1;
59    var leftMid = current - midSize <= endSize ? current - midSize + endSize : current - midSize;
60    var rightMid = current + midSize + endSize > total ? current + midSize - endSize : current + midSize;
61    var spaceHtml = '<span class="space">' + space + '</span>';
62
63    // Display pages on the left edge
64    for (i = 1; i <= leftEnd; i++) {
65      result += pageLink(i);
66    }
67
68    // Display spaces between edges and middle pages
69    if (space && current - endSize - midSize > 1) {
70      result += spaceHtml;
71    }
72
73    // Display left middle pages
74    if (leftMid > leftEnd) {
75      for (i = leftMid; i < current; i++) {
76        result += pageLink(i);
77      }
78    }
79
80    // Display the current page
81    result += currentPage;
82
83    // Display right middle pages
84    if (rightMid < rightEnd) {
85      for (i = current + 1; i <= rightMid; i++) {
86        result += pageLink(i);
87      }
88    }
89
90    // Display spaces between edges and middle pages
91    if (space && total - endSize - midSize > current) {
92      result += spaceHtml;
93    }
94
95    // Dispaly pages on the right edge
96    for (i = rightEnd; i <= total; i++) {
97      result += pageLink(i);
98    }
99  }
100
101  // Display the link to the next page
102  if (prevNext && current < total) {
103    result += '<a class="extend next" rel="next" href="' + link(current + 1) + '">' + nextText + '</a>';
104  }
105
106  return result;
107}
108
109window.paginator = paginatorHelper;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.