Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 42 additions & 38 deletions src/paging.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ angular.module('bw.paging', []).directive('paging', function () {
* Feel free to tweak / fork values for your application
*/
var regex = /\{page\}/g;


/**
* The angular return value required for the directive
Expand All @@ -31,7 +31,7 @@ angular.module('bw.paging', []).directive('paging', function () {

// Assign the angular link function
link: fieldLink,

// Assign the angular directive template HTML
template: fieldTemplate,

Expand Down Expand Up @@ -60,9 +60,11 @@ angular.module('bw.paging', []).directive('paging', function () {
textTitleFirst: '@',
textTitleLast: '@',
textTitleNext: '@',
textTitlePrev: '@'
textTitlePrev: '@',
defaultLiClass: '@',
defaultAClass: '@',
}

};


Expand All @@ -80,12 +82,12 @@ angular.module('bw.paging', []).directive('paging', function () {
build(scope, attrs);
});
}


/**
* Create our template html
* Create our template html
* We use a function to figure out how to handle href correctly
*
*
* @param {object} el - Angular link element
* @param {object} attrs - Angular link attribute
*/
Expand All @@ -95,14 +97,14 @@ angular.module('bw.paging', []).directive('paging', function () {
'title="{{Item.title}}" ' +
'data-ng-class="Item.liClass" ' +
'data-ng-repeat="Item in List"> ' +
'<a ' +
'<a ' +
(attrs.pgHref ? 'data-ng-href="{{Item.pgHref}}" ' : 'href ') +
'data-ng-class="Item.aClass" ' +
'data-ng-click="Item.action()" ' +
'data-ng-bind="Item.value">'+
'data-ng-bind="Item.value">'+
'</a> ' +
'</li>' +
'</ul>'
'</ul>'
}


Expand All @@ -117,14 +119,14 @@ angular.module('bw.paging', []).directive('paging', function () {

scope.List = [];
scope.Hide = false;

scope.page = parseInt(scope.page) || 1;
scope.total = parseInt(scope.total) || 0;
scope.adjacent = parseInt(scope.adjacent) || 2;

scope.pgHref = scope.pgHref || '';
scope.dots = scope.dots || '...';

scope.ulClass = scope.ulClass || 'pagination';
scope.activeClass = scope.activeClass || 'active';
scope.disabledClass = scope.disabledClass || 'disabled';
Expand All @@ -133,17 +135,17 @@ angular.module('bw.paging', []).directive('paging', function () {
scope.textLast = scope.textLast || '>>';
scope.textNext = scope.textNext || '>';
scope.textPrev = scope.textPrev || '<';

scope.textFirstClass = scope.textFirstClass || '';
scope.textLastClass= scope.textLastClass || '';
scope.textNextClass = scope.textNextClass || '';
scope.textPrevClass = scope.textPrevClass || '';

scope.textTitlePage = scope.textTitlePage || 'Page {page}';
scope.textTitleFirst = scope.textTitleFirst || 'First Page';
scope.textTitleLast = scope.textTitleLast || 'Last Page';
scope.textTitleNext = scope.textTitleNext || 'Next Page';
scope.textTitlePrev = scope.textTitlePrev || 'Previous Page';
scope.textTitleFirst = scope.textTitleFirst || 'First Page';
scope.textTitleLast = scope.textTitleLast || 'Last Page';
scope.textTitleNext = scope.textTitleNext || 'Next Page';
scope.textTitlePrev = scope.textTitlePrev || 'Previous Page';

scope.hideIfEmpty = evalBoolAttribute(scope, attrs.hideIfEmpty);
scope.showPrevNext = evalBoolAttribute(scope, attrs.showPrevNext);
Expand All @@ -156,7 +158,7 @@ angular.module('bw.paging', []).directive('paging', function () {
/**
* A helper to perform our boolean eval on attributes
* This allows flexibility in the attribute for strings and variables in scope
*
*
* @param {Object} scope - The local directive scope object
* @param {Object} value - The attribute value of interest
*/
Expand Down Expand Up @@ -212,7 +214,7 @@ angular.module('bw.paging', []).directive('paging', function () {
return;
}

// Block if we are forcing disabled
// Block if we are forcing disabled
if(scope.isDisabled)
{
return;
Expand Down Expand Up @@ -266,19 +268,19 @@ angular.module('bw.paging', []).directive('paging', function () {
if(scope.showFirstLast){
alpha = {
value: scope.textFirst,
title: scope.textTitleFirst,
title: scope.textTitleFirst,
aClass: scope.textFirstClass,
page: 1
};
};
}

if(scope.showPrevNext){
beta = {
value: scope.textPrev,
title: scope.textTitlePrev,
title: scope.textTitlePrev,
aClass: scope.textPrevClass,
page: prevPage
};
};
}

} else {
Expand All @@ -289,37 +291,37 @@ angular.module('bw.paging', []).directive('paging', function () {
if(scope.showPrevNext){
alpha = {
value: scope.textNext,
title: scope.textTitleNext,
title: scope.textTitleNext,
aClass: scope.textNextClass,
page: nextPage
};
};
}

if(scope.showFirstLast){
beta = {
value: scope.textLast,
title: scope.textTitleLast,
title: scope.textTitleLast,
aClass: scope.textLastClass,
page: pageCount
};
};
}

}

// Create the Add Item Function
var buildItem = function (item, disabled) {
return {
title: item.title,
aClass: item.aClass,
aClass: item.aClass + ' ' + scope.defaultAClass,
value: item.aClass ? '' : item.value,
liClass: disabled ? scope.disabledClass : '',
liClass: (disabled ? scope.disabledClass : '') + ' ' + scope.defaultLiClass,
pgHref: disabled ? '' : scope.pgHref.replace(regex, item.page),
action: function () {
if (!disabled) {
internalAction(scope, item.page);
}
}
};
};
};

// Force disabled if specified
Expand All @@ -330,13 +332,13 @@ angular.module('bw.paging', []).directive('paging', function () {
// Add alpha items
if(alpha){
var alphaItem = buildItem(alpha, disabled);
scope.List.push(alphaItem);
scope.List.push(alphaItem);
}

// Add beta items
if(beta){
var betaItem = buildItem(beta, disabled);
scope.List.push(betaItem);
scope.List.push(betaItem);
}
}

Expand All @@ -350,13 +352,13 @@ angular.module('bw.paging', []).directive('paging', function () {
* @param {Object} scope - The local directive scope object
*/
function addRange(start, finish, scope) {

// Add our items where i is the page number
var i = 0;
for (i = start; i <= finish; i++) {

var pgHref = scope.pgHref.replace(regex, i);
var liClass = scope.page == i ? scope.activeClass : '';
var liClass = (scope.page == i ? scope.activeClass : '') + ' ' + scope.defaultLiClass;

// Handle items that are affected by disabled
if(scope.isDisabled){
Expand All @@ -370,6 +372,7 @@ angular.module('bw.paging', []).directive('paging', function () {
title: scope.textTitlePage.replace(regex, i),
liClass: liClass,
pgHref: pgHref,
aClass: scope.defaultAClass,
action: function () {
internalAction(scope, this.value);
}
Expand All @@ -387,6 +390,7 @@ angular.module('bw.paging', []).directive('paging', function () {
function addDots(scope) {
scope.List.push({
value: scope.dots,
aClass: scope.defaultAClass,
liClass: scope.disabledClass
});
}
Expand Down