Skip to content

Commit

Permalink
release 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadym Petrychenko committed Dec 7, 2014
1 parent 9e99cb6 commit 3ba5508
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.idea
components
bower_components
node_modules

*.log
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Vadym Petrychenko (http://7ninjas.com)
Copyright (c) 2014 Vadym Petrychenko (http://petrychenko.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
223 changes: 129 additions & 94 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,159 @@
# Angular Paginate
[![Gittip](http://img.shields.io/gittip/darthwade.svg)](https://www.gittip.com/darthwade/)
[![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=darthwade&url=https://github.com/darthwade/angular-paginate&title=Angular%20Paginate&language=&tags=github&category=software)

Angular directive that lets you to prevent user interaction with part of the page and display loading/busy indicator (spinner based on spin.js)
Most clean, powerful and customizable pagination for angular.

**Demo:** http://embed.plnkr.co/XLL3li/preview
## Installation

## 1. Getting Started
Using `bower`:
```shell
$ bower install angular-paginate --save
```

Using `git`:
```shell
$ git clone https://github.com/darthwade/angular-paginate.git
```

## Requirements & Dependencies
- Angular

Install with bower `bower install angular-loading --save` or clone the repo `git clone git://github.com/darthwade/angular-loading.git` or [download the latest release](https://github.com/darthwade/angular-loading/zipball/master).
## Usage

Add `angular-loading.min.js` and `angular-loading.css` to your HTML. Also add [spin.js](https://github.com/fgnass/spin.js) library.
Add `angular-paginate.min.js` to your HTML.
``` html
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/spin.js/1.2.7/spin.min.js"></script>
<script src="//rawgithub.com/darthwade/angular-loading/master/angular-loading.min.js"></script>

<link rel="stylesheet" type="text/css" href="//rawgithub.com/darthwade/angular-loading/master/angular-loading.css"/>
<script src="//rawgithub.com/darthwade/angular-paginate/master/angular-paginate.min.js"></script>
```

Add `darthwade.dwLoading` as a module dependency for your module.
Add `darthwade.paginate` as a module dependency for your app.
``` javascript
angular.module('myApp', ['darthwade.dwLoading']);
angular.module('myApp', ['darthwade.paginate']);
```

## 2. Usage
Add `dw-loading` directive to that block which you want to lock during loading.
``` html
<div dw-loading="key" dw-loading-options="options"></div>
```
## 3. Sample
## Example

``` html
<div dw-loading="users" dw-loading-options="{text: 'Loading users...'}" class="users-list">
<p ng-repeat="user in users">{{user.name}}</p>
<div ng-controller="MainCtrl">
<h1>Numbers List</h1>
<div class="numbers">
<div ng-repeat="number in numbers.$objects track by $index">Number {{number}}</div>
</div>

<div>{{numbers.$startIndex}}-{{numbers.$endIndex}} of {{numbers.$totalCount}}</div>
<div dw-paginate="numbers" class="pagination-sm"></div>
</div>
```
``` javascript
function SampleCtrl($scope, $loading) {
$scope.loadUsers = function() {
// Lock UI and show spinner
$loading.start('users');

$http({method: 'GET', url: '/someUrl'})
.success(function(data, status, headers, config) {
$scope.users = data;

// Unlock UI and hide spinner
$loading.finish('users');
});
};

$scope.loadUsers();
}
angular.module('demoApp', [
'darthwade.paginate'
])

.config(function($paginateProvider) {
$paginateProvider.setTemplateUrl('../angular-paginate.html');
})

.controller('MainCtrl', function ($scope, $q, $timeout, $paginate) {

var getNumbers = function() {
var deferred = $q.defer();

$timeout(function() {
var numbers = [];
for (var i = 0; i < 10; i++) {
numbers.push(Math.floor(Math.random() * 11));
}
deferred.resolve(numbers);
}, 20);

return deferred.promise;
};


$scope.loadNumbers = function(page) {

getNumbers()
.then(function(numbers) {
$scope.numbers = $paginate({
$objects: numbers,
$totalCount: numbers.length * 10,
$page: page,
onPageChange: function() {
$scope.loadNumbers(this.$page);
},
perPage: 10, // Items count per page.
range: 5, // Number of pages neighbouring the current page which will be displayed.
boundaryLinks: true, // Whether to display First / Last buttons.
directionLinks: true, // Whether to display Previous / Next buttons.
rotate: true, // Whether to keep current page in the middle of the visible ones.
paramName: 'page',
previousText: 'Previous', // Text for previous button
nextText: 'Next' // Text for next button
});
});
};

$scope.loadNumbers(1);
});
```

## 4. Options
## Options

``` javascript
{
active: false, // Defines current loading state
text: 'Loading...', // Display text
className: '', // Custom class, added to directive
overlay: true, // Display overlay
spinner: true, // Display spinner
spinnerOptions: {
lines: 12, // The number of lines to draw
length: 7, // The length of each line
width: 4, // The line thickness
radius: 10, // The radius of the inner circle
rotate: 0, // Rotation offset
corners: 1, // Roundness (0..1)
color: '#000', // #rgb or #rrggbb
direction: 1, // 1: clockwise, -1: counterclockwise
speed: 2, // Rounds per second
trail: 100, // Afterglow percentage
opacity: 1 / 4, // Opacity of the lines
fps: 20, // Frames per second when using setTimeout()
zIndex: 2e9, // Use a high z-index by default
className: 'dw-spinner', // CSS class to assign to the element
top: 'auto', // Center vertically
left: 'auto', // Center horizontally
position: 'relative' // Element position
}
perPage: 10, // Items count per page.
range: 5, // Number of pages neighbouring the current page which will be displayed.
boundaryLinks: true, // Whether to display First / Last buttons.
directionLinks: true, // Whether to display Previous / Next buttons.
rotate: true, // Whether to keep current page in the middle of the visible ones.
paramName: 'page',
previousText: 'Previous', // Text for previous button
nextText: 'Next', // Text for next button
moreText: '...' // Text for more button
}
```

## 5. API
This module provide service `dwLoading` (`$loading` just a shortcut).

`dwLoading.setDefaultOptions(options)` - Overrides default options.

`dwLoading.start(key)` - Activates loading state by key.
## API

`dwLoading.finish(key)` - Deactivates loading state by key.
`$paginateProvider.getDefaultOptions()` - Returns default options.
`$paginateProvider.getTemplateUrl()` - Returns dw-paginate directive template URL.
`$paginateProvider.setDefaultOptions(options)` - Overrides default options.
`$paginateProvider.setTemplateUrl(templateUrl)` - Sets dw-paginate directive template URL.

## 6. Events
`$dwLoadingStart` - Fired once the loading is started. The '$rootScope' emits the event.
``` javascript
$scope.$on('$dwLoadingStart', function(event, key){ ... });
## Styling
``` html
<ul class="dw-paginate pagination" ng-show="paginator.$totalPages > 1">
<li ng-if="paginator.directionLinks" ng-class="{disabled: !paginator.hasPrevious()}" class="dw-paginate-previous">
<a href ng-click="paginator.previous()">{{paginator.previousText}}</a>
</li>
<li ng-repeat="page in paginator.$pages track by $index" ng-class="{active: page.active}" class="dw-paginate-page">
<a href ng-click="paginator.page(page.number)">{{page.text}}</a>
</li>
<li ng-if="paginator.directionLinks" ng-class="{disabled: !paginator.hasNext()}" class="dw-paginate-next">
<a href ng-click="paginator.next()">{{paginator.nextText}}</a>
</li>
</ul>
```

`$dwLoadingFinish` - Fired once the loading is finished. The '$rootScope' emits the event.
``` javascript
$scope.$on('$dwLoadingFinish', function(event, key){ ... });
## Testing
```shell
$ git clone https://github.com/darthwade/angular-paginate.git
$ cd angular-paginate
$ vagrant up
```

## 7. Styling
``` html
<div dw-loading="key" dw-loading-options="{className: 'custom-loading', spinnerOptions: {className: 'custom-spinner'}}" class="my-block">
<p>Content</p>
</div>
```
Will generate:
``` html
<div dw-loading="key" dw-loading-options="{active: true, text: 'Please Wait...', className: 'custom-loading', spinnerOptions: {className: 'custom-spinner'}}" class="my-block">
<p>Content</p>
<div class="dw-loading dw-loading-overlay dw-loading-active custom-loading">
<div class="dw-loading-body">
<div class="dw-loading-spinner">
<div class="custom-spinner"></div>
</div>
<div class="dw-loading-text">Please Wait...</div>
</div>
</div>
</div>
```
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests and examples for any new or changed functionality.

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

## License

Licensed under the MIT License. See the LICENSE file for details.

Copyright (c) 2014 [Vadym Petrychenko](http://petrychenko.com/)
27 changes: 18 additions & 9 deletions angular-paginate.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
(function(factory) {
/* AMD module */
if (typeof define == 'function' && define.amd) {
/**
* Angular Paginate
* @homepage https://github.com/darthwade/angular-paginate
* @author Vadym Petrychenko https://github.com/darthwade
* @license The MIT License (http://www.opensource.org/licenses/mit-license.php)
* @copyright 2014 Vadym Petrychenko
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['angular'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(require('angular'));
} else {
// Browser globals
factory(window.angular)
}
/* Browser global */
else {
factory(window.angular);
}
}(function(angular) {
}(function (angular) {
'use strict';

angular.module('darthwade.dwPaginate', [])
angular.module('darthwade.paginate', [])

.provider('$paginate', function () {
var provider = this;
Expand Down
2 changes: 1 addition & 1 deletion angular-paginate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "angular-paginate",
"version": "0.1.2-0",
"version": "1.0.0",
"description": "Most clean, powerful and customizable pagination for angular.",
"homepage": "https://github.com/darthwade/angular-paginate",
"bugs": "https://github.com/darthwade/angular-paginate/issues",
"author": {
"name": "Vadym Petrychenko",
"email": "darthwade@yandex.com",
"url": "http://7ninjas.com"
"email": "vadympetrychenko@gmail.com",
"url": "http://petrychenko.com"
},
"license": "MIT",
"repository": {
Expand Down
15 changes: 10 additions & 5 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
}
</style>

<script type="text/javascript" src="../components/angular/angular.js"></script>
<script type="text/javascript" src="../bower_components/angular/angular.js"></script>
<script type="text/javascript" src="../angular-paginate.js"></script>
<script>
angular.module('demoApp', [
'darthwade.dwPaginate'
'darthwade.paginate'
])

.config(function($paginateProvider) {
$paginateProvider.setTemplateUrl('/angular-paginate/angular-paginate.html');
$paginateProvider.setTemplateUrl('../angular-paginate.html');
})

.controller('MainCtrl', function ($scope, $q, $timeout, $paginate) {
Expand Down Expand Up @@ -95,11 +95,16 @@
</head>
<body ng-app="demoApp">
<div ng-controller="MainCtrl">

<h1>Numbers List</h1>
<div class="numbers">
<p ng-repeat="number in numbers.$objects track by $index">{{number}}</p>
<div ng-repeat="number in numbers.$objects track by $index">Number {{number}}<hr></div>
</div>


<hr>
<hr>
Pagination:

<div>{{numbers.$startIndex}}-{{numbers.$endIndex}} of {{numbers.$totalCount}}</div>
<div dw-paginate="numbers" class="pagination-sm"></div>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-paginate",
"version": "0.1.2-0",
"version": "1.0.0",
"repository": {
"type": "git",
"url": "git://github.com/darthwade/angular-paginate.git"
Expand Down

0 comments on commit 3ba5508

Please sign in to comment.