import ui.bootstrap.pagination
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 25 Jan 2013 18:45:05 +0000 (19:45 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 25 Jan 2013 18:45:05 +0000 (19:45 +0100)
app/js/pagination.js [changed from symlink to file mode: 0644]

deleted file mode 120000 (symlink)
index cfd2d8c17600e263cd2c1f9bdbb7647f7beea801..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1 +0,0 @@
-../lib/angular-ui/bootstrap/src/pagination/pagination.js
\ No newline at end of file
new file mode 100644 (file)
index 0000000000000000000000000000000000000000..ac10dad10dabde51384725daaba84b9fe2bfef1c
--- /dev/null
@@ -0,0 +1,66 @@
+angular.module('ui.bootstrap.pagination', [])
+
+.directive('pagination', function() {
+  return {
+    restrict: 'E',
+    scope: {
+      numPages: '=',
+      currentPage: '=',
+      maxSize: '=',
+      onSelectPage: '&'
+    },
+    templateUrl: 'template/pagination/pagination.html',
+    replace: true,
+    link: function(scope) {
+      scope.$watch('numPages + currentPage + maxSize', function() {
+        scope.pages = [];
+        
+        //set the default maxSize to numPages
+        var maxSize = ( scope.maxSize && scope.maxSize < scope.numPages ) ? scope.maxSize : scope.numPages;
+        var startPage = scope.currentPage - Math.floor(maxSize/2);
+        
+        //adjust the startPage within boundary
+        if(startPage < 1) {
+            startPage = 1;
+        }
+        if ((startPage + maxSize - 1) > scope.numPages) {
+            startPage = startPage - ((startPage + maxSize - 1) - scope.numPages );
+        }
+
+        for(var i=0; i < maxSize && i < scope.numPages ;i++) {
+          scope.pages.push(startPage + i);
+        }
+        if ( scope.currentPage > scope.numPages ) {
+          scope.selectPage(scope.numPages);
+        }
+      });
+      scope.noPrevious = function() {
+        return scope.currentPage === 1;
+      };
+      scope.noNext = function() {
+        return scope.currentPage === scope.numPages;
+      };
+      scope.isActive = function(page) {
+        return scope.currentPage === page;
+      };
+
+      scope.selectPage = function(page) {
+        if ( ! scope.isActive(page) ) {
+          scope.currentPage = page;
+          scope.onSelectPage({ page: page });
+        }
+      };
+
+      scope.selectPrevious = function() {
+        if ( !scope.noPrevious() ) {
+          scope.selectPage(scope.currentPage-1);
+        }
+      };
+      scope.selectNext = function() {
+        if ( !scope.noNext() ) {
+          scope.selectPage(scope.currentPage+1);
+        }
+      };
+    }
+  };
+});
\ No newline at end of file