Content deleted Content added
Mike Dillon (talk | contribs) mNo edit summary |
Mike Dillon (talk | contribs) modularize attribute handling; skip nulls after evalation of function-valued attributes |
||
Line 3:
function createEasyDomFunction(name) {
var stringType = typeof '';
var functionType = typeof function() {};
// Detects if the first element is a hash of attributes and if so,
return function() {▼
// uses it to set attributes on the DOM node
var elem = document.createElement(name);▼
//
// Returns the number of elements processed to let the caller know
// how many of the arguments to skip
var processAttributes = function(elem, args) {
return 0;
}
var firstArgType = typeof args[0];
if (firstArgType == stringType) {
return 0;
}
if (
}
// Detect DOM
return
▲ if (attrValue == null) {
// Assume that we got a hash of attributes as the first
var attrs =
for (var attrName in attrs) {
var
// Invoke functions and use their result as
if (typeof attrValue ==
elem.setAttribute(attrName, attrValue);▼
}
if (attrValue == null) {
continue;
}
// Set the attribute
}
// Return the number of arguments processed
return 1;
};
▲ return function() {
▲ var elem = document.createElement(name);
// Process attribute hash, if any and skip the argument count returned
var firstChild = processAttributes(elem, arguments);
// Process the remaining children, if any
for (var i = firstChild; i < arguments.length; i++) {
var child = arguments[i];
|