word-games-theme 1.1.1 → 1.1.2

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