-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add event listener for language dropdown
- Loading branch information
1 parent
2bb0215
commit c75711a
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Define the common callback function | ||
const handleLanguageChange = (event) => { | ||
// Retrieve the ID of the clicked item | ||
const itemId = event.target.id; | ||
|
||
// Extract the {key} value from the ID (assuming ID format is 'langChoice-{key}') | ||
const key = itemId.split('langChoice-')[1]; | ||
|
||
// Set a cookie with the name 'currentLocale' and the extracted {key} value | ||
document.cookie = `currentLocale=${key}; path=/;`; | ||
|
||
// Reload the page | ||
location.reload(); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function() { | ||
// Get all elements with class 'dropdown-item' that are children of the element with ID 'langChoicesDropdownItems' | ||
const dropdownItems = document.querySelectorAll('#langChoicesDropdownItems .dropdown-item'); | ||
|
||
// Loop through each element and add a click event listener with the callback function | ||
dropdownItems.forEach(function(item) { | ||
item.addEventListener('click', handleLanguageChange); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/i18nextHttpBackend.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/1.1.2/js/bootstrap-multiselect.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script> | ||
<script src="assets/js/common.js"></script> | ||
<script>const locale = '<?php echo $i18n->locale ?>';</script> | ||
<?php | ||
if ($pageName === 'admin') { | ||
|