actually i was using it for evaluating the first parameter as an
expression... (true,false). Then adopting the subsequent elements if
true...
I found this better than conditionals specifically when the adopt was
nested several elements in, for example:
var moo = true;
if(moo){
new Element('div').adopt(new Element('div'), new
Element('div').conditionalAdopt(moo, new Element('div'));
}
else{
new Element('div').adopt(new Element('div'), new Element('div'));
}
becomes instead:
var moo = true;
new Element('div').adopt(new Element('div'), new
Element('div').conditionalAdopt(moo, new Element('div'));
On Mar 30, 2:58 am, Barry van Oudtshoorn <[email protected]>
wrote:
> Well, writing
>
> myElem.conditionalAdopt(elema, elemb, elemc);
>
> is a couple of characters shorter than writing
>
> if (elema) {
> myElem.grab(elema);}
>
> if (elemb) {
> myElem.grab(elemb);}
>
> if (elemc) {
> myElem.grab(elemc);
>
> }
>
> (even when minified), so if you use this pattern a lot, it could pay off. :)
>
> Pragmatically, to reduce DOM manipulation, wouldn't this implementation
> of the function be somewhat more efficient:
>
> Element.implement({
> conditionalAdopt: function() {
> var els = [];
> $A(arguments).each(function(item) {
> item = document.id(item);
> if (item) els.push(item);
> }
> return this.adopt(els);
> }
>
> });
>
> On 30/03/2010 5:23 PM, Oskar Krawczyk wrote:
>
>
>
>
>
> > ... on the web where every byte counts.
>
> > Haven't heard anyone saying that since 1999 - you know, 56K modems and
> > all :-)
>
> > 2010/3/29 jacob <[email protected]
> > <mailto:[email protected]>>
>
> > Anyone ever implemented something like this? or have a nicer
> > way of
> > doing it?
>
> > http://mootools.net/shell/KPPNg/
>
> > Element.implement({
>
> > conditionalAdopt: function(){
> > if(Array.prototype.splice.apply(arguments,[0,1])[0]){
> > Array.flatten(arguments).each(function(element){
> > element = document.id
> > <http://document.id>(element, true);
> > if (element) this.appendChild(element);
> > }, this);
> > return this;
> > }
> > return this;
> > }
>
> > });
>
> > To unsubscribe from this group, send email to
> > mootools-users+unsubscribegooglegroups.com
> > <http://unsubscribegooglegroups.com> or reply to this email
> > with the words "REMOVE ME" as the subject.
>
> > To unsubscribe from this group, send email to
> > mootools-users+unsubscribegooglegroups.com
> > <http://unsubscribegooglegroups.com> or reply to this email with
> > the words "REMOVE ME" as the subject.
>
> > To unsubscribe from this group, send email to
> > mootools-users+unsubscribegooglegroups.com or reply to this email with
> > the words "REMOVE ME" as the subject.
>
> --
> Not sent from my Apple ?Phone
To unsubscribe from this group, send email to
mootools-users+unsubscribegooglegroups.com or reply to this email with the
words "REMOVE ME" as the subject.