Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function (module) {
- 'use strict';
- module.filter('offset', function() {
- return function(input, start) {
- if(input){
- start = parseInt(start, 10);
- return input.slice(start);
- }
- return input;
- };
- });
- })(angular.module('offset-filter',[]));
- (function (module) {
- 'use strict';
- module.directive('pagination', [function () {
- var htmlTemplate = [
- '<ul class="pagination">',
- '<li ng-class="prevPageDisabled()">',
- '<a href="javascript:void(0);" ng-click="prevPage()">ยซ Prev</a>',
- '</li>',
- '<li ng-repeat="n in range()" ng-class="{active: n == currentPage}" ng-click="setPage(n)">',
- '<a href="javascript:void(0);">{{n+1}}</a>',
- '</li>',
- '<li ng-class="nextPageDisabled()">',
- '<a href="javascript:void(0);" ng-click="nextPage()">Next ยป</a>',
- '</li>',
- '</ul>'].join('');
- return {
- restrict: 'E',
- scope: {
- currentPage: '=',
- total: '=',
- itemsPerPage: '='
- },
- template: htmlTemplate,
- link: function (scope,el,attr) {
- console.log(attr.total);
- scope.pageCount = function() {
- return Math.ceil(attr.total/scope.itemsPerPage)-1;
- };
- scope.range = function() {
- var ret = [];
- for (var i=0; i<scope.pageCount(); i++) {
- ret.push(i);
- }
- return ret;
- };
- scope.prevPage = function() {
- if (scope.currentPage > 0) {
- scope.currentPage--;
- }
- };
- scope.prevPageDisabled = function() {
- return scope.currentPage === 0 ? "disabled" : "";
- };
- scope.nextPage = function() {
- if (scope.currentPage < scope.pageCount() - 1) {
- scope.currentPage++;
- }
- };
- scope.nextPageDisabled = function() {
- return scope.currentPage === scope.pageCount() - 1 ? "disabled" : "";
- };
- scope.pageCount = function() {
- return Math.ceil(scope.total/scope.itemsPerPage);
- };
- scope.setPage = function(n) {
- scope.currentPage = n;
- };
- }
- }
- }]);
- })(angular.module('pagination-directive', []));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement