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

Content deleted Content added
helper functions...
m rollback
Line 2:
 
function createEasyDomFunction(name) {
var isTypeboolType = function (o, t) { return typeof o == t }true;
var isBoolstringType = function (o) { return isType(o, typeof true); }'';
var isStringnumberType = function (o) { return isType(o, typeof ''); }0;
var isNumberfunctionType = typeof function (o) { return isType(o, typeof 0); };
var isFunction = function (o) { return isType(o, typeof function () {}); };
var isObject = function (o) { return isType(o, typeof new Object()); };
var isUndefined = function (o) { return isType(o, (function (x) { return typeof x })()); };
var isDefined = function (o) { return !isUndefined(o); }; // NOTE: null is "defined"
var isPrimitive = function (o) {
return isString(o) || isNumber(o) || isBool(o) || isFunction(o);
}
var isNode = function (o) { return isDefined(o) && o != null && isNumber(o.nodeType); }
 
// Creates the DOM element
Line 39 ⟶ 31:
// Invoke function callbacks and use their result as the value,
// unless the attribute name starts with "on" (i.e. an event handler)
if (isFunction(typeof attrValue) == functionType) {
// Use direct object property assignment for "on" attributes
// These properties will not be copied by Node.cloneNode
if (attrName.indexOf("on") == 0) {
elem[attrName] = attrValue;
Line 47 ⟶ 38:
}
 
// Invoke the callback otherwise, passing null for "this"
attrValue = attrValue.call(null, elem);
}
 
Line 57 ⟶ 48:
 
// Stringify non-string values
if (!isString(typeof attrValue) != stringType) {
attrValue = attrValue.toString();
}
Line 75 ⟶ 66:
}
 
// No attributes to process ifDetect null is theas first argument
if (args[0] == null) {
return 0;
}
 
// NoDetect attributesnon-objects to process if a "primitive" is theas first argument
ifvar firstArgType = typeof (isPrimitive(args[0])) {;
if (firstArgType == boolType ||
firstArgType == stringType ||
firstArgType == numberType ||
firstArgType == functionType) {
return 0;
}
 
// No attributes to process if aDetect DOM node isnodes theas first argument
if (isNode(typeof args[0].nodeType) != 'undefined') {
return 0;
}
 
// ProcessAssume thethat firstwe argument asgot a hash of attributes as the first arg...
var attrs = args[0];
for (var attrName in attrs) {
Line 113 ⟶ 108:
continue;
}
if (!isNode(typeof child).nodeType == 'undefined') {
// Convert any non-DOM nodes to text nodes with toString()
if (!isNode(child)) {
child = document.createTextNode(child.toString());
}