User:Mike Dillon/Scripts/easydom.js: Difference between revisions

Content deleted Content added
m skip nulls passed to easyDOM functions
m make this stuff work with booleans and numbers as children and attribute values
Line 2:
 
function createEasyDomFunction(name) {
var boolType = typeof true;
var stringType = typeof '';
var numberType = typeof 0;
var functionType = typeof function() {};
 
Line 46 ⟶ 48:
if (attrValue == null) {
return;
}
 
// Stringify non-string values
if (typeof attrValue != stringValue) {
attrValue = attrValue.toString();
}
 
Line 62 ⟶ 69:
}
 
// Detect stringnull argumentsas first argument
var firstArgType = typeofif (args[0]; == null) {
if (firstArgType == stringType) {
return 0;
}
 
// Detect functionnon-objects argumentsas first argument
ifvar (firstArgType == functionType)typeof {args[0];
if (firstArgType == boolType ||
if ( firstArgType == stringType) {||
firstArgType == numberType ||
firstArgType == functionType) {
return 0;
}
 
// Detect DOM nodes as first argument
if (typeof args[0].nodeType != 'undefined') {
return 0;
Line 101 ⟶ 111:
continue;
}
if (typeof child.nodeType == stringType'undefined') {
child = document.createTextNode(child.toString());
}
elem.appendChild(child);