PDA

View Full Version : DomQuery Select interest



javajunky
16 Jan 2007, 11:58 AM
I'm having some 'fun' with the 0.40 alpha, I understand this is 'bleeding edge' so I appreciate I may not get any 'help' on this issue. But really I just want a clarification on how I should expect it to work, I've got some markup in my page along the lines of :


<div id="tools">
Configuration (Config.aspx)
Diagnostics (Diagnose.aspx)
</div>


Which I want to convert to buttons with yui-ext. To do this I thought I could use a DomQuery selector to pull out these links and replace them automatically with buttons or templates or something ?
So I wrote the following basic code:


var tools = getEl('tools');
tools.select('a').each( function(el) {
alert(el.innerHTML);
el.remove();
} );


Expecting to be able to execute the 'el.remove()' and adding to the tools element a new button, however el.remove() fails. When I look with the debugger, this is because the select('a').each is passing a *real* Dom Element [in this case an instance of HTMLAnchorElement] into the callback, rather than a yui-ext Element, type object. Is this correct? The documentation isn't entirely clear on whether this should be the expected behaviour of a CompositeElement or not :( :


Calls the passed function passing (el, this, index) for each element in this composite.

I think I'm most probably doing something wrong, but I would appreciate a comment on whether its the right thing to do, should I be bothering to convert links to buttons, or should I just write out the buttons originally ? [/code]

tryanDLS
16 Jan 2007, 12:07 PM
Just guessing here since I haven't played with this at all, but if pass true as a 2nd arg to select(), you get CompositeElement, rather than the Lite version, which may allow you to operate on the individual items.

javajunky
16 Jan 2007, 12:30 PM
You sir, are a star! That appears to work as I would expect, however I would *never* have guessed this, as the documentation [at least the documentation I was working with!] labels the second parameter as: 'Boolean unique'. Is this because I'm looking at the wrong documentation?

tryanDLS
16 Jan 2007, 12:43 PM
No it's the same doc - the explanation goes on to say
'true to create a unique YAHOO.ext.Element for each child (defaults to a shared flyweight object)'
shared flyweight object means CompositeElementLite

It might have been clearer if it said 'defaults to false which uses a shared flyweight object').

javajunky
16 Jan 2007, 12:49 PM
Ah, my bad! Thanks for the help, s'all good now!

jack.slocum
20 Jan 2007, 6:36 AM
In the next release the Flyweight version has some enhancements, including each passing in the flyweight instead of the raw dom node. Event handlers with the flyweight version also work as expected.