word-games-theme 1.1.1 → 1.1.4

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