pagination
Advanced tools
Comparing version 0.3.7 to 0.3.8
@@ -62,2 +62,3 @@ (function(module) { | ||
var keys, i, len; | ||
/* validate in this.set if needed */ | ||
this.options = { | ||
@@ -171,4 +172,27 @@ totalResult : 0, | ||
if(this.options.hasOwnProperty(option)) { | ||
switch(option) { | ||
case 'current': | ||
case 'totalResult': | ||
case 'pageLinks': | ||
case 'rowsPerPage': | ||
value = parseInt(value, 10); | ||
if (isNaN(value)) { | ||
throw new Error('Invalid value for "' + option + '", expected an integer'); | ||
} | ||
break; | ||
case 'translator': | ||
if (!(value && value.constructor && value.call && value.apply)) { | ||
throw new Error('Translator must be a function'); | ||
} | ||
break; | ||
case 'translationCacheKey': | ||
case 'pageParamName': | ||
case 'prelink': | ||
value = String(value); | ||
break; | ||
} | ||
this.options[option] = value; | ||
this._result = null; | ||
if (this._result) { | ||
this._result = null; | ||
} | ||
} | ||
@@ -175,0 +199,0 @@ }, |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"scripts": { | ||
@@ -17,0 +17,0 @@ "test": "vows --spec tests/*" |
@@ -188,2 +188,65 @@ var assert = require('assert'); | ||
}, | ||
getPaginationData1 : function() { | ||
var item = new Paginator({ | ||
prelink : '/', | ||
pageLinks : 5, | ||
current : 1, | ||
totalResult : 100 | ||
}); | ||
assert.deepEqual({ | ||
prelink : '/', | ||
current : 1, | ||
previous : null, | ||
next : 2, | ||
first : null, | ||
last : 10, | ||
range : [1, 2, 3, 4, 5], | ||
fromResult : 1, | ||
toResult : 10, | ||
totalResult : 100, | ||
pageCount : 10 | ||
}, item.getPaginationData()); | ||
}, | ||
getPaginationData3 : function() { | ||
var item = new Paginator({ | ||
prelink : '/', | ||
pageLinks : 5, | ||
current : 3, | ||
totalResult : 100 | ||
}); | ||
assert.deepEqual({ | ||
prelink : '/', | ||
current : 3, | ||
previous : 2, | ||
next : 4, | ||
first : 1, | ||
last : 10, | ||
range : [1, 2, 3, 4, 5], | ||
fromResult : 21, | ||
toResult : 30, | ||
totalResult : 100, | ||
pageCount : 10 | ||
}, item.getPaginationData()); | ||
}, | ||
getPaginationData4 : function() { | ||
var item = new Paginator({ | ||
prelink : '/', | ||
pageLinks : 5, | ||
current : 4, | ||
totalResult : 100 | ||
}); | ||
assert.deepEqual({ | ||
prelink : '/', | ||
current : 4, | ||
previous : 3, | ||
next : 5, | ||
first : 1, | ||
last : 10, | ||
range : [2, 3, 4, 5, 6], | ||
fromResult : 31, | ||
toResult : 40, | ||
totalResult : 100, | ||
pageCount : 10 | ||
}, item.getPaginationData()); | ||
}, | ||
testPreparePreLink : function() { | ||
@@ -238,7 +301,8 @@ var item = new Paginator({ | ||
}); | ||
var test_translator = function() {} | ||
item.set('totalResult', 3000); | ||
item.set('notSupported', 'notfound'); | ||
// ugly :-) | ||
item.set('translator', null); | ||
item.set('translator', test_translator); | ||
assert.deepEqual({ | ||
@@ -250,3 +314,3 @@ totalResult : 3000, | ||
current : 5, | ||
translator : null, | ||
translator : test_translator, | ||
translationCache : false, | ||
@@ -253,0 +317,0 @@ translationCacheKey: 'en', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36498
15
969