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

Content deleted Content added
m rollback
m this should fix the builder functions
Line 1:
// <pre><nowiki>
 
function createEasyDomFunctionbuildEasyDomNamespace(namenamespace) {
var isType = function (o, t) { return typeof o == t };
var isBool = function (o) { return isType(o, typeof true); };
Line 14:
}
var isNode = function (o) { return isDefined(o) && o != null && isNumber(o.nodeType); }
 
// The tag names that will be created in the namespace
var tags = }[
"bdo",
"script",
"object", "param",
}"iframe",
"link", "meta",
"p", "pre",
"a",
"div", "span",
"ul", "ol", "li",
"img",
"hr",
"br",
"em", "strong", "sup", "sub", "tt", "abbr", "acronym",
"del", "ins", "cite", "blockquote",
"table", "tbody", "tfoot", "tr", "th", "td", "col", "colgroup", "caption",
"form", "input", "select", "option", "optgroup", "button",
"h1", "h2", "h3", "h4", "h5", "h6",
"label"
];
 
// Creates the DOM element
Line 100 ⟶ 122:
};
 
// ReturnCreate the function that creates new DOM elementselement builders
returnvar createDomElementBuilder = function (name) {
varreturn elem = createDomElementfunction(name); {
var elem.appendChild = createDomElement(childname);
 
// Process attribute hash, if any and skip the argument count returned
var firstChild = processDomAttributes(elem, arguments);
 
// Process the remaining children, if any
for (var i = firstChild; i < arguments.length; i++) {
var child = arguments[i];
if (child == null) {
continue;
}
// Convert any non-DOM nodes to text nodes with toString()
if (!isNode(child)) {
child = document.createTextNode(child.toString());
}
elem.appendChild(child);
}
// Convert any non-DOM nodes to text nodes with toString()
if (!isNode(child)) {
child = document.createTextNode(child.toString());
}
elem.appendChild(child);
}
 
return elem;
};
};
}
 
// Populate the namespace
var easyDomTags = [
if (isUndefined(namespace)) namespace = {};
"bdo",
for (var i in easyDomTagstags) {
"script",
namespace[tags[i]] = createDomElementBuilder(tags[i]);
"object", "param",
"iframe",}
"link", "meta",
"p", "pre",
"a",
"div", "span",
"ul", "ol", "li",
"img",
"hr",
"br",
"em", "strong", "sup", "sub", "tt", "abbr", "acronym",
"del", "ins", "cite", "blockquote",
"table", "tbody", "tfoot", "tr", "th", "td", "col", "colgroup", "caption",
"form", "input", "select", "option", "optgroup", "button",
"h1", "h2", "h3", "h4", "h5", "h6",
"label"
];
 
// Return the namespace for those relying on anonymous creation
var easyDom = {};
return namespace;
for (var i in easyDomTags) {
easyDom[easyDomTags[i]] = createEasyDomFunction(easyDomTags[i]);
}
 
// Build the Easy DOM functions in an anonymous namespace
easyDom = buildEasyDomNamespace();
 
// Namespace pollution
var easydom = easyDOM = easyDom;
var easyDOM = easyDom;
 
// </nowiki></pre>