Skip to content

Commit

Permalink
only call setLocale() if locale has changed (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin authored Mar 16, 2020
1 parent d24e6b2 commit c1d4726
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions assets/js/multilingual.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@
this.$dropdown = $('ul.ml-dropdown-menu', this.$el)
this.$placeholder = $(this.options.placeholderField)

this.$dropdown.on('click', '[data-switch-locale]', function(event){
/*
* Init locale
*/
this.activeLocale = this.options.defaultLocale
this.$activeField = this.getLocaleElement(this.activeLocale)
this.$activeButton.text(this.activeLocale)

this.$dropdown.on('click', '[data-switch-locale]', this.$activeButton, function(event){
var currentLocale = event.data.text();
var selectedLocale = $(this).data('switch-locale')
self.setLocale(selectedLocale)

// only call setLocale() if locale has changed
if (selectedLocale != currentLocale) {
self.setLocale(selectedLocale)
}

/*
* If Ctrl/Cmd key is pressed, find other instances and switch
Expand All @@ -45,13 +57,6 @@
self.$activeField.val(this.value)
})

/*
* Init locale
*/
this.activeLocale = this.options.defaultLocale
this.$activeField = this.getLocaleElement(this.activeLocale)
this.$activeButton.text(this.activeLocale)

/*
* Handle oc.inputPreset.beforeUpdate event
*/
Expand Down

0 comments on commit c1d4726

Please sign in to comment.