From a44cf574132ae9332ab68ddbcda8849e3e71c54b Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 12 Jul 2012 11:50:46 +0100 Subject: Added data-ci-pagination-page="x" to pagination output so JS frameworks can hook on. --- system/libraries/Pagination.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'system/libraries/Pagination.php') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 75745dd48..ed9964590 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -70,6 +70,7 @@ class CI_Pagination { protected $_attributes = ''; protected $_link_types = array(); protected $reuse_query_string = FALSE; + protected $data_page_attr = 'data-ci-pagination-page'; /** * Constructor @@ -234,6 +235,8 @@ class CI_Pagination { // Unset the controll, method, old-school routing options unset($get['c'], $get['m'], $get[$this->query_string_segment]); + if ( ! $get) $get = array(); + // Put everything else onto the end $query_string = (strpos($this->base_url, '&') !== FALSE ? '&' : '?') . http_build_query($get, '', '&'); @@ -245,7 +248,11 @@ class CI_Pagination { if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { $first_url = ($this->first_url === '') ? $this->base_url : $this->first_url; - $output .= $this->first_tag_open.'_attributes.$this->_attr_rel('start').'>' + + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); + + $output .= $this->first_tag_open.'_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; } @@ -254,15 +261,18 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page; + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + if ($i === $base_page && $this->first_url !== '') { - $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } else { $append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix; - $output .= $this->prev_tag_open.'_attributes.$this->_attr_rel('prev').'>' + $output .= $this->prev_tag_open.'_attr_rel('prev').'>' .$this->prev_link.''.$this->prev_tag_close; } @@ -275,6 +285,10 @@ class CI_Pagination { for ($loop = $start -1; $loop <= $end; $loop++) { $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page; + + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + if ($i >= $base_page) { if ($this->cur_page === $loop) @@ -286,13 +300,13 @@ class CI_Pagination { $n = ($i === $base_page) ? '' : $i; if ($n === '' && ! empty($this->first_url)) { - $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } else { $append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix; - $output .= $this->num_tag_open.'_attributes.$this->_attr_rel('start').'>' + $output .= $this->num_tag_open.'_attr_rel('start').'>' .$loop.''.$this->num_tag_close; } } @@ -305,7 +319,10 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page; - $output .= $this->next_tag_open.'_attributes + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + + $output .= $this->next_tag_open.'_attr_rel('next').'>'.$this->next_link.''.$this->next_tag_close; } @@ -314,7 +331,10 @@ class CI_Pagination { { $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - $output .= $this->last_tag_open.'_attributes.'>' + // Take the general parameters, and squeeze this pagination-page attr in there for JS fw's + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + + $output .= $this->last_tag_open.'' .$this->last_link.''.$this->last_tag_close; } -- cgit v1.2.3-24-g4f1b