diff --git a/wire/modules/Markup/MarkupPagerNav/MarkupPagerNav.module b/wire/modules/Markup/MarkupPagerNav/MarkupPagerNav.module index 60d14518..61ccba19 100644 --- a/wire/modules/Markup/MarkupPagerNav/MarkupPagerNav.module +++ b/wire/modules/Markup/MarkupPagerNav/MarkupPagerNav.module @@ -1,73 +1,108 @@ find("id>0, limit=10"); // replace id>0 with your selector - * $pager = $modules->get("MarkupPagerNav"); - * echo ""; - * echo $pager->render($items); // render the pagination navigation - * - * MarkupPagerNav generates it's own HTML5/XHTML markup. To modify its markup - * or options, specify a second $options array to the render() method. See - * the MarkupPagerNav::$options to see what defaults can be overridden. - * - * PLEASE NOTE - * - * The MarkupPageArray class uses MarkupPagerNav automatically when - * rendering a PageArray that was retrieved with a "limit=n" selector. - * - * MarkupPageArray also adds a PageArray::renderPager (i.e. $myPages->renderPager()) - * method which is the same as MarkupPagerNav::render() (i.e. $pager->render($items). - * - * - * ProcessWire 3.x, Copyright 2016 by Ryan Cramer - * https://processwire.com - * - */ - require_once(dirname(__FILE__) . '/PagerNav.php'); - /** - * Class MarkupPagerNav + * MarkupPagerNav Module for generating pagination markup * - * ProcessWire module that provides pagination for PageArray types + * ProcessWire 3.x, Copyright 2016 by Ryan Cramer + * https://processwire.com + * + * #pw-summary Module for generating pagination markup automatically for paginated WireArray types. + * #pw-var $pager + * #pw-instantiate $pager = $modules->get('MarkupPagerNav'); + * #pw-summary-options-methods Specific to setting certain options that are typically set automatically. Not necessary to use these unless for a specific purpose. * - * @property int $numPageLinks 10 number of links that the pagination navigation should have (typically 10) - * @property array $getVars get vars that should appear in the pagination, or leave empty and populate $input->whitelist (preferred) - * @property string $baseUrl the baseUrl from which the navigation item links will start (default='') - * @property null|Page $page the current Page, or leave NULL to autodetect - * @property string $listMarkup List container markup. Place {out} where you want the individual items rendered (default="") - * @property string $itemMarkup List item markup. Place {class} for item class (required), and {out} for item content. (default="
  • {out}
  • ") - * @property string $linkMarkup Link markup. Place {url} for href attribute, and {out} for label content. (default="{out}") - * @property string $currentLinkMarkup Link markup for current page. Place {url} for href attribute and {out} for label content. (default="{out}") - * @property string $nextItemLabel label used for the 'Next' button (default='Next') - * @property string $previousItemLabel label used for the 'Previous' button (default='Prev') - * @property string $separatorItemLabel label used in the separator item (default='…') - * @property string $separatorItemClass Class for separator item (default='MarkupPagerNavSeparator') - * @property string $firstItemClass Class for first item (default='MarkupPagerNavFirst') - * @property string $firstNumberItemClass Class for first numbered item (default='MarkupPagerNavFirstNum') - * @property string $nextItemClass Class for next item (default='MarkupPagerNavNext') - * @property string $previousItemClass Class for previous item (default='MarkupPagerNavPrevious') - * @property string $lastItemClass Class for last item (default='MarkupPagerNavLast') - * @property string $lastNumberItemClass Class for last numbered item (default='MarkupPagerNavLastNum') - * @property string $currentItemClass Class for current item (default='MarkupPagerNavOn') - * @property string $pagerAriaLabel label announcing pagination to screen readers (default='Pager Navigation') - * @property string $itemAriaLabel label announcing page number to screen readers (default='Page ') - * @property string $itemCurrentAriaLabel label announcing current page to screen readers (default=', current page') - * @property bool $arrayToCSV when arrays are present in getVars, they will be translated to CSV strings in the queryString: ?var=a,b,c. if set to false, then arrays will be kept in traditional format: ?var[]=a&var[]=b&var=c (default=true) - * @property int $totalItems Get total number of items to paginate (set automatically) - * @property int $itemsPerPage Get number of items to display per page (set automatically) - * @property int $pageNum Get the current page number (1-based, set automatically) - * @property string $queryString the queryString used in links (set automatically, based on whitelist or getVars array) - * @property bool $isLastPage Is the current pagination the last? Set automatically after a render() call. + * #pw-body = + * This module can create pagination for a `PageArray` or any other kind of `PaginatedArray` type. + * Below is an example of creating pagination for a PageArray returned from `$pages->find()`. + * ~~~~~ + * // $items can be PageArray or any other kind of PaginatedArray type + * $items = $pages->find("id>0, limit=10"); // replace id>0 with your selector + * if($items->count()) { + * $pager = $modules->get("MarkupPagerNav"); + * echo ""; + * echo $pager->render($items); // render the pagination navigation + * } else { + * echo "

    Sorry there were no items found

    "; + * } + * ~~~~~ + * Here’s a shortcut alternative that you can use for PageArray types (thanks to the `MarkupPageArray` module). + * Note that in this case, it’s not necessary to load the MarkupPagerNav module yourself: + * ~~~~~ + * $items = $pages->find("id>0, limit=10"); // replace id>0 with your selector + * if($items->count()) { + * echo ""; + * echo $items->renderPager(); // render the pagination navigation + * } else { + * echo "

    Sorry there were no items found

    "; + * } + * ~~~~~ + * It’s common to specify different markup and/or classes specific to the need when rendering + * pagination. This is done by providing an `$options` array to the `MarkupPagerNav::render()` call. + * In the example below, we'll specify Uikit markup rather then the default markup: + * ~~~~~ + * // Change options for Uikit "uk-pagination" navigation + * $options = array( + * 'numPageLinks' => 5, + * 'listClass' => 'uk-pagination', + * 'linkMarkup' => "{out}", + * 'currentItemClass' => 'uk-active', + * 'separatorItemLabel' => '', + * 'separatorItemClass' => 'uk-disabled', + * 'currentLinkMarkup' => "{out}" + * 'nextItemLabel' => '', + * 'previousItemLabel' => '', + * 'nextItemClass' => '', // blank out classes irrelevant to Uikit + * 'previousItemClass' => '', + * 'lastItemClass' => '', + * ); + * + * $items = $pages->find("id>0, limit=10"); // replace id>0 with your selector + * + * if($items->count()) { + * $pager = $modules->get('MarkupPagerNav'); + * echo ""; + * echo $pager->render($items, $options); // provide the $options array + * } else { + * echo "

    Sorry there were no items found

    "; + * } + * ~~~~~ + * The full list of options can be seen below. Please note that most options are set automatically since this module can + * determine most of the needed information directly from the WireArray that it’s given. As a result, it’s often + * not necessary to change any of the default options unless you want to change the markup and/or classes used in output. + * #pw-body + * + * @property int $numPageLinks The number of links that the pagination navigation should have (default=10). #pw-group-general-options + * @property array $getVars GET vars that should appear in the pagination, or leave empty and populate $input->whitelist (recommended). #pw-group-general-options + * @property string $baseUrl The base URL from which the navigation item links will start (default=''). #pw-group-general-options + * @property null|Page $page The current Page, or leave NULL to autodetect. #pw-group-general-options + * @property string $listMarkup List container markup. Place {out} where you want the individual items rendered and {class} where you want the list class (default=""). #pw-group-markup-options + * @property string $listClass The class name to use in the $listMarkup (default='MarkupPageNav'). #pw-group-class-options + * @property string $itemMarkup List item markup. Place {class} for item class (required), and {out} for item content. (default="
  • {out}
  • "). #pw-group-markup-options + * @property string $linkMarkup Link markup. Place {url} for href attribute, and {out} for label content. (default="{out}"). #pw-group-markup-options + * @property string $currentLinkMarkup Link markup for current page. Place {url} for href attribute and {out} for label content. (default="{out}"). #pw-group-markup-options + * @property string $nextItemLabel label used for the 'Next' button (default='Next'). #pw-group-label-options + * @property string $previousItemLabel label used for the 'Previous' button (default='Prev'). #pw-group-label-options + * @property string $separatorItemMarkup Markup to use for the "..." separator item, or NULL to use $itemMarkup (default=NULL). #pw-group-markup-options + * @property string $separatorItemLabel label used in the separator item (default='…'). #pw-group-label-options + * @property string $separatorItemClass Class for separator item (default='MarkupPagerNavSeparator'). #pw-group-class-options + * @property string $firstItemClass Class for first item (default='MarkupPagerNavFirst'). #pw-group-class-options + * @property string $firstNumberItemClass Class for first numbered item (default='MarkupPagerNavFirstNum'). #pw-group-class-options + * @property string $nextItemClass Class for next item (default='MarkupPagerNavNext'). #pw-group-class-options + * @property string $previousItemClass Class for previous item (default='MarkupPagerNavPrevious'). #pw-group-class-options + * @property string $lastItemClass Class for last item (default='MarkupPagerNavLast'). #pw-group-class-options + * @property string $lastNumberItemClass Class for last numbered item (default='MarkupPagerNavLastNum'). #pw-group-class-options + * @property string $currentItemClass Class for current item (default='MarkupPagerNavOn'). #pw-group-class-options + * @property string $listAriaLabel Label announcing pagination to screen readers (default='Pagination links'). #pw-group-label-options + * @property string $itemAriaLabel Label announcing page number to screen readers (default='Page {n}'). #pw-group-label-options + * @property string $currentItemAriaLabel Label announcing current page to screen readers (default='Page {n}, current page'). #pw-group-label-options + * @property-write bool $arrayToCSV When arrays are present in getVars, they will be translated to CSV strings in the queryString "?var=a,b,c". If set to false, then arrays will be kept in traditional format: "?var[]=a&var[]=b&var=c". (default=true) #pw-group-other-options + * @property int $totalItems Get total number of items to paginate (set automatically). #pw-group-other-options + * @property-read int $itemsPerPage Get number of items to display per page (set automatically, pulled from limit=n). #pw-group-other-options + * @property int $pageNum Get or set the current page number (1-based, set automatically). #pw-group-other-options + * @property string $queryString Get or set query string used in links (set automatically, based on $input->whitelist or getVars array). #pw-group-other-options + * @property-read bool $isLastPage Is the current pagination the last? Set automatically after a render() call. #pw-internal * * @method string render(WirePaginatable $items, $options = array()) * @@ -106,10 +141,16 @@ class MarkupPagerNav extends Wire implements Module { 'page' => null, // List container markup. Place {out} where you want the individual items rendered. - 'listMarkup' => "\n", + 'listMarkup' => "\n", + + // class attribute for