[studs-user] studs.taglib.html.BaseInteractiveTag
Status: Beta
Brought to you by:
mojavelinux
|
From: Earnie B. <ea...@us...> - 2006-05-19 15:54:09
|
Dan,
I'm contemplating the following change. I've created a private helper
function _renderAttribute($attr, $label = null) that is used to return
the string for the attribute for use in renderStyleAttributes(),
renderMetaAttributes() and renderEventAttributes(). Its purpose is to
avoid the if constructs by placing the filters inside the helper
function. I'm interested in your comments before I submit the patch.
If the extended class does not support the additional attributes I've
added the rendering doesn't happen; i.e. a null string is returned from
_renderAttribute.
<diff file="studs/tablib/html/BaseInteractiveTag.php>
Index: BaseInteractiveTag.php
===================================================================
--- BaseInteractiveTag.php (revision 1)
+++ BaseInteractiveTag.php (working copy)
@@ -98,22 +98,10 @@
function renderStyleAttributes()
{
$styles = '';
+ $styles .= $this->_renderAttribute('style');
+ $styles .= $this->_renderAttribute('styleClass', 'class');
+ $styles .= $this->_renderAttribute('styleId', 'id');
- if (!is_null($this->style))
- {
- $styles .= ' style="' . $this->style . '"';
- }
-
- if (!is_null($this->styleClass))
- {
- $styles .= ' class="' . $this->styleClass . '"';
- }
-
- if (!is_null($this->styleId))
- {
- $styles .= ' id="' . $this->styleId . '"';
- }
-
return $styles;
}
@@ -121,15 +109,13 @@
{
$meta = '';
- if (!is_null($this->title))
- {
- $meta .= ' title="' . $this->title . '"';
- }
+ $meta .= $this->_renderAttribute('title');
+ $meta .= $this->_renderAttribute('target');
// NOTE: perhaps image tag should have an HtmlBaseImageTag parent?
- if (!is_null($this->alt) && (is_a($this, 'HtmlImageTag') ||
is_a($this, 'HtmlImgTag')))
+ if (is_a($this, 'HtmlImageTag') || is_a($this, 'HtmlImgTag'))
{
- $meta .= ' alt="' . $this->alt . '"';
+ $meta .= $this->_renderAttribute('alt');
}
return $meta;
@@ -138,18 +124,37 @@
function renderEventAttributes()
{
$events = '';
+ $events .= $this->_renderAttribute('onclick');
+ $events .= $this->_renderAttribute('onchange');
+ $events .= $this->_renderAttribute('onblur');
+ $events .= $this->_renderAttribute('ondblclick');
+ $events .= $this->_renderAttribute('onfocus');
+ $events .= $this->_renderAttribute('onkeydown');
+ $events .= $this->_renderAttribute('onkeypress');
+ $events .= $this->_renderAttribute('onkeyup');
+ $events .= $this->_renderAttribute('onmousedown');
+ $events .= $this->_renderAttribute('onmousemove');
+ $events .= $this->_renderAttribute('onmouseover');
+ $events .= $this->_renderAttribute('onmouseup');
- if (!is_null($this->onclick))
- {
- $events .= ' onclick="' . $this->onclick . '"';
- }
+ return $events;
+ }
- if (!is_null($this->onchange))
+ function _renderAttribute($attr, $label = null)
+ {
+ $ret = null;
+ if (isset($this->$attr))
{
- $events .= ' onchange="' . $this->onchange . '"';
+ if (!is_null($this->$attr))
+ {
+ if (is_null($label))
+ {
+ $label = $attr;
+ }
+ $ret = ' ' . $label .'="'. $this->$attr . '"';
+ }
}
-
- return $events;
+ return "$ret";
}
}
?>
</diff>
Earnie Boyd
http://shop.siebunlimited.com
|