| 1029 | | // If 2 arguments are passed, acts as a getter. |
| 1030 | | // If a third argument is passed, acts as a setter. |
| | 1029 | // Handles normalized getting and setting of attributes on DOM |
| | 1030 | // Nodes. If 2 arguments are passed, and a the second argumnt is a |
| | 1031 | // string, acts as a getter. |
| | 1032 | // |
| | 1033 | // If a third argument is passed, or if the second argumnt is a |
| | 1034 | // map of attributes, acts as a setter. |
| | 1047 | // example: |
| | 1048 | // | // get the current value of the "foo" attribute on a node |
| | 1049 | // | dojo.attr(dojo.byId("nodeId"), "foo"); |
| | 1050 | // | |
| | 1051 | // | // we can just pass the id: |
| | 1052 | // | dojo.attr("nodeId", "foo"); |
| | 1053 | // | |
| | 1054 | // | // use attr() to set the tab index |
| | 1055 | // | dojo.attr("nodeId", "tabindex", 3); |
| | 1056 | // | |
| | 1057 | // | // set multiple values at once, including event handlers: |
| | 1058 | // | dojo.attr("formId", { |
| | 1059 | // | "foo": "bar", |
| | 1060 | // | "tabindex": -1, |
| | 1061 | // | "method": "POST", |
| | 1062 | // | "onsubmit": function(e){ |
| | 1063 | // | dojo.stopEvent(e); |
| | 1064 | // | // submit the form with Ajax |
| | 1065 | // | dojo.xhrPost({ form: "formId" }); |
| | 1066 | // | } |
| | 1067 | // | }); |
| | 1068 | |
| | 1069 | var args = arguments.length; |
| | 1070 | if(args == 2 && !dojo.isString(name)){ |
| | 1071 | for(var x in name){ dojo.attr(node, x, name[x]); } |
| | 1072 | return; |
| | 1073 | } |
| 1044 | | if(arguments.length == 3){ |
| 1045 | | if(typeof value == "function" || typeof value == "boolean"){ // e.g. onsubmit, disabled |
| | 1076 | if(args == 3){ |
| | 1077 | if(dojo.isFunction(value)){ |
| | 1078 | delete node[name]; // preserve clobbering behavior |
| | 1079 | // ensure that event objects are normalized, etc. |
| | 1080 | dojo.connect(node, name, value); |
| | 1081 | }else if(typeof value == "boolean"){ // e.g. onsubmit, disabled |
| | 1082 | // if a function, we should normalize the event object here!!! |