[Prototype-core] DOM builder in Prototype core?

2007-02-06 Thread Tom Gregory
While I love the simplicity of the function, there is one workaround  
that I think needs to be considered.  IE does not allow the 'name'  
attribute to be changed after createElement() is called.

To quote MSDN: "The NAME attribute cannot be set at run time on  
elements dynamically created with the createElement method."
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/ 
dhtml/reference/properties/name_2.asp

Workarounds have been posted here:
http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name- 
attribute-in-internet-explorer/
http://alt-tag.com/blog/archives/2006/02/ie-dom-bugs/

May I suggest the following:

function Element(tagName, options) {
var el = null;
if (options.name) {
try {
document.createElement('<'+ tagName +' 
name="'+options.name+'">');
delete options.name;
} catch () {} //fails if not IE
}
el = el  || document.createElement(tagName)); //create if null

 return Element.extend(el).writeAttributes(options || {});
}


TAG

On Feb 6, 2007, at 7:56 AM, Mislav Marohnić wrote:

> Andrew: that two features bring us back to Dan's or mine  
> implementations and take out the lightweightness of Martin's  
> elegant solution.
>
> Martin: by all means, submit a patch with tests on the already  
> existing ticket:
> http://dev.rubyonrails.org/ticket/7476#comment:1
>
> Doing so will enable easy reviewing and comparing.
>
> -m
>
> On 2/6/07, Andrew Dupont <[EMAIL PROTECTED]> wrote:
>
> Martin, I like your implementation a lot (especially the
> Element.writeAttributes idea, which I think should be added no matter
> what) but it's missing two things I like most about Dan Webb's
> DOMBuilder:
>
> * Tags as method names.  Much easier to do x.DIV(foo, bar) than to do
> new Element("div", foo, bar).
> * Easy nesting (like "x.DIV( x.P ( x.SPAN() ) )").  DOMBuilder
> responds differently based on the number and types of arguments
> passed.
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] DOM builder in Prototype core?

2007-02-03 Thread Mislav Marohnić
I just submitted a simple DOM builder enhancement [1]. The framework is
currently strong on DOM manipulation, but for content updates it only relies
on innerHTML. What I always use in my projects is a simple wrapper around
createElement() and appendChild() DOM methods - recently I though it would
make a nice addition to the core.

Other DOM builders out there are script.aculo.us' [2], which is IMO too big
for core (what are those hacks for, anyway?); Vivabit DOM builder [3]
(original blog post currently unavailable); and Mochikit DOM [4], which is
huge and full-featured but we don't really need most of it.

Personally I think Dan's approach is most "Prototypish" and it also
generated a lot of blog buzz when it came out - it was exactly what most of
the people needed. Mine is similar, but without the method creation feature:
no html.DIV() or html.INPUT(), just plain ol' string arguments.

var form = $E('form',
  $E('div',
$E('input', {type : 'text', name : 'email'}),
$E('input', {type : 'text', name : 'password'}),
$E('input', {type : 'submit'})
  )
);

What do you think? Do you need it? Does it belong to core? If so, what
approach should we take?

--
Mislav

p.s. my patch in Trac still lacks attribute fixes for IE, I'm quite aware of
that... right now it's just proof of concept ;)


[1] http://dev.rubyonrails.org/ticket/7476
[2] http://dev.rubyonrails.org/browser/spinoffs/scriptaculous/src/builder.js
[3] http://ajaxian.com/archives/dom-builder-a-nicer-dom
[4] http://mochikit.com/doc/html/MochiKit/DOM.html

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---