Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pagination

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pagination - npm Package Compare versions

Comparing version 0.3.0 to 0.3.2

497

lib/pagination.js

@@ -1,283 +0,302 @@

var util;
(function(module) {
"use strict";
var util;
/* Check if clientside or serverside */
if( typeof module == "undefined") {
window.pagination = {};
module = {
exports : window.pagination
};
util = {
inherits : function(subc, superc) {
if(!superc || !subc) {
throw new Error("extend failed, please check that all dependencies are included.");
}
var F = function() {
};
F.prototype = superc.prototype;
subc.prototype = new F();
subc.prototype.constructor = subc;
subc.superclass = superc.prototype;
if(superc.prototype.constructor == Object.prototype.constructor) {
superc.prototype.constructor = superc;
}
}
};
/* Check if clientside or serverside */
if( typeof module == "undefined" && typeof window == "object") {
window.pagination = {};
module = {
exports : window.pagination
};
util = {
inherits : function(subc, superc) {
if(!superc || !subc) {
throw new Error("extend failed, please check that all dependencies are included.");
if(!Object.keys) {
Object.keys = function(o) {
var rt = [], p, hasOwnProperty = Object.prototype.hasOwnProperty;
if(o !== Object(o)) {
throw new TypeError('Object.keys called on a non-object');
}
for(p in o) {
if(hasOwnProperty.call(o, p)) {
rt.push(p);
}
}
return rt;
}
var F = function() {
};
F.prototype = superc.prototype;
subc.prototype = new F();
subc.prototype.constructor = subc;
subc.superclass = superc.prototype;
if(superc.prototype.constructor == Object.prototype.constructor) {
superc.prototype.constructor = superc;
}
}
} else {
util = require('util');
}
var translations = {
'NEXT' : 'Next',
'PREVIOUS' : 'Previous',
'FIRST' : 'First',
'LAST' : 'Last',
'CURRENT_PAGE_REPORT' : 'Results {FromResult} - {ToResult} of {TotalResult}'
};
} else {
util = require('util');
}
var translations = {
'NEXT' : 'Next',
'PREVIOUS' : 'Previous',
'FIRST' : 'First',
'LAST' : 'Last',
'CURRENT_PAGE_REPORT' : 'Results {FromResult} - {ToResult} of {TotalResult}'
};
var translationCache = {
CURRENT_PAGE_REPORT : null
};
var translationCache = {
CURRENT_PAGE_REPORT : null
};
var translator = function(str) {
return translations[str];
};
var Paginator = function(options) {
this.options = {
totalResult : 0,
prelink : '',
rowsPerPage : 10,
pageLinks : 5,
current : 1,
translator : translator,
translationCache : false
var translator = function(str) {
return translations[str];
};
for(var keys = Object.keys(options), i = 0, len = keys.length; i < len; i++) {
try {
this.set(keys[i], options[keys[i]]);
} catch(e) {
var Paginator = function(options) {
var keys, i, len;
this.options = {
totalResult : 0,
prelink : '',
rowsPerPage : 10,
pageLinks : 5,
current : 1,
translator : translator,
translationCache : false
};
for( keys = Object.keys(options), i = 0, len = keys.length; i < len; i++) {
try {
this.set(keys[i], options[keys[i]]);
} catch(e) {
}
}
}
this._result = null;
};
this._result = null;
};
module.exports.Paginator = Paginator;
module.exports.Paginator = Paginator;
Paginator.prototype = {
getPaginationData : function() {
if(!this._result) {
this._result = this.calc();
}
return this._result;
},
calc : function() {
var totalResult = this.options.totalResult
var pageLinks = this.options.pageLinks
var rowsPerPage = this.options.rowsPerPage;
var current = this.options.current;
var startPage, pageCount;
var oldPageLinks = (pageLinks % 2 == 0) ? 1 : 0, i;
var result = {
prelink : this.options.prelink,
current : current,
previous : null,
next : null,
first : null,
last : null,
range : [],
fromResult : null,
toResult : null,
totalResult : totalResult,
pageCount : null
};
/* zero division; negative */
if(rowsPerPage <= 0) {
return result;
}
pageCount = Math.ceil(totalResult / rowsPerPage);
result.pageCount = pageCount;
if(pageCount < 2) {
result.fromResult = 1;
result.toResult = totalResult;
return result;
}
Paginator.prototype = {
getPaginationData : function() {
if(!this._result) {
this._result = this.calc();
}
return this._result;
},
calc : function() {
var totalResult = this.options.totalResult
var pageLinks = this.options.pageLinks
var rowsPerPage = this.options.rowsPerPage;
var current = this.options.current;
var startPage, endPage, pageCount;
var oldPageLinks = (pageLinks % 2 == 0) ? 1 : 0, i, half;
var result = {
prelink : this.options.prelink,
current : current,
previous : null,
next : null,
first : null,
last : null,
range : [],
fromResult : null,
toResult : null,
totalResult : totalResult,
pageCount : null
};
/* zero division; negative */
if(rowsPerPage <= 0) {
return result;
}
pageCount = Math.ceil(totalResult / rowsPerPage);
result.pageCount = pageCount;
if(pageCount < 2) {
result.fromResult = 1;
result.toResult = totalResult;
return result;
}
if(current > pageCount) {
current = pageCount;
result.current = current;
}
half = Math.floor(pageLinks / 2);
startPage = current - half;
endPage = current + half - oldPageLinks;
if(current > pageCount) {
current = pageCount;
result.current = current;
}
half = Math.floor(pageLinks / 2);
startPage = current - half;
endPage = current + half - oldPageLinks;
if(startPage < 1) {
startPage = 1;
endPage = startPage + pageLinks;
if(startPage < 1) {
startPage = 1;
endPage = startPage + pageLinks;
if(endPage > pageCount) {
endPage = pageCount;
}
}
if(endPage > pageCount) {
endPage = pageCount;
startPage = endPage - pageLinks + 1;
if(startPage < 1) {
startPage = 1;
}
}
}
if(endPage > pageCount) {
endPage = pageCount;
startPage = endPage - pageLinks + 1;
if(startPage < 1) {
startPage = 1;
for( i = startPage; i <= endPage; i++) {
result.range.push(i);
}
}
for( i = startPage; i <= endPage; i++) {
result.range.push(i);
}
if(current > 1) {
result.first = 1;
result.previous = current - 1;
}
if(current > 1) {
result.first = 1;
result.previous = current - 1;
}
if(current < pageCount) {
result.last = pageCount;
result.next = current + 1;
}
if(current < pageCount) {
result.last = pageCount;
result.next = current + 1;
}
result.fromResult = (current - 1) * rowsPerPage + 1;
if(current == pageCount) {
result.toResult = totalResult;
} else {
result.toResult = result.fromResult + rowsPerPage - 1;
}
result.fromResult = (current - 1) * rowsPerPage + 1;
if(current == pageCount) {
result.toResult = totalResult;
} else {
result.toResult = result.fromResult + rowsPerPage - 1;
}
return result;
},
set : function(option, value) {
if(this.options.hasOwnProperty(option)) {
this.options[option] = value;
this._result = null;
}
},
preparePreLink : function(prelink) {
if(prelink.indexOf('?') != -1) {
if(prelink[prelink.length - 1] != '?' && prelink[prelink.length - 1] != '&') {
prelink += '&';
}
} else {
prelink += '?';
}
return result;
},
set : function(option, value) {
if(this.options.hasOwnProperty(option)) {
this.options[option] = value;
this._result = null;
return prelink;
},
render : function() {
throw new Error('Implement');
}
},
preparePreLink : function(prelink) {
if(prelink.indexOf('?') != -1) {
if(prelink[prelink.length - 1] != '?' && prelink[prelink.length - 1] != '&') {
prelink += '&';
}
} else {
prelink += '?';
}
};
return prelink;
},
render : function() {
throw new Error('Implement');
}
};
var SearchPaginator = function(options) {
Paginator.call(this, options);
var SearchPaginator = function(options) {
Paginator.call(this, options);
};
};
module.exports.SearchPaginator = SearchPaginator;
module.exports.SearchPaginator = SearchPaginator;
util.inherits(SearchPaginator, Paginator);
util.inherits(SearchPaginator, Paginator);
SearchPaginator.prototype.render = function() {
var i, len, className;
var result = this.getPaginationData();
var prelink = this.preparePreLink(result.prelink);
var html = '';
html += '<div class="paginator">';
SearchPaginator.prototype.render = function() {
var i, className;
var result = this.getPaginationData();
var prelink = this.preparePreLink(result.prelink);
html = '';
html += '<div class="paginator">';
if(result.pageCount < 2) {
html += '</div>';
return html;
}
if(result.previous) {
html += '<a href="' + prelink + 'page=' + result.previous + '" class="paginator-previous">' + this.options.translator('PREVIOUS') + '</a>';
}
if(result.pageCount < 2) {
html += '</div>';
return html;
}
if(result.previous) {
html += '<a href="' + prelink + 'page=' + result.previous + '" class="paginator-previous">' + this.options.translator('PREVIOUS') + '</a>';
}
if(result.range.length) {
for( i = 0, len = result.range.length; i < len; i++) {
className = 'paginator-page';
if(result.range.length) {
for( i = 0, len = result.range.length; i < len; i++) {
className = 'paginator-page';
if(result.range[i] == result.current) {
className = 'paginator-current';
if(result.range[i] == result.current) {
className = 'paginator-current';
}
if(i == 0) {
className += ' paginator-page-first';
} else if(i == len - 1) {
className += ' paginator-page-last';
}
html += '<a href="' + prelink + 'page=' + result.range[i] + '" class="' + className + '">' + result.range[i] + '</a>';
}
if(i == 0) {
className += ' paginator-page-first';
} else if(i == len - 1) {
className += ' paginator-page-last';
}
html += '<a href="' + prelink + 'page=' + result.range[i] + '" class="' + className + '">' + result.range[i] + '</a>';
}
}
if(result.next) {
html += '<a href="' + prelink + 'page=' + result.next + '" class="paginator-next">' + this.options.translator('NEXT') + '</a>';
}
html += '</div>';
return html;
};
var ItemPaginator = function(options) {
Paginator.call(this, options);
this.set('pageLinks', 1);
if(result.next) {
html += '<a href="' + prelink + 'page=' + result.next + '" class="paginator-next">' + this.options.translator('NEXT') + '</a>';
}
html += '</div>';
return html;
};
var ItemPaginator = function(options) {
Paginator.call(this, options);
this.set('pageLinks', 1);
};
module.exports.ItemPaginator = ItemPaginator;
};
module.exports.ItemPaginator = ItemPaginator;
util.inherits(ItemPaginator, Paginator);
util.inherits(ItemPaginator, Paginator);
ItemPaginator.prototype.renderCurrentPageReport = function(fromResult, toResult, totalResult) {
if(!this.options.translationCache) {
return this.options.translator('CURRENT_PAGE_REPORT').replace('{FromResult}', fromResult).replace('{ToResult}', toResult).replace('{TotalResult}', totalResult);
ItemPaginator.prototype.renderCurrentPageReport = function(fromResult, toResult, totalResult) {
var template;
if(!this.options.translationCache) {
return this.options.translator('CURRENT_PAGE_REPORT').replace('{FromResult}', fromResult).replace('{ToResult}', toResult).replace('{TotalResult}', totalResult);
}
if(!translationCache.CURRENT_PAGE_REPORT) {
template = "return '" + (this.options.translator('CURRENT_PAGE_REPORT').replace("'", "\'").replace('{FromResult}', "' + fromResult + '").replace('{ToResult}', "' + toResult + '").replace('{TotalResult}', "' + totalResult + '")) + "';";
translationCache.CURRENT_PAGE_REPORT = new Function('fromResult, toResult, totalResult', template);
}
return translationCache.CURRENT_PAGE_REPORT(fromResult, toResult, totalResult);
}
if(!translationCache.CURRENT_PAGE_REPORT) {
var template = "return '" + (this.options.translator('CURRENT_PAGE_REPORT').replace("'", "\'").replace('{FromResult}', "' + fromResult + '").replace('{ToResult}', "' + toResult + '").replace('{TotalResult}', "' + totalResult + '")) + "';";
translationCache.CURRENT_PAGE_REPORT = new Function('fromResult, toResult, totalResult', template);
}
return translationCache.CURRENT_PAGE_REPORT(fromResult, toResult, totalResult);
}
ItemPaginator.prototype.render = function() {
var result = this.getPaginationData();
var prelink = this.preparePreLink(result.prelink);
var html = '';
html += '<div class="paginator">';
html += '<span class="paginator-current-report">';
html += this.renderCurrentPageReport(result.fromResult, result.toResult, result.totalResult);
html += '</span>';
ItemPaginator.prototype.render = function() {
var result = this.getPaginationData();
var prelink = this.preparePreLink(result.prelink);
var html = '';
html += '<div class="paginator">';
html += '<span class="paginator-current-report">';
html += this.renderCurrentPageReport(result.fromResult, result.toResult, result.totalResult);
html += '</span>';
if(result.first) {
html += '<a href="' + prelink + 'page=' + result.first + '" class="paginator-first">' + this.options.translator('FIRST') + '</a>';
} else {
html += '<span class="paginator-first">' + this.options.translator('FIRST') + '</span>';
}
if(result.first) {
html += '<a href="' + prelink + 'page=' + result.first + '" class="paginator-first">' + this.options.translator('FIRST') + '</a>';
} else {
html += '<span class="paginator-first">' + this.options.translator('FIRST') + '</span>';
}
if(result.previous) {
html += '<a href="' + prelink + 'page=' + result.previous + '" class="paginator-previous">' + this.options.translator('PREVIOUS') + '</a>';
} else {
html += '<span class="paginator-previous">' + this.options.translator('PREVIOUS') + '</span>';
}
if(result.previous) {
html += '<a href="' + prelink + 'page=' + result.previous + '" class="paginator-previous">' + this.options.translator('PREVIOUS') + '</a>';
} else {
html += '<span class="paginator-previous">' + this.options.translator('PREVIOUS') + '</span>';
}
if(result.next) {
html += '<a href="' + prelink + 'page=' + result.next + '" class="paginator-next">' + this.options.translator('NEXT') + '</a>';
} else {
html += '<span class="paginator-next">' + this.options.translator('NEXT') + '</span>';
}
if(result.next) {
html += '<a href="' + prelink + 'page=' + result.next + '" class="paginator-next">' + this.options.translator('NEXT') + '</a>';
} else {
html += '<span class="paginator-next">' + this.options.translator('NEXT') + '</span>';
}
if(result.last) {
html += '<a href="' + prelink + 'page=' + result.last + '" class="paginator-last">' + this.options.translator('LAST') + '</a>';
} else {
html += '<span class="paginator-last">' + this.options.translator('LAST') + '</span>';
}
html += '</div>';
return html;
};
if(result.last) {
html += '<a href="' + prelink + 'page=' + result.last + '" class="paginator-last">' + this.options.translator('LAST') + '</a>';
} else {
html += '<span class="paginator-last">' + this.options.translator('LAST') + '</span>';
}
html += '</div>';
return html;
};
module.exports.create = function(type, options) {
switch(type) {
case 'item':
return new ItemPaginator(options);
case 'search':
default:
return new SearchPaginator(options);
}
};
module.exports.create = function(type, options) {
switch(type) {
case 'item':
return new ItemPaginator(options);
case 'search':
default:
return new SearchPaginator(options);
}
};
})(( typeof module !== 'undefined' && module.exports) ? module : undefined)
{
"name": "pagination",
"description": "Pagination for javascript/nodejs",
"keywords": ["pagination", "nodejs"],
"keywords": ["pagination", "nodejs", "client"],
"author": "Nguyen Van Nhu",

@@ -9,2 +9,3 @@ "homepage": "https://github.com/vanng822/pagination",

"dependencies": [],
"devDependencies": ["vows"],
"repository": {

@@ -14,3 +15,3 @@ "type": "git",

},
"version": "0.3.0"
"version": "0.3.2"
}

@@ -5,34 +5,37 @@ var assert = require('assert');

function test() {
console.log('Running ItemPaginator test');
/* pageLinks 5 by default; howto specify for Item Pattern */
var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 98
});
assert.equal('<div class="paginator"><span class="paginator-current-report">Results 41 - 50 of 98</span><a href="/?page=1" class="paginator-first">First</a><a href="/?page=4" class="paginator-previous">Previous</a><a href="/?page=6" class="paginator-next">Next</a><a href="/?page=10" class="paginator-last">Last</a></div>', item.render());
var vows = require('vows');
var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 1,
totalResult : 98
});
assert.equal('<div class="paginator"><span class="paginator-current-report">Results 1 - 10 of 98</span><span class="paginator-first">First</span><span class="paginator-previous">Previous</span><a href="/?page=2" class="paginator-next">Next</a><a href="/?page=10" class="paginator-last">Last</a></div>', item.render());
vows.describe('Test suite for ItemPagination').addBatch({
renderCurrentMiddle : function() {
/* pageLinks 5 by default; howto specify for Item Pattern */
var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 10,
totalResult : 98
});
assert.equal('<div class="paginator"><span class="paginator-current-report">Results 91 - 98 of 98</span><a href="/?page=1" class="paginator-first">First</a><a href="/?page=9" class="paginator-previous">Previous</a><span class="paginator-next">Next</span><span class="paginator-last">Last</span></div>', item.render());
var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 98
});
}
assert.equal('<div class="paginator"><span class="paginator-current-report">Results 41 - 50 of 98</span><a href="/?page=1" class="paginator-first">First</a><a href="/?page=4" class="paginator-previous">Previous</a><a href="/?page=6" class="paginator-next">Next</a><a href="/?page=10" class="paginator-last">Last</a></div>', item.render());
},
renderCurrentFirst : function() {
var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 1,
totalResult : 98
});
test();
assert.equal('<div class="paginator"><span class="paginator-current-report">Results 1 - 10 of 98</span><span class="paginator-first">First</span><span class="paginator-previous">Previous</span><a href="/?page=2" class="paginator-next">Next</a><a href="/?page=10" class="paginator-last">Last</a></div>', item.render());
},
renderCurrentLast : function() {
var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 10,
totalResult : 98
});
assert.equal('<div class="paginator"><span class="paginator-current-report">Results 91 - 98 of 98</span><a href="/?page=1" class="paginator-first">First</a><a href="/?page=9" class="paginator-previous">Previous</a><span class="paginator-next">Next</span><span class="paginator-last">Last</span></div>', item.render());
}
}).export(module)

@@ -5,209 +5,222 @@ var assert = require('assert');

function test() {
console.log('Running Paginator test');
var item = new Paginator({
current : 11,
pageLinks : 7,
totalResult : 100
});
assert.deepEqual({
prelink : "",
current : 10,
previous : 9,
next : null,
first : 1,
last : null,
range : [4, 5, 6, 7, 8, 9, 10],
fromResult : 91,
toResult : 100,
totalResult : 100,
pageCount : 10
}, item.calc());
var vows = require('vows');
var item = new Paginator({
current : 8,
pageLinks : 7,
totalResult : 100
});
assert.deepEqual({
prelink : "",
current : 8,
previous : 7,
next : 9,
first : 1,
last : 10,
range : [4, 5, 6, 7, 8, 9, 10],
fromResult : 71,
toResult : 80,
totalResult : 100,
pageCount : 10
}, item.getPaginationData());
vows.describe('Test suite for Paginator').addBatch({
calc : function() {
var item = new Paginator({
current : 11,
pageLinks : 7,
totalResult : 100
});
var item = new Paginator({
prelink : '/',
current : 10,
pageLinks : 7,
totalResult : 98
});
assert.deepEqual({
prelink : "",
current : 10,
previous : 9,
next : null,
first : 1,
last : null,
range : [4, 5, 6, 7, 8, 9, 10],
fromResult : 91,
toResult : 100,
totalResult : 100,
pageCount : 10
}, item.calc());
assert.deepEqual({
prelink : '/',
current : 10,
previous : 9,
next : null,
first : 1,
last : null,
range : [4, 5, 6, 7, 8, 9, 10],
fromResult : 91,
toResult : 98,
totalResult : 98,
pageCount : 10
}, item.calc());
var item = new Paginator({
prelink : '/',
pageLinks : 7,
totalResult : 9
});
var item = new Paginator({
prelink : '/',
current : 10,
pageLinks : 7,
totalResult : 98
});
assert.deepEqual({
prelink : '/',
current : 1,
previous : null,
next : null,
first : null,
last : null,
range : [],
fromResult : 1,
toResult : 9,
totalResult : 9,
pageCount : 1
}, item.calc());
assert.deepEqual({
prelink : '/',
current : 10,
previous : 9,
next : null,
first : 1,
last : null,
range : [4, 5, 6, 7, 8, 9, 10],
fromResult : 91,
toResult : 98,
totalResult : 98,
pageCount : 10
}, item.calc());
var item = new Paginator({
current : 5,
pageLinks : 7,
totalResult : 100
});
assert.deepEqual({
prelink : "",
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [2, 3, 4, 5, 6, 7, 8],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
var item = new Paginator({
prelink : '/',
pageLinks : 7,
totalResult : 9
});
var item = new Paginator({
current : 5,
pageLinks : 6,
totalResult : 100
});
assert.deepEqual({
prelink : '/',
current : 1,
previous : null,
next : null,
first : null,
last : null,
range : [],
fromResult : 1,
toResult : 9,
totalResult : 9,
pageCount : 1
}, item.calc());
assert.deepEqual({
prelink : "",
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [2, 3, 4, 5, 6, 7],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
var item = new Paginator({
current : 5,
pageLinks : 7,
totalResult : 100
});
assert.deepEqual({
prelink : "",
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [2, 3, 4, 5, 6, 7, 8],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
var item = new Paginator({
current : 5,
pageLinks : 4,
totalResult : 100
});
assert.deepEqual({
prelink : "",
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [3, 4, 5, 6],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
var item = new Paginator({
current : 5,
pageLinks : 6,
totalResult : 100
});
var item = new Paginator({
prelink : '/',
current : 5,
pageLinks : 4,
totalResult : 100
});
assert.deepEqual({
prelink : '/',
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [3, 4, 5, 6],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
assert.deepEqual({
prelink : "",
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [2, 3, 4, 5, 6, 7],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
/* pageLinks 5 by default; howto specify for Item Pattern */
var item = new Paginator({
current : 5,
totalResult : 100
});
assert.deepEqual({
prelink : '',
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [3, 4, 5, 6, 7],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
var item = new Paginator({
current : 5,
pageLinks : 4,
totalResult : 100
});
assert.deepEqual({
prelink : "",
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [3, 4, 5, 6],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
var item = new Paginator({
prelink : '/',
current : 5,
pageLinks : 4,
totalResult : 100
});
var item = new Paginator({
prelink : '/',
current : 5,
pageLinks : 4,
totalResult : 100
});
assert.deepEqual({
prelink : '/',
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [3, 4, 5, 6],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
assert.equal('/?', item.preparePreLink('/'));
assert.equal('/?q=testing&', item.preparePreLink('/?q=testing'));
assert.equal('http//igeonote.com/?', item.preparePreLink('http//igeonote.com/'));
assert.equal('http//sibox.isgoodness.com/q/testing?', item.preparePreLink('http//sibox.isgoodness.com/q/testing'));
/* pageLinks 5 by default; howto specify for Item Pattern */
var item = new Paginator({
current : 5,
totalResult : 100
});
assert.deepEqual({
prelink : '',
current : 5,
previous : 4,
next : 6,
first : 1,
last : 10,
range : [3, 4, 5, 6, 7],
fromResult : 41,
toResult : 50,
totalResult : 100,
pageCount : 10
}, item.calc());
},
getPaginationData: function() {
var item = new Paginator({
current : 8,
pageLinks : 7,
totalResult : 100
});
assert.deepEqual({
prelink : "",
current : 8,
previous : 7,
next : 9,
first : 1,
last : 10,
range : [4, 5, 6, 7, 8, 9, 10],
fromResult : 71,
toResult : 80,
totalResult : 100,
pageCount : 10
}, item.getPaginationData());
},
testPreparePreLink : function() {
var item = new Paginator({
prelink : '/',
current : 5,
pageLinks : 4,
totalResult : 100
});
item.set('totalResult', 3000);
item.set('notSupported', 'notfound');
// ugly :-)
item.set('translator', null);
assert.deepEqual({
totalResult : 3000,
prelink : '/',
rowsPerPage : 10,
pageLinks : 4,
current : 5,
translator : null,
translationCache : false
}, item.options);
assert.equal('/?', item.preparePreLink('/'));
assert.equal('/?q=testing&', item.preparePreLink('/?q=testing'));
assert.equal('http//igeonote.com/?', item.preparePreLink('http//igeonote.com/'));
assert.equal('http//sibox.isgoodness.com/q/testing?', item.preparePreLink('http//sibox.isgoodness.com/q/testing'));
}
},
testSet : function() {
var item = new Paginator({
prelink : '/',
current : 5,
pageLinks : 4,
totalResult : 100
});
item.set('totalResult', 3000);
item.set('notSupported', 'notfound');
// ugly :-)
item.set('translator', null);
assert.deepEqual({
totalResult : 3000,
prelink : '/',
rowsPerPage : 10,
pageLinks : 4,
current : 5,
translator : null,
translationCache : false
}, item.options);
test();
}
}).export(module);

@@ -5,16 +5,16 @@ var assert = require('assert');

function test() {
console.log('Running SearchPaginator test');
var item = new SearchPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100
});
assert.equal('<div class="paginator"><a href="/?page=4" class="paginator-previous">Previous</a><a href="/?page=3" class="paginator-page paginator-page-first">3</a><a href="/?page=4" class="paginator-page">4</a><a href="/?page=5" class="paginator-current">5</a><a href="/?page=6" class="paginator-page">6</a><a href="/?page=7" class="paginator-page paginator-page-last">7</a><a href="/?page=6" class="paginator-next">Next</a></div>', item.render());
var vows = require('vows');
}
vows.describe('Test suite for SearchPaginator').addBatch({
render : function() {
var item = new SearchPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100
});
test();
assert.equal('<div class="paginator"><a href="/?page=4" class="paginator-previous">Previous</a><a href="/?page=3" class="paginator-page paginator-page-first">3</a><a href="/?page=4" class="paginator-page">4</a><a href="/?page=5" class="paginator-current">5</a><a href="/?page=6" class="paginator-page">6</a><a href="/?page=7" class="paginator-page paginator-page-last">7</a><a href="/?page=6" class="paginator-next">Next</a></div>', item.render());
}
}).export(module)

@@ -6,62 +6,67 @@ var assert = require('assert');

function test() {
console.log('Running translation test');
var translations = {
'PREVIOUS' : 'Voorgaand',
'NEXT' : 'Volgende',
'FIRST' : 'Eerst',
'LAST' : 'Laatste',
'CURRENT_PAGE_REPORT' : 'Resulten {FromResult} - {ToResult} van {TotalResult}'
};
var item = new SearchPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100,
translator : function(str) {
return translations[str];
}
});
var vows = require('vows');
assert.equal('<div class="paginator"><a href="/?page=4" class="paginator-previous">Voorgaand</a><a href="/?page=3" class="paginator-page paginator-page-first">3</a><a href="/?page=4" class="paginator-page">4</a><a href="/?page=5" class="paginator-current">5</a><a href="/?page=6" class="paginator-page">6</a><a href="/?page=7" class="paginator-page paginator-page-last">7</a><a href="/?page=6" class="paginator-next">Volgende</a></div>', item.render());
var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100,
translator : function(str) {
return translations[str];
}
});
vows.describe('Test suite for translation').addBatch({
searchPaginator : function() {
var translations = {
'PREVIOUS' : 'Voorgaand',
'NEXT' : 'Volgende',
'FIRST' : 'Eerst',
'LAST' : 'Laatste',
'CURRENT_PAGE_REPORT' : 'Resulten {FromResult} - {ToResult} van {TotalResult}'
};
var item = new SearchPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100,
translator : function(str) {
return translations[str];
}
});
assert.equal('<div class="paginator"><span class="paginator-current-report">Resulten 41 - 50 van 100</span><a href="/?page=1" class="paginator-first">Eerst</a><a href="/?page=4" class="paginator-previous">Voorgaand</a><a href="/?page=6" class="paginator-next">Volgende</a><a href="/?page=10" class="paginator-last">Laatste</a></div>', item.render());
assert.equal('<div class="paginator"><a href="/?page=4" class="paginator-previous">Voorgaand</a><a href="/?page=3" class="paginator-page paginator-page-first">3</a><a href="/?page=4" class="paginator-page">4</a><a href="/?page=5" class="paginator-current">5</a><a href="/?page=6" class="paginator-page">6</a><a href="/?page=7" class="paginator-page paginator-page-last">7</a><a href="/?page=6" class="paginator-next">Volgende</a></div>', item.render());
},
itemPaginator: function() {
var translations = {
'PREVIOUS' : 'Voorgaand',
'NEXT' : 'Volgende',
'FIRST' : 'Eerst',
'LAST' : 'Laatste',
'CURRENT_PAGE_REPORT' : 'Resulten {FromResult} - {ToResult} van {TotalResult}'
};
var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100,
translator : function(str) {
return translations[str];
}
});
}
assert.equal('<div class="paginator"><span class="paginator-current-report">Resulten 41 - 50 van 100</span><a href="/?page=1" class="paginator-first">Eerst</a><a href="/?page=4" class="paginator-previous">Voorgaand</a><a href="/?page=6" class="paginator-next">Volgende</a><a href="/?page=10" class="paginator-last">Laatste</a></div>', item.render());
},
testWithMarkup : function() {
var translations = {
'PREVIOUS' : '<span class="left-arrow"></span><span class="text">Voorgaand</span>',
'NEXT' : '<span class="right-arrow"></span><span class="text">Volgende</span>',
'FIRST' : 'Eerst',
'LAST' : 'Laatste',
'CURRENT_PAGE_REPORT' : 'Resulten {FromResult} - {ToResult} van {TotalResult}'
};
var item = new SearchPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100,
translator : function(str) {
return translations[str];
}
});
function testMarkup() {
console.log('Running translation test, markup');
var translations = {
'PREVIOUS' : '<span class="left-arrow"></span><span class="text">Voorgaand</span>',
'NEXT' : '<span class="right-arrow"></span><span class="text">Volgende</span>',
'FIRST' : 'Eerst',
'LAST' : 'Laatste',
'CURRENT_PAGE_REPORT' : 'Resulten {FromResult} - {ToResult} van {TotalResult}'
};
var item = new SearchPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100,
translator : function(str) {
return translations[str];
}
});
assert.equal('<div class="paginator"><a href="/?page=4" class="paginator-previous"><span class="left-arrow"></span><span class="text">Voorgaand</span></a><a href="/?page=3" class="paginator-page paginator-page-first">3</a><a href="/?page=4" class="paginator-page">4</a><a href="/?page=5" class="paginator-current">5</a><a href="/?page=6" class="paginator-page">6</a><a href="/?page=7" class="paginator-page paginator-page-last">7</a><a href="/?page=6" class="paginator-next"><span class="right-arrow"></span><span class="text">Volgende</span></a></div>', item.render());
}
test();
testMarkup();
assert.equal('<div class="paginator"><a href="/?page=4" class="paginator-previous"><span class="left-arrow"></span><span class="text">Voorgaand</span></a><a href="/?page=3" class="paginator-page paginator-page-first">3</a><a href="/?page=4" class="paginator-page">4</a><a href="/?page=5" class="paginator-current">5</a><a href="/?page=6" class="paginator-page">6</a><a href="/?page=7" class="paginator-page paginator-page-last">7</a><a href="/?page=6" class="paginator-next"><span class="right-arrow"></span><span class="text">Volgende</span></a></div>', item.render());
}
}).export(module)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc