avr39ripe

jsPaginatorDraft

Jun 3rd, 2021
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Paginator</title>
  6. </head>
  7. <body>
  8.     <script>
  9.         'use strict'
  10.         // let data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
  11.         // idx = 0, page =1
  12.         // next() idx = 5, page = 2
  13.         // next() idx = 10, page = 3
  14.  
  15.         class Paginator {
  16.             constructor(startPage = 1, dataSourceLength, dataSourcePortion, pageCount) {
  17.                 this._minPage = 1;
  18.  
  19.                 this._page = 1;
  20.                 this.page = startPage; // current page
  21.                 this.dataSourceLength = dataSourceLength; // how many elements (objects) is in dataSource
  22.                 this.dataSourcePortion = dataSourcePortion; // how many elements of data source is on one page
  23.                 this.pageCount = pageCount; // how many pages we want to divide our dataSource
  24.  
  25.                 this._maxPage = this.dataSourceLength / this.dataSourcePortion;
  26.                 this._dataSourceCurrPos = 0; // current position (index??) in datasource
  27.  
  28.             }
  29.  
  30.             set page(val) {
  31.                 // TODO: check for over/under follow
  32.  
  33.                 this._page = val;
  34.  
  35.                 if (this._page < this._minPage) {
  36.                     this._page = this._minPage;
  37.                 }
  38.  
  39.                 if (this._page > this._maxPage) {
  40.                     this._page = this._maxPage;
  41.                 }
  42.  
  43.                 // this._dataSourceCurrPos = ??? :)
  44.             }
  45.  
  46.             get page() {
  47.                 return this._page;
  48.             }
  49.  
  50.             prev() {
  51.                 --this.page;
  52.             }
  53.  
  54.             next() {
  55.                 ++this.page;
  56.             }
  57.  
  58.             setPage(pageNum) {
  59.                 this.page = pageNum;
  60.             }
  61.  
  62.             getCurrentPage() {
  63.                 return this.page;
  64.             }
  65.         }
  66.        
  67.     </script>
  68. </body>
  69.  
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment