word-games-theme 2.4.2 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,214 @@
1
+ let txtBox = document.querySelector('.txtBox')
2
+ txtBox.focus()
3
+ let letterCloseButton = document.querySelector('.letter-close-button')
4
+
5
+ let startsWith = document.getElementById("startsWith");
6
+ let mustInclude = document.getElementById("mustInclude");
7
+ let endsWith = document.getElementById("endsWith");
8
+ let exculdeWith = document.getElementById("exculdeWith");
9
+ let inculdeWith = document.getElementById("inculdeWith");
10
+ let wordLength = document.getElementById("wordLength");
11
+
12
+ // // when typing on input
13
+ txtBox.addEventListener('input', (e) => {
14
+ if (e.target.value === "") {
15
+ letterCloseButton.style.display = "none"
16
+ }
17
+ else {
18
+ letterCloseButton.style.display = "block"
19
+ }
20
+ e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, "")
21
+ let rangeOfBlankTile = 3
22
+ if (rangeOfBlankTile === "") {
23
+ rangeOfBlankTile = 3
24
+ }
25
+ e.target.value = e.target.value.replace(/ /g, '?')
26
+ let data = []
27
+ data = e.target.value.split('').filter((i) => i === '?')
28
+ if (data.length > rangeOfBlankTile) {
29
+ e.target.value = e.target.value.replace(/\?$/, '')
30
+ }
31
+ })
32
+ letterCloseButton.addEventListener("click", () => {
33
+ txtBox.value = ""
34
+ letterCloseButton.style.display = "none"
35
+ })
36
+ //tooltips for advanced filter
37
+ const filterInputs = document.querySelectorAll('.filter_val');
38
+ Array.from(filterInputs).forEach((item) => {
39
+ item.addEventListener("input", (e) => {
40
+ const inputValue = e.target.value;
41
+ const parentElement = e.target.parentElement;
42
+ const imgElement = parentElement.querySelector('img');
43
+ const tooltipElement = parentElement.querySelector('.filter-tooltip');
44
+
45
+ if (inputValue == "") {
46
+ imgElement.src = "/assets/images/questionmark.svg"
47
+ setTimeout(() => {
48
+ item.nextElementSibling.setAttribute("data-tip", item.nextElementSibling.id)
49
+ }, 100);
50
+ tooltipElement.style.setProperty('--tooltip-padding', '0.5rem');
51
+ tooltipElement.style.setProperty('--tooltip-border-style', 'soild');
52
+
53
+ } else {
54
+ item.nextElementSibling.removeAttribute("data-tip")
55
+ imgElement.src = "/assets/images/close-btn.svg"
56
+ tooltipElement.style.setProperty('--tooltip-padding', '0');
57
+ tooltipElement.style.setProperty('--tooltip-border-style', 'none');
58
+ }
59
+ item.nextElementSibling.addEventListener("click", () => {
60
+ e.target.value = ""
61
+ imgElement.src = "/assets/images/questionmark.svg"
62
+ setTimeout(() => {
63
+ item.nextElementSibling.setAttribute("data-tip", item.nextElementSibling.id)
64
+ }, 100);
65
+ tooltipElement.style.setProperty('--tooltip-padding', '0.5rem');
66
+ tooltipElement.style.setProperty('--tooltip-border-style', 'soild');
67
+ })
68
+ })
69
+ })
70
+ const loadResource = (FILE_URL, async = true, type = "text/javascript") => {
71
+ return new Promise((resolve, reject) => {
72
+ let resourceEle;
73
+
74
+ if (type === "text/javascript") {
75
+ resourceEle = document.createElement("script");
76
+ } else if (type === "text/css") {
77
+ resourceEle = document.createElement("link");
78
+ resourceEle.rel = "stylesheet";
79
+ } else {
80
+ reject({
81
+ status: false,
82
+ message: `Unsupported resource type: ${type}`,
83
+ });
84
+ return;
85
+ }
86
+
87
+ resourceEle.type = type;
88
+ resourceEle.async = async;
89
+ resourceEle.href = FILE_URL;
90
+
91
+
92
+ resourceEle.addEventListener("load", () => {
93
+ resolve({ status: true });
94
+ });
95
+
96
+ resourceEle.addEventListener("error", () => {
97
+ reject({
98
+ status: false,
99
+ message: `Failed to load the resource ${FILE_URL}`,
100
+ });
101
+ });
102
+
103
+ if (type === "text/javascript") {
104
+ document.body.appendChild(resourceEle);
105
+ } else if (type === "text/css") {
106
+ document.head.appendChild(resourceEle);
107
+ }
108
+ });
109
+ };
110
+ const formElement = document.querySelector("#form");
111
+ formElement.addEventListener("submit", function (e) {
112
+ e.preventDefault();
113
+
114
+ document.querySelector(".fillterWrapper").classList.add("hide")
115
+ let selectedDictionary = document.querySelector(".select_dropDown2").value;
116
+ if (history.pushState) {
117
+ var newurl =
118
+ window.location.protocol +
119
+ "//" +
120
+ window.location.host +
121
+ window.location.pathname +
122
+ "?" +
123
+ "search" +
124
+ "=" +
125
+ txtBox.value.toLowerCase() +
126
+ "&" +
127
+ "dictionary" +
128
+ "=" +
129
+ selectedDictionary +
130
+ "&" +
131
+ "prefix" +
132
+ "=" +
133
+ startsWith.value +
134
+ "&" +
135
+ "contains" +
136
+ "=" +
137
+ mustInclude.value +
138
+ "&" +
139
+ "suffix" +
140
+ "=" +
141
+ endsWith.value +
142
+ "&" +
143
+ "exclude" +
144
+ "=" +
145
+ exculdeWith.value +
146
+ "&" +
147
+ "include" +
148
+ "=" +
149
+ inculdeWith.value +
150
+ "&" +
151
+ "length" +
152
+ "=" +
153
+ wordLength.value;
154
+ window.history.pushState({ path: newurl }, "", newurl);
155
+
156
+ const params = new URLSearchParams(window.location.search);
157
+ serachValue = params.get("search");
158
+ prefixValue = params.get("prefix");
159
+ containsValue = params.get("contains");
160
+ suffixValue = params.get("suffix");
161
+ exculdeValue = params.get("exclude");
162
+ includeValue = params.get("include");
163
+ lengthValue = params.get("length");
164
+ dictonary = params.get("dictionary");
165
+
166
+ gtag("event", "page_view", {
167
+ page_location: window.location.pathname + location.search,
168
+ });
169
+ }
170
+
171
+ const paramName = 'search';
172
+ if (new URLSearchParams(window.location.search).has(paramName)) {
173
+ loadResource("/assets/css/wordfinder-result.css", true, "text/css")
174
+ .then((data) => {
175
+ console.log("CSS loaded:", data);
176
+ // Once the CSS is loaded, create the script element for JavaScript
177
+ const jsScript = document.createElement("script");
178
+ jsScript.src = "/assets/js/xletter-result.js";
179
+ jsScript.onload = () => {
180
+ getData(txtBox.value.toLowerCase());
181
+ };
182
+ document.body.appendChild(jsScript);
183
+ })
184
+ .catch((error) => {
185
+ console.error("Error loading resource:", error);
186
+ });
187
+ }
188
+ });
189
+
190
+ // Now you can use the loadScript function with additional data
191
+ function checkQueryParam() {
192
+ const urlParams = new URLSearchParams(window.location.search);
193
+ const paramName = 'search';
194
+ if (urlParams.has(paramName)) {
195
+ loadResource("/assets/css/wordfinder-result.css", true, "text/css")
196
+ .then((data) => {
197
+ console.log("CSS loaded:", data);
198
+ // Once the CSS is loaded, create the script element for JavaScript
199
+ const jsScript = document.createElement("script");
200
+ jsScript.src = "/assets/js/xletter-result.js";
201
+ jsScript.onload = () => {
202
+ console.log("JS loaded");
203
+ getData(txtBox.value.toLowerCase());
204
+ };
205
+ document.body.appendChild(jsScript);
206
+ })
207
+ .catch((error) => {
208
+ console.error("Error loading resource:", error);
209
+ });
210
+ }
211
+ }
212
+ checkQueryParam();
213
+
214
+