forked from hammadsaedi/regex-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
142 lines (126 loc) · 5.48 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import pages from './pages.js';
import { createFormWithRegex, createExtractionForm, createSanitizationForm } from './factory.js';
const mainElement = document.querySelector("main");
populateHome();
// Wait for the DOM to be fully loaded
document.addEventListener("DOMContentLoaded", function () {
const regexLink = document.querySelector("a[href='#']");
regexLink.addEventListener("click", function () {
populateHome();
});
// Add an event listener to the "Validation" link in the navigation menu
const validationLink = document.querySelector("a[href='#validation']");
validationLink.addEventListener("click", function () {
populateValidationForms();
});
// Add an event listener to the "Extraction" link in the navigation menu
const extractionLink = document.querySelector("a[href='#extraction']");
extractionLink.addEventListener("click", function () {
populateExtractionForms();
});
const sanitizationLink = document.querySelector("a[href='#sanitization']");
sanitizationLink.addEventListener("click", function () {
populateSanitizationForm();
});
});
function populateHome() {
// Clear the existing content in the <main> element
mainElement.innerHTML = `
<section id="features">
<h2>Discover the Power of Regular Expressions</h2>
<p>Regex Pro is your all-in-one solution for working with regular expressions. Whether you're a developer or just curious about regex, we've got you covered.</p>
<div class="feature-card">
<h3>Regular Expression Testing</h3>
<p>Test your regular expressions against sample text and see instant results. Debug and perfect your regex patterns effortlessly.</p>
</div>
<div class="feature-card">
<h3>Data Validation</h3>
<p>Use our pre-built validation forms to check data types like dates, URLs, and more. Ensure your input data meets your criteria.</p>
</div>
<div class="feature-card">
<h3>Data Extraction</h3>
<p>Effortlessly extract information from text using regular expressions. Extract emails, phone numbers, and more with ease.</p>
</div>
<div class="feature-card">
<h3>Data Sanitization</h3>
<p>Cleanse your data by removing unwanted content, such as HTML or SQL code. Keep your data safe and tidy.</p>
</div>
</section>`;
}
function populateValidationForms() {
// Check if validation data exists in the pages object
if (pages.validation && pages.validation.length > 0) {
// Clear the existing content in the <main> element
const mainElement = document.querySelector("main");
mainElement.innerHTML = '';
// Loop through the validation data in the pages object and create forms
pages.validation.forEach((validationData, index) => {
const form = createFormWithRegex(
validationData.title,
validationData.explanation,
validationData.regexPattern
);
// Add an identifier to the form to distinguish it from others
form.dataset.formId = index;
mainElement.appendChild(form);
});
dynamicTextarea()
}
}
function populateExtractionForms() {
// Check if extraction data exists in the pages object
if (pages.extraction && pages.extraction.length > 0) {
// Clear the existing content in the <main> element
mainElement.innerHTML = '';
// Loop through the extraction data in the pages object and create forms
pages.extraction.forEach((extractionData, index) => {
const form = createExtractionForm(
extractionData.title,
extractionData.explanation,
extractionData.regexPattern
);
// Add an identifier to the form to distinguish it from others
form.dataset.formId = index;
mainElement.appendChild(form);
});
dynamicTextarea()
}
}
function populateSanitizationForm(){
if (pages.sanitization && pages.sanitization.length > 0) {
// Clear the existing content in the <main> element
mainElement.innerHTML = '';
// Loop through the extraction data in the pages object and create forms
pages.sanitization.forEach((sanitizationData, index) => {
const form = createSanitizationForm(
sanitizationData.title,
sanitizationData.explanation,
sanitizationData.regexPattern
);
// Add an identifier to the form to distinguish it from others
form.dataset.formId = index;
mainElement.appendChild(form);
});
dynamicTextarea()
}
}
const menuToggle = document.getElementById('menu-toggle');
const navList = document.getElementById('nav-list');
menuToggle.addEventListener('click', () => {
navList.classList.toggle('active');
});
const navLinks = document.querySelectorAll('.nav-list a');
navLinks.forEach(link => {
link.addEventListener('click', () => {
navList.classList.remove('active');
});
});
function dynamicTextarea(){
const textareas = document.querySelectorAll('textarea')
textareas.forEach((textarea) => {
textarea.addEventListener('input', () => {
textarea.style.height = "auto"
textarea.style.height = textarea.scrollHeight + "px"
})
})
}