luci-base: luci.js: convert LuCI.dom to Class instance
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
344c4c5119
commit
26e54bb01f
1 changed files with 148 additions and 135 deletions
|
@ -653,14 +653,12 @@
|
||||||
halt: function() { return Request.poll.stop() },
|
halt: function() { return Request.poll.stop() },
|
||||||
run: function() { return Request.poll.start() },
|
run: function() { return Request.poll.start() },
|
||||||
|
|
||||||
Class: Class,
|
|
||||||
Request: Request
|
|
||||||
});
|
|
||||||
|
|
||||||
/* DOM manipulation */
|
/* DOM manipulation */
|
||||||
LuCI.prototype.dom = {
|
dom: Class.singleton({
|
||||||
|
__name__: 'LuCI.DOM',
|
||||||
|
|
||||||
elem: function(e) {
|
elem: function(e) {
|
||||||
return (typeof(e) === 'object' && e !== null && 'nodeType' in e);
|
return (e != null && typeof(e) == 'object' && 'nodeType' in e);
|
||||||
},
|
},
|
||||||
|
|
||||||
parse: function(s) {
|
parse: function(s) {
|
||||||
|
@ -751,7 +749,7 @@
|
||||||
attr = {}, attr[key] = val;
|
attr = {}, attr[key] = val;
|
||||||
|
|
||||||
for (key in attr) {
|
for (key in attr) {
|
||||||
if (!attr.hasOwnProperty(key) || attr[key] === null || attr[key] === undefined)
|
if (!attr.hasOwnProperty(key) || attr[key] == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (typeof(attr[key])) {
|
switch (typeof(attr[key])) {
|
||||||
|
@ -771,16 +769,27 @@
|
||||||
|
|
||||||
create: function() {
|
create: function() {
|
||||||
var html = arguments[0],
|
var html = arguments[0],
|
||||||
attr = (arguments[1] instanceof Object && !Array.isArray(arguments[1])) ? arguments[1] : null,
|
attr = arguments[1],
|
||||||
data = attr ? arguments[2] : arguments[1],
|
data = arguments[2],
|
||||||
elem;
|
elem;
|
||||||
|
|
||||||
if (this.elem(html))
|
if (!(attr instanceof Object) || Array.isArray(attr))
|
||||||
|
data = attr, attr = null;
|
||||||
|
|
||||||
|
if (Array.isArray(html)) {
|
||||||
|
elem = document.createDocumentFragment();
|
||||||
|
for (var i = 0; i < html.length; i++)
|
||||||
|
elem.appendChild(this.create(html[i]));
|
||||||
|
}
|
||||||
|
else if (this.elem(html)) {
|
||||||
elem = html;
|
elem = html;
|
||||||
else if (html.charCodeAt(0) === 60)
|
}
|
||||||
|
else if (html.charCodeAt(0) === 60) {
|
||||||
elem = this.parse(html);
|
elem = this.parse(html);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
elem = document.createElement(html);
|
elem = document.createElement(html);
|
||||||
|
}
|
||||||
|
|
||||||
if (!elem)
|
if (!elem)
|
||||||
return null;
|
return null;
|
||||||
|
@ -790,7 +799,11 @@
|
||||||
|
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
};
|
}),
|
||||||
|
|
||||||
|
Class: Class,
|
||||||
|
Request: Request
|
||||||
|
});
|
||||||
|
|
||||||
XHR = Class.extend({
|
XHR = Class.extend({
|
||||||
__name__: 'LuCI.XHR',
|
__name__: 'LuCI.XHR',
|
||||||
|
|
Loading…
Reference in a new issue