Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. (function (module) {
  2.  
  3. 'use strict';
  4. module.filter('offset', function() {
  5. return function(input, start) {
  6. if(input){
  7. start = parseInt(start, 10);
  8. return input.slice(start);
  9. }
  10. return input;
  11. };
  12. });
  13.  
  14. })(angular.module('offset-filter',[]));
  15.  
  16.  
  17. (function (module) {
  18. 'use strict';
  19.  
  20. module.directive('pagination', [function () {
  21.  
  22. var htmlTemplate = [
  23. '<ul class="pagination">',
  24. '<li ng-class="prevPageDisabled()">',
  25. '<a href="javascript:void(0);" ng-click="prevPage()">ยซ Prev</a>',
  26. '</li>',
  27. '<li ng-repeat="n in range()" ng-class="{active: n == currentPage}" ng-click="setPage(n)">',
  28. '<a href="javascript:void(0);">{{n+1}}</a>',
  29. '</li>',
  30. '<li ng-class="nextPageDisabled()">',
  31. '<a href="javascript:void(0);" ng-click="nextPage()">Next ยป</a>',
  32. '</li>',
  33. '</ul>'].join('');
  34.  
  35. return {
  36. restrict: 'E',
  37. scope: {
  38. currentPage: '=',
  39. total: '=',
  40. itemsPerPage: '='
  41. },
  42. template: htmlTemplate,
  43. link: function (scope,el,attr) {
  44. console.log(attr.total);
  45. scope.pageCount = function() {
  46. return Math.ceil(attr.total/scope.itemsPerPage)-1;
  47. };
  48.  
  49. scope.range = function() {
  50. var ret = [];
  51. for (var i=0; i<scope.pageCount(); i++) {
  52. ret.push(i);
  53. }
  54. return ret;
  55. };
  56.  
  57. scope.prevPage = function() {
  58. if (scope.currentPage > 0) {
  59. scope.currentPage--;
  60. }
  61. };
  62.  
  63. scope.prevPageDisabled = function() {
  64. return scope.currentPage === 0 ? "disabled" : "";
  65. };
  66.  
  67. scope.nextPage = function() {
  68. if (scope.currentPage < scope.pageCount() - 1) {
  69. scope.currentPage++;
  70. }
  71. };
  72.  
  73. scope.nextPageDisabled = function() {
  74. return scope.currentPage === scope.pageCount() - 1 ? "disabled" : "";
  75. };
  76.  
  77. scope.pageCount = function() {
  78. return Math.ceil(scope.total/scope.itemsPerPage);
  79. };
  80.  
  81. scope.setPage = function(n) {
  82. scope.currentPage = n;
  83. };
  84. }
  85. }
  86. }]);
  87.  
  88. })(angular.module('pagination-directive', []));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement