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).

// step = e.g. 100
// value = 0 to count
static S pageNav2(S baseLink, int count, int value, int step, S nVar, O... _) {
  new L<S> l;
  baseLink = unnull(baseLink) + (contains(baseLink, "?") ? "&" : "?") + urlencode(nVar) + "=";
  if (value > 0) l.add(ahref(baseLink + max(0, value-step),
    stringPar leftArrow(_, htmlencode(unicode_leftPointingTriangle()))));
  for (int i = 0; i < count; i += step) {
    int n = i/step+1;
    if (pageNav2_showPage(value, i, step, count))
      if (value == i)
        l.add(b(n));
      else
        l.add(ahref(baseLink + i, n));
  }
  if (value+step < count) l.add(ahref(baseLink + (value+step),
    stringPar rightArrow(_, htmlencode(unicode_rightPointingTriangle()))));
  ret p("Pages: " + lines(l));
}

sbool pageNav2_showPage(int actual, int i, int step, int count) {
  int diff = abs(actual-i)/step;
  ret i == 0
    || i >= (count-1)/step*step
    || diff <= 10
    || diff <= 100 && ((i/step) % 10) == 9
    || diff <= 1000 && ((i/step) % 100) == 99
    || ((i/step) % 1000) == 999;
}

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: 530 / 618
Version history: 24 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)