From db3c3594066a66174ec3d6acfb57a7e4ea7bbddc Mon Sep 17 00:00:00 2001 From: "leon.shi" Date: Sun, 6 Dec 2015 22:31:47 +0800 Subject: [PATCH] update docs --- README.md | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e7765eb..229a86d 100644 --- a/README.md +++ b/README.md @@ -9,25 +9,111 @@ paginationjs -See demos and full documentation at [Documentation](http://paginationjs.com/docs/index.html) +See demos and full documentation at official site: [http://paginationjs.com](http://paginationjs.com) # Installation / Download `bower install paginationjs` or just download [pagination.js](dist/pagination.js) from the git repo. -# Usage: +# Quick Start + +HTML: + +```html +
+
+``` + +JS: ```js -$('#container').pagination({ +$('#pagination-container').pagination({ dataSource: [1, 2, 3, 4, 5, 6, 7, ... , 195], callback: function(data, pagination) { // template method of yourself var html = template(data); + $('#data-container').html(html); + } +}) +``` + +# Data rendering + +Below is a minimal data rendering method: + +```js +function simpleRender(data) { + var html = ''; + return html; +} +``` + +Calling: + +```js +$('#container').pagination({ + dataSource: [1, 2, 3, 4, 5, 6, 7, ... , 195], + callback: function(data, pagination) { + var html = simpleRender(data); dataContainer.html(html); } }) ``` +To make it easier to maintain, you'd better use specialized templating engine to do the data rendering. + +Below is an example using [undercore.template](http://underscorejs.org/#template): + +```js +$('#container').pagination({ + dataSource: [1, 2, 3, 4, 5, 6, 7, ... , 195], + callback: function(data, pagination) { + var html = _.template(templateString, { + data: data + }); + + /* templateString: + + */ + + dataContainer.html(html); + } +}) +``` + +Using [Handlebars](http://handlebarsjs.com/): + +```js +$('#container').pagination({ + dataSource: [1, 2, 3, 4, 5, 6, 7, ... , 195], + callback: function(data, pagination) { + var html = Handlebars.compile(templateString, { + data: data + }); + + /* templateString: + + {{/each}} + */ + + dataContainer.html(html); + } +}) +``` + +Or any other templating engine what you prefer. + # License Released under the MIT license. -- GitLab