/*
* Ext JS Library 2.2.1
* Copyright(c) 2006-2009, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext.DomHelper = function () {
var n = null;
var g = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i;
var b = /^table|tbody|tr|td$/i;
var a = function (w) {
if (typeof w == "string") {
return w
}
var q = "";
if (Ext.isArray(w)) {
for (var u = 0, r = w.length; u < r; u++) {
q += a(w[u])
}
return q
}
if (!w.tag) {
w.tag = "div"
}
q += "<" + w.tag;
for (var p in w) {
if (p == "tag" || p == "children" || p == "cn" || p == "html" || typeof w[p] == "function") {
continue
}
if (p == "style") {
var v = w.style;
if (typeof v == "function") {
v = v.call()
}
if (typeof v == "string") {
q += ' style="' + v + '"'
} else {
if (typeof v == "object") {
q += ' style="';
for (var t in v) {
if (typeof v[t] != "function") {
q += t + ":" + v[t] + ";"
}
}
q += '"'
}
}
} else {
if (p == "cls") {
q += ' class="' + w.cls + '"'
} else {
if (p == "htmlFor") {
q += ' for="' + w.htmlFor + '"'
} else {
q += " " + p + '="' + w[p] + '"'
}
}
}
}
if (g.test(w.tag)) {
q += "/>"
} else {
q += ">";
var x = w.children || w.cn;
if (x) {
q += a(x)
} else {
if (w.html) {
q += w.html
}
}
q += "</" + w.tag + ">"
}
return q
};
var o = function (v, q) {
var u;
if (Ext.isArray(v)) {
u = document.createDocumentFragment();
for (var t = 0, r = v.length; t < r; t++) {
o(v[t], u)
}
} else {
if (typeof v == "string") {
u = document.createTextNode(v)
} else {
u = document.createElement(v.tag || "div");
var s = !!u.setAttribute;
for (var p in v) {
if (p == "tag" || p == "children" || p == "cn" || p == "html" || p == "style" || typeof v[p] == "function") {
continue
}
if (p == "cls") {
u.className = v.cls
} else {
if (s) {
u.setAttribute(p, v[p])
} else {
u[p] = v[p]
}
}
}
Ext.DomHelper.applyStyles(u, v.style);
var w = v.children || v.cn;
if (w) {
o(w, u)
} else {
if (v.html) {
u.innerHTML = v.html
}
}
}
}
if (q) {
q.appendChild(u)
}
return u
};
var k = function (v, t, r, u) {
n.innerHTML = [t, r, u].join("");
var p = -1,
q = n;
while (++p < v) {
q = q.firstChild
}
return q
};
var l = "<table>",
e = "</table>",
c = l + "<tbody>",
m = "</tbody>" + e,
i = c + "<tr>",
d = "</tr>" + m;
var h = function (p, q, s, r) {
if (!n) {
n = document.createElement("div")
}
var t;
var u = null;
if (p == "td") {
if (q == "afterbegin" || q == "beforeend") {
return
}
if (q == "beforebegin") {
u = s;
s = s.parentNode
} else {
u = s.nextSibling;
s = s.parentNode
}
t = k(4, i, r, d)
} else {
if (p == "tr") {
if (q == "beforebegin") {
u = s;
s = s.parentNode;
t = k(3, c, r, m)
} else {
if (q == "afterend") {
u = s.nextSibling;
s = s.parentNode;
t = k(3, c, r, m)
} else {
if (q == "afterbegin") {
u = s.firstChild
}
t = k(4, i, r, d)
}
}
} else {
if (p == "tbody") {
if (q == "beforebegin") {
u = s;
s = s.parentNode;
t = k(2, l, r, e)
} else {
if (q == "afterend") {
u = s.nextSibling;
s = s.parentNode;
t = k(2, l, r, e)
} else {
if (q == "afterbegin") {
u = s.firstChild
}
t = k(3, c, r, m)
}
}
} else {
if (q == "beforebegin" || q == "afterend") {
return
}
if (q == "afterbegin") {
u = s.firstChild
}
t = k(2, l, r, e)
}
}
}
s.insertBefore(t, u);
return t
};
return {
useDom: false,
markup: function (p) {
return a(p)
},
applyStyles: function (r, s) {
if (s) {
r = Ext.fly(r);
if (typeof s == "string") {
var q = /\s?([a-z\-]*)\:\s?([^;]*);?/gi;
var t;
while ((t = q.exec(s)) != null) {
r.setStyle(t[1], t[2])
}
} else {
if (typeof s == "object") {
for (var p in s) {
r.setStyle(p, s[p])
}
} else {
if (typeof s == "function") {
Ext.DomHelper.applyStyles(r, s.call())
}
}
}
}
},
insertHtml: function (r, t, s) {
r = r.toLowerCase();
if (t.insertAdjacentHTML) {
if (b.test(t.tagName)) {
var q;
if (q = h(t.tagName.toLowerCase(), r, t, s)) {
return q
}
}
switch (r) {
case "beforebegin":
t.insertAdjacentHTML("BeforeBegin", s);
return t.previousSibling;
case "afterbegin":
t.insertAdjacentHTML("AfterBegin", s);
return t.firstChild;
case "beforeend":
t.insertAdjacentHTM
评论2
最新资源