Cleaned up elementPlace legacy code, no longer relys on elementCreate

This commit is contained in:
bluesaxman 2022-03-22 15:48:38 -06:00
parent 006f6e5ade
commit cfc60ebd1d

View File

@ -60,24 +60,21 @@ function elementMake (ID,Class,element) { //new and improved, I can use more tha
} }
function elementPlace (parentID, ID, Class, element, position) { function elementPlace (parentID, ID, Class, element, position) {
parentID = "string" == typeof parentID ? parentID.replace(/ /g,"_") : parentID; var newObject = document.createElement(element);
ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID; if ("string" == typeof Class) { newObject.setAttribute("class",Class); }
var newElement = elementMake(ID,Class,element); if ("string" == typeof ID) {
if ( (typeof document.querySelector(parentID).append && typeof document.querySelector(parentID).prepend) !== "undefined") { // Are we compliant? ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID;
if ("before" == position) { newObject.id = ID;
document.querySelector(parentID).prepend(newElement);
} else {
document.querySelector(parentID).append(newElement);
}
} else { //No? Ok we will use the old way.
if ("before" == position) {
var p = document.querySelector(parentID);
p.insertBefore(newElement,p.firstChild);
} else {
document.querySelector(parentID).appendChild(newElement);
}
} }
return newElement; parentID = "string" == typeof parentID ? parentID.replace(/ /g,"_") : parentID;
var p = document.querySelector(parentID);
var compliant = ( (typeof document.querySelector(parentID).append && typeof document.querySelector(parentID).prepend) !== "undefined"); // Are we compliant?
if ("before" == position) {
compliant ? p.prepend(newObject) : p.insertBefore(newObject, p.firstChild);
} else {
compliant ? p.append(newObject) : p.appendChild(newObject);
}
return newObject;
} }
function titledContainer (ParentID,ID,Class,Element,Position,Title) { function titledContainer (ParentID,ID,Class,Element,Position,Title) {