pager-js

1.0.1 • Public • Published

Pager v1.0.1

A very simple and useful pager boilerplate

Bower version npm version


Usage

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);

Options

  • 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

API

.set(index)

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

.hasPrev()

myPager.hasPrev(); // return boolean

Returns if there is a previous index

.hasNext()

myPager.hasNext(); // return boolean

Returns if there is a next index

.getPrev()

myPager.getPrev(); // return number or false

Returns the previous index if it exists

.getNext()

myPager.getNext(); // return number or false

Returns the next index if it exists

.getFirst()

myPager.getFirst(); // return number

Returns the first index

.getLast()

myPager.getLast(); // return number

Returns the last index

.prev()

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

.next()

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

.first()

myPager.first(); // return number

Sets the current index with the first index and return it

.last()

myPager.last(); // return number

Sets the current index with the last index and return it

Building

First of all, you need have installed Node.js and Gulp globally. Then you can:

  • Clone the repo: git clone git@github.com:acauamontiel/pager.git
  • Enter the folder: cd pager
  • Finally install Node dependencies: npm install

Running

You can build by Gulp

Available Gulp commands

Default - gulp

Run gulp to lint and minify the code

Watch - gulp watch

Run gulp watch to watch JavaScript files

License

© 2014 Acauã Montiel

MIT License

Readme

Keywords

Package Sidebar

Install

npm i pager-js

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • acaua