word-games-theme 1.2.7 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,888 @@
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
+ if (main.dataset.value !== "null") {
373
+ if (allGroupWords) {
374
+ Array.from(getAllGroupWords).forEach((item) => {
375
+ if (item.id.slice(6) <= stringLength.length) {
376
+ // if (item.nextSibling !== null && item.nextSibling.classList !== undefined && item.nextSibling.classList.contains("mmtwrappos")) {
377
+ // item.nextSibling.style.display = "block"
378
+ // }
379
+ item.style.display = "block"
380
+ }
381
+ else {
382
+ if (item.nextSibling !== null && item.nextSibling.classList !== undefined && item.nextSibling.classList.contains("mmtwrappos")) {
383
+ item.nextSibling.style.visibility = "hidden"
384
+ item.nextSibling.style.height = "0"
385
+ }
386
+ item.style.display = "none"
387
+ }
388
+ })
389
+ allGroupWords.innerHTML = `
390
+ <div class="wordListHeading">
391
+ <h3 class="lead">${i} Letter Words</h3>
392
+ </div>
393
+ <div class="wordList">
394
+ <ul class="ul list-unstyled">
395
+ ${result.join('')}
396
+ </ul>
397
+ </div>
398
+ `
399
+ }
400
+ else {
401
+ console.log(true)
402
+ let getAllGroupWords = [...main.getElementsByClassName('allGroupWords')]
403
+ let allGroupWords = document.createElement("div")
404
+ allGroupWords.className = "allGroupWords wordlistContainer"
405
+ allGroupWords.id = `alpha_${i}`
406
+ allGroupWords.innerHTML = `
407
+ <div class="wordListHeading">
408
+ <h3 class="lead">${i} Letter Words</h3>
409
+ </div>
410
+ <div class="wordList">
411
+ <ul class="ul list-unstyled">
412
+ ${result.join('')}
413
+ </ul>
414
+ </div>
415
+ `
416
+ blank.push(allGroupWords)
417
+ let newCreated = stringLength.length - getAllGroupWords.length - 1
418
+ inc = inc + 1
419
+ if (inc === newCreated) {
420
+ Array.from(blank).reverse().map((item) => {
421
+ main.prepend(item)
422
+ })
423
+ }
424
+ }
425
+ }
426
+ else {
427
+ if (i === 2) {
428
+ main.dataset.value = "not_null"
429
+ }
430
+ main.innerHTML += `
431
+ <div class="allGroupWords wordlistContainer" id="alpha_${i}">
432
+ <div class="wordListHeading">
433
+ <h3 class="lead">${i} Letter Words</h3>
434
+ </div>
435
+ <div class="wordList">
436
+ <ul class="ul list-unstyled">
437
+ ${result.join('')}
438
+ </ul>
439
+ </div>
440
+ </div>`
441
+
442
+ }
443
+ }
444
+ }
445
+ }
446
+ if (newWordsLength === 0) {
447
+ errorMsg.innerHTML = 'no words found'
448
+ } else {
449
+ wordCount.innerHTML = `<strong> Found ${newWordsLength} words with letters with ${serachValue.split(
450
+ ''
451
+ )
452
+ }</strong>`
453
+ }
454
+ }
455
+ }
456
+
457
+ // sorting by points
458
+ function sortPointsby(sortValue, data) {
459
+ // main.innerHTML = ''
460
+ if (sortValue) {
461
+ let newWordsLength = 0
462
+ for (let i = serachValue.length; i >= 1; i--) {
463
+ var newdata = data.filter((item) => item.length === i)
464
+
465
+ if (newdata.length === 0) {
466
+ main.innerHTML += ''
467
+ } else {
468
+ newWordsLength += newdata.length
469
+ var newArray = []
470
+ newdata.map((item) => {
471
+ if (item.length === 1) {
472
+ ok = false
473
+ newWordsLength = newWordsLength - 1
474
+ } else {
475
+ let ScrabbleLetterScore = ScrabbleScore()
476
+ let points = 0
477
+ item = item.toLowerCase()
478
+ for (let i = 0; i < item.length; i++) {
479
+ points += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
480
+ }
481
+ const value = {
482
+ words: item,
483
+ points: points,
484
+ }
485
+ newArray.push(value)
486
+ }
487
+ })
488
+
489
+ newArray.sort(function (a, b) {
490
+ return b.points - a.points
491
+ })
492
+
493
+ const result = newArray.map((item) => {
494
+ var text1 = serachValue.replace('?', '')
495
+ var text2 = item.words
496
+ var text3 = item.words
497
+
498
+
499
+ function findIndex(str, char) {
500
+ const strLength = str.length
501
+ const indexes = []
502
+ let newStr = str
503
+ while (newStr && newStr.indexOf(char) > -1) {
504
+ indexes.push(newStr.indexOf(char) + strLength - newStr.length)
505
+ newStr = newStr.substring(newStr.indexOf(char) + 1)
506
+ newStr = newStr.substring(newStr.indexOf(char) + 1)
507
+ }
508
+ return indexes
509
+ }
510
+ let chars = text1.split('')
511
+ let indexs = []
512
+ chars.map((i) => {
513
+ let findIndexes = findIndex(text3, i)
514
+ if (findIndexes.length > 0) {
515
+ text3 = text3.split('')
516
+ text3[findIndexes] = '$'
517
+ text3 = text3.join('')
518
+ indexs = [...indexs, ...findIndexes]
519
+ }
520
+ })
521
+ let itemHtml = ''
522
+ text2.split('').map((itemValue, index) => {
523
+ let check = indexs.find((i) => i === index)
524
+ if (check !== undefined) {
525
+ itemHtml += `${itemValue}`
526
+ } else {
527
+ itemHtml += `<span class='highlight'>${itemValue}</span>`
528
+ }
529
+ })
530
+ return `<a class="anchor__style" title = "Lookup ${item} in Dictionary" target = "_blank" href = "/word-meaning?search=${item.words}" >
531
+ <li>${itemHtml}
532
+ <span class="points" value="${item.points}" style="position:relative; top:4px; font-size:12px"> ${item.points}</span>
533
+ </li></a> `
534
+ })
535
+
536
+ let allGroupWords = document.getElementById(`alpha_${i}`)
537
+ if (allGroupWords) {
538
+ allGroupWords.innerHTML = `
539
+ <div class="wordListHeading">
540
+ <h3 class="lead">${i} Letter Words</h3>
541
+ </div>
542
+ <div class="wordList">
543
+ <ul class="ul list-unstyled">
544
+ ${result.join('')}
545
+ </ul>
546
+ </div>
547
+ `
548
+ }
549
+
550
+ }
551
+ }
552
+ }
553
+ }
554
+ // sort by aplhabets
555
+ function sortby(sortBool, data) {
556
+ if (sortBool) {
557
+ // main.innerHTML = ''
558
+ data.reverse()
559
+ let newWordsLength = 0
560
+ for (let i = serachValue.length; i >= 1; i--) {
561
+ var newdata = data.filter((item) => item.length === i)
562
+
563
+ if (newdata.length === 0) {
564
+ main.innerHTML += ''
565
+ } else {
566
+ newWordsLength += newdata.length
567
+
568
+ const result = newdata.map((item) => {
569
+ var text1 = serachValue.replace('?', '')
570
+ var text2 = item
571
+ var text3 = item
572
+ let chars = text1.split('')
573
+ let indexs = []
574
+ chars.map((i) => {
575
+ let findIndexes = findIndex(text3, i)
576
+ if (findIndexes.length > 0) {
577
+ text3 = text3.split('')
578
+ text3[findIndexes] = '$'
579
+ text3 = text3.join('')
580
+ indexs = [...indexs, ...findIndexes]
581
+ }
582
+ })
583
+ let itemHtml = ''
584
+ text2.split('').map((itemValue, index) => {
585
+ let check = indexs.find((i) => i === index)
586
+ if (check !== undefined) {
587
+ itemHtml += `${itemValue}`
588
+ } else {
589
+ itemHtml += `<span class='highlight'>${itemValue}</span>`
590
+ }
591
+ })
592
+ if (item.length === 1) {
593
+ ok = false
594
+ newWordsLength = newWordsLength - 1
595
+ } else {
596
+ let ScrabbleLetterScore = ScrabbleScore()
597
+ let sum = 0
598
+ item = item.toLowerCase()
599
+ for (let i = 0; i < item.length; i++) {
600
+ sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
601
+ }
602
+
603
+ return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target ="_blank" href="/word-meaning?search=${item.toLowerCase()}" >
604
+ <li>${itemHtml}
605
+ <span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px">${sum}</span>
606
+ </li></a> `
607
+ }
608
+ })
609
+ let allGroupWords = document.getElementById(`alpha_${i}`)
610
+ if (allGroupWords) {
611
+ allGroupWords.innerHTML = `
612
+ <div class="wordListHeading">
613
+ <h3 class="lead">${i} Letter Words</h3>
614
+ </div>
615
+ <div class="wordList">
616
+ <ul class="ul list-unstyled">
617
+ ${result.join('')}
618
+ </ul>
619
+ </div>
620
+ `
621
+ }
622
+ }
623
+ }
624
+ } else {
625
+ // main.innerHTML = ''
626
+ data.sort()
627
+ for (let i = serachValue.length; i >= 1; i--) {
628
+ var newdata = data.filter((item) => item.length === i)
629
+ if (newdata.length === 0) {
630
+ main.innerHTML += ''
631
+ } else {
632
+ const result = newdata.map((item) => {
633
+ var text1 = serachValue.replace('?', '')
634
+ var text2 = item
635
+ var text3 = item
636
+ let chars = text1.split('')
637
+ let indexs = []
638
+ chars.map((i) => {
639
+ let findIndexes = findIndex(text3, i)
640
+ if (findIndexes.length > 0) {
641
+ text3 = text3.split('')
642
+ text3[findIndexes] = '$'
643
+ text3 = text3.join('')
644
+ indexs = [...indexs, ...findIndexes]
645
+ }
646
+ })
647
+ let itemHtml = ''
648
+ text2.split('').map((itemValue, index) => {
649
+ let check = indexs.find((i) => i === index)
650
+ if (check !== undefined) {
651
+ itemHtml += `${itemValue}`
652
+ } else {
653
+ itemHtml += `<span class='highlight'>${itemValue}</span>`
654
+ }
655
+ })
656
+ if (item.length === 1) {
657
+ ok = false
658
+ } else {
659
+ let ScrabbleLetterScore = ScrabbleScore()
660
+ let sum = 0
661
+ item = item.toLowerCase()
662
+ for (let i = 0; i < item.length; i++) {
663
+ sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
664
+ }
665
+
666
+ return `<a class="anchor__style" title = "Lookup ${item} in Dictionary" target = "_blank" href="/word-meaning?search=${item.toLowerCase()}" >
667
+ <li>${itemHtml}
668
+ <span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px">${sum}</span>
669
+ </li></a> `
670
+ }
671
+ })
672
+ let allGroupWords = document.getElementById(`alpha_${i}`)
673
+ if (allGroupWords) {
674
+ allGroupWords.innerHTML = `
675
+ <div class="wordListHeading">
676
+ <h3 class="lead">${i} Letter Words</h3>
677
+ </div>
678
+ <div class="wordList">
679
+ <ul class="ul list-unstyled">
680
+ ${result.join('')}
681
+ </ul>
682
+ </div>
683
+ `
684
+ }
685
+
686
+ }
687
+ }
688
+ }
689
+ }
690
+
691
+ // Scrabble Point Array
692
+ const ScrabbleScore = () => {
693
+ let twl06_sowpods = {
694
+ a: 1,
695
+ e: 1,
696
+ i: 1,
697
+ o: 1,
698
+ u: 1,
699
+ l: 1,
700
+ n: 1,
701
+ r: 1,
702
+ s: 1,
703
+ t: 1,
704
+ d: 2,
705
+ g: 2,
706
+ b: 3,
707
+ c: 3,
708
+ m: 3,
709
+ p: 3,
710
+ f: 4,
711
+ h: 4,
712
+ v: 4,
713
+ w: 4,
714
+ y: 4,
715
+ k: 5,
716
+ j: 8,
717
+ x: 8,
718
+ q: 10,
719
+ z: 10,
720
+ }
721
+
722
+ let wwfScore = {
723
+ a: 1,
724
+ b: 4,
725
+ c: 4,
726
+ d: 2,
727
+ e: 1,
728
+ f: 4,
729
+ g: 3,
730
+ h: 3,
731
+ i: 1,
732
+ j: 10,
733
+ k: 5,
734
+ l: 2,
735
+ m: 4,
736
+ n: 2,
737
+ o: 1,
738
+ p: 4,
739
+ q: 10,
740
+ r: 1,
741
+ s: 1,
742
+ t: 1,
743
+ u: 2,
744
+ v: 5,
745
+ w: 4,
746
+ x: 8,
747
+ y: 3,
748
+ z: 10,
749
+ }
750
+
751
+ if (dictonary === 'wwf') {
752
+ return wwfScore
753
+ } else {
754
+ return twl06_sowpods
755
+ }
756
+ }
757
+ //Handling of filter counter in advanced filter
758
+ function addFilterCount() {
759
+ let filter_val = document.getElementsByClassName('filter_val')
760
+ let filter = document.querySelector('.filter_count')
761
+ let filter_count = 0
762
+
763
+ filter_val[0].value = prefixValue
764
+ filter_val[1].value = containsValue
765
+ filter_val[2].value = suffixValue
766
+ filter_val[3].value = exculdeValue
767
+ filter_val[4].value = includeValue
768
+ filter_val[5].value = lengthValue
769
+
770
+ for (var i = 0; i <= 5; i++) {
771
+ if (filter_val[i].value != '') {
772
+ filter_count += 1
773
+ }
774
+ if (filter_count === 0) {
775
+ filter.style.display = 'none'
776
+ } else {
777
+ filter.style.display = 'inline-block'
778
+ }
779
+
780
+ filter.innerHTML = filter_count
781
+ }
782
+ }
783
+ addFilterCount()
784
+ // handling of filter on scroll
785
+ window.onscroll = function () {
786
+ var section = document.querySelectorAll('.wordlistContainer')
787
+ let new_sections = {}
788
+ Array.prototype.forEach.call(section, function (e) {
789
+ if (document.body.clientWidth > 991) {
790
+ new_sections[e.id] = e.offsetTop - 10
791
+ } else {
792
+ new_sections[e.id] = e.offsetTop - 10
793
+ }
794
+ })
795
+ var scrollPosition =
796
+ document.documentElement.scrollTop || document.body.scrollTop
797
+
798
+ for (i in new_sections) {
799
+ let sort_val = document.querySelector('.sort-select').value
800
+ if (
801
+ i.split('_')[0] == sort_val &&
802
+ new_sections[i] &&
803
+ new_sections[i] <= scrollPosition
804
+ ) {
805
+ document.querySelector('.active-tab').classList.remove('active-tab')
806
+ var active_now = document.querySelector('#Tab_' + i.split('_')[1])
807
+ active_now.classList.add('active-tab')
808
+ active_now.scrollIntoView({ block: 'nearest' })
809
+ }
810
+ }
811
+ }
812
+
813
+ // Add Filtering
814
+ let sections = {}
815
+ function Filtering(id) {
816
+ let tabs = document.getElementsByClassName('tab_link')
817
+ tabs[0] ? tabs[0].classList.add('active-tab') : ''
818
+
819
+ Array.from(tabs).map((item) => {
820
+ item.classList.remove('active-tab')
821
+ })
822
+ main.innerHTML += ``
823
+ let activeLetter = event.target
824
+ activeLetter.classList.add('active-tab')
825
+
826
+
827
+ var section = document.querySelectorAll('.wordlistContainer')
828
+ var sort_val = document.querySelector('.sort-select').value
829
+ Array.prototype.forEach.call(section, function (e) {
830
+ if (document.body.clientWidth > 991) {
831
+ sections[e.id] = e.offsetTop - 10
832
+ } else {
833
+ sections[e.id] = e.offsetTop - 10
834
+ }
835
+ })
836
+
837
+ document.documentElement.scrollTop = sections[sort_val + '_' + id] + 5
838
+ }
839
+
840
+ // next && previous functionality
841
+ let prev = document.getElementById('prev')
842
+ let next = document.getElementById('next')
843
+
844
+ if (prev) {
845
+ prev.onclick = scroll_Right
846
+ }
847
+ if (next) {
848
+ next.onclick = scroll_Left
849
+ }
850
+ window.addEventListener('resize', function () {
851
+ scroll_visible()
852
+ })
853
+ window.addEventListener('scroll', function () {
854
+ scroll_visible()
855
+ })
856
+ function scroll_visible() {
857
+ let tab_container = document.querySelector('#tab-container')
858
+ if (tab_container) {
859
+ if (tab_container.clientWidth === tab_container.scrollWidth) {
860
+ prev.style.display = 'none'
861
+ next.style.display = 'none'
862
+ } else {
863
+ prev.style.display = 'block'
864
+ next.style.display = 'block'
865
+ }
866
+ }
867
+ }
868
+ scroll_visible()
869
+
870
+ function scroll_Left() {
871
+ tab_container.scrollLeft += 130
872
+ }
873
+ function scroll_Right() {
874
+ tab_container.scrollLeft -= 130
875
+ }
876
+ function findIndex(str, char) {
877
+ const strLength = str.length
878
+ const indexes = []
879
+ let newStr = str
880
+
881
+ while (newStr && newStr.indexOf(char) > -1) {
882
+ indexes.push(newStr.indexOf(char) + strLength - newStr.length)
883
+ newStr = newStr.substring(newStr.indexOf(char) + 5)
884
+ newStr = newStr.substring(newStr.indexOf(char) + 5)
885
+ }
886
+
887
+ return indexes
888
+ }