forked from BabDev/Pagerfanta
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from loic425/semantic_ui
Add support for semantic ui
- Loading branch information
Showing
5 changed files
with
522 additions
and
25 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
[![Build Status](https://travis-ci.org/whiteoctober/Pagerfanta.png?branch=master)](https://travis-ci.org/whiteoctober/Pagerfanta) [![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/whiteoctober/Pagerfanta/badges/quality-score.png?s=1ee480491644c07812b5206cf07d33a5035d0118)](https://scrutinizer-ci.com/g/whiteoctober/Pagerfanta/) [![Code Coverage](https://scrutinizer-ci.com/g/whiteoctober/Pagerfanta/badges/coverage.png?s=284be0616a9ba0439ee1123bcaf5fb3f6bfb0e50)](https://scrutinizer-ci.com/g/whiteoctober/Pagerfanta/) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/9e710230-b088-4904-baef-5f5e2d62e681/mini.png)](https://insight.sensiolabs.com/projects/9e710230-b088-4904-baef-5f5e2d62e681) [![Latest Stable Version](https://poser.pugx.org/pagerfanta/pagerfanta/v/stable.png)](https://packagist.org/packages/pagerfanta/pagerfanta) [![Total Downloads](https://poser.pugx.org/pagerfanta/pagerfanta/downloads.png)](https://packagist.org/packages/pagerfanta/pagerfanta) | ||
|
||
Pagination for PHP 5.3 | ||
Pagination for PHP >= 5.3 | ||
|
||
## Usage | ||
|
||
|
@@ -26,7 +26,7 @@ $currentPageResults = $pagerfanta->getCurrentPageResults(); | |
|
||
$pagerfanta->getNbPages(); | ||
|
||
$pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page | ||
$pagerfanta->haveToPaginate(); // whether the number of results is higher than the max per page | ||
|
||
$pagerfanta->hasPreviousPage(); | ||
$pagerfanta->getPreviousPage(); | ||
|
@@ -336,8 +336,8 @@ $adapter = new FixedAdapter($nbResults, $results); | |
## Views | ||
|
||
Views are to render pagerfantas, this way you can reuse your | ||
pagerfantas' html in several projects, share them and use another | ||
ones from another developers. | ||
pagerfantas' HTML in several projects, share them and use another | ||
ones from another developer's. | ||
|
||
The views implement the `Pagerfanta\View\ViewInterface` interface, | ||
which has two methods: | ||
|
@@ -374,10 +374,10 @@ $routeGenerator = function($page) { | |
return '/path?page='.$page; | ||
} | ||
``` | ||
|
||
Pagerfanta comes with three views, the default one, one for | ||
[Twitter Bootstrap](https://github.com/twitter/bootstrap) and | ||
an special optionable view. | ||
Pagerfanta comes with five views: The default one, two for | ||
[Twitter Bootstrap](https://github.com/twitter/bootstrap), one for | ||
[Semantic UI](https://github.com/Semantic-Org/Semantic-UI) and | ||
a special optionable view. | ||
|
||
### DefaultView | ||
|
||
|
@@ -406,8 +406,6 @@ Options (default): | |
* page_template (<a href="%href%">%text%</a>) | ||
* span_template (<span class="%class%">%text%</span>) | ||
|
||
![Pagerfanta DefaultView](http://img813.imageshack.us/img813/601/pagerfanta.png) | ||
|
||
CSS: | ||
|
||
```css | ||
|
@@ -467,11 +465,13 @@ COLORS: | |
} | ||
``` | ||
|
||
### TwitterBootstrapView | ||
### TwitterBootstrapView and TwitterBootstrap3View | ||
|
||
This view generates a pagination for | ||
These views generate paginators designed for use with | ||
[Twitter Bootstrap](https://github.com/twitter/bootstrap). | ||
|
||
`TwitterBootstrapView` is for Bootstrap 2; `TwitterBootstrap3View` is for Bootstrap 3. | ||
|
||
```php | ||
<?php | ||
|
||
|
@@ -498,6 +498,38 @@ Options (default): | |
* css_dots_class (disabled) | ||
* css_active_class (active) | ||
|
||
### SemanticUiView | ||
|
||
This view generates a pagination for | ||
[Semantic UI](https://github.com/Semantic-Org/Semantic-UI). | ||
|
||
```php | ||
<?php | ||
|
||
use Pagerfanta\View\SemanticUiView; | ||
|
||
$view = new SemanticUiView(); | ||
$options = array('proximity' => 3); | ||
$html = $view->render($pagerfanta, $routeGenerator, $options); | ||
``` | ||
|
||
Options (default): | ||
|
||
* proximity (3) | ||
* prev_message (← Previous) | ||
* prev_disabled_href () | ||
* next_message (Next →) | ||
* next_disabled_href () | ||
* dots_message (…) | ||
* dots_href () | ||
* css_container_class (pagination) | ||
* css_item_class (item) | ||
* css_prev_class (prev) | ||
* css_next_class (next) | ||
* css_disabled_class (disabled) | ||
* css_dots_class (disabled) | ||
* css_active_class (active) | ||
|
||
### OptionableView | ||
|
||
This view is to reuse options in different views. | ||
|
@@ -522,20 +554,12 @@ $pagerfantaHtml = $myView2->render($pagerfanta, $routeGenerator); | |
$pagerfantaHtml = $myView2->render($pagerfanta, $routeGenerator, array('next_message' => 'Siguiente!!')); | ||
``` | ||
|
||
## Todo | ||
|
||
## Author | ||
|
||
Pablo Díez - <[email protected]> | ||
|
||
## License | ||
|
||
Pagerfanta is licensed under the MIT License. See the LICENSE file for full details. | ||
## Acknowledgements | ||
|
||
## Sponsors | ||
Pagerfanta is inspired by [Zend Paginator](https://github.com/zendframework/zf2). | ||
|
||
[WhiteOctober](http://www.whiteoctober.co.uk/) | ||
Thanks also to Pablo Díez ([email protected]) for most of the work on the first versions of Pagerfanta. | ||
|
||
## Acknowledgements | ||
## Licence | ||
|
||
Pagerfanta is inspired by [Zend Paginator](https://github.com/zendframework/zf2). | ||
Pagerfanta is licensed under the [MIT License](LICENCE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Pagerfanta package. | ||
* | ||
* (c) Pablo Díez <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pagerfanta\View; | ||
|
||
use Pagerfanta\View\Template\SemanticUiTemplate; | ||
|
||
/** | ||
* SemanticUiView. | ||
* | ||
* View that can be used with the pagination module | ||
* from the Semantic UI CSS Toolkit | ||
* http://semantic-ui.com/ | ||
* | ||
* @author Loïc Frémont <[email protected]> | ||
*/ | ||
class SemanticUiView extends DefaultView | ||
{ | ||
protected function createDefaultTemplate() | ||
{ | ||
return new SemanticUiTemplate(); | ||
} | ||
|
||
protected function getDefaultProximity() | ||
{ | ||
return 3; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'semantic_ui'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Pagerfanta package. | ||
* | ||
* (c) Pablo Díez <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pagerfanta\View\Template; | ||
|
||
/** | ||
* @author Loïc Frémont <[email protected]> | ||
*/ | ||
class SemanticUiTemplate extends Template | ||
{ | ||
static protected $defaultOptions = array( | ||
'prev_message' => '← Previous', | ||
'next_message' => 'Next →', | ||
'dots_message' => '…', | ||
'active_suffix' => '', | ||
'css_container_class' => 'ui stackable fluid pagination menu', | ||
'css_item_class' => 'item', | ||
'css_prev_class' => 'prev', | ||
'css_next_class' => 'next', | ||
'css_disabled_class' => 'disabled', | ||
'css_dots_class' => 'disabled', | ||
'css_active_class' => 'active', | ||
); | ||
|
||
public function container() | ||
{ | ||
return sprintf('<div class="%s">%%pages%%</div>', | ||
$this->option('css_container_class') | ||
); | ||
} | ||
|
||
public function page($page) | ||
{ | ||
$text = $page; | ||
|
||
return $this->pageWithText($page, $text); | ||
} | ||
|
||
public function pageWithText($page, $text) | ||
{ | ||
$class = null; | ||
|
||
return $this->pageWithTextAndClass($page, $text, $class); | ||
} | ||
|
||
private function pageWithTextAndClass($page, $text, $class) | ||
{ | ||
$href = $this->generateRoute($page); | ||
|
||
return $this->link($class, $href, $text); | ||
} | ||
|
||
public function previousDisabled() | ||
{ | ||
$class = $this->previousDisabledClass(); | ||
$text = $this->option('prev_message'); | ||
|
||
return $this->div($class, $text); | ||
} | ||
|
||
private function previousDisabledClass() | ||
{ | ||
return $this->option('css_prev_class').' '.$this->option('css_disabled_class'); | ||
} | ||
|
||
public function previousEnabled($page) | ||
{ | ||
$text = $this->option('prev_message'); | ||
$class = $this->option('css_prev_class'); | ||
|
||
return $this->pageWithTextAndClass($page, $text, $class); | ||
} | ||
|
||
public function nextDisabled() | ||
{ | ||
$class = $this->nextDisabledClass(); | ||
$text = $this->option('next_message'); | ||
|
||
return $this->div($class, $text); | ||
} | ||
|
||
private function nextDisabledClass() | ||
{ | ||
return $this->option('css_next_class').' '.$this->option('css_disabled_class'); | ||
} | ||
|
||
public function nextEnabled($page) | ||
{ | ||
$text = $this->option('next_message'); | ||
$class = $this->option('css_next_class'); | ||
|
||
return $this->pageWithTextAndClass($page, $text, $class); | ||
} | ||
|
||
public function first() | ||
{ | ||
return $this->page(1); | ||
} | ||
|
||
public function last($page) | ||
{ | ||
return $this->page($page); | ||
} | ||
|
||
public function current($page) | ||
{ | ||
$text = trim($page.' '.$this->option('active_suffix')); | ||
$class = $this->option('css_active_class'); | ||
|
||
return $this->div($class, $text); | ||
} | ||
|
||
public function separator() | ||
{ | ||
$class = $this->option('css_dots_class'); | ||
$text = $this->option('dots_message'); | ||
|
||
return $this->div($class, $text); | ||
} | ||
|
||
private function link($class, $href, $text) | ||
{ | ||
$item_class = $this->option('css_item_class'); | ||
|
||
return sprintf('<a class="%s %s" href="%s">%s</a>', $item_class, $class, $href, $text); | ||
} | ||
|
||
private function div($class, $text) | ||
{ | ||
$item_class = $this->option('css_item_class'); | ||
|
||
return sprintf('<div class="%s %s">%s</div>', $item_class, $class, $text); | ||
} | ||
} |
Oops, something went wrong.