-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
102 lines (91 loc) · 3.62 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
______ ______ __ __ __ __ _____ __
/ ____/___ / ____/_______ ____ _____/ /_ / /_ __ __ / /___ / /_ ____ / ___/____ ____ _/ /_ _____
/ / __/ __ \/ /_ / ___/ _ \/ __ \/ ___/ __ \ / __ \/ / / / __ / / __ \/ __ \/ __ \ \__ \/ __ \/ __ `/ __ \/ ___/
/ /_/ / /_/ / __/ / / / __/ / / / /__/ / / / / /_/ / /_/ / / /_/ / /_/ / / / / / / / ___/ / /_/ / /_/ / / / / /
\____/\____/_/ /_/ \___/_/ /_/\___/_/ /_/ /_.___/\__, / \____/\____/_/ /_/_/ /_/ /____/ .___/\__,_/_/ /_/_/
/____/ /_/
Copyright (c) John Spahr, 2019-2024.
*/
//focus on inputTxt when GoFrench loads
document.addEventListener(
'DOMContentLoaded',
function() {
document.getElementById('inputTxt').focus();
},
false
);
//handle button presses in search bar
function txtChange(e) {
if (e.keyCode == 13) {
//if enter key is pressed, get site
getSite();
return false;
}
}
//handle special chars buttons
function specialChar(button) {
navigator.clipboard.writeText(button.textContent); //copy button text to clipboard
alert("Copied character to clipboard."); //give user feedback
}
//toggle accents visibility
function toggleChars(button) {
//get special chars div
var specialChars = document.getElementById("specialChars");
if (specialChars.style.display == "inline") {
//hide
specialChars.style.display = "none";
button.textContent = "Show Accents";
button.innerHTML = "<i class=\"fas fa-chevron-down\"></i> Show Accents";
} else {
//show
specialChars.style.display = "inline";
button.innerHTML = "<i class=\"fas fa-chevron-up\"></i> Hide Accents";
}
}
//handle search functionality
function getSite() {
var inputString = document.getElementById('inputTxt').value.trim(); //trims input
if (inputString != '') {
//makes sure text box isn't blank
var count = (inputString.match(/ /g) || []).length; //gets number of spaces in text box.
if (count == 0) {
//no spaces
//open wordreference
window.open('http://www.wordreference.com/enfr/' + inputString, '_blank');
} else {
//spaces
//open linguee
window.open(
'http://linguee.com/english-french/search?source=auto&query=' +
inputString,
'_blank'
);
}
document.getElementById('inputTxt').value = ''; //reset text input field
} else {
alert('Please enter a search query.'); //if input is blank
}
}
function conjugate() {
//open wordreference word conjugation
var inputString = document.getElementById('inputTxt').value.trim(); //get input value
if (inputString != '') {
//open conjugation result in new tab
window.open(
'http://www.wordreference.com/conj/frverbs.aspx?v=' +
inputString,
'_blank'
);
document.getElementById('inputTxt').value = ''; //reset text input field
} else {
alert('Please enter a search query.'); //if input is blank
}
}
$(document).ready(function() {
if ($(window).width() < 560) {
//hide accents
specialChars.style.display = "none";
document.getElementById("charsBtn").innerHTML = "<i class=\"fas fa-chevron-down\"></i> Show Accents";
}
});