ultimate-pagination
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -62,3 +62,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
}); | ||
exports.ITEM_TYPES = undefined; | ||
exports.ITEM_KEYS = exports.ITEM_TYPES = undefined; | ||
exports.getPaginationModel = getPaginationModel; | ||
@@ -74,2 +74,8 @@ | ||
}); | ||
Object.defineProperty(exports, 'ITEM_KEYS', { | ||
enumerable: true, | ||
get: function get() { | ||
return _ultimatePaginationConstants.ITEM_KEYS; | ||
} | ||
}); | ||
@@ -82,5 +88,8 @@ var _ultimatePaginationUtils = __webpack_require__(2); | ||
function getPaginationModel(currentPage, totalPages) { | ||
function getPaginationModel(options) { | ||
var currentPage = options.currentPage; | ||
var totalPages = options.totalPages; | ||
var paginationModel = []; | ||
var createPage = (0, _ultimatePaginationItemFactories.createPageFunctionFactory)(currentPage); | ||
var createPage = (0, _ultimatePaginationItemFactories.createPageFunctionFactory)(options); | ||
@@ -92,2 +101,5 @@ // Calculate group of central pages | ||
paginationModel.push((0, _ultimatePaginationItemFactories.createFirstPageLink)(options)); | ||
paginationModel.push((0, _ultimatePaginationItemFactories.createPreviousPageLink)(options)); | ||
// Always add the first page | ||
@@ -115,2 +127,4 @@ paginationModel.push(createPage(1)); | ||
paginationModel.push(createPage(totalPages)); | ||
paginationModel.push((0, _ultimatePaginationItemFactories.createNextPageLink)(options)); | ||
paginationModel.push((0, _ultimatePaginationItemFactories.createLastPageLink)(options)); | ||
@@ -131,5 +145,18 @@ return paginationModel; | ||
PAGE: 'PAGE', | ||
ELLIPSIS: 'ELLIPSIS' | ||
ELLIPSIS: 'ELLIPSIS', | ||
FIRST_PAGE_LINK: 'FIRST_PAGE_LINK', | ||
PREVIOS_PAGE_LINK: 'PREVIOS_PAGE_LINK', | ||
NEXT_PAGE_LINK: 'NEXT_PAGE_LINK', | ||
LAST_PAGE_LINK: 'LAST_PAGE_LINK' | ||
}; | ||
var ITEM_KEYS = exports.ITEM_KEYS = { | ||
FIRST_ELLIPSIS: -1, | ||
SECOND_ELLISPIS: -2, | ||
FIRST_PAGE_LINK: -3, | ||
PREVIOS_PAGE_LINK: -4, | ||
NEXT_PAGE_LINK: -5, | ||
LAST_PAGE_LINK: -6 | ||
}; | ||
/***/ }, | ||
@@ -162,31 +189,80 @@ /* 2 */ | ||
}); | ||
exports.createEllipsis = exports.createSecondEllipsis = exports.createFirstEllipsis = exports.createPageFunctionFactory = undefined; | ||
exports.createPageFunctionFactory = exports.createLastPageLink = exports.createNextPageLink = exports.createPreviousPageLink = exports.createFirstPageLink = exports.createSecondEllipsis = exports.createFirstEllipsis = undefined; | ||
var _ultimatePaginationConstants = __webpack_require__(1); | ||
var createPageFunctionFactory = exports.createPageFunctionFactory = function createPageFunctionFactory(currentPage) { | ||
return function (pageNumber) { | ||
return { | ||
type: _ultimatePaginationConstants.ITEM_TYPES.PAGE, | ||
value: pageNumber, | ||
isActive: pageNumber === currentPage | ||
}; | ||
var createFirstEllipsis = exports.createFirstEllipsis = function createFirstEllipsis() { | ||
return { | ||
type: _ultimatePaginationConstants.ITEM_TYPES.ELLIPSIS, | ||
key: _ultimatePaginationConstants.ITEM_KEYS.FIRST_ELLIPSIS | ||
}; | ||
}; | ||
// Use -1 and -2 value to make value an uniq key for items | ||
var createFirstEllipsis = exports.createFirstEllipsis = function createFirstEllipsis() { | ||
return createEllipsis(-1); | ||
}; | ||
var createSecondEllipsis = exports.createSecondEllipsis = function createSecondEllipsis() { | ||
return createEllipsis(-2); | ||
return { | ||
type: _ultimatePaginationConstants.ITEM_TYPES.ELLIPSIS, | ||
key: _ultimatePaginationConstants.ITEM_KEYS.SECOND_ELLISPIS | ||
}; | ||
}; | ||
var createEllipsis = exports.createEllipsis = function createEllipsis(value) { | ||
var createFirstPageLink = exports.createFirstPageLink = function createFirstPageLink(_ref) { | ||
var currentPage = _ref.currentPage; | ||
return { | ||
type: _ultimatePaginationConstants.ITEM_TYPES.ELLIPSIS, | ||
value: value | ||
type: _ultimatePaginationConstants.ITEM_TYPES.FIRST_PAGE_LINK, | ||
key: _ultimatePaginationConstants.ITEM_KEYS.FIRST_PAGE_LINK, | ||
value: 1, | ||
isActive: currentPage === 1 | ||
}; | ||
}; | ||
var createPreviousPageLink = exports.createPreviousPageLink = function createPreviousPageLink(_ref2) { | ||
var currentPage = _ref2.currentPage; | ||
var totalPages = _ref2.totalPages; | ||
return { | ||
type: _ultimatePaginationConstants.ITEM_TYPES.PREVIOS_PAGE_LINK, | ||
key: _ultimatePaginationConstants.ITEM_KEYS.PREVIOS_PAGE_LINK, | ||
value: Math.max(1, currentPage - 1), | ||
isActive: currentPage === 1 | ||
}; | ||
}; | ||
var createNextPageLink = exports.createNextPageLink = function createNextPageLink(_ref3) { | ||
var currentPage = _ref3.currentPage; | ||
var totalPages = _ref3.totalPages; | ||
return { | ||
type: _ultimatePaginationConstants.ITEM_TYPES.NEXT_PAGE_LINK, | ||
key: _ultimatePaginationConstants.ITEM_KEYS.NEXT_PAGE_LINK, | ||
value: Math.min(totalPages, currentPage + 1), | ||
isActive: currentPage === totalPages | ||
}; | ||
}; | ||
var createLastPageLink = exports.createLastPageLink = function createLastPageLink(_ref4) { | ||
var currentPage = _ref4.currentPage; | ||
var totalPages = _ref4.totalPages; | ||
return { | ||
type: _ultimatePaginationConstants.ITEM_TYPES.LAST_PAGE_LINK, | ||
key: _ultimatePaginationConstants.ITEM_KEYS.LAST_PAGE_LINK, | ||
value: totalPages, | ||
isActive: currentPage === totalPages | ||
}; | ||
}; | ||
var createPageFunctionFactory = exports.createPageFunctionFactory = function createPageFunctionFactory(_ref5) { | ||
var currentPage = _ref5.currentPage; | ||
return function (pageNumber) { | ||
return { | ||
type: _ultimatePaginationConstants.ITEM_TYPES.PAGE, | ||
key: pageNumber, | ||
value: pageNumber, | ||
isActive: pageNumber === currentPage | ||
}; | ||
}; | ||
}; | ||
/***/ } | ||
@@ -193,0 +269,0 @@ /******/ ]) |
{ | ||
"name": "ultimate-pagination", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/ultimate-pagination.js", |
10385
211