remove dom.setText, use classList, document.head
This commit is contained in:
parent
4b3f8a2a90
commit
ebe03bbe70
1 changed files with 74 additions and 60 deletions
|
|
@ -39,15 +39,28 @@ exports.createElement = function(tag, ns) {
|
||||||
document.createElement(tag);
|
document.createElement(tag);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setText = function(elem, text) {
|
if (typeof DOMTokenList === 'function') {
|
||||||
if (elem.innerText !== undefined) {
|
exports.hasCssClass = function(el, name) {
|
||||||
elem.innerText = text;
|
return el.classList.contains(name);
|
||||||
}
|
|
||||||
if (elem.textContent !== undefined) {
|
|
||||||
elem.textContent = text;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.addCssClass = function(el, name) {
|
||||||
|
el.classList.add(name);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.removeCssClass = function(el, name) {
|
||||||
|
el.classList.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.toggleCssClass = function(el, name) {
|
||||||
|
el.classList.toggle(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.setCssClass = function(el, name, include) {
|
||||||
|
el.classList[include ? 'add' : 'remove'](name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
exports.hasCssClass = function(el, name) {
|
exports.hasCssClass = function(el, name) {
|
||||||
var classes = el.className.split(/\s+/g);
|
var classes = el.className.split(/\s+/g);
|
||||||
return classes.indexOf(name) !== -1;
|
return classes.indexOf(name) !== -1;
|
||||||
|
|
@ -105,6 +118,7 @@ exports.setCssClass = function(node, className, include) {
|
||||||
exports.removeCssClass(node, className);
|
exports.removeCssClass(node, className);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
exports.hasCssString = function(id, doc) {
|
exports.hasCssString = function(id, doc) {
|
||||||
var index = 0, sheets;
|
var index = 0, sheets;
|
||||||
|
|
@ -143,7 +157,7 @@ exports.importCssString = function importCssString(cssText, id, doc) {
|
||||||
if (id)
|
if (id)
|
||||||
style.id = id;
|
style.id = id;
|
||||||
|
|
||||||
var head = doc.getElementsByTagName("head")[0] || doc.documentElement;
|
var head = doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
|
||||||
head.appendChild(style);
|
head.appendChild(style);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -156,7 +170,7 @@ exports.importCssStylsheet = function(uri, doc) {
|
||||||
link.rel = 'stylesheet';
|
link.rel = 'stylesheet';
|
||||||
link.href = uri;
|
link.href = uri;
|
||||||
|
|
||||||
var head = doc.getElementsByTagName("head")[0] || doc.documentElement;
|
var head = doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement;
|
||||||
head.appendChild(link);
|
head.appendChild(link);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -273,7 +287,7 @@ exports.getInnerText = function(el) {
|
||||||
if (document.body && "textContent" in document.body)
|
if (document.body && "textContent" in document.body)
|
||||||
return el.textContent;
|
return el.textContent;
|
||||||
else
|
else
|
||||||
return el.innerText || el.textContent || "";
|
return el.innerText;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getParentWindow = function(document) {
|
exports.getParentWindow = function(document) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue