At the moment even when using the programmatic syntax, the div (or any other DOM element with an ID needs to be present in the markup). This is due to what I think is a limitation with Zend_Dojo_View_Helper_Dojo (feel free to correct me) where the following code is used in programmatic mode:
Just a couple of quick questions - for tooltips to work they must be declared in a <div> ? Or is this part of my second question - which is the code is designed to work for declarative syntax only?
dojo.addOnLoad(function() { dojo.forEach(zendDijits, function(info) { var n = dojo.byId(info.id); if (null != n) { dojo.attr(n, dojo.mixin({ id: info.id }, info.params)); } }); dojo.parser.parse(); }); So, even with programmatic syntax in use, the dojo view helper looks for a DOM element to attach the functionality to. This is the sole reason I had to put an empty div in the helper.I am sure this will be improved in future releases when it becomes apparent that a fair few dijits do not require any markup whatsoever when used in programmatic mode.
Perhaps, and I have not thought this through at all, the programmatic syntax should use constructors instead of attaching attributes to DOM nodes. This would be fine for Tooltip except that the view helper would need to know in advance whether declarative mode is enabled or not (and this may change even after the helper is called). Also, even in programmatic mode the dijit form helpers must return markup.
I will think about this further if I get some time.
My next step is to use this View Helper within a Zend_Form decorator (or a Dojo_Form) pulling in the description element - does this sound reasonable?I can't think of any reason why not off the top of my head. Let me know if you get it working well.
Daniel
Steven wrote:
Daniel,
Thanks alot for this - its helped me get a better idea about how the Dojo integration works, plus it does exactly what I was hoping for.
Just a couple of quick questions - for tooltips to work they must be declared in a <div> ? Or is this part of my second question - which is the code is designed to work for declarative syntax only?
My next step is to use this View Helper within a Zend_Form decorator (or a Dojo_Form) pulling in the description element - does this sound reasonable?
Cheers,
Steve
On Sat, Oct 18, 2008 at 7:28 PM, Daniel Skinner <skinner@destiny-denied.co.uk> wrote:
Steven,
I have a working example for you. The following code will allow you to create dijit.Tooltip elements:
<?php
class My_View_Helper_Tooltip extends Zend_Dojo_View_Helper_Dijit$html = '<div' . $this->_htmlAttribs($attribs) . '>'
{
protected $_dijit = 'dijit.Tooltip';
protected $_module = 'dijit.Tooltip';
public function tooltip($id, $value = null, array $params = array(), array $attribs = array())
{
$attribs = $this->_prepareDijit($attribs, $params, null);
. $value
. "</div>\n";
return $html;
}
}
/* and in your view scripts */
<?php echo $this->tooltip('test', null, array(
'connectId' => 'username',
'label' => 'My Tooltip',
), array(
'id' => 'test'
)); ?>
This is far from an ideal solution but it's a good start.
Matthew and others: Any comments on how to refactor this into something worthy?
A few concerns:
* The div markup still needs to be created even when using
programmatic otherwise the main dojo helper will not attach the
params.
* The method signature for Tooltip::tooltip can definately be
tidied. $value makes no sense for a start
* The client code in the view script currently requires
$attribs['id'] to be set. This could be tidied away in the method.
Daniel
Daniel Skinner wrote:
Ok. Tooltip should be quite simple. Take a look at one of the current dijit implementations:
class Zend_Dojo_View_Helper_Textarea extends Zend_Dojo_View_Helper_Dijit
{
protected $_dijit = 'dijit.form.Textarea';
protected $_module = 'dijit.form.Textarea';
public function textarea($id, $value = null, array $params = array(), array $attribs = array())
{
...
}
}
So, with absolutely no pre-thought to if this will actually work, I would start out with:
class My_Dojo_View_Helper_Tooltip extends Zend_Dojo_View_Helper_Dijit
{
protected $_dijit = 'dijit.Tooltip';
protected $_module = 'dijit.Tooltip';
public function tooltip($id, $value = null, array $params = array(), array $attribs = array())
{
$attribs = $this->_prepareDijit($attribs, $params, null);
/* Output div dojoType="dijit.Tooltip" markup here only if use declarative */
}
}
Daniel
Steven wrote:
I wasnt thinking of anything that ambitious - I don't really know alot about JavaScript hence my interest in ZFs Dojo implementation.
I was hoping to implement digit.tooltip, dojox.analytics - and maybe some type of carousell.
Steve
On Sat, Oct 18, 2008 at 5:51 PM, Daniel Skinner <skinner@destiny-denied.co.uk <mailto:skinner@destiny-denied.co.uk>> wrote:
What dijits are you looking to implement specifically?
Take a look at Zend_Dojo_View_Helper_Dijit. This is the base
class you will be extending from.
A few of us are in the early states of proposing dijit.Tree,
dojo(X) data stores and DnD components. Let us know if that
compliments your interests.
Daniel
Steven wrote:
Hi there,
I'm not that familiar with Dojo but would like to implement
View Helpers for some of the other Dijits not currently
included with ZF - however the manual doesn't really outline
the specifics for doing so. Can anyone help me out?
Cheers
Steve
没有评论:
发表评论