View Full Version : getEls and cssQuery
jamaljohnson
1 Dec 2006, 5:19 PM
i'm trying to make getEls use cssQuery. i have cssQuery included before yui-ext, and i'm doing this:
YAHOO.log("not: "+getEls("img[tooltip]").length, "warn");
YAHOO.log("css: "+cssQuery("img[tooltip]").length, "warn");
the cssQuery one outputs the correct number, and getEls says 'undefined'. what am i doing wrong?
thanx...[/code]
arnair
1 Dec 2006, 11:45 PM
getEls(...) returns a CompositeElement(Lite), and 'length' is not a valid attribute. You may want to try getEls(...).elements.length.
jack.slocum
2 Dec 2006, 5:15 AM
Make sure you look at the docs for CompositeElement(Lite). I think you may like them much better than an Array!
jamaljohnson
3 Dec 2006, 11:50 AM
thanx!
jamaljohnson
3 Dec 2006, 12:30 PM
sorry, one more question. thought i read somewhere about allowing this stuff to use a 'light' version (reusing object) vs a few other types of implementations. i can't find the documentation for getEls so was wondering how it's used and how you can set it to use the diff types of implementations, faster vs slower etc... thanx again!
jack.slocum
3 Dec 2006, 2:25 PM
getEls uses the "lite" version by default. If you pass true as the second parameter, it creates the standard non-"lite" version. The time when you would want to use the standard version is when you attaching event handlers or you are referencing "this" for the element somewhere. If you are just setting properties (i.e. setWidth(100)) then the lite version is faster.
In my tests I can create 10,000 Element objects in under 500 milliseconds, so performance is always pretty good.
jamaljohnson
3 Dec 2006, 2:54 PM
so this is what i'm doing:
getEls( ((query)?query:"[tooltip]"), ((target)?target.contentWindow:null) ).addHandler(
"mouseover", true, this.mouseOver, this, true ).addHandler(
"mouseout", true, this.mouseOut, this, true );
as you can see, i'm attaching handlers so i'm gonna want to use the non-lite one i suppose.
given that, the second parameter for cssQuery is an optional 'target' to do the selector query on. so do i pass 'true' as the _third_ parameter after the target?
tryanDLS
3 Dec 2006, 3:10 PM
It doesn't look like that's supported yet. In the interim, can you split into 2 pieces?
1) call cssQuery to get an arary passing (selector, target)
2) call getEls passing the array and true
jack.slocum
3 Dec 2006, 5:39 PM
target is generally for querying xml documents and it not supported by Element anyway. What exactly are you trying to do?
jamaljohnson
3 Dec 2006, 10:22 PM
i'm actually doing some refactoring.... but basically we've used cssQuery in the past to attach events to objects that are in an iframe embedded in a page, and the iframe.contentWindow.document being the target so cssQuery knows where to start from.
jack.slocum
4 Dec 2006, 5:30 AM
Ah, yeah that will bomb. yui-ext uses YAHOO.util.Dom.get() in the background and it uses the current document.
jamaljohnson
4 Dec 2006, 8:53 AM
since cssQuery allows a target to be passed in, will getEls() support this in the future? for now at least, i'll just use cssQuery.
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.