-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguageSelector.vue
150 lines (126 loc) · 3.06 KB
/
LanguageSelector.vue
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
<div class="dropdown">
<div class="dropbtnBackground">
<button @click="dropdownClick" class="dropbtn">🌐</button>
</div>
<div id="myDropdown" class="dropdown-content">
<div class="lgItem cat" value='ca' @click='changeLanguage' href="#">Català</div>
<div class="lgItem es" value='es' @click='changeLanguage' href="#">Español</div>
<div class="lgItem en" value='en' @click='changeLanguage' href="#">English</div>
</div>
</div>
</template>
<script>
export default {
name: "app-manager",
created(){
// Set default navigator language
this.$i18n.locale = navigator.language;
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
},
mounted () {
},
data () {
return {
}
},
methods: {
// INTERNAL EVENTS
dropdownClick: function(){
document.getElementById("myDropdown").classList.toggle("show");
},
// Change language
changeLanguage: function(el){
this.$i18n.locale = el.target.getAttribute('value');
},
},
components: {
},
computed: {
}
}
</script>
<style scoped>
/* Dropdown Button */
.dropbtn {
background-color: #5580b4;
border-radius: 4px;
color: white;
padding: 4px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropbtnBackground{
background-color: #ffffff74;
border-radius: 4px;
padding: 3px;
}
/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
background-color: #2d5a91;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
z-index: 3;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #a0d7f2;;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
/* Links inside the dropdown */
.dropdown-content .lgItem {
color: black;
padding: 4px 4px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content .lgItem:hover {
background-color: #63c0ee;
cursor: pointer;
}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}
.lgItem:before {
content: '';
display: inline-block;
width: 25px;
height: 25px;
vertical-align: middle;
margin-right: 10px;
margin-left: 10px;
background-size: contain;
background-repeat: no-repeat;
}
.es:before {
content: '';
background-image: url(img/es-200.png);
}
.en:before {
content: '';
background-image: url(img/en-200.png);
}
.cat:before {
content: '';
background-image: url(img/ca-200.png);
}
</style>