Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Paginator</title>
- </head>
- <body>
- <script>
- 'use strict'
- // let data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
- // idx = 0, page =1
- // next() idx = 5, page = 2
- // next() idx = 10, page = 3
- class Paginator {
- constructor(startPage = 1, dataSourceLength, dataSourcePortion, pageCount) {
- this._minPage = 1;
- this._page = 1;
- this.page = startPage; // current page
- this.dataSourceLength = dataSourceLength; // how many elements (objects) is in dataSource
- this.dataSourcePortion = dataSourcePortion; // how many elements of data source is on one page
- this.pageCount = pageCount; // how many pages we want to divide our dataSource
- this._maxPage = this.dataSourceLength / this.dataSourcePortion;
- this._dataSourceCurrPos = 0; // current position (index??) in datasource
- }
- set page(val) {
- // TODO: check for over/under follow
- this._page = val;
- if (this._page < this._minPage) {
- this._page = this._minPage;
- }
- if (this._page > this._maxPage) {
- this._page = this._maxPage;
- }
- // this._dataSourceCurrPos = ??? :)
- }
- get page() {
- return this._page;
- }
- prev() {
- --this.page;
- }
- next() {
- ++this.page;
- }
- setPage(pageNum) {
- this.page = pageNum;
- }
- getCurrentPage() {
- return this.page;
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment