From b034d9d8690d629bb079078ba3e361046d131ae3 Mon Sep 17 00:00:00 2001 From: Harold Putman Date: Mon, 1 Oct 2012 12:14:57 -0400 Subject: [PATCH 1/3] Twitter Bootstrap Compatibility Wrap inactive elements in span (current page, prev/next buttons at ends of range). --- lib/Cake/View/Helper/PaginatorHelper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index 252aea8a4..a42b23c6c 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -471,10 +471,10 @@ class PaginatorHelper extends AppHelper { $url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url); if ($this->{$check}($model)) { - return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape', 'model'))), compact('class')); + return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape'))), compact('class')); } else { unset($options['rel']); - return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class'))); + return $this->Html->tag($tag, $this->Html->tag('span', $title, compact('escape')), array_merge($options, compact('class'))); } } @@ -714,7 +714,7 @@ class PaginatorHelper extends AppHelper { if ($class) { $currentClass .= ' ' . $class; } - $out .= $this->Html->tag($tag, $params['page'], array('class' => $currentClass)); + $out .= $this->Html->tag($tag, $this->Html->tag('span', $params['page']), array('class' => $currentClass)); if ($i != $params['pageCount']) { $out .= $separator; } @@ -747,7 +747,7 @@ class PaginatorHelper extends AppHelper { if ($class) { $currentClass .= ' ' . $class; } - $out .= $this->Html->tag($tag, $i, array('class' => $currentClass)); + $out .= $this->Html->tag($tag, $this->Html->tag('span',$i), array('class' => $currentClass)); } else { $out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class')); } From ed2f7013c993cc7175b85215c4d1668f03a613a6 Mon Sep 17 00:00:00 2001 From: Harold Putman Date: Mon, 1 Oct 2012 14:20:49 -0400 Subject: [PATCH 2/3] More Flexible Paginator Zurb foundation expects pagination links wrapped in anchor tags even on the current page. This seems like a safer approach. --- lib/Cake/View/Helper/PaginatorHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index a42b23c6c..0049bcb74 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -474,7 +474,7 @@ class PaginatorHelper extends AppHelper { return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape'))), compact('class')); } else { unset($options['rel']); - return $this->Html->tag($tag, $this->Html->tag('span', $title, compact('escape')), array_merge($options, compact('class'))); + return $this->Html->tag($tag, ''.h($title).'', array_merge($options, compact('class'))); } } @@ -714,7 +714,7 @@ class PaginatorHelper extends AppHelper { if ($class) { $currentClass .= ' ' . $class; } - $out .= $this->Html->tag($tag, $this->Html->tag('span', $params['page']), array('class' => $currentClass)); + $out .= $this->Html->tag($tag, ''.$params['page'].'', array('class' => $currentClass)); if ($i != $params['pageCount']) { $out .= $separator; } @@ -747,7 +747,7 @@ class PaginatorHelper extends AppHelper { if ($class) { $currentClass .= ' ' . $class; } - $out .= $this->Html->tag($tag, $this->Html->tag('span',$i), array('class' => $currentClass)); + $out .= $this->Html->tag($tag, "$i", array('class' => $currentClass)); } else { $out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class')); } From 6f238a40480e1d5de2e8471d2acd7f0adb865fcd Mon Sep 17 00:00:00 2001 From: Harold Putman Date: Tue, 2 Oct 2012 08:39:25 -0400 Subject: [PATCH 3/3] Framework-compatible breadcrumbs Add new options to getCrumbList to allow it to be used to make breadcrumbs in Twitter Bootstrap or Zurb foundation. Follows the model of PaginatorHelper --- lib/Cake/View/Helper/HtmlHelper.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index fb53cf340..194bc31c3 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -681,6 +681,11 @@ class HtmlHelper extends AppHelper { * similar to HtmlHelper::getCrumbs(), so it uses options which every * crumb was added with. * + * ### Options + * - 'separator' Separator content to insert in between breadcrumbs, defaults to '»' + * - 'firstClass' Class for wrapper tag on the first breadcrumb, defaults to 'first' + * - 'lastClass' Class for wrapper tag on current active page, defaults to 'last' + * * @param array $options Array of html attributes to apply to the generated list elements. * @param string|array|boolean $startText This will be the first crumb, if false it defaults to first crumb in array. Can * also be an array, see `HtmlHelper::getCrumbs` for details. @@ -688,6 +693,12 @@ class HtmlHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper */ public function getCrumbList($options = array(), $startText = false) { + $defaults = array('firstClass'=>'first', 'lastClass'=>'last', 'separator' => ''); + $options += $defaults; + $firstClass = $options['firstClass']; + $lastClass = $options['lastClass']; + $separator = $options['separator']; + unset($options['firstClass'], $options['lastClass'], $options['separator']); $crumbs = $this->_prepareCrumbs($startText); if (!empty($crumbs)) { $result = ''; @@ -701,9 +712,12 @@ class HtmlHelper extends AppHelper { $elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]); } if ($which == 0) { - $options['class'] = 'first'; + $options['class'] = $firstClass; } elseif ($which == $crumbCount - 1) { - $options['class'] = 'last'; + $options['class'] = $lastClass; + } + if (!empty($separator) && ($crumbCount - $which >= 2)) { + $elementContent .= $separator; } $result .= $this->tag('li', $elementContent, $options); }