-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add language dropdown menu to My Preferences
- Loading branch information
1 parent
b154cef
commit fc255e1
Showing
4 changed files
with
84 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,32 @@ | ||
$(document).ready(function () { | ||
$("#available_languages_menu").prop("hidden", false); | ||
$("#user_languages, #available_languages").on("input", updateButtons); | ||
updateButtons(); | ||
|
||
$("#add_preferred_language").click(function () { | ||
var preferredLanguagesValue = $("#user_languages").val().trim(); | ||
var selectedLanguage = $("#available_languages").val(); | ||
$("#user_languages").val(selectedLanguage + " " + preferredLanguagesValue); | ||
updateButtons(); | ||
$("#remove_preferred_language").trigger("focus"); | ||
}); | ||
|
||
$("#remove_preferred_language").click(function () { | ||
var preferredLanguages = $("#user_languages").val().trim().split(/\s+/); | ||
var selectedLanguage = $("#available_languages").val(); | ||
var updatedPreferredLanguages = preferredLanguages.filter(function (language) { | ||
return language !== selectedLanguage; | ||
}); | ||
$("#user_languages").val(updatedPreferredLanguages.join(" ")); | ||
updateButtons(); | ||
$("#add_preferred_language").trigger("focus"); | ||
}); | ||
|
||
function updateButtons() { | ||
var preferredLanguages = $("#user_languages").val().trim().split(/\s+/); | ||
var selectedLanguage = $("#available_languages").val(); | ||
var languageAlreadyAdded = preferredLanguages.includes(selectedLanguage); | ||
$("#add_preferred_language").prop("hidden", languageAlreadyAdded); | ||
$("#remove_preferred_language").prop("hidden", !languageAlreadyAdded); | ||
} | ||
}); |
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
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
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