Skip to content

Commit

Permalink
Release 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaSh committed May 26, 2016
1 parent ed994a4 commit c18f880
Show file tree
Hide file tree
Showing 13 changed files with 1,011 additions and 145 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
It's basically a directive with a bunch of methods defined on the vm. When you
use this directive on some list, it'll be sliced according to the number of
items per page, which you specify. Then, you'll work with those slices using the
methods & data that automatically gets defined on the vm — not all vms, only the
one you used the directive in.
items per page, which you specify. Then, you'll work with those slices using the methods & data that automatically gets defined on the vm — not all vms, only the one you used the directive in.

## Setup

Expand Down Expand Up @@ -34,8 +32,7 @@ Vue.use(VuePaginate)

#### Include

Include it directly with a `<script>` tag. In this case, you don't need to write
`Vue.use(VuePaginate)`, this will be done automatically for you.
Include it directly with a `<script>` tag. In this case, you don't need to write `Vue.use(VuePaginate)`, this will be done automatically for you.

## Usage

Expand All @@ -62,7 +59,7 @@ new Vue({
<ul>
<li v-for="langLink in langsLinks">
<a @click="changeLangsPage(langLink)" href="#">
{{ langLink + 1 }}
{{ langLink }}
</a>
</li>
</ul>
Expand All @@ -72,19 +69,13 @@ That's it!

#### How it works?

When you try the previous example, you'll get two pages, each one contains three
items. We specified that by using `:3` argument, which means we want to show 3
items per page!
When you try the previous example, you'll get two pages, each one contains three items. We specified that by using `:3` argument, which means we want to show 3 items per page!

In the links section, we used a variable named `langsLinks`. This one is
generated for us by the plugin, which follows the convention `[listName]Links`.
This variable contains the total number of pages needed to display the whole
list.
This variable contains an array of all pages' numbers that we need to navigate the content of the list.

To show the links, we ran a loop — to get all page numbers, from zero to the
last one — and used each one in the method `changeLangsPage()` (which also
follows a convention: `change[listName]Page`). This method takes the page number
and return all items in that page.
So, to show the links, we ran a loop and used each one in the method `changeLangsPage()` (which also follows a convention: `change[listName]Page`). This method takes the page number and return all items in that page.

#### Use Next/Prev buttons

Expand Down Expand Up @@ -113,9 +104,36 @@ This plugin operates on the original data that you've defined in your vm. This
means, you'll no longer have access to the full version (before slicing).

However, before the plugin does its slicing, it stores the full version in
another list named `full[listName]`. So for this example it would be
another list named `full[listName]`. So, for this example it would be
`fullLangs`.

#### Limit the number of displayed links

When your number of pages gets bigger, it becomes unpractical to display all of your links. What we prefer to do instead is to limit the number of links displayed in the links section. Doing that with this plugin is a cinch!

All you have to do is to use `limited[listName]Links` in place of `[listName]Links`. As a default, your links will be limited to `4`, but of course you can change it by using the parameter `limit` along with `v-paginate`. For example:

``` html
<section v-paginate:2="posts" limit="2">
<ul v-for="post in posts">
<li>{{ post }}</li>
</ul>
</section>
```

#### Updating the full list manually

In many cases you will find the need to change/assign the content of the list manually — for example from an Ajax response. You can do that simply by changing the value of the full version of the list `full[listName]`. For example, here's how you would change your list content when performing an Ajax request:

``` js
this.$http.get('/posts')
.then(function (response) {
this.fullPosts = response.data;
}
);
```


## Conventions

#### Methods
Expand All @@ -126,6 +144,8 @@ another list named `full[listName]`. So for this example it would be

#### Data

- `[listName]Links`: The total number of pages of the list.
- `[listName]Links`: Array of the needed links.
- `limited[listName]Links`: Array of limited links.
- `full[listName]`: The full version of the list (before slicing).
- `current[listName]Page`: The current page of the list you're viewing (e.g. `currentLangsPage`).
- `has[listName]Links`: A check to see if there's a need to display the links.
Loading

0 comments on commit c18f880

Please sign in to comment.