Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit e1bff6b

Browse files
bekospkozlowski-opensource
authored andcommitted
fix(pagination): bind *-text attributes
BREAKING CHANGE: The 'first-text', 'previous-text', 'next-text' and 'last-text' attributes are now binded to parent scope. To migrate your code, surround the text of these attributes with quotes. Before: <pagination first-text="<<" ...></pagination> After: <pagination first-text="'<<'" ...></pagination>
1 parent 53e0a39 commit e1bff6b

File tree

4 files changed

+76
-11
lines changed

4 files changed

+76
-11
lines changed

src/pagination/docs/demo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<h4>Default</h4>
33

44
<pagination num-pages="noOfPages" current-page="currentPage"></pagination>
5-
<pagination boundary-links="true" num-pages="noOfPages" current-page="currentPage" class="pagination-small" previous-text="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;"></pagination>
5+
<pagination boundary-links="true" num-pages="noOfPages" current-page="currentPage" class="pagination-small" previous-text="'&lsaquo;'" next-text="'&rsaquo;'" first-text="'&laquo;'" last-text="'&raquo;'"></pagination>
66
<pagination direction-links="false" boundary-links="true" num-pages="noOfPages" current-page="currentPage"></pagination>
77
<pagination direction-links="false" num-pages="noOfPages" current-page="currentPage"></pagination>
88

src/pagination/docs/readme.md

+48-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
11

2-
A lightweight pagination directive that is focused on ... providing pagination!
2+
A lightweight pagination directive that is focused on ... providing pagination & will take care of visualising a pagination bar and enable / disable buttons correctly!
33

4-
It will take care of visualising a pagination bar. Additionally it will make sure that the state (enabled / disabled) of the Previous / Next and First / Last buttons (if exist) is maintained correctly.
4+
### Settings ###
5+
6+
Settings can be provided as attributes in the `<pagination>` or globally configured through the `paginationConfig`.
7+
8+
* `num-pages` <i class="icon-eye-open"></i>
9+
:
10+
Number of total pages.
11+
12+
* `current-page` <i class="icon-eye-open"></i>
13+
:
14+
Current page number.
15+
16+
* `max-size` <i class="icon-eye-open"></i>
17+
_(Defaults: null)_ :
18+
Limit number for pagination size.
19+
20+
* `rotate`
21+
_(Defaults: true)_ :
22+
Whether to keep current page in the middle of the visible ones.
23+
24+
* `on-select-page (page)`
25+
_(Default: null)_ :
26+
An optional expression called when a page is selected having the page number as argument.
27+
28+
* `direction-links`
29+
_(Default: true)_ :
30+
Whether to display Previous / Next buttons.
31+
32+
* `previous-text`
33+
_(Default: 'Previous')_ :
34+
Text for Previous button.
35+
36+
* `next-text`
37+
_(Default: 'Next')_ :
38+
Text for Next button.
39+
40+
* `boundary-links`
41+
_(Default: false)_ :
42+
Whether to display First / Last buttons.
43+
44+
* `first-text`
45+
_(Default: 'First')_ :
46+
Text for First button.
47+
48+
* `last-text`
49+
_(Default: 'Last')_ :
50+
Text for Last button.
551

6-
It also provides optional attribute max-size to limit the size of pagination bar & rotate attribute whether to keep current page in the middle of the visible ones.

src/pagination/pagination.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ angular.module('ui.bootstrap.pagination', [])
2626
// Setup configuration parameters
2727
var boundaryLinks = angular.isDefined(attrs.boundaryLinks) ? scope.$eval(attrs.boundaryLinks) : paginationConfig.boundaryLinks;
2828
var directionLinks = angular.isDefined(attrs.directionLinks) ? scope.$eval(attrs.directionLinks) : paginationConfig.directionLinks;
29-
var firstText = angular.isDefined(attrs.firstText) ? attrs.firstText : paginationConfig.firstText;
30-
var previousText = angular.isDefined(attrs.previousText) ? attrs.previousText : paginationConfig.previousText;
31-
var nextText = angular.isDefined(attrs.nextText) ? attrs.nextText : paginationConfig.nextText;
32-
var lastText = angular.isDefined(attrs.lastText) ? attrs.lastText : paginationConfig.lastText;
29+
var firstText = angular.isDefined(attrs.firstText) ? scope.$parent.$eval(attrs.firstText) : paginationConfig.firstText;
30+
var previousText = angular.isDefined(attrs.previousText) ? scope.$parent.$eval(attrs.previousText) : paginationConfig.previousText;
31+
var nextText = angular.isDefined(attrs.nextText) ? scope.$parent.$eval(attrs.nextText) : paginationConfig.nextText;
32+
var lastText = angular.isDefined(attrs.lastText) ? scope.$parent.$eval(attrs.lastText) : paginationConfig.lastText;
3333
var rotate = angular.isDefined(attrs.rotate) ? scope.$eval(attrs.rotate) : paginationConfig.rotate;
3434

3535
// Create page object used in template

src/pagination/test/pagination.spec.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,35 @@ describe('pagination directive with added first & last links', function () {
353353
});
354354

355355
it('changes "first" & "last" text from attributes', function() {
356-
element = $compile('<pagination boundary-links="true" first-text="<<<" last-text=">>>" num-pages="numPages" current-page="currentPage"></pagination>')($rootScope);
356+
element = $compile('<pagination boundary-links="true" first-text="\'<<<\'" last-text="\'>>>\'" num-pages="numPages" current-page="currentPage"></pagination>')($rootScope);
357357
$rootScope.$digest();
358358

359359
expect(element.find('li').eq(0).text()).toBe('<<<');
360360
expect(element.find('li').eq(-1).text()).toBe('>>>');
361361
});
362362

363363
it('changes "previous" & "next" text from attributes', function() {
364-
element = $compile('<pagination boundary-links="true" previous-text="<<" next-text=">>" num-pages="numPages" current-page="currentPage"></pagination>')($rootScope);
364+
element = $compile('<pagination boundary-links="true" previous-text="\'<<\'" next-text="\'>>\'" num-pages="numPages" current-page="currentPage"></pagination>')($rootScope);
365+
$rootScope.$digest();
366+
367+
expect(element.find('li').eq(1).text()).toBe('<<');
368+
expect(element.find('li').eq(-2).text()).toBe('>>');
369+
});
370+
371+
it('changes "first" & "last" text from attribute variables', function() {
372+
$rootScope.myfirstText = '<<<';
373+
$rootScope.mylastText = '>>>';
374+
element = $compile('<pagination boundary-links="true" first-text="myfirstText" last-text="mylastText" num-pages="numPages" current-page="currentPage"></pagination>')($rootScope);
375+
$rootScope.$digest();
376+
377+
expect(element.find('li').eq(0).text()).toBe('<<<');
378+
expect(element.find('li').eq(-1).text()).toBe('>>>');
379+
});
380+
381+
it('changes "previous" & "next" text from attribute variables', function() {
382+
$rootScope.previousText = '<<';
383+
$rootScope.nextText = '>>';
384+
element = $compile('<pagination boundary-links="true" previous-text="previousText" next-text="nextText" num-pages="numPages" current-page="currentPage"></pagination>')($rootScope);
365385
$rootScope.$digest();
366386

367387
expect(element.find('li').eq(1).text()).toBe('<<');
@@ -566,7 +586,7 @@ describe('pagination bypass configuration from attributes', function () {
566586
$rootScope = _$rootScope_;
567587
$rootScope.numPages = 5;
568588
$rootScope.currentPage = 3;
569-
element = $compile('<pagination boundary-links="true" first-text="<<" previous-text="<" next-text=">" last-text=">>" num-pages="numPages" current-page="currentPage"></pagination>')($rootScope);
589+
element = $compile('<pagination boundary-links="true" first-text="\'<<\'" previous-text="\'<\'" next-text="\'>\'" last-text="\'>>\'" num-pages="numPages" current-page="currentPage"></pagination>')($rootScope);
570590
$rootScope.$digest();
571591
}));
572592

0 commit comments

Comments
 (0)