Skip to content

Commit

Permalink
Merge pull request #67 from larsyngvelundin/remove-logs
Browse files Browse the repository at this point in the history
Comment all logs
  • Loading branch information
larsyngvelundin authored Jul 5, 2024
2 parents 8cce4d6 + a127792 commit 647112e
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 84 deletions.
18 changes: 9 additions & 9 deletions conditions_form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
console.log("Loaded script");
// // console.log("Loaded script");

async function startInForm() {
await waitForElm(".form-all");
Expand Down Expand Up @@ -31,7 +31,7 @@ async function startInForm() {
let calculations = JotForm.calculations;

for (let iCon = 0; iCon < conditions.length; iCon++) {
console.log(`Condition ${iCon}`, conditions[iCon]);
// console.log(`Condition ${iCon}`, conditions[iCon]);
var conditionLi = getConditionLi(conditions[iCon], iCon);
conditionList.appendChild(conditionLi);
}
Expand Down Expand Up @@ -82,25 +82,25 @@ let resultOperators = [


window.navigation.addEventListener("navigate", (event) => {
console.log('location changed!');
console.log(event);
console.log(event.srcElement.currentEntry.url);
// console.log('location changed!');
// console.log(event);
// console.log(event.srcElement.currentEntry.url);
currentUrl = event.destination.url + "";
console.log(typeof currentUrl);
// console.log(typeof currentUrl);
if (currentUrl.includes("/settings/conditions")){
console.log("In conditions, starting script");
// console.log("In conditions, starting script");
startInBuilder();

}
else{
console.log("Not in conditions, waiting");
// console.log("Not in conditions, waiting");
}
})

if(!document.location.href.includes("build")){
startInForm();
}
else if(document.location.href.includes("/settings/conditions")){
console.log("In conditions, starting script");
// console.log("In conditions, starting script");
startInBuilder();
}
2 changes: 1 addition & 1 deletion conditions_formbg.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("test background");
// console.log("test background");
8 changes: 4 additions & 4 deletions modules/builder/fetchFormProps.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
async function fetchFormProps(htmlContent) {
// console.log("Fetching Full Question Names");
// // console.log("Fetching Full Question Names");
const formPropsRegex = /window\.__formProps\s*=\s*(\{[\s\S]*?\});/m;
let match = htmlContent.match(formPropsRegex);
let formProps;
if (match && match[1]) {
let formPropsString = match[1];
try {
formProps = JSON.parse(formPropsString);
// console.log("formProps",formProps);
// // console.log("formProps",formProps);
} catch (error) {
console.error('Error parsing formProps:', error);
}
} else {
console.log('The variable window.__formProps was not found in the HTML content.');
// console.log('The variable window.__formProps was not found in the HTML content.');
}

// console.log("Returning formProps", formProps);
// // console.log("Returning formProps", formProps);
return formProps;
}
4 changes: 2 additions & 2 deletions modules/builder/fetchQuestionsProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ async function fetchQuestionsProps(htmlContent) {
let questionPropsString = match[1];
try {
questionProps = JSON.parse(questionPropsString);
// console.log("questionProps", questionProps);
// // console.log("questionProps", questionProps);
} catch (error) {
console.error('Error parsing questionProps:', error);
}
} else {
console.log('The variable window.__questionProps was not found in the HTML content.');
// console.log('The variable window.__questionProps was not found in the HTML content.');
}
return questionProps;
}
34 changes: 17 additions & 17 deletions modules/builder/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ async function startInBuilder() {
//go through field/fields and save each as it's own "condition"
//Save each action with a new "actionIndex"
let questionProps = await fetchQuestionsProps(htmlContent);
// console.log("conditions", conditions);
// console.log("questionProps",questionProps);
// // console.log("conditions", conditions);
// // console.log("questionProps",questionProps);

//maybe this await doesn't do anything?
await preprocessElements(conditionElements, conditions, questionProps);
Expand All @@ -29,11 +29,11 @@ async function startInBuilder() {
let new_element = cur_element.cloneNode(true);
cur_element.parentNode.replaceChild(new_element, cur_element);

// console.log(`Condition ${iCon}`, conditions[iCon]);
// // console.log(`Condition ${iCon}`, conditions[iCon]);
// var conditionLi = getConditionLi(conditions[iCon], iCon);
// conditionList.appendChild(conditionLi);
if (conditions[iCon].type == "field" || conditions[iCon].type == "require" || conditions[iCon].type == "mask") {
// console.log("Condition type:", conditions[iCon].type);
// // console.log("Condition type:", conditions[iCon].type);
for (let iAct = 0; iAct < conditions[iCon].action.length; iAct++) {
//for each action
//go through the actions of conditions after iCon
Expand All @@ -45,8 +45,8 @@ async function startInBuilder() {
&& getActionType(conditions[iCon].action[iAct]) ==
getActionType(conditions[iCon2].action[iAct2])) {

// console.log("SAME FIELD SAME ACTION");
// console.log(conditions[iCon].action[iAct]);
// // console.log("SAME FIELD SAME ACTION");
// // console.log(conditions[iCon].action[iAct]);
// conditionElements[iCon].style.backgroundColor = "red";
// let className = `conflict-${iCon}-${iAct}_${iCon2}-${iAct2}`;
let className = `conflict-${conditions[iCon].action[iAct].field}-${getActionType(conditions[iCon].action[iAct])}`;
Expand All @@ -70,14 +70,14 @@ async function startInBuilder() {
// addHoverEffect(actionElements2[iAct2]);
// conditionElements[iCon].classList.add(className);
//add an icon to warn
// console.log(conditionElements[iCon]);
// console.log(conditionElements[iCon].getElementsByClassName("conditionWarningIcon").length == 0);
// // console.log(conditionElements[iCon]);
// // console.log(conditionElements[iCon].getElementsByClassName("conditionWarningIcon").length == 0);
if (conditionElements[iCon].getElementsByClassName("conditionWarningIcon").length == 0) {
conditionElements[iCon].appendChild(warningIcon.cloneNode());
}

// console.log(conditionElements[iCon2]);
// console.log(conditionElements[iCon2].getElementsByClassName("conditionWarningIcon").length == 0);
// // console.log(conditionElements[iCon2]);
// // console.log(conditionElements[iCon2].getElementsByClassName("conditionWarningIcon").length == 0);
if (conditionElements[iCon2].getElementsByClassName("conditionWarningIcon").length == 0) {
conditionElements[iCon2].appendChild(warningIcon.cloneNode());
}
Expand All @@ -90,14 +90,14 @@ async function startInBuilder() {
// addHoverEffect(conditionElements[iCon]);
}
else if (conditions[iCon].type == "calculation") {
// console.log("Condition type:", conditions[iCon].type);
// // console.log("Condition type:", conditions[iCon].type);
for (let iAct = 0; iAct < conditions[iCon].action.length; iAct++) {
for (let iCon2 = iCon + 1; iCon2 < conditions.length; iCon2++) {
for (let iAct2 = 0; iAct2 < conditions[iCon2].action.length; iAct2++) {
if (conditions[iCon].action[iAct].resultField ==
conditions[iCon2].action[iAct2].resultField) {
// console.log("SAME FIELD SAME ACTION");
// console.log(conditions[iCon].action[iAct]);
// // console.log("SAME FIELD SAME ACTION");
// // console.log(conditions[iCon].action[iAct]);
let className = `conflict-${conditions[iCon].action[iAct].resultField}-${getActionType(conditions[iCon].action[iAct])}`;
conditionElements[iCon].classList.add(className);
conditionElements[iCon2].classList.add(className);
Expand All @@ -110,14 +110,14 @@ async function startInBuilder() {
actionElements2[iAct2].classList.add(className);
addHoverEffect(actionElements2[iAct2]);

// console.log(conditionElements[iCon]);
// console.log(conditionElements[iCon].getElementsByClassName("conditionWarningIcon").length == 0);
// // console.log(conditionElements[iCon]);
// // console.log(conditionElements[iCon].getElementsByClassName("conditionWarningIcon").length == 0);
if (conditionElements[iCon].getElementsByClassName("conditionWarningIcon").length == 0) {
conditionElements[iCon].appendChild(warningIcon.cloneNode());
}

// console.log(conditionElements[iCon2]);
// console.log(conditionElements[iCon2].getElementsByClassName("conditionWarningIcon").length == 0);
// // console.log(conditionElements[iCon2]);
// // console.log(conditionElements[iCon2].getElementsByClassName("conditionWarningIcon").length == 0);
if (conditionElements[iCon2].getElementsByClassName("conditionWarningIcon").length == 0) {
conditionElements[iCon2].appendChild(warningIcon.cloneNode());
}
Expand Down
2 changes: 1 addition & 1 deletion modules/builder/preprocessConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ function preprocessConditions(conditions){
}
}
}
// console.log("preprocessed conditions", conditions);
// // console.log("preprocessed conditions", conditions);
return conditions
}
32 changes: 16 additions & 16 deletions modules/builder/preprocessElements.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function preprocessElements(elementList, conditions, questions) {
console.log("Processing Elements");
console.log("elementList", elementList);
console.log("conditions", conditions);
console.log("questions", questions);
// console.log("Processing Elements");
// console.log("elementList", elementList);
// console.log("conditions", conditions);
// console.log("questions", questions);

for (let iCon = 0; iCon < conditions.length; iCon++) {
//Check Terms
let termElementCount = elementList[iCon].getElementsByClassName("if").length;
console.log("Found this many term elements:", termElementCount);
console.log("Found this many terms in condition:", conditions[iCon].terms.length);
// console.log("Found this many term elements:", termElementCount);
// console.log("Found this many terms in condition:", conditions[iCon].terms.length);
if (termElementCount != conditions[iCon].terms.length) {
//for simplicity's sake, delete current term elements
let termElements = elementList[iCon].getElementsByClassName("if");
Expand All @@ -17,17 +17,17 @@ function preprocessElements(elementList, conditions, questions) {
}


console.log("There's elements to be unfolded for condition:", iCon);
// console.log("There's elements to be unfolded for condition:", iCon);
let moreElement = elementList[iCon].getElementsByClassName("more")[0];
console.log("The more element?", moreElement);
// console.log("The more element?", moreElement);
//What even is this selector
let spanElement = elementList[iCon].getElementsByClassName("content")[0].getElementsByTagName("span")[0];
console.log("The spanElement?", spanElement);
// console.log("The spanElement?", spanElement);
for (let iTer = 0; iTer < conditions[iCon].terms.length; iTer++) {

let newTermElement = createTermElement(conditions[iCon].terms[iTer], questions);
spanElement.insertBefore(newTermElement, moreElement);
// console.log(newTermElement);
// // console.log(newTermElement);
}
moreElement.remove();

Expand All @@ -39,27 +39,27 @@ function preprocessElements(elementList, conditions, questions) {


let actionElementCount = elementList[iCon].getElementsByClassName("do").length;
console.log("Found this many action elements:", actionElementCount);
console.log("Found this many actions in condition:", conditions[iCon].action.length);
// console.log("Found this many action elements:", actionElementCount);
// console.log("Found this many actions in condition:", conditions[iCon].action.length);

if (actionElementCount != conditions[iCon].action.length) {
console.log("There's elements to be unfolded for condition:", iCon);
// console.log("There's elements to be unfolded for condition:", iCon);
//for simplicity's sake, delete current action elements
let actionElements = elementList[iCon].getElementsByClassName("do");
for (let iAct = actionElements.length - 1; iAct >= 0; iAct--) {
actionElements[iAct].remove();
}

let moreElement = elementList[iCon].getElementsByClassName("more")[0];
console.log("The more element?", moreElement);
// console.log("The more element?", moreElement);
//What even is this selector
let spanElement = elementList[iCon].getElementsByClassName("content")[0].getElementsByTagName("span")[0];
console.log("The spanElement?", spanElement);
// console.log("The spanElement?", spanElement);
for (let iAct = 0; iAct < conditions[iCon].action.length; iAct++) {

let newActionElement = createActionElement(conditions[iCon].action[iAct], questions);
spanElement.insertBefore(newActionElement, moreElement);
// console.log(newTermElement);
// // console.log(newTermElement);
}
moreElement.remove();
}
Expand Down
17 changes: 9 additions & 8 deletions modules/helpFunctions/addHoverEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ function addHoverEffect(element) {
function getClassListStr() {
var classListStr = "";
var classList = element.classList;
// console.log(" classListStr", classListStr);
// // console.log(" classListStr", classListStr);
classList.forEach(classEntry => {
// console.log("classEntry", classEntry);
// // console.log("classEntry", classEntry);
if (classEntry.indexOf("conflict-") > -1) {
classListStr = classListStr + "." + classEntry + ",";
}
});
classListStr = classListStr.slice(0, -1);
// console.log("trying to show", classListStr);
// // console.log("trying to show", classListStr);
return classListStr;
}

Expand All @@ -33,7 +33,7 @@ function addHoverEffect(element) {
// catch {
// var elms = []
// }
// console.log("elms", elms);
// // console.log("elms", elms);
// var n = elms.length;
function addConflictClass() {
// console.log("In addConflictClass");
Expand All @@ -42,7 +42,7 @@ function addHoverEffect(element) {
// console.log(element.classList.contains("content-infos"));
try {
var elms = document.querySelectorAll(getClassListStr());
// console.log("this is the elements:", elms);
// // console.log("this is the elements:", elms);
}
catch {
var elms = []
Expand All @@ -55,9 +55,9 @@ function addHoverEffect(element) {
}
//Check if hover is directly on an action
if (element.classList.contains("content-infos")) {
// console.log("Hovering directly on action");
// // console.log("Hovering directly on action");
let conflictClass = getClassListStr().slice(1);
// console.log("conflictClass", conflictClass);
// // console.log("conflictClass", conflictClass);
let conditionsListElement = document.getElementsByClassName('listGroup-content')[0];
let actionElements = conditionsListElement.getElementsByClassName("content-infos");
for (var iActive = 0; iActive < actionElements.length; iActive++) {
Expand Down Expand Up @@ -89,7 +89,7 @@ function addHoverEffect(element) {
}
}
element.onmouseover = function () {
console.log("Mouse hover, and clickToggle is", clickToggle);
// console.log("Mouse hover, and clickToggle is", clickToggle);
if (!clickToggle) {
addConflictClass();
}
Expand All @@ -111,6 +111,7 @@ function addHoverEffect(element) {
}
else {
clickToggle = false;

// removeConflictClass();
// console.log("Removing hover effects");
}
Expand Down
10 changes: 5 additions & 5 deletions modules/helpFunctions/getActionType.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function getActionType(action) {
if (action.hasOwnProperty("visibility")) {
let actionType = action.visibility;
// console.log("actionType", actionType);
// console.log("action", action);
// // console.log("actionType", actionType);
// // console.log("action", action);
switch (actionType) {
case "Show":
case "Hide":
Expand All @@ -24,7 +24,7 @@ function getActionType(action) {
}
else if (action.hasOwnProperty("skipHide")) {
let actionType = action.skipHide;
console.log("actionType", actionType);
// console.log("actionType", actionType);
switch (actionType) {
case "hidePage":
return "skipHide";
Expand All @@ -35,7 +35,7 @@ function getActionType(action) {
return "calculation";
}
else {
console.log("Found edge case");
console.log(action);
// console.log("Found edge case");
// console.log(action);
}
}
2 changes: 1 addition & 1 deletion modules/helpFunctions/hasAfter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const hasAfter = selector => {
console.log("hasAfter Selector", selector);
// console.log("hasAfter Selector", selector);
const el = document.querySelector(selector);
return getComputedStyle(el, '::after').content !== 'none';
}
Expand Down
6 changes: 3 additions & 3 deletions modules/list/getConditionLi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function getConditionLi(condition, iCon) {
innerHTML += `<div class="actionDiv" style="display:block;">`;
for (let iAct = 0; iAct < condition.action.length; iAct++) {
var action = condition.action[iAct];
console.log(action);
// console.log(action);
if ('field' in action) {
innerHTML += `<div>`;
innerHTML += `<span id="${iCon}-${iAct}-${action.id}" class="conditionActionResult"></span>`;
Expand All @@ -42,8 +42,8 @@ function getConditionLi(condition, iCon) {
innerHTML += `</div>`;
}
else{
console.log("Couldn't find");
console.log(action);
// console.log("Couldn't find");
// console.log(action);
}
}
innerHTML += "</div>"
Expand Down
Loading

0 comments on commit 647112e

Please sign in to comment.