Last active
June 9, 2020 15:58
-
-
Save genakim/9c842465b9512aaf8c2a33397374faa3 to your computer and use it in GitHub Desktop.
Revisions
-
genakim revised this gist
Jun 9, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ this.pages = []; if (startPage <= 1) { startPage = 1; } else { if((totalPages - startPage) < pages){ //вмещается ли нужный диапазон startPage = totalPages - pages; if (startPage <= 1){ startPage = 1; -
genakim created this gist
Jun 9, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ this.pages = []; const pages = 5; const currentPage = this.data.current_page; const totalPages = this.data.last_page; const offSide = Math.floor(pages / 2); // первая страница let startPage = currentPage - offSide; if (startPage <= 1) { startPage = 1; } else { if(totalPages - startPage < pages){ //вмещается ли нужный диапазон startPage = totalPages - pages; if (startPage <= 1){ startPage = 1; } } } // последняя страница let lastPage = startPage + pages - 1; if (lastPage > totalPages) { lastPage = totalPages; } for (let i = startPage; i <= lastPage; i++) { this.pages.push({ url: this.data.path + '?page=' + i, number: i, active: i === currentPage }); }