Add element manipulation to dom.js and fix createStyle

This commit is contained in:
chylex 2016-10-23 03:13:43 +02:00
parent c4f4180e76
commit 00e951076e

View File

@ -46,18 +46,35 @@ var DOM = (function(){
},
/*
* Creates a new style element with the specified CSS contents, and returns a function that deletes the element.
* Creates an element, adds it to the DOM, and returns it.
*/
createStyle: function(style){
createElement: function(tag, parent){
var ele = document.createElement(tag);
parent.appendChild(ele);
return ele;
},
/*
* Removes an element from the DOM.
*/
removeElement: function(ele){
ele.parentNode.removeChild(ele);
},
/*
* Creates a new style element with the specified CSS contents and returns it.
*/
createStyle: function(styles){
var ele = document.createElement("style");
ele.setAttribute("type", "text/css");
document.head.appendChild(ele);
ele.sheet.insertRule(style, 0);
return function(){
document.head.removeChild(ele);
};
styles.forEach(function(style){
ele.sheet.insertRule(style, 0);
});
return ele;
},
/*