Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

29
LINES

< > BotCompany Repo | #1011562 // pageNav2 - HTML page navigation with flexible base link

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3428L/20K).

1  
// step = e.g. 100
2  
// value = 0 to count
3  
static S pageNav2(S baseLink, int count, int value, int step, S nVar, O... _) {
4  
  new L<S> l;
5  
  baseLink = unnull(baseLink) + (contains(baseLink, "?") ? "&" : "?") + urlencode(nVar) + "=";
6  
  if (value > 0) l.add(ahref(baseLink + max(0, value-step),
7  
    stringPar leftArrow(_, htmlencode(unicode_leftPointingTriangle()))));
8  
  for (int i = 0; i < count; i += step) {
9  
    int n = i/step+1;
10  
    if (pageNav2_showPage(value, i, step, count))
11  
      if (value == i)
12  
        l.add(b(n));
13  
      else
14  
        l.add(ahref(baseLink + i, n));
15  
  }
16  
  if (value+step < count) l.add(ahref(baseLink + (value+step),
17  
    stringPar rightArrow(_, htmlencode(unicode_rightPointingTriangle()))));
18  
  ret p("Pages: " + lines(l));
19  
}
20  
21  
sbool pageNav2_showPage(int actual, int i, int step, int count) {
22  
  int diff = abs(actual-i)/step;
23  
  ret i == 0
24  
    || i >= (count-1)/step*step
25  
    || diff <= 10
26  
    || diff <= 100 && ((i/step) % 10) == 9
27  
    || diff <= 1000 && ((i/step) % 100) == 99
28  
    || ((i/step) % 1000) == 999;
29  
}

Author comment

Began life as a copy of #1002547

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1011562
Snippet name: pageNav2 - HTML page navigation with flexible base link
Eternal ID of this version: #1011562/25
Text MD5: 4d3fa40138b9183127d398b84d0bd125
Transpilation MD5: 8739d6a07a88f18176392e3ca47330eb
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-04 21:03:04
Source code size: 1061 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 528 / 615
Version history: 24 change(s)
Referenced in: [show references]