assets/js/X-letter.js in word-games-theme-1.0.1 vs assets/js/X-letter.js in word-games-theme-1.0.2
- old
+ new
@@ -1,8 +1,6 @@
----
----
-const getScript=document.currentScript
+const getScript = document.currentScript
const letterLen = getScript.dataset.letter
const ablank = getScript.dataset.ablank
const siteUrl = getScript.dataset.url
@@ -31,19 +29,34 @@
let txtBox = document.querySelector('.txtBox')
txtBox.focus()
txtBox.value = serachValue
-if(ablank){
-if(!serachValue.includes("?")){
- if(serachValue.length < letterLen){
- serachValue = serachValue + '?'
+if (ablank) {
+ if (!serachValue.includes("?")) {
+ if (serachValue.length < letterLen) {
+ serachValue = serachValue + '?'
+ }
}
- }
}
+
+let letterCloseButton = document.querySelector('.letter-close-button-commonPage')
+if (serachValue) {
+ letterCloseButton.classList.add("ltr-cls-btn-commonPage")
+}
+letterCloseButton.addEventListener("click", () => {
+ txtBox.value = ""
+ letterCloseButton.classList.remove("ltr-cls-btn-commonPage")
+})
+
txtBox.addEventListener('input', (e) => {
+ if (e.target.value === "") {
+ letterCloseButton.classList.remove("ltr-cls-btn-commonPage")
+ } else {
+ letterCloseButton.classList.add("ltr-cls-btn-commonPage")
+ }
let rangeOfBlankTile = script.dataset.range
e.target.value = e.target.value.replace(/[^a-zA-Z? ]/g, '')
if (rangeOfBlankTile === '') {
rangeOfBlankTile = 5
}
@@ -178,12 +191,12 @@
inculdeWith.classList.add('tick')
inculdeWith.value = includeValue
filterData = data
}
-
+
if (filterData.length === 0) {
main.innerHTML += ''
errorMsg.innerHTML = 'No words Found with this length'
} else {
// sort eventlistener
@@ -246,12 +259,12 @@
itemHtml += `${itemValue}`
} else {
itemHtml += `<span class='highlight'>${itemValue}</span>`
}
})
-
-
+
+
return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item}">
<li>${itemHtml}
<span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span>
</li></a>`
})
@@ -264,12 +277,12 @@
// `
// let tabs = document.getElementsByClassName('tab_link')
// tabs[0] ? tabs[0].classList.add('active-tab') : ''
- home_page_search_result.href = homePageSearchResult
- home_page_search_result.innerHTML = `See words of any length with letters ${serachValue.split("")}`
+ home_page_search_result.href = homePageSearchResult
+ home_page_search_result.innerHTML = `See words of any length with letters ${serachValue.split("")}`
main.innerHTML += `
<div class="allGroupWords">
<div class="wordListHeading">
@@ -338,43 +351,43 @@
return b.points - a.points
})
})
const result = newArray.map((item) => {
var text1 = serachValue.replace('?', '')
- var text2 = item.words
- var text3 = item.words
- function findIndex(str, char) {
- const strLength = str.length
- const indexes = []
- let newStr = str
- while (newStr && newStr.indexOf(char) > -1) {
- indexes.push(newStr.indexOf(char) + strLength - newStr.length)
- newStr = newStr.substring(newStr.indexOf(char) + 1)
- newStr = newStr.substring(newStr.indexOf(char) + 1)
- }
- return indexes
+ var text2 = item.words
+ var text3 = item.words
+ function findIndex(str, char) {
+ const strLength = str.length
+ const indexes = []
+ let newStr = str
+ while (newStr && newStr.indexOf(char) > -1) {
+ indexes.push(newStr.indexOf(char) + strLength - newStr.length)
+ newStr = newStr.substring(newStr.indexOf(char) + 1)
+ newStr = newStr.substring(newStr.indexOf(char) + 1)
}
- let chars = text1.split('')
- let indexs = []
- chars.map((i) => {
- let findIndexes = findIndex(text3, i)
- if (findIndexes.length > 0) {
- text3 = text3.split('')
- text3[findIndexes] = '$'
- text3 = text3.join('')
- indexs = [...indexs, ...findIndexes]
- }
- })
- let itemHtml = ''
- text2.split('').map((itemValue, index) => {
- let check = indexs.find((i) => i === index)
- if (check !== undefined) {
- itemHtml += `${itemValue}`
- } else {
- itemHtml += `<span class='highlight'>${itemValue}</span>`
- }
- })
+ return indexes
+ }
+ let chars = text1.split('')
+ let indexs = []
+ chars.map((i) => {
+ let findIndexes = findIndex(text3, i)
+ if (findIndexes.length > 0) {
+ text3 = text3.split('')
+ text3[findIndexes] = '$'
+ text3 = text3.join('')
+ indexs = [...indexs, ...findIndexes]
+ }
+ })
+ let itemHtml = ''
+ text2.split('').map((itemValue, index) => {
+ let check = indexs.find((i) => i === index)
+ if (check !== undefined) {
+ itemHtml += `${itemValue}`
+ } else {
+ itemHtml += `<span class='highlight'>${itemValue}</span>`
+ }
+ })
return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item.words}">
<li>${itemHtml}
<span class="points" value="${item.points}" style="position:relative; top:4px; font-size:12px"> ${item.points}</span>
</li></a>`
})
@@ -438,11 +451,11 @@
itemHtml += `${itemValue}`
} else {
itemHtml += `<span class='highlight'>${itemValue}</span>`
}
})
-
+
return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item}">
<li>${itemHtml}
<span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span>
</li></a>`
})
@@ -503,10 +516,10 @@
itemHtml += `${itemValue}`
} else {
itemHtml += `<span class='highlight'>${itemValue}</span>`
}
})
-
+
return `<a class="anchor__style" title="Lookup ${item} in Dictionary" target="_blank" href="/word-meaning?search=${item}">
<li>${itemHtml}
<span class="points" value="${sum}" style="position:relative; top:4px; font-size:12px"> ${sum}</span>
</li></a>`
})