From cfc60ebd1dbb51d1818607560c815e66a7dfefd7 Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Tue, 22 Mar 2022 15:48:38 -0600 Subject: [PATCH] Cleaned up elementPlace legacy code, no longer relys on elementCreate --- libs/bluecore.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/libs/bluecore.js b/libs/bluecore.js index 79a7d5e..3eb1f1d 100644 --- a/libs/bluecore.js +++ b/libs/bluecore.js @@ -60,24 +60,21 @@ function elementMake (ID,Class,element) { //new and improved, I can use more tha } function elementPlace (parentID, ID, Class, element, position) { - parentID = "string" == typeof parentID ? parentID.replace(/ /g,"_") : parentID; - ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID; - var newElement = elementMake(ID,Class,element); - if ( (typeof document.querySelector(parentID).append && typeof document.querySelector(parentID).prepend) !== "undefined") { // Are we compliant? - if ("before" == position) { - 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); - } + var newObject = document.createElement(element); + if ("string" == typeof Class) { newObject.setAttribute("class",Class); } + if ("string" == typeof ID) { + ID = "string" == typeof ID ? ID.replace(/ /g,"_") : ID; + newObject.id = ID; } - 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) {