summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorEric Barnes <eric@ericlbarnes.com>2012-07-28 20:57:04 +0200
committerEric Barnes <eric@ericlbarnes.com>2012-07-28 20:57:04 +0200
commit62ab8b24fc37a25eab9205c46321fa41729e5faf (patch)
tree5afb35e82120a141fcaac6294d93783da38a8289 /system
parentd83e727d6deedded5b637e685accb4fac0dc3985 (diff)
Adding optional attributes as array or object for html helper
Diffstat (limited to 'system')
-rw-r--r--system/helpers/html_helper.php59
1 files changed, 40 insertions, 19 deletions
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 6fabf9c05..96234bb02 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -51,7 +51,7 @@ if ( ! function_exists('heading'))
*/
function heading($data = '', $h = '1', $attributes = '')
{
- return '<h'.$h.($attributes !== '' ? ' ' : '').$attributes.'>'.$data.'</h'.$h.'>';
+ return '<h'.$h._html_attributes_to_string($attributes).'>'.$data.'</h'.$h.'>';
}
}
@@ -119,23 +119,8 @@ if ( ! function_exists('_list'))
// Set the indentation based on the depth
$out = str_repeat(' ', $depth);
- // Were any attributes submitted? If so generate a string
- if (is_array($attributes))
- {
- $atts = '';
- foreach ($attributes as $key => $val)
- {
- $atts .= ' '.$key.'="'.$val.'"';
- }
- $attributes = $atts;
- }
- elseif (is_string($attributes) && strlen($attributes) > 0)
- {
- $attributes = ' '.$attributes;
- }
-
// Write the opening list tag
- $out .= '<'.$type.$attributes.">\n";
+ $out .= '<'.$type._html_attributes_to_string($attributes).">\n";
// Cycle through the list elements. If an array is
// encountered we will recursively call _list()
@@ -191,9 +176,10 @@ if ( ! function_exists('img'))
*
* @param mixed
* @param bool
+ * @param mixed
* @return string
*/
- function img($src = '', $index_page = FALSE)
+ function img($src = '', $index_page = FALSE, $attributes = '')
{
if ( ! is_array($src) )
{
@@ -229,7 +215,7 @@ if ( ! function_exists('img'))
}
}
- return $img.'/>';
+ return $img._html_attributes_to_string($attributes).'/>';
}
}
@@ -407,5 +393,40 @@ if ( ! function_exists('nbs'))
}
}
+if ( ! function_exists('_html_attributes_to_string'))
+{
+ /**
+ * Attributes To String
+ *
+ * Helper function used to convert array or object of attributes to a string
+ *
+ * @param mixed
+ * @param bool
+ * @return string
+ */
+ function _html_attributes_to_string($attributes)
+ {
+ if (is_object($attributes) && count($attributes) > 0)
+ {
+ $attributes = (array) $attributes;
+ }
+
+ if (is_array($attributes) && count($attributes) > 0)
+ {
+ $atts = '';
+ foreach ($attributes as $key => $val)
+ {
+ $atts .= ' '.$key.'="'.$val.'"';
+ }
+ return $atts;
+ }
+ elseif (is_string($attributes) && strlen($attributes) > 0)
+ {
+ return ' '.$attributes;
+ }
+
+ return $attributes;
+ }
+}
/* End of file html_helper.php */
/* Location: ./system/helpers/html_helper.php */ \ No newline at end of file