word-games-theme 1.2.6 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,890 @@
1
+ /***************
2
+ SCRABBLER_JS
3
+ ***************/
4
+ const getScript = document.currentScript
5
+ let form = document.querySelector('#form')
6
+ let wordCount = document.querySelector('.wordCount')
7
+ let main = document.querySelector('.main')
8
+ let loader = document.querySelector(".main-loader")
9
+ let errorMsg = document.querySelector('.errorMsg')
10
+ let script = document.currentScript
11
+
12
+ // getqueryUrl from form
13
+ const params = new URLSearchParams(window.location.search)
14
+ let serachValue = params.get('search').toLowerCase()
15
+ let prefixValue = params.get('prefix')
16
+ let containsValue = params.get('contains')
17
+ let suffixValue = params.get('suffix')
18
+ let exculdeValue = params.get('exculde')
19
+ let includeValue = params.get('include')
20
+ let lengthValue = params.get('length')
21
+ let dictonary = params.get('dictionary')
22
+
23
+ // advanced filter element grabs
24
+ let tick
25
+ let startsWith = document.getElementById('startsWith')
26
+ let mustInclude = document.getElementById('mustInclude')
27
+ let endsWith = document.getElementById('endsWith')
28
+ let exculdeWith = document.getElementById('exculdeWith')
29
+ let inculdeWith = document.getElementById('inculdeWith')
30
+ let wordLength = document.getElementById('wordLength')
31
+
32
+ let ok = true
33
+
34
+ let tab_container = document.querySelector('.tab_container')
35
+ const siteUrl = getScript.dataset.url
36
+ var sortValue
37
+ var sortBool = false
38
+
39
+ let letterCloseButton = document.querySelector('.letter-close-button-commonPage')
40
+ if (serachValue) {
41
+ letterCloseButton.classList.add("ltr-cls-btn-commonPage")
42
+ }
43
+ letterCloseButton.addEventListener("click", () => {
44
+ txtBox.value = ""
45
+ letterCloseButton.classList.remove("ltr-cls-btn-commonPage")
46
+ })
47
+ let txtBox = document.querySelector('.txtBox')
48
+ txtBox.focus()
49
+ txtBox.value = serachValue
50
+ txtBox.addEventListener('input', (e) => {
51
+ if (e.target.value === "") {
52
+ letterCloseButton.classList.remove("ltr-cls-btn-commonPage")
53
+ } else {
54
+ letterCloseButton.classList.add("ltr-cls-btn-commonPage")
55
+ }
56
+ let rangeOfBlankTile = script.dataset.range
57
+ e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, '')
58
+ if (rangeOfBlankTile === '') {
59
+ rangeOfBlankTile = 3
60
+ }
61
+ e.target.value = e.target.value.replace(/ /g, '?')
62
+ let data = []
63
+ data = e.target.value.split('').filter((i) => i === '?')
64
+ if (data.length > rangeOfBlankTile) {
65
+ e.target.value = e.target.value.replace(/\?$/, '')
66
+ }
67
+ })
68
+ let rangeOfBlankTile = script.dataset.range
69
+ let quesMark = "?"
70
+ if (rangeOfBlankTile) {
71
+ if (!serachValue.includes("?")) {
72
+ serachValue = serachValue + quesMark.repeat(rangeOfBlankTile); //
73
+ txtBox.value = serachValue
74
+ }
75
+ }
76
+
77
+ let theSelect = document.getElementById('select_dropDown')
78
+ const sortup = document.querySelector(".sortup-icon")
79
+ let bool = false
80
+ sortup.addEventListener("click", () => {
81
+ if (bool) {
82
+ theSelect.size = 0
83
+ bool = false
84
+ theSelect.style.display = "none"
85
+ }
86
+ else {
87
+ bool = true
88
+ theSelect.size = 3
89
+ theSelect.style.display = "block"
90
+ }
91
+ })
92
+ document.querySelector('.select_dropDown2').value = dictonary
93
+ const getDiff = (text1, text2) => {
94
+ var diffRange = []
95
+ var currentRange = undefined
96
+ for (var i = 0; i < text1.length; i++) {
97
+ if (text1[i] != text2[i]) {
98
+ if (currentRange == undefined) {
99
+ currentRange = [i]
100
+ }
101
+ }
102
+ if (currentRange != undefined && text1[i] == text2[i]) {
103
+ currentRange.push(i)
104
+ diffRange.push(currentRange)
105
+ currentRange = undefined
106
+ }
107
+ }
108
+ if (currentRange != undefined) {
109
+ currentRange.push(i)
110
+ diffRange.push(currentRange)
111
+ }
112
+ return diffRange
113
+ }
114
+ // getWords define...
115
+ let stringLength = null
116
+ let blank = []
117
+ const getData = async (serachValue) => {
118
+ try {
119
+ errorMsg.innerHTML = ""
120
+ wordCount.innerHTML = ""
121
+ let selectedDictionary = document.querySelector('.select_dropDown2').value
122
+ loader.innerHTML = `<div class="loader">
123
+ <img src='/assets/images/loading.gif'>
124
+ <div style="font-weight:900;font-size:14px" >Finding words - Powered by ${siteUrl.replace(/^https?:\/\//, '')}</div>
125
+ </div>`
126
+ /// loader
127
+ const response = await fetch(
128
+ `/.netlify/functions/getWords?name=${serachValue}&selecteddictionary=${selectedDictionary}`
129
+ )
130
+ const data = await response.json()
131
+
132
+ function longestString(...strs) {
133
+ return strs.sort(function (a, b) { return b.length - a.length })[0];
134
+ }
135
+
136
+ stringLength = longestString(...data)
137
+
138
+ loader.innerHTML = ''
139
+ getWords(data)
140
+ //getWords calling...
141
+ } catch (error) {
142
+ console.log(error)
143
+ }
144
+ }
145
+ //getData calling...
146
+ if (lengthValue === '1') {
147
+ errorMsg.innerHTML = 'words length should be more than 1'
148
+ } else {
149
+ getData(serachValue.toLowerCase())
150
+ function logSubmit(event) {
151
+ const scrollingElement = (document.scrollingElement || document.body);
152
+ scrollingElement.scroll({ top: 0, behavior: 'smooth' });
153
+ if (rangeOfBlankTile) {
154
+ if (!txtBox.value.includes("?")) {
155
+ txtBox.value = txtBox.value + quesMark.repeat(rangeOfBlankTile); //
156
+ }
157
+ }
158
+
159
+ let selectedDictionary = document.querySelector('.select_dropDown2').value
160
+ event.preventDefault();
161
+ if (history.pushState) {
162
+ var newurl = window.location.protocol + "//" + window.location.host +
163
+ window.location.pathname + '?' + "search" + "=" + txtBox.value.toLowerCase() + '&' +
164
+ 'dictionary' + '=' + selectedDictionary +
165
+ '&' + 'prefix' + '=' + startsWith.value + '&' + 'contains' + '=' + mustInclude.value +
166
+ '&' + 'suffix' + '=' + endsWith.value + '&' + 'exculde' + '=' + exculdeWith.value +
167
+ '&' + 'include' + '=' + inculdeWith.value + '&' + 'length' + '=' + wordLength.value;
168
+ window.history.pushState({ path: newurl }, '', newurl);
169
+
170
+ const params = new URLSearchParams(window.location.search)
171
+ serachValue = params.get('search')
172
+ prefixValue = params.get('prefix')
173
+ containsValue = params.get('contains')
174
+ suffixValue = params.get('suffix')
175
+ exculdeValue = params.get('exculde')
176
+ includeValue = params.get('include')
177
+ lengthValue = params.get('length')
178
+ dictonary = params.get('dictionary')
179
+
180
+ gtag('event', 'page_view', {
181
+ page_location: window.location.pathname + location.search,
182
+ })
183
+ }
184
+ getData(txtBox.value.toLowerCase())
185
+ addFilterCount()
186
+
187
+ }
188
+
189
+ let selectedDictionary = document.querySelector('.select_dropDown2')
190
+ selectedDictionary.addEventListener("change", ((e) => {
191
+ logSubmit(e)
192
+ }))
193
+ applyBtn.addEventListener('submit', logSubmit)
194
+ form.addEventListener('submit', logSubmit);
195
+ }
196
+
197
+ function getWords(data) {
198
+ // main.innerHTML = ""
199
+ tab_container.innerHTML = ""
200
+ if (typeof data === 'string') {
201
+ errorMsg.innerHTML = 'no words found'
202
+ wordCount.innerHTML = `<strong>Found 0 words with letters ${serachValue.split(
203
+ ''
204
+ )}</strong>`
205
+ } else {
206
+ let newWordsLength = 0
207
+ theSelect.addEventListener('change', () => {
208
+ sortValue = theSelect[theSelect.selectedIndex].text
209
+ if (sortValue == 'Z-A') {
210
+ sortBool = true
211
+ sortby(sortBool, data)
212
+ } else {
213
+ sortBool = false
214
+ sortby(sortBool, data)
215
+ }
216
+ if (sortValue == 'Points') {
217
+ sortBool = true
218
+ sortPointsby(sortBool, data)
219
+ }
220
+ })
221
+ let inc = 0
222
+ for (let i = serachValue.length; i >= 1; i--) {
223
+ let newdata = data.filter((item) => item.length === i)
224
+
225
+ if (prefixValue) {
226
+ newdata = newdata.filter((item2) =>
227
+ item2.startsWith(prefixValue.toLowerCase())
228
+ )
229
+ startsWith.classList.add('tick')
230
+ startsWith.value = prefixValue
231
+ } else {
232
+ startsWith.classList.remove('tick')
233
+ }
234
+ if (containsValue) {
235
+ newdata = newdata.filter((item) =>
236
+ item.includes(containsValue.toLowerCase())
237
+ )
238
+ mustInclude.classList.add('tick')
239
+ mustInclude.value = containsValue
240
+ }
241
+ else {
242
+ mustInclude.classList.remove('tick')
243
+ }
244
+ if (suffixValue) {
245
+ newdata = newdata.filter((item) =>
246
+ item.endsWith(suffixValue.toLowerCase())
247
+ )
248
+ endsWith.classList.add('tick')
249
+ endsWith.value = suffixValue
250
+ } else {
251
+ endsWith.classList.remove('tick')
252
+ }
253
+ if (exculdeValue) {
254
+ let data = []
255
+ newdata.map((item) => {
256
+ let check = false
257
+ for (let e = 0; e < exculdeValue.length; e++) {
258
+ const element = exculdeValue[e].toLowerCase()
259
+ if (item.includes(element)) {
260
+ check = true
261
+ break
262
+ } else {
263
+ check = false
264
+ }
265
+ }
266
+ if (check === false) {
267
+ data.push(item)
268
+ }
269
+ })
270
+ exculdeWith.classList.add('tick')
271
+ exculdeWith.value = exculdeValue
272
+ newdata = data
273
+ } else {
274
+ exculdeWith.classList.remove('tick')
275
+ }
276
+ if (includeValue) {
277
+ let data = []
278
+ newdata.map((item) => {
279
+ let check = false
280
+ for (let e = 0; e < includeValue.length; e++) {
281
+ const element = includeValue[e].toLowerCase()
282
+ if (!item.includes(element)) {
283
+ check = true
284
+ break
285
+ } else {
286
+ check = false
287
+ }
288
+ }
289
+ if (check === false) {
290
+ data.push(item)
291
+ }
292
+ })
293
+ inculdeWith.classList.add('tick')
294
+ inculdeWith.value = includeValue
295
+ newdata = data
296
+ } else {
297
+ inculdeWith.classList.remove('tick')
298
+ }
299
+ if (lengthValue) {
300
+ newdata = newdata.filter((item) => item.length == lengthValue)
301
+ wordLength.classList.add('tick')
302
+ wordLength.value = lengthValue
303
+ } else {
304
+ wordLength.classList.remove('tick')
305
+ }
306
+
307
+ if (newdata.length === 0) {
308
+ main.innerHTML += ''
309
+ } else {
310
+ newWordsLength += newdata.length
311
+ const result = newdata.map((item) => {
312
+ var text1 = serachValue.replace('?', '')
313
+ var text2 = item
314
+ var text3 = item
315
+ let chars = text1.split('')
316
+
317
+
318
+ let indexs = []
319
+ chars.map((i) => {
320
+ let findIndexes = findIndex(text3, i)
321
+ if (findIndexes.length > 0) {
322
+ text3 = text3.split('')
323
+ text3[findIndexes] = '$'
324
+ text3 = text3.join('')
325
+
326
+ indexs = [...indexs, ...findIndexes]
327
+ }
328
+ })
329
+ let itemHtml = ''
330
+ text2.split('').map((itemValue, index) => {
331
+ let check = indexs.find((i) => i === index)
332
+
333
+ if (check !== undefined) {
334
+ itemHtml += `${itemValue}`
335
+ } else {
336
+ itemHtml += `<span class='highlight'>${itemValue}</span>`
337
+ }
338
+ })
339
+
340
+ if (item.length === 1) {
341
+ ok = false
342
+ newWordsLength = newWordsLength - 1
343
+ } else {
344
+ let ScrabbleLetterScore = ScrabbleScore()
345
+ sum = 0
346
+ item = item.toLowerCase()
347
+ for (let i = 0; i < item.length; i++) {
348
+ sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
349
+ }
350
+ return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item.toLowerCase()}">
351
+ <li>${itemHtml}
352
+ <span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span>
353
+ </li></a>`
354
+ }
355
+ })
356
+
357
+
358
+
359
+ if (result[0] !== undefined) {
360
+
361
+
362
+ tab_container.innerHTML += `
363
+ <input type="button" id="Tab_${i}" onclick="Filtering(${i})" value="${i} Letter"
364
+ class="tab_link cursorPointer"/>
365
+ `
366
+ let tabs = document.getElementsByClassName('tab_link')
367
+ tabs[0] ? tabs[0].classList.add('active-tab') : ''
368
+
369
+ let allGroupWords = document.getElementById(`alpha_${i}`)
370
+ let getAllGroupWords = [...main.getElementsByClassName('allGroupWords')]
371
+
372
+
373
+ if (main.dataset.value !== "null") {
374
+ if (allGroupWords) {
375
+ Array.from(getAllGroupWords).forEach((item) => {
376
+ if (item.id.slice(6) <= stringLength.length) {
377
+ if (item.nextSibling !== null && item.nextSibling.classList !== undefined && item.nextSibling.classList.contains("mmtwrappos")) {
378
+ item.nextSibling.style.visibility = "visible"
379
+ item.nextSibling.style.height = "auto"
380
+ }
381
+ allGroupWords.innerHTML = ""
382
+ item.style.display = "block"
383
+ }
384
+ else {
385
+ if (item.nextSibling !== null && item.nextSibling.classList !== undefined && item.nextSibling.classList.contains("mmtwrappos")) {
386
+ item.nextSibling.style.visibility = "hidden"
387
+ item.nextSibling.style.height = "0"
388
+ }
389
+ item.style.display = "none"
390
+ }
391
+ })
392
+ allGroupWords.innerHTML = `
393
+ <div class="wordListHeading">
394
+ <h3 class="lead">${i} Letter Words</h3>
395
+ </div>
396
+ <div class="wordList">
397
+ <ul class="ul list-unstyled">
398
+ ${result.join('')}
399
+ </ul>
400
+ </div>
401
+ `
402
+ }
403
+ else {
404
+ let getAllGroupWords = [...main.getElementsByClassName('allGroupWords')]
405
+ let allGroupWords = document.createElement("div")
406
+ allGroupWords.className = "allGroupWords wordlistContainer"
407
+ allGroupWords.id = `alpha_${i}`
408
+ allGroupWords.innerHTML = `
409
+ <div class="wordListHeading">
410
+ <h3 class="lead">${i} Letter Words</h3>
411
+ </div>
412
+ <div class="wordList">
413
+ <ul class="ul list-unstyled">
414
+ ${result.join('')}
415
+ </ul>
416
+ </div>
417
+ `
418
+ blank.push(allGroupWords)
419
+ let newCreated = stringLength.length - getAllGroupWords.length - 1
420
+ inc = inc + 1
421
+ if (inc === newCreated) {
422
+ Array.from(blank).reverse().map((item) => {
423
+ main.prepend(item)
424
+ })
425
+ }
426
+ }
427
+ }
428
+ else {
429
+ if (i === 2) {
430
+ main.dataset.value = "not_null"
431
+ }
432
+ main.innerHTML += `
433
+ <div class="allGroupWords wordlistContainer" id="alpha_${i}">
434
+ <div class="wordListHeading">
435
+ <h3 class="lead">${i} Letter Words</h3>
436
+ </div>
437
+ <div class="wordList">
438
+ <ul class="ul list-unstyled">
439
+ ${result.join('')}
440
+ </ul>
441
+ </div>
442
+ </div>`
443
+
444
+ }
445
+ }
446
+ }
447
+ }
448
+ if (newWordsLength === 0) {
449
+ errorMsg.innerHTML = 'no words found'
450
+ } else {
451
+ wordCount.innerHTML = `<strong> Found ${newWordsLength} words with letters with ${serachValue.split(
452
+ ''
453
+ )
454
+ }</strong>`
455
+ }
456
+ }
457
+ }
458
+
459
+ // sorting by points
460
+ function sortPointsby(sortValue, data) {
461
+ // main.innerHTML = ''
462
+ if (sortValue) {
463
+ let newWordsLength = 0
464
+ for (let i = serachValue.length; i >= 1; i--) {
465
+ var newdata = data.filter((item) => item.length === i)
466
+
467
+ if (newdata.length === 0) {
468
+ main.innerHTML += ''
469
+ } else {
470
+ newWordsLength += newdata.length
471
+ var newArray = []
472
+ newdata.map((item) => {
473
+ if (item.length === 1) {
474
+ ok = false
475
+ newWordsLength = newWordsLength - 1
476
+ } else {
477
+ let ScrabbleLetterScore = ScrabbleScore()
478
+ let points = 0
479
+ item = item.toLowerCase()
480
+ for (let i = 0; i < item.length; i++) {
481
+ points += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
482
+ }
483
+ const value = {
484
+ words: item,
485
+ points: points,
486
+ }
487
+ newArray.push(value)
488
+ }
489
+ })
490
+
491
+ newArray.sort(function (a, b) {
492
+ return b.points - a.points
493
+ })
494
+
495
+ const result = newArray.map((item) => {
496
+ var text1 = serachValue.replace('?', '')
497
+ var text2 = item.words
498
+ var text3 = item.words
499
+
500
+
501
+ function findIndex(str, char) {
502
+ const strLength = str.length
503
+ const indexes = []
504
+ let newStr = str
505
+ while (newStr && newStr.indexOf(char) > -1) {
506
+ indexes.push(newStr.indexOf(char) + strLength - newStr.length)
507
+ newStr = newStr.substring(newStr.indexOf(char) + 1)
508
+ newStr = newStr.substring(newStr.indexOf(char) + 1)
509
+ }
510
+ return indexes
511
+ }
512
+ let chars = text1.split('')
513
+ let indexs = []
514
+ chars.map((i) => {
515
+ let findIndexes = findIndex(text3, i)
516
+ if (findIndexes.length > 0) {
517
+ text3 = text3.split('')
518
+ text3[findIndexes] = '$'
519
+ text3 = text3.join('')
520
+ indexs = [...indexs, ...findIndexes]
521
+ }
522
+ })
523
+ let itemHtml = ''
524
+ text2.split('').map((itemValue, index) => {
525
+ let check = indexs.find((i) => i === index)
526
+ if (check !== undefined) {
527
+ itemHtml += `${itemValue}`
528
+ } else {
529
+ itemHtml += `<span class='highlight'>${itemValue}</span>`
530
+ }
531
+ })
532
+ return `<a class="anchor__style" title = "Lookup ${item} in Dictionary" target = "_blank" href = "/word-meaning?search=${item.words}" >
533
+ <li>${itemHtml}
534
+ <span class="points" value="${item.points}" style="position:relative; top:4px; font-size:12px"> ${item.points}</span>
535
+ </li></a> `
536
+ })
537
+
538
+ let allGroupWords = document.getElementById(`alpha_${i}`)
539
+ if (allGroupWords) {
540
+ allGroupWords.innerHTML = `
541
+ <div class="wordListHeading">
542
+ <h3 class="lead">${i} Letter Words</h3>
543
+ </div>
544
+ <div class="wordList">
545
+ <ul class="ul list-unstyled">
546
+ ${result.join('')}
547
+ </ul>
548
+ </div>
549
+ `
550
+ }
551
+
552
+ }
553
+ }
554
+ }
555
+ }
556
+ // sort by aplhabets
557
+ function sortby(sortBool, data) {
558
+ if (sortBool) {
559
+ // main.innerHTML = ''
560
+ data.reverse()
561
+ let newWordsLength = 0
562
+ for (let i = serachValue.length; i >= 1; i--) {
563
+ var newdata = data.filter((item) => item.length === i)
564
+
565
+ if (newdata.length === 0) {
566
+ main.innerHTML += ''
567
+ } else {
568
+ newWordsLength += newdata.length
569
+
570
+ const result = newdata.map((item) => {
571
+ var text1 = serachValue.replace('?', '')
572
+ var text2 = item
573
+ var text3 = item
574
+ let chars = text1.split('')
575
+ let indexs = []
576
+ chars.map((i) => {
577
+ let findIndexes = findIndex(text3, i)
578
+ if (findIndexes.length > 0) {
579
+ text3 = text3.split('')
580
+ text3[findIndexes] = '$'
581
+ text3 = text3.join('')
582
+ indexs = [...indexs, ...findIndexes]
583
+ }
584
+ })
585
+ let itemHtml = ''
586
+ text2.split('').map((itemValue, index) => {
587
+ let check = indexs.find((i) => i === index)
588
+ if (check !== undefined) {
589
+ itemHtml += `${itemValue}`
590
+ } else {
591
+ itemHtml += `<span class='highlight'>${itemValue}</span>`
592
+ }
593
+ })
594
+ if (item.length === 1) {
595
+ ok = false
596
+ newWordsLength = newWordsLength - 1
597
+ } else {
598
+ let ScrabbleLetterScore = ScrabbleScore()
599
+ let sum = 0
600
+ item = item.toLowerCase()
601
+ for (let i = 0; i < item.length; i++) {
602
+ sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
603
+ }
604
+
605
+ return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target ="_blank" href="/word-meaning?search=${item.toLowerCase()}" >
606
+ <li>${itemHtml}
607
+ <span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px">${sum}</span>
608
+ </li></a> `
609
+ }
610
+ })
611
+ let allGroupWords = document.getElementById(`alpha_${i}`)
612
+ if (allGroupWords) {
613
+ allGroupWords.innerHTML = `
614
+ <div class="wordListHeading">
615
+ <h3 class="lead">${i} Letter Words</h3>
616
+ </div>
617
+ <div class="wordList">
618
+ <ul class="ul list-unstyled">
619
+ ${result.join('')}
620
+ </ul>
621
+ </div>
622
+ `
623
+ }
624
+ }
625
+ }
626
+ } else {
627
+ // main.innerHTML = ''
628
+ data.sort()
629
+ for (let i = serachValue.length; i >= 1; i--) {
630
+ var newdata = data.filter((item) => item.length === i)
631
+ if (newdata.length === 0) {
632
+ main.innerHTML += ''
633
+ } else {
634
+ const result = newdata.map((item) => {
635
+ var text1 = serachValue.replace('?', '')
636
+ var text2 = item
637
+ var text3 = item
638
+ let chars = text1.split('')
639
+ let indexs = []
640
+ chars.map((i) => {
641
+ let findIndexes = findIndex(text3, i)
642
+ if (findIndexes.length > 0) {
643
+ text3 = text3.split('')
644
+ text3[findIndexes] = '$'
645
+ text3 = text3.join('')
646
+ indexs = [...indexs, ...findIndexes]
647
+ }
648
+ })
649
+ let itemHtml = ''
650
+ text2.split('').map((itemValue, index) => {
651
+ let check = indexs.find((i) => i === index)
652
+ if (check !== undefined) {
653
+ itemHtml += `${itemValue}`
654
+ } else {
655
+ itemHtml += `<span class='highlight'>${itemValue}</span>`
656
+ }
657
+ })
658
+ if (item.length === 1) {
659
+ ok = false
660
+ } else {
661
+ let ScrabbleLetterScore = ScrabbleScore()
662
+ let sum = 0
663
+ item = item.toLowerCase()
664
+ for (let i = 0; i < item.length; i++) {
665
+ sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
666
+ }
667
+
668
+ return `<a class="anchor__style" title = "Lookup ${item} in Dictionary" target = "_blank" href="/word-meaning?search=${item.toLowerCase()}" >
669
+ <li>${itemHtml}
670
+ <span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px">${sum}</span>
671
+ </li></a> `
672
+ }
673
+ })
674
+ let allGroupWords = document.getElementById(`alpha_${i}`)
675
+ if (allGroupWords) {
676
+ allGroupWords.innerHTML = `
677
+ <div class="wordListHeading">
678
+ <h3 class="lead">${i} Letter Words</h3>
679
+ </div>
680
+ <div class="wordList">
681
+ <ul class="ul list-unstyled">
682
+ ${result.join('')}
683
+ </ul>
684
+ </div>
685
+ `
686
+ }
687
+
688
+ }
689
+ }
690
+ }
691
+ }
692
+
693
+ // Scrabble Point Array
694
+ const ScrabbleScore = () => {
695
+ let twl06_sowpods = {
696
+ a: 1,
697
+ e: 1,
698
+ i: 1,
699
+ o: 1,
700
+ u: 1,
701
+ l: 1,
702
+ n: 1,
703
+ r: 1,
704
+ s: 1,
705
+ t: 1,
706
+ d: 2,
707
+ g: 2,
708
+ b: 3,
709
+ c: 3,
710
+ m: 3,
711
+ p: 3,
712
+ f: 4,
713
+ h: 4,
714
+ v: 4,
715
+ w: 4,
716
+ y: 4,
717
+ k: 5,
718
+ j: 8,
719
+ x: 8,
720
+ q: 10,
721
+ z: 10,
722
+ }
723
+
724
+ let wwfScore = {
725
+ a: 1,
726
+ b: 4,
727
+ c: 4,
728
+ d: 2,
729
+ e: 1,
730
+ f: 4,
731
+ g: 3,
732
+ h: 3,
733
+ i: 1,
734
+ j: 10,
735
+ k: 5,
736
+ l: 2,
737
+ m: 4,
738
+ n: 2,
739
+ o: 1,
740
+ p: 4,
741
+ q: 10,
742
+ r: 1,
743
+ s: 1,
744
+ t: 1,
745
+ u: 2,
746
+ v: 5,
747
+ w: 4,
748
+ x: 8,
749
+ y: 3,
750
+ z: 10,
751
+ }
752
+
753
+ if (dictonary === 'wwf') {
754
+ return wwfScore
755
+ } else {
756
+ return twl06_sowpods
757
+ }
758
+ }
759
+ //Handling of filter counter in advanced filter
760
+ function addFilterCount() {
761
+ let filter_val = document.getElementsByClassName('filter_val')
762
+ let filter = document.querySelector('.filter_count')
763
+ let filter_count = 0
764
+
765
+ filter_val[0].value = prefixValue
766
+ filter_val[1].value = containsValue
767
+ filter_val[2].value = suffixValue
768
+ filter_val[3].value = exculdeValue
769
+ filter_val[4].value = includeValue
770
+ filter_val[5].value = lengthValue
771
+
772
+ for (var i = 0; i <= 5; i++) {
773
+ if (filter_val[i].value != '') {
774
+ filter_count += 1
775
+ }
776
+ if (filter_count === 0) {
777
+ filter.style.display = 'none'
778
+ } else {
779
+ filter.style.display = 'inline-block'
780
+ }
781
+
782
+ filter.innerHTML = filter_count
783
+ }
784
+ }
785
+ addFilterCount()
786
+ // handling of filter on scroll
787
+ window.onscroll = function () {
788
+ var section = document.querySelectorAll('.wordlistContainer')
789
+ let new_sections = {}
790
+ Array.prototype.forEach.call(section, function (e) {
791
+ if (document.body.clientWidth > 991) {
792
+ new_sections[e.id] = e.offsetTop - 10
793
+ } else {
794
+ new_sections[e.id] = e.offsetTop - 10
795
+ }
796
+ })
797
+ var scrollPosition =
798
+ document.documentElement.scrollTop || document.body.scrollTop
799
+
800
+ for (i in new_sections) {
801
+ let sort_val = document.querySelector('.sort-select').value
802
+ if (
803
+ i.split('_')[0] == sort_val &&
804
+ new_sections[i] &&
805
+ new_sections[i] <= scrollPosition
806
+ ) {
807
+ document.querySelector('.active-tab').classList.remove('active-tab')
808
+ var active_now = document.querySelector('#Tab_' + i.split('_')[1])
809
+ active_now.classList.add('active-tab')
810
+ active_now.scrollIntoView({ block: 'nearest' })
811
+ }
812
+ }
813
+ }
814
+
815
+ // Add Filtering
816
+ let sections = {}
817
+ function Filtering(id) {
818
+ let tabs = document.getElementsByClassName('tab_link')
819
+ tabs[0] ? tabs[0].classList.add('active-tab') : ''
820
+
821
+ Array.from(tabs).map((item) => {
822
+ item.classList.remove('active-tab')
823
+ })
824
+ main.innerHTML += ``
825
+ let activeLetter = event.target
826
+ activeLetter.classList.add('active-tab')
827
+
828
+
829
+ var section = document.querySelectorAll('.wordlistContainer')
830
+ var sort_val = document.querySelector('.sort-select').value
831
+ Array.prototype.forEach.call(section, function (e) {
832
+ if (document.body.clientWidth > 991) {
833
+ sections[e.id] = e.offsetTop - 10
834
+ } else {
835
+ sections[e.id] = e.offsetTop - 10
836
+ }
837
+ })
838
+
839
+ document.documentElement.scrollTop = sections[sort_val + '_' + id] + 5
840
+ }
841
+
842
+ // next && previous functionality
843
+ let prev = document.getElementById('prev')
844
+ let next = document.getElementById('next')
845
+
846
+ if (prev) {
847
+ prev.onclick = scroll_Right
848
+ }
849
+ if (next) {
850
+ next.onclick = scroll_Left
851
+ }
852
+ window.addEventListener('resize', function () {
853
+ scroll_visible()
854
+ })
855
+ window.addEventListener('scroll', function () {
856
+ scroll_visible()
857
+ })
858
+ function scroll_visible() {
859
+ let tab_container = document.querySelector('#tab-container')
860
+ if (tab_container) {
861
+ if (tab_container.clientWidth === tab_container.scrollWidth) {
862
+ prev.style.display = 'none'
863
+ next.style.display = 'none'
864
+ } else {
865
+ prev.style.display = 'block'
866
+ next.style.display = 'block'
867
+ }
868
+ }
869
+ }
870
+ scroll_visible()
871
+
872
+ function scroll_Left() {
873
+ tab_container.scrollLeft += 130
874
+ }
875
+ function scroll_Right() {
876
+ tab_container.scrollLeft -= 130
877
+ }
878
+ function findIndex(str, char) {
879
+ const strLength = str.length
880
+ const indexes = []
881
+ let newStr = str
882
+
883
+ while (newStr && newStr.indexOf(char) > -1) {
884
+ indexes.push(newStr.indexOf(char) + strLength - newStr.length)
885
+ newStr = newStr.substring(newStr.indexOf(char) + 5)
886
+ newStr = newStr.substring(newStr.indexOf(char) + 5)
887
+ }
888
+
889
+ return indexes
890
+ }