A very simple and useful pager boilerplate
It's very simple to use Pager. You will need to download the files, or just run some of these following command lines: bower install pager --save
or npm i pager-js --save
Then you just need to include the file in your HTML:
<script src="bower_components/pager.min.js"></script>
If you're in a CommonJS environment:
var Pager = require('pager-js');
Or if you're in a AMD environment:
require(['path-to/pager'], function (Pager) {
// ...
});
Now you can create a new instance:
var myPager = new Pager(length, circular);
- length
Number
- Specifies the amount of items - circular
Boolean
- Specifies whether to wrap at the first/last item and jump back to the start/end
myPager.set(2); // return number
Sets the current index with the number entered in the index parameter if it is not greater than the last index
myPager.hasPrev(); // return boolean
Returns if there is a previous index
myPager.hasNext(); // return boolean
Returns if there is a next index
myPager.getPrev(); // return number or false
Returns the previous index if it exists
myPager.getNext(); // return number or false
Returns the next index if it exists
myPager.getFirst(); // return number
Returns the first index
myPager.getLast(); // return number
Returns the last index
myPager.prev(); // return number
Sets and returns the current index with the previous index, if the circular option is true and the current index is 0 it will return the last index
myPager.next(); // return number
Sets and returns the current index with the next index, if the circular option is true and the current index is the last index it will return the first index
myPager.first(); // return number
Sets the current index with the first index and return it
myPager.last(); // return number
Sets the current index with the last index and return it
First of all, you need have installed Node.js and Gulp globally. Then you can:
- Clone the repo:
git clone [email protected]:acauamontiel/pager.git
- Enter the folder:
cd pager
- Finally install Node dependencies:
npm install
You can build by Gulp
Run gulp
to lint and minify the code
Run gulp watch
to watch JavaScript files
© 2014 Acauã Montiel