If I understand you correctly, I think createDOMFuncExt already
accomodates this:

CHECKBOX = createDOMFuncExt(null, "input", ["name"], { type: "checkbox" });
HIDDEN = createDOMFuncExt(null, "input", ["name", "value"], { type: "hidden" });

I'm using this to create SVG functions with required parameters (such
as 'x' and 'y' coordinates and similar).

Cheers,

/Per

On Thu, Jun 12, 2008 at 6:13 PM, machineghost <[EMAIL PROTECTED]> wrote:
>
> I really like your idea of making the creation of the input functions
> more generalized.  However, if we wanted to preserve the:
> CHECKBOX("myNameIsBox1") ==
> <input type="checkbox" name="myNameIsBox1"/>
> functionality we'd need a slight modification to createDOMFuncExt.
> Specifically, we'd need one more argument that let's you specify a
> "default attribute"; if a default attribute was specified and a
> createDOMFuncExt function was only passed a single scalar (string or
> number) argument, it would treat it as if it had been passed
> {*defaultAttribute*:arguments[0]}; here's a quick (untested) draft of
> what I mean ...
>
> MochiKit.DOM.createDOMFuncExt = function(ns, tag, args, attrs,
> defaultAttr/*, ...*/) {
>    args = args || [];
>    attrs = attrs || {};
>    var children = MochiKit.Base.extend([], arguments, 4);
>    return function(/*arg1, ..., argN, attrs, ...*/) {
>        var myAttrs = MochiKit.Base.update({}, attrs);
>        for (var pos = 0; pos < args.length; pos++) {
>            if (arguments[pos] == null) {
>                throw new Error("Argument '" + args[pos] + "' cannot
> be null");
>            }
>            myAttrs[args[pos]] = arguments[pos];
>        }
>        if(arguments.length == 1 && typeof(defaultArgument) !=
> undefined &&
>            (typeof(arguments[0]) == "string" || typeof(arguments[0])
> == "number")) {
>            myAttrs[defaultArgument] = arguments[0];
>            return MochiKit.DOM.createDOMExt(ns, tag, myAttrs);
>       } else {
>            MochiKit.Base.update(myAttrs, arguments[args.length]);
>            var myChildren = MochiKit.Base.extend([], children);
>            MochiKit.Base.extend(myChildren, arguments, args.length +
> 1);
>            return MochiKit.DOM.createDOMExt(ns, tag, myAttrs,
> myChildren);
>    }
> }
>
> If we had that, then we could do:
>    HIDDEN = createDOMFuncExt(null, "input", null, { type: "hidden" },
> "name");
>    CHECKBOX = createDOMFuncExt(null, "input", null, { type:
> "checkbox" }, "name");
> and even:
>    FORMBUTTON = createDOMFuncExt(null, "input", null, { type:
> "button" }, "value");
>    SUBMIT = createDOMFuncExt(null, "input", null, { type: "button" },
> "value");
> since buttons and submits generally don't have names as often as the
> INPUTs that actually receive input.
>
> We could even go further down this path, and make defaultArgument in
> to defaultArguments, an array of default arguments that would get set
> if the arguments length was the number of default arguments or less
> and all arguments were scalar.  If we did that we, could even do:
>    HIDDEN = createDOMFuncExt(null, "input", null, { type: "hidden" },
> ["name", "value"]);
> and then do:
> HIDDEN("myName", "myValue");
>
> On the flip side, I don't know that we really *need* any shorthand
> syntax at all.  I just think the syntax is cool in the createDOM
> functions, and could be similarly cool for the createINPUTs.  I mean,
> which looks better:
>
> 1) var a = INPUT({"type":"hidden", "name":"myName",
> "value":"myValue"});
>
> 2) var a = HIDDEN({"name":"myName", "value":"myValue"});
>
> 3) var a = HIDDEN("myName", "myValue");
>
> Personally, I'd much rather have #3 in my code, especially if I'm
> making a lot of INPUTs at the same time.
>
> Jeremy
>
> On Jun 11, 12:05 am, "Per Cederberg" <[EMAIL PROTECTED]> wrote:
>> The tab indentation is now fixed in svn trunk [1384].
>>
>> Regarding the createINPUT and createINPUTFunc functions, I think it
>> would be better with a more generic solution. When creating SVG DOM
>> nodes I wrote a createDOMFuncExt function that should work here also.
>> Seehttp://trac.mochikit.com/wiki/MochiKitDOMExtensionsfor the source
>> code.
>>
>> Using that function, the partial versions would instead look like:
>>
>>   FORMBUTTON = createDOMFuncExt(null, "input", null, { type: "button" });
>>   CHECKBOX = createDOMFuncExt(null, "input", null, { type: "checkbox" });
>>
>> Or if you think form elements should always be provided with a name 
>> attribute:
>>
>>   FORMBUTTON = createDOMFuncExt(null, "input", ["name"], { type: "button" });
>>   CHECKBOX = createDOMFuncExt(null, "input", ["name"], { type: "checkbox" });
>>
>> Either way, I'd like to push this to MochiKit 1.5. I'm currently
>> mostly doing bug fixes in svn trunk so that we can get to a release of
>> 1.4 as soon as possible.
>>
>> Cheers,
>>
>> /Per
>>
>> On Tue, Jun 10, 2008 at 10:37 PM, machineghost <[EMAIL PROTECTED]> wrote:
>>
>> > I mentioned the idea of a createINPUT function awhile ago, but no one
>> > seemed terribly interested so I've been slacking on submitting it.
>> > However, I think a lot of createDOM fans could find createINPUT
>> > similarly useful, and with the recent flurry of submissions I figured
>> > now was as good of a time as any to submit it.
>>
>> > For those of you who missed my previous posts, the idea behind
>> > createINPUT (and all of its partial versions) is to do the same thing
>> > for the different sub-types of INPUT that createDOM did for every
>> > other element, as these sub-types are practically different elements.
>>
>> > So, with (the various partial forms of) createINPUT, you can do stuff
>> > like:
>>
>> > var oldWay = INPUT({"type":"hidden"});
>> > var newWay = HIDDEN();
>> > // oldWay.outerHTML == newWay.outerHTML
>>
>> > var oldWay2 = INPUT({"type":"text", "name":"someName"});
>> > var newWay2 = TEXT("someName");
>> > // oldWay2.outerHTML == newWay2.outerHTML
>>
>> > var oldWay2 = INPUT({"type":"checkbox", "name":"someName",
>> > "class":"someClass"});
>> > var newWay2 = CHECKBOX({"name":"someName", "class":"someClass"});
>> > // oldWay2.outerHTML == newWay2.outerHTML
>>
>> > Since there is already an HTML element called button, I named the
>> > <INPUT type="button"> function "FORMBUTTON"; the rest of the aliases
>> > are just their type .toUpperCase().
>>
>> > Here's the diff:
>> > 32a33,34
>> >>     "createINPUT",
>> >>     "createINPUTFunc",
>> > 83a86,95
>> >>     "FORMBUTTON",
>> >>     "CHECKBOX",
>> >>     "FILE",
>> >>     "HIDDEN",
>> >>     "IMAGE",
>> >>     "PASSWORD",
>> >>     "RADIO",
>> >>     "RESET",
>> >>     "TEXT",
>> >>     "SUBMIT",
>> > 627a640,658
>>
>> >>     /** @id MochiKit.DOM.createINPUTFunc */
>> >>     createINPUT: function (type, otherattrs) {
>> >>         var m = MochiKit.Base;
>> >>         if (typeof(otherattrs) == "string" || typeof(otherattrs) == 
>> >> "number")
>> >>             return MochiKit.DOM.createDOM("input", {"name":otherattrs, 
>> >> "type":type});
>> >>         return MochiKit.DOM.createDOM("input", m.update(otherattrs, 
>> >> {"type":type}));
>>
>> >>     },
>>
>> >>     /** @id MochiKit.DOM.createINPUTFunc */
>> >>     createINPUTFunc: function (/* type, otherattrs */) {
>> >>         var m = MochiKit.Base;
>> >>         return m.partial.apply(
>> >>             this,
>> >>             m.extend([MochiKit.DOM.createINPUT], arguments)
>> >>         );
>>
>> >>     },
>> > 1254a1286,1306
>> >>         var createINPUTFunc = this.createINPUTFunc;
>> >>         /** @id MochiKit.DOM.FORMBUTTON =  */
>> >>         this.FORMBUTTON = createINPUTFunc("button");
>> >>         /** @id MochiKit.DOM.CHECKBOX */
>> >>         this.CHECKBOX = createINPUTFunc("checkbox");
>> >>         /** @id MochiKit.DOM.FILE */
>> >>         this.FILE = createINPUTFunc("file");
>> >>         /** @id MochiKit.DOM.HIDDEN */
>> >>         this.HIDDEN = createINPUTFunc("hidden");
>> >>         /** @id MochiKit.DOM.IMAGE */
>> >>         this.IMAGE = createINPUTFunc("image");
>> >>         /** @id MochiKit.DOM.PASSWORD */
>> >>         this.PASSWORD = createINPUTFunc("password");
>> >>         /** @id MochiKit.DOM.RADIO */
>> >>         this.RADIO = createINPUTFunc("radio");
>> >>         /** @id MochiKit.DOM.RESET */
>> >>         this.RESET = createINPUTFunc("reset");
>> >>         /** @id MochiKit.DOM.TEXT */
>> >>         this.TEXT = createINPUTFunc("text");
>> >>         /** @id MochiKit.DOM.SUBMIT */
>> >>         this.SUBMIT = createINPUTFunc("submit");
>>
>> > Also, while I was working in DOM.js I noticed that the entire file
>> > uses spaces, EXCEPT for three tabs; the following diff converts these
>> > tabs to spaces:
>> > 1181c1212
>> > <               /** @id MochiKit.DOM.DL */
>> > ---
>> >>         /** @id MochiKit.DOM.DL */
>> > 1183c1214
>> > <               /** @id MochiKit.DOM.DT */
>> > ---
>> >>         /** @id MochiKit.DOM.DT */
>> > 1185c1216
>> > <               /** @id MochiKit.DOM.DD */
>> > ---
>> >>         /** @id MochiKit.DOM.DD */
> >
>

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

Reply via email to