Preferred Languages - Version 1.5.0

Version Description

  • Enhancement: Improved compatibility with multilingual plugins like Polylang.
  • Fixed: Fixes an issue with keyboard navigation.
  • Fixed: Make sure the correct languages are retrieved when updating the settings.
Download this release

Release Info

Developer swissspidy
Plugin Icon Preferred Languages
Version 1.5.0
Comparing to
See all releases

Code changes from version 1.4.0 to 1.5.0

CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
  # Changelog
2
 
 
 
 
 
 
 
3
  ## 1.4.0
4
 
5
  * New: Keyboard navigation improvements.
1
  # Changelog
2
 
3
+ ## 1.5.0
4
+
5
+ * Enhancement: Improved compatibility with multilingual plugins like Polylang.
6
+ * Fixed: Fixes an issue with keyboard navigation.
7
+ * Fixed: Make sure the correct languages are retrieved when updating the settings.
8
+
9
  ## 1.4.0
10
 
11
  * New: Keyboard navigation improvements.
css/preferred-languages-rtl.css CHANGED
@@ -1 +1 @@
1
- .active-locales{margin:1em 0}.active-locales-list,.inactive-locales-list{width:25em;margin:0 0 1em 1em;clear:both;float:right}.active-locales-controls{clear:both}.active-locales-controls .button,.active-locales-controls ul{margin:0}@media screen and (min-width:510px){.active-locales-controls{clear:none}}.active-locales-list{height:98px;overflow-y:scroll;margin-top:0;background:#fff;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);border:1px solid #ddd;color:#32373c;box-sizing:border-box}.active-locales-list.empty-list{background:hsla(0,0%,100%,.5);border-color:hsla(0,0%,87%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:-webkit-box;display:flex;-webkit-box-align:center;align-items:center}.active-locales-list li{box-sizing:border-box;width:100%;height:28px;line-height:28px;margin:0;padding:0 8px 0 0;cursor:pointer}.active-locales-list li:hover{background:rgba(0,0,0,.07)}.active-locales-list li[aria-selected=true]{background:rgba(0,0,0,.15)}#active-locales-empty-message{display:-webkit-box;display:flex;-webkit-box-pack:center;justify-content:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column;position:relative;text-align:center;width:25em;height:98px;margin-bottom:-98px;box-sizing:border-box;color:rgba(51,51,51,.5)}#active-locales-empty-message.hidden{display:none}.inactive-locales{clear:both}.inactive-locales select{width:100%}.preferred-languages .notice{display:inline-block}.no-js #preferred-languages-label,.no-js .preferred-languages,.no-js .user-preferred-languages-wrap{display:none}@-webkit-keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}@keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}.tooltipped{position:relative}.tooltipped:active:after,.tooltipped:active:before,.tooltipped:focus:after,.tooltipped:focus:before,.tooltipped:hover:after,.tooltipped:hover:before{opacity:1;display:inline-block;text-decoration:none;-webkit-animation-name:tooltip-appear;animation-name:tooltip-appear;-webkit-animation-duration:.1s;animation-duration:.1s;-webkit-animation-fill-mode:backwards;animation-fill-mode:backwards;-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in;-webkit-animation-delay:.4s;animation-delay:.4s}.tooltipped:before{z-index:1000001;width:0;height:0;color:#191e23;content:"";border:6px solid transparent;top:-7px;left:50%;bottom:auto;margin-left:-6px;border-top-color:#191e23}.tooltipped:after,.tooltipped:before{position:absolute;display:none;pointer-events:none;opacity:0}.tooltipped:after{z-index:1000000;padding:.5em .75em;font:normal normal 11px/1.5 -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif;-webkit-font-smoothing:subpixel-antialiased;color:#fff;text-align:center;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-wrap:break-word;white-space:pre;content:attr(data-tooltip);background:#191e23;border-radius:3px;left:auto;right:50%;margin-right:-16px;bottom:100%;margin-bottom:6px}
1
+ .active-locales{margin:1em 0}.active-locales-list,.inactive-locales-list{width:25em;margin:0 0 1em 1em;clear:both;float:right}.active-locales-controls{clear:both}.active-locales-controls .button,.active-locales-controls ul{margin:0}@media screen and (min-width:510px){.active-locales-controls{clear:none}}.active-locales-list{height:98px;overflow-y:scroll;margin-top:0;background:#fff;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);border:1px solid #ddd;color:#32373c;box-sizing:border-box}.active-locales-list.empty-list{background:hsla(0,0%,100%,.5);border-color:hsla(0,0%,87.1%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:flex;align-items:center}.active-locales-list li{box-sizing:border-box;width:100%;height:28px;line-height:28px;margin:0;padding:0 8px 0 0;cursor:pointer}.active-locales-list li:hover{background:rgba(0,0,0,.07)}.active-locales-list li[aria-selected=true]{background:rgba(0,0,0,.15)}#active-locales-empty-message{display:flex;justify-content:center;flex-direction:column;position:relative;text-align:center;width:25em;height:98px;margin-bottom:-98px;box-sizing:border-box;color:rgba(51,51,51,.5)}#active-locales-empty-message.hidden{display:none}.inactive-locales{clear:both}.inactive-locales select{width:100%}.preferred-languages .notice{display:inline-block}.no-js #preferred-languages-label,.no-js .preferred-languages,.no-js .user-preferred-languages-wrap{display:none}@keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}.tooltipped{position:relative}.tooltipped:active:after,.tooltipped:active:before,.tooltipped:focus:after,.tooltipped:focus:before,.tooltipped:hover:after,.tooltipped:hover:before{opacity:1;display:inline-block;text-decoration:none;animation-name:tooltip-appear;animation-duration:.1s;animation-fill-mode:backwards;animation-timing-function:ease-in;animation-delay:.4s}.tooltipped:before{z-index:1000001;width:0;height:0;color:#191e23;content:"";top:-7px;left:50%;bottom:auto;margin-left:-6px;border:6px solid transparent;border-top-color:#191e23}.tooltipped:after,.tooltipped:before{position:absolute;display:none;pointer-events:none;opacity:0}.tooltipped:after{z-index:1000000;padding:.5em .75em;font:normal normal 11px/1.5 -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;-webkit-font-smoothing:subpixel-antialiased;color:#fff;text-align:center;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-wrap:break-word;white-space:pre;content:attr(data-tooltip);background:#191e23;border-radius:3px;left:auto;right:50%;margin-right:-16px;bottom:100%;margin-bottom:6px}
css/preferred-languages.css CHANGED
@@ -1 +1 @@
1
- .active-locales{margin:1em 0}.active-locales-list,.inactive-locales-list{width:25em;margin:0 1em 1em 0;clear:both;float:left}.active-locales-controls{clear:both}.active-locales-controls .button,.active-locales-controls ul{margin:0}@media screen and (min-width:510px){.active-locales-controls{clear:none}}.active-locales-list{height:98px;overflow-y:scroll;margin-top:0;background:#fff;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);border:1px solid #ddd;color:#32373c;box-sizing:border-box}.active-locales-list.empty-list{background:hsla(0,0%,100%,.5);border-color:hsla(0,0%,87%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:-webkit-box;display:flex;-webkit-box-align:center;align-items:center}.active-locales-list li{box-sizing:border-box;width:100%;height:28px;line-height:28px;margin:0;padding:0 0 0 8px;cursor:pointer}.active-locales-list li:hover{background:rgba(0,0,0,.07)}.active-locales-list li[aria-selected=true]{background:rgba(0,0,0,.15)}#active-locales-empty-message{display:-webkit-box;display:flex;-webkit-box-pack:center;justify-content:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column;position:relative;text-align:center;width:25em;height:98px;margin-bottom:-98px;box-sizing:border-box;color:rgba(51,51,51,.5)}#active-locales-empty-message.hidden{display:none}.inactive-locales{clear:both}.inactive-locales select{width:100%}.preferred-languages .notice{display:inline-block}.no-js #preferred-languages-label,.no-js .preferred-languages,.no-js .user-preferred-languages-wrap{display:none}@-webkit-keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}@keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}.tooltipped{position:relative}.tooltipped:active:after,.tooltipped:active:before,.tooltipped:focus:after,.tooltipped:focus:before,.tooltipped:hover:after,.tooltipped:hover:before{opacity:1;display:inline-block;text-decoration:none;-webkit-animation-name:tooltip-appear;animation-name:tooltip-appear;-webkit-animation-duration:.1s;animation-duration:.1s;-webkit-animation-fill-mode:backwards;animation-fill-mode:backwards;-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in;-webkit-animation-delay:.4s;animation-delay:.4s}.tooltipped:before{z-index:1000001;width:0;height:0;color:#191e23;content:"";border:6px solid transparent;top:-7px;right:50%;bottom:auto;margin-right:-6px;border-top-color:#191e23}.tooltipped:after,.tooltipped:before{position:absolute;display:none;pointer-events:none;opacity:0}.tooltipped:after{z-index:1000000;padding:.5em .75em;font:normal normal 11px/1.5 -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif;-webkit-font-smoothing:subpixel-antialiased;color:#fff;text-align:center;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-wrap:break-word;white-space:pre;content:attr(data-tooltip);background:#191e23;border-radius:3px;right:auto;left:50%;margin-left:-16px;bottom:100%;margin-bottom:6px}
1
+ .active-locales{margin:1em 0}.active-locales-list,.inactive-locales-list{width:25em;margin:0 1em 1em 0;clear:both;float:left}.active-locales-controls{clear:both}.active-locales-controls .button,.active-locales-controls ul{margin:0}@media screen and (min-width:510px){.active-locales-controls{clear:none}}.active-locales-list{height:98px;overflow-y:scroll;margin-top:0;background:#fff;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);border:1px solid #ddd;color:#32373c;box-sizing:border-box}.active-locales-list.empty-list{background:hsla(0,0%,100%,.5);border-color:hsla(0,0%,87.1%,.75);box-shadow:inset 0 1px 2px rgba(0,0,0,.04);display:flex;align-items:center}.active-locales-list li{box-sizing:border-box;width:100%;height:28px;line-height:28px;margin:0;padding:0 0 0 8px;cursor:pointer}.active-locales-list li:hover{background:rgba(0,0,0,.07)}.active-locales-list li[aria-selected=true]{background:rgba(0,0,0,.15)}#active-locales-empty-message{display:flex;justify-content:center;flex-direction:column;position:relative;text-align:center;width:25em;height:98px;margin-bottom:-98px;box-sizing:border-box;color:rgba(51,51,51,.5)}#active-locales-empty-message.hidden{display:none}.inactive-locales{clear:both}.inactive-locales select{width:100%}.preferred-languages .notice{display:inline-block}.no-js #preferred-languages-label,.no-js .preferred-languages,.no-js .user-preferred-languages-wrap{display:none}@keyframes tooltip-appear{0%{opacity:0}to{opacity:1}}.tooltipped{position:relative}.tooltipped:active:after,.tooltipped:active:before,.tooltipped:focus:after,.tooltipped:focus:before,.tooltipped:hover:after,.tooltipped:hover:before{opacity:1;display:inline-block;text-decoration:none;animation-name:tooltip-appear;animation-duration:.1s;animation-fill-mode:backwards;animation-timing-function:ease-in;animation-delay:.4s}.tooltipped:before{z-index:1000001;width:0;height:0;color:#191e23;content:"";top:-7px;right:50%;bottom:auto;margin-right:-6px;border:6px solid transparent;border-top-color:#191e23}.tooltipped:after,.tooltipped:before{position:absolute;display:none;pointer-events:none;opacity:0}.tooltipped:after{z-index:1000000;padding:.5em .75em;font:normal normal 11px/1.5 -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;-webkit-font-smoothing:subpixel-antialiased;color:#fff;text-align:center;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-wrap:break-word;white-space:pre;content:attr(data-tooltip);background:#191e23;border-radius:3px;right:auto;left:50%;margin-left:-16px;bottom:100%;margin-bottom:6px}
inc/functions.php CHANGED
@@ -31,7 +31,9 @@ function preferred_languages_register_setting() {
31
  */
32
  function preferred_languages_register_meta() {
33
  register_meta(
34
- 'user', 'preferred_languages', array(
 
 
35
  'type' => 'string',
36
  'description' => 'List of preferred languages',
37
  'single' => true,
@@ -173,7 +175,7 @@ function preferred_languages_update_user_meta( $meta_id, $object_id, $meta_key,
173
  add_filter( 'update_user_meta', 'preferred_languages_update_user_meta', 10, 4 );
174
 
175
  // Reload translations after save.
176
- $preferred_languages_list = preferred_languages_get_list();
177
  load_default_textdomain( reset( $preferred_languages_list ) );
178
  }
179
 
@@ -218,7 +220,7 @@ function preferred_languages_update_option( $old_value, $value ) {
218
  add_filter( 'update_option_preferred_languages', 'preferred_languages_update_option', 10, 2 );
219
 
220
  // Reload translations after save.
221
- $preferred_languages_list = preferred_languages_get_list();
222
  load_default_textdomain( reset( $preferred_languages_list ) );
223
  }
224
 
@@ -332,6 +334,11 @@ function preferred_languages_load_textdomain_mofile( $mofile ) {
332
 
333
  $current_locale = get_locale();
334
 
 
 
 
 
 
335
  foreach ( $preferred_locales as $locale ) {
336
  $preferred_mofile = str_replace( $current_locale, $locale, $mofile );
337
 
@@ -359,7 +366,7 @@ function preferred_languages_register_scripts() {
359
  'jquery-ui-sortable',
360
  'wp-a11y',
361
  ),
362
- '20180727',
363
  true
364
  );
365
 
@@ -459,7 +466,8 @@ function preferred_languages_display_form( $args = array() ) {
459
  wp_enqueue_script( 'preferred-languages' );
460
 
461
  $args = wp_parse_args(
462
- $args, array(
 
463
  'selected' => array(),
464
  'show_available_translations' => current_user_can( 'install_languages' ),
465
  'show_option_site_default' => false,
@@ -654,7 +662,7 @@ function preferred_languages_init_registry() {
654
  }
655
 
656
  /**
657
- * Filters gettext call to work around limitations in just-in-time loading of translations.
658
  *
659
  * @since 1.1.0
660
  *
@@ -675,7 +683,7 @@ function preferred_languages_filter_gettext( $translation, $text, $domain ) {
675
  /* @var Preferred_Languages_Textdomain_Registry $preferred_languages_textdomain_registry */
676
  global $preferred_languages_textdomain_registry;
677
 
678
- if ( ! $preferred_languages_textdomain_registry instanceof Preferred_Languages_Textdomain_Registry ) {
679
  preferred_languages_init_registry();
680
  }
681
 
@@ -693,6 +701,11 @@ function preferred_languages_filter_gettext( $translation, $text, $domain ) {
693
 
694
  $preferred_locales = preferred_languages_get_list();
695
 
 
 
 
 
 
696
  foreach ( $preferred_locales as $locale ) {
697
  $mofile = "{$path}/{$domain}-{$locale}.mo";
698
 
31
  */
32
  function preferred_languages_register_meta() {
33
  register_meta(
34
+ 'user',
35
+ 'preferred_languages',
36
+ array(
37
  'type' => 'string',
38
  'description' => 'List of preferred languages',
39
  'single' => true,
175
  add_filter( 'update_user_meta', 'preferred_languages_update_user_meta', 10, 4 );
176
 
177
  // Reload translations after save.
178
+ $preferred_languages_list = preferred_languages_get_user_list( $object_id );
179
  load_default_textdomain( reset( $preferred_languages_list ) );
180
  }
181
 
220
  add_filter( 'update_option_preferred_languages', 'preferred_languages_update_option', 10, 2 );
221
 
222
  // Reload translations after save.
223
+ $preferred_languages_list = preferred_languages_get_site_list();
224
  load_default_textdomain( reset( $preferred_languages_list ) );
225
  }
226
 
334
 
335
  $current_locale = get_locale();
336
 
337
+ // Locale has been filtered by something else.
338
+ if ( ! in_array( $current_locale, $preferred_locales, true ) ) {
339
+ return $mofile;
340
+ }
341
+
342
  foreach ( $preferred_locales as $locale ) {
343
  $preferred_mofile = str_replace( $current_locale, $locale, $mofile );
344
 
366
  'jquery-ui-sortable',
367
  'wp-a11y',
368
  ),
369
+ '20181010',
370
  true
371
  );
372
 
466
  wp_enqueue_script( 'preferred-languages' );
467
 
468
  $args = wp_parse_args(
469
+ $args,
470
+ array(
471
  'selected' => array(),
472
  'show_available_translations' => current_user_can( 'install_languages' ),
473
  'show_option_site_default' => false,
662
  }
663
 
664
  /**
665
+ * Filters gettext calls to work around limitations in just-in-time loading of translations.
666
  *
667
  * @since 1.1.0
668
  *
683
  /* @var Preferred_Languages_Textdomain_Registry $preferred_languages_textdomain_registry */
684
  global $preferred_languages_textdomain_registry;
685
 
686
+ if ( ! $preferred_languages_textdomain_registry instanceof Preferred_Languages_Textdomain_Registry ) {
687
  preferred_languages_init_registry();
688
  }
689
 
701
 
702
  $preferred_locales = preferred_languages_get_list();
703
 
704
+ // Locale has been filtered by something else.
705
+ if ( ! in_array( get_locale(), $preferred_locales, true ) ) {
706
+ return $translation;
707
+ }
708
+
709
  foreach ( $preferred_locales as $locale ) {
710
  $mofile = "{$path}/{$domain}-{$locale}.mo";
711
 
js/preferred-languages.js CHANGED
@@ -1,329 +1,307 @@
1
- 'use strict';
2
 
3
  (function (wp, settings, $) {
4
- var $document = $(document);
5
- var $activeLocales = $('.active-locales-list');
6
- var $activeLocalesControls = $('.active-locales-controls');
7
- var $emptyMessage = $('#active-locales-empty-message');
8
- var $inactiveLocalesWrap = $('.inactive-locales-list');
9
- var $inactiveLocales = $inactiveLocalesWrap.find('select');
10
- var $inactiveLocalesControls = $('.inactive-locales-controls');
11
- var $inputField = $('input[name="preferred_languages"]');
12
- var $selectedLocale = $activeLocales.find('li[aria-selected="true"]');
13
-
14
- var KEY_UP = 38;
15
- var KEY_DOWN = 40;
16
- var KEY_BACKSPACE = 8;
17
-
18
- /**
19
- * Changes the move button states.
20
- *
21
- * @since 1.0.0
22
- *
23
- * @param {jQuery} activeLocale Active locale element.
24
- */
25
- function changeButtonState(activeLocale) {
26
- var activeLocalesList = $activeLocales.find('.active-locale');
27
-
28
- $activeLocalesControls.find('.locales-move-up').attr('disabled', $activeLocales.hasClass('empty-list') || activeLocalesList.first().is(activeLocale));
29
- $activeLocalesControls.find('.locales-move-down').attr('disabled', $activeLocales.hasClass('empty-list') || activeLocalesList.last().is(activeLocale));
30
- $activeLocalesControls.find('.locales-remove').attr('disabled', $activeLocales.hasClass('empty-list'));
31
- $inactiveLocalesControls.find('.locales-add').attr('disabled', 'disabled' === $inactiveLocales.attr('disabled'));
32
- }
33
-
34
- /**
35
- * Toggles a locale.
36
- *
37
- * @since 1.0.0
38
- *
39
- * @param {jQuery} $locale Locale element.
40
- */
41
- function toggleLocale($locale) {
42
- var selected = $locale.attr('aria-selected');
43
- var newState = 'true' !== selected;
44
-
45
- // It's already the current locale, so nothing to do here.
46
- if ('true' === selected) {
47
- return;
48
- }
49
-
50
- $selectedLocale.attr('aria-selected', false);
51
-
52
- $locale.attr('aria-selected', newState);
53
-
54
- if (true === newState) {
55
- $selectedLocale = $locale;
56
-
57
- $activeLocales.attr('aria-activedescendant', $selectedLocale.attr('id'));
58
- }
59
-
60
- changeButtonState($locale);
61
- }
62
-
63
- /**
64
- * Updates the preferred languages input field after a change.
65
- *
66
- * @since 1.0.0
67
- */
68
- function updateHiddenInput() {
69
- var locales = [];
70
-
71
- $activeLocales.children('.active-locale').each(function (index, el) {
72
- locales.push($(el).attr('id'));
73
- });
74
-
75
- $inputField.val(locales.join(','));
76
- }
77
-
78
- /**
79
- * Moves a locale up in the list.
80
- *
81
- * @since 1.0.0
82
- */
83
- function moveLocaleUp() {
84
-
85
- // 1. Change position if possible.
86
- $selectedLocale.insertBefore($selectedLocale.prev());
87
-
88
- // 2. Update hidden input field.
89
- updateHiddenInput();
90
-
91
- // 3. Update buttons.
92
- changeButtonState($selectedLocale);
93
-
94
- // 4. Announce to assistive technologies.
95
- wp.a11y.speak(settings.l10n.movedUp);
96
- }
97
-
98
- /**
99
- * Moves a locale down in the list.
100
- *
101
- * @since 1.0.0
102
- */
103
- function moveLocaleDown() {
104
-
105
- // 1. Change position if possible.
106
- $selectedLocale.insertAfter($selectedLocale.next());
107
-
108
- // 2. Update hidden input field.
109
- updateHiddenInput();
110
-
111
- // 3. Update buttons.
112
- changeButtonState($selectedLocale);
113
-
114
- // 4. Announce to assistive technologies.
115
- wp.a11y.speak(settings.l10n.movedDown);
116
- }
117
-
118
- /**
119
- * Displays a message in case the list of active locales is empty.
120
- *
121
- * @since 1.1.1
122
- */
123
- function toggleEmptyListMessage() {
124
- if ($activeLocales.hasClass('empty-list')) {
125
- $activeLocales.removeClass('empty-list');
126
- $emptyMessage.addClass('hidden');
127
- } else {
128
- $activeLocales.addClass('empty-list');
129
- $activeLocales.attr('aria-activedescendant', '');
130
- $emptyMessage.removeClass('hidden');
131
-
132
- wp.a11y.speak($emptyMessage.data('a11y-message'));
133
- }
134
- }
135
-
136
- /**
137
- * Removes an active locale from the list.
138
- *
139
- * @since 1.0.0
140
- */
141
- function makeLocaleInactive() {
142
- var locale = $selectedLocale.attr('id');
143
- var $successor = void 0;
144
-
145
- $successor = $selectedLocale.prevAll(':first');
146
-
147
- if (0 === $successor.length) {
148
- $successor = $selectedLocale.nextAll(':first');
149
- }
150
-
151
- // 1. Remove selected locale.
152
- $selectedLocale.remove();
153
-
154
- // 2. Make another locale the current one.
155
- if ($successor.length) {
156
- toggleLocale($successor);
157
- } else {
158
- toggleEmptyListMessage();
159
- }
160
-
161
- // 3. Make visible in dropdown again.
162
- $inactiveLocales.find('option[value="' + locale + '"]').removeClass('hidden');
163
- $inactiveLocales.attr('disabled', false);
164
-
165
- // 4. Update hidden input field.
166
- updateHiddenInput();
167
-
168
- // 5. Update buttons.
169
- changeButtonState($selectedLocale);
170
-
171
- // 6. Announce to assistive technologies.
172
- wp.a11y.speak(settings.l10n.localeRemoved);
173
- }
174
-
175
- /**
176
- * Makes an inactive locale active.
177
- *
178
- * @since 1.0.0
179
- *
180
- * @param {jQuery} option The locale element.
181
- */
182
- function makeLocaleActive(option) {
183
- var locale = option.val() || 'en_US';
184
- var $newLocale = $('<li/>', { text: option.text(), 'role': 'option', 'aria-selected': false, 'id': locale, 'class': 'active-locale' });
185
- var $successor = void 0;
186
-
187
- // 1. Hide from dropdown.
188
- option.removeAttr('selected').addClass('hidden');
189
-
190
- $successor = option.prevAll(':not(.hidden):first');
191
-
192
- if (!$successor.length) {
193
- $successor = option.nextAll(':not(.hidden):first');
194
- }
195
-
196
- // Empty optgroup, just select the first option we can find.
197
- if (!$successor.length) {
198
- $successor = $inactiveLocales.find('option:not(.hidden):first');
199
- }
200
-
201
- if (!$successor.length) {
202
- $inactiveLocales.attr('disabled', true);
203
- }
204
-
205
- // 2. Change selected value in dropdown.
206
- $successor.attr('selected', true);
207
- $inactiveLocalesControls.val($successor.val());
208
-
209
- // It's already in the list of active locales, stop here.
210
- if ($activeLocales.find('#' + locale).length) {
211
- return;
212
- }
213
-
214
- // 3. Hide empty list message if present.
215
- if ($activeLocales.hasClass('empty-list')) {
216
- toggleEmptyListMessage();
217
- }
218
-
219
- // 4. Add to list.
220
- $activeLocales.append($newLocale);
221
-
222
- toggleLocale($newLocale);
223
-
224
- // 5. Scroll into view.
225
- $activeLocales.animate({
226
- scrollTop: $newLocale.offset().top - $activeLocales.offset().top + $activeLocales.scrollTop()
227
- });
228
-
229
- // 5. Update hidden input field.
230
- updateHiddenInput();
231
-
232
- // 6. Announce to assistive technologies.
233
- wp.a11y.speak(settings.l10n.localeAdded);
234
- }
235
-
236
- // Hide original language settings.
237
- $('.user-language-wrap').remove();
238
- $('#WPLANG').parent().parent().remove();
239
-
240
- // Remove en_US as an option from the dropdown.
241
- $inactiveLocalesWrap.filter('[data-show-en_US="false"]').find('[lang="en"][value=""]').remove();
242
-
243
- // Change initial button state.
244
- changeButtonState($selectedLocale);
245
-
246
- // Initially hide already active locales from dropdown.
247
- if ($inputField.val().length) {
248
- $.each($inputField.val().split(','), function (index, value) {
249
- value = 'en_US' === value ? '' : value;
250
-
251
- var $option = $inactiveLocales.find('[value="' + value + '"]');
252
-
253
- // 2. Hide from dropdown.
254
- $option.removeAttr('selected').addClass('hidden');
255
- });
256
-
257
- var $firstInactiveLocale = $inactiveLocales.find('option:not(.hidden):first');
258
-
259
- $firstInactiveLocale.attr('selected', true);
260
- $inactiveLocalesControls.val($firstInactiveLocale.val());
261
- }
262
-
263
- // Enabling sorting locales using drag and drop.
264
- $activeLocales.sortable({
265
- axis: 'y',
266
- cursor: 'move',
267
- items: ':not(#active-locales-list-empty-message)'
268
- });
269
-
270
- // Active locales keyboard shortcuts.
271
- $document.on('keydown', $activeLocales, function (e) {
272
- switch (e.which) {
273
- case KEY_UP:
274
- if (e.altKey) {
275
- moveLocaleUp();
276
- } else {
277
- $selectedLocale.prev().length && toggleLocale($selectedLocale.prev());
278
- }
279
-
280
- e.preventDefault();
281
- break;
282
-
283
- case KEY_DOWN:
284
- if (e.altKey) {
285
- moveLocaleDown();
286
- } else {
287
- $selectedLocale.next().length && toggleLocale($selectedLocale.next());
288
- }
289
-
290
- e.preventDefault();
291
- break;
292
-
293
- case KEY_BACKSPACE:
294
- makeLocaleInactive();
295
- e.preventDefault();
296
- break;
297
- }
298
- });
299
-
300
- // Inactive Locales keyboard shortcuts.
301
- $document.on('keydown', $inactiveLocales, function (e) {
302
-
303
- // Letter "A".
304
- if (65 === e.which) {
305
- if (e.altKey) {
306
- makeLocaleActive($inactiveLocales.find('option:selected'));
307
- }
308
-
309
- e.preventDefault();
310
- }
311
- });
312
-
313
- // Add new locale to list.
314
- $inactiveLocalesControls.find('.locales-add').on('click', function () {
315
- makeLocaleActive($inactiveLocales.find('option:selected'));
316
- });
317
-
318
- // Select a locale.
319
- $activeLocales.on('click', '.active-locale', function (e) {
320
- toggleLocale($(e.currentTarget));
321
- });
322
-
323
- $activeLocalesControls.find('.locales-move-up').on('click', moveLocaleUp);
324
-
325
- $activeLocalesControls.find('.locales-move-down').on('click', moveLocaleDown);
326
-
327
- // Remove locale from list.
328
- $activeLocalesControls.find('.locales-remove').on('click', makeLocaleInactive);
329
  })(wp, preferredLanguages, jQuery);
1
+ "use strict";
2
 
3
  (function (wp, settings, $) {
4
+ var $document = $(document);
5
+ var $activeLocales = $('.active-locales-list');
6
+ var $activeLocalesControls = $('.active-locales-controls');
7
+ var $emptyMessage = $('#active-locales-empty-message');
8
+ var $inactiveLocalesWrap = $('.inactive-locales-list');
9
+ var $inactiveLocales = $inactiveLocalesWrap.find('select');
10
+ var $inactiveLocalesControls = $('.inactive-locales-controls');
11
+ var $inputField = $('input[name="preferred_languages"]');
12
+ var $selectedLocale = $activeLocales.find('li[aria-selected="true"]');
13
+ var KEY_UP = 38;
14
+ var KEY_DOWN = 40;
15
+ var KEY_BACKSPACE = 8;
16
+ var KEY_A = 65;
17
+ /**
18
+ * Changes the move button states.
19
+ *
20
+ * @since 1.0.0
21
+ *
22
+ * @param {jQuery} activeLocale Active locale element.
23
+ */
24
+
25
+ function changeButtonState(activeLocale) {
26
+ var activeLocalesList = $activeLocales.find('.active-locale');
27
+ $activeLocalesControls.find('.locales-move-up').attr('disabled', $activeLocales.hasClass('empty-list') || activeLocalesList.first().is(activeLocale));
28
+ $activeLocalesControls.find('.locales-move-down').attr('disabled', $activeLocales.hasClass('empty-list') || activeLocalesList.last().is(activeLocale));
29
+ $activeLocalesControls.find('.locales-remove').attr('disabled', $activeLocales.hasClass('empty-list'));
30
+ $inactiveLocalesControls.find('.locales-add').attr('disabled', 'disabled' === $inactiveLocales.attr('disabled'));
31
+ }
32
+ /**
33
+ * Toggles a locale.
34
+ *
35
+ * @since 1.0.0
36
+ *
37
+ * @param {jQuery} $locale Locale element.
38
+ */
39
+
40
+
41
+ function toggleLocale($locale) {
42
+ var selected = $locale.attr('aria-selected');
43
+ var newState = 'true' !== selected; // It's already the current locale, so nothing to do here.
44
+
45
+ if ('true' === selected) {
46
+ return;
47
+ }
48
+
49
+ $selectedLocale.attr('aria-selected', false);
50
+ $locale.attr('aria-selected', newState);
51
+
52
+ if (true === newState) {
53
+ $selectedLocale = $locale;
54
+ $activeLocales.attr('aria-activedescendant', $selectedLocale.attr('id'));
55
+ }
56
+
57
+ changeButtonState($locale);
58
+ }
59
+ /**
60
+ * Updates the preferred languages input field after a change.
61
+ *
62
+ * @since 1.0.0
63
+ */
64
+
65
+
66
+ function updateHiddenInput() {
67
+ var locales = [];
68
+ $activeLocales.children('.active-locale').each(function (index, el) {
69
+ locales.push($(el).attr('id'));
70
+ });
71
+ $inputField.val(locales.join(','));
72
+ }
73
+ /**
74
+ * Moves a locale up in the list.
75
+ *
76
+ * @since 1.0.0
77
+ */
78
+
79
+
80
+ function moveLocaleUp() {
81
+ // 1. Change position if possible.
82
+ $selectedLocale.insertBefore($selectedLocale.prev()); // 2. Update hidden input field.
83
+
84
+ updateHiddenInput(); // 3. Update buttons.
85
+
86
+ changeButtonState($selectedLocale); // 4. Announce to assistive technologies.
87
+
88
+ wp.a11y.speak(settings.l10n.movedUp);
89
+ }
90
+ /**
91
+ * Moves a locale down in the list.
92
+ *
93
+ * @since 1.0.0
94
+ */
95
+
96
+
97
+ function moveLocaleDown() {
98
+ // 1. Change position if possible.
99
+ $selectedLocale.insertAfter($selectedLocale.next()); // 2. Update hidden input field.
100
+
101
+ updateHiddenInput(); // 3. Update buttons.
102
+
103
+ changeButtonState($selectedLocale); // 4. Announce to assistive technologies.
104
+
105
+ wp.a11y.speak(settings.l10n.movedDown);
106
+ }
107
+ /**
108
+ * Displays a message in case the list of active locales is empty.
109
+ *
110
+ * @since 1.1.1
111
+ */
112
+
113
+
114
+ function toggleEmptyListMessage() {
115
+ if ($activeLocales.hasClass('empty-list')) {
116
+ $activeLocales.removeClass('empty-list');
117
+ $emptyMessage.addClass('hidden');
118
+ } else {
119
+ $activeLocales.addClass('empty-list');
120
+ $activeLocales.attr('aria-activedescendant', '');
121
+ $emptyMessage.removeClass('hidden');
122
+ wp.a11y.speak($emptyMessage.data('a11y-message'));
123
+ }
124
+ }
125
+ /**
126
+ * Removes an active locale from the list.
127
+ *
128
+ * @since 1.0.0
129
+ */
130
+
131
+
132
+ function makeLocaleInactive() {
133
+ var locale = $selectedLocale.attr('id');
134
+ var $successor;
135
+ $successor = $selectedLocale.prevAll(':first');
136
+
137
+ if (0 === $successor.length) {
138
+ $successor = $selectedLocale.nextAll(':first');
139
+ } // 1. Remove selected locale.
140
+
141
+
142
+ $selectedLocale.remove(); // 2. Make another locale the current one.
143
+
144
+ if ($successor.length) {
145
+ toggleLocale($successor);
146
+ } else {
147
+ toggleEmptyListMessage();
148
+ } // 3. Make visible in dropdown again.
149
+
150
+
151
+ $inactiveLocales.find("option[value=\"".concat(locale, "\"]")).removeClass('hidden');
152
+ $inactiveLocales.attr('disabled', false); // 4. Update hidden input field.
153
+
154
+ updateHiddenInput(); // 5. Update buttons.
155
+
156
+ changeButtonState($selectedLocale); // 6. Announce to assistive technologies.
157
+
158
+ wp.a11y.speak(settings.l10n.localeRemoved);
159
+ }
160
+ /**
161
+ * Makes an inactive locale active.
162
+ *
163
+ * @since 1.0.0
164
+ *
165
+ * @param {jQuery} option The locale element.
166
+ */
167
+
168
+
169
+ function makeLocaleActive(option) {
170
+ var locale = option.val() || 'en_US';
171
+ var $newLocale = $('<li/>', {
172
+ text: option.text(),
173
+ 'role': 'option',
174
+ 'aria-selected': false,
175
+ 'id': locale,
176
+ 'class': 'active-locale'
177
+ });
178
+ var $successor; // 1. Hide from dropdown.
179
+
180
+ option.removeAttr('selected').addClass('hidden');
181
+ $successor = option.prevAll(':not(.hidden):first');
182
+
183
+ if (!$successor.length) {
184
+ $successor = option.nextAll(':not(.hidden):first');
185
+ } // Empty optgroup, just select the first option we can find.
186
+
187
+
188
+ if (!$successor.length) {
189
+ $successor = $inactiveLocales.find('option:not(.hidden):first');
190
+ }
191
+
192
+ if (!$successor.length) {
193
+ $inactiveLocales.attr('disabled', true);
194
+ } // 2. Change selected value in dropdown.
195
+
196
+
197
+ $successor.attr('selected', true);
198
+ $inactiveLocalesControls.val($successor.val()); // It's already in the list of active locales, stop here.
199
+
200
+ if ($activeLocales.find("#".concat(locale)).length) {
201
+ return;
202
+ } // 3. Hide empty list message if present.
203
+
204
+
205
+ if ($activeLocales.hasClass('empty-list')) {
206
+ toggleEmptyListMessage();
207
+ } // 4. Add to list.
208
+
209
+
210
+ $activeLocales.append($newLocale);
211
+ toggleLocale($newLocale); // 5. Scroll into view.
212
+
213
+ $activeLocales.animate({
214
+ scrollTop: $newLocale.offset().top - $activeLocales.offset().top + $activeLocales.scrollTop()
215
+ }); // 5. Update hidden input field.
216
+
217
+ updateHiddenInput(); // 6. Announce to assistive technologies.
218
+
219
+ wp.a11y.speak(settings.l10n.localeAdded);
220
+ } // Hide original language settings.
221
+
222
+
223
+ $('.user-language-wrap').remove();
224
+ $('#WPLANG').parent().parent().remove(); // Remove en_US as an option from the dropdown.
225
+
226
+ $inactiveLocalesWrap.filter('[data-show-en_US="false"]').find('[lang="en"][value=""]').remove(); // Change initial button state.
227
+
228
+ changeButtonState($selectedLocale); // Initially hide already active locales from dropdown.
229
+
230
+ if ($inputField.val().length) {
231
+ $.each($inputField.val().split(','), function (index, value) {
232
+ value = 'en_US' === value ? '' : value;
233
+ var $option = $inactiveLocales.find("[value=\"".concat(value, "\"]")); // 2. Hide from dropdown.
234
+
235
+ $option.removeAttr('selected').addClass('hidden');
236
+ });
237
+ var $firstInactiveLocale = $inactiveLocales.find('option:not(.hidden):first');
238
+ $firstInactiveLocale.attr('selected', true);
239
+ $inactiveLocalesControls.val($firstInactiveLocale.val());
240
+ } // Enabling sorting locales using drag and drop.
241
+
242
+
243
+ $activeLocales.sortable({
244
+ axis: 'y',
245
+ cursor: 'move',
246
+ items: ':not(#active-locales-list-empty-message)'
247
+ }); // Active locales keyboard shortcuts.
248
+
249
+ $document.on('keydown', function (e) {
250
+ if (!document.querySelector('.preferred-languages').contains(document.activeElement)) {
251
+ return;
252
+ }
253
+
254
+ switch (e.which) {
255
+ case KEY_UP:
256
+ if (e.altKey) {
257
+ moveLocaleUp();
258
+ } else if ($selectedLocale.prev().length) {
259
+ toggleLocale($selectedLocale.prev());
260
+ } else {
261
+ // We're at the top of the list.
262
+ $activeLocales.focus();
263
+ }
264
+
265
+ e.preventDefault();
266
+ break;
267
+
268
+ case KEY_DOWN:
269
+ if (e.altKey) {
270
+ moveLocaleDown();
271
+ } else if ($selectedLocale.next().length) {
272
+ toggleLocale($selectedLocale.next());
273
+ } else {
274
+ // We're at the bottom of the list.
275
+ $activeLocales.focus();
276
+ }
277
+
278
+ e.preventDefault();
279
+ break;
280
+
281
+ case KEY_A:
282
+ if (e.altKey) {
283
+ makeLocaleActive($inactiveLocales.find('option:selected'));
284
+ }
285
+
286
+ e.preventDefault();
287
+ break;
288
+
289
+ case KEY_BACKSPACE:
290
+ makeLocaleInactive();
291
+ e.preventDefault();
292
+ break;
293
+ }
294
+ }); // Add new locale to list.
295
+
296
+ $inactiveLocalesControls.find('.locales-add').on('click', function () {
297
+ makeLocaleActive($inactiveLocales.find('option:selected'));
298
+ }); // Select a locale.
299
+
300
+ $activeLocales.on('click', '.active-locale', function (e) {
301
+ toggleLocale($(e.currentTarget));
302
+ });
303
+ $activeLocalesControls.find('.locales-move-up').on('click', moveLocaleUp);
304
+ $activeLocalesControls.find('.locales-move-down').on('click', moveLocaleDown); // Remove locale from list.
305
+
306
+ $activeLocalesControls.find('.locales-remove').on('click', makeLocaleInactive);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  })(wp, preferredLanguages, jQuery);
js/preferred-languages.min.js CHANGED
@@ -1 +1 @@
1
- "use strict";(function(wp,settings,$){var $document=$(document);var $activeLocales=$(".active-locales-list");var $activeLocalesControls=$(".active-locales-controls");var $emptyMessage=$("#active-locales-empty-message");var $inactiveLocalesWrap=$(".inactive-locales-list");var $inactiveLocales=$inactiveLocalesWrap.find("select");var $inactiveLocalesControls=$(".inactive-locales-controls");var $inputField=$('input[name="preferred_languages"]');var $selectedLocale=$activeLocales.find('li[aria-selected="true"]');var KEY_UP=38;var KEY_DOWN=40;var KEY_BACKSPACE=8;function changeButtonState(activeLocale){var activeLocalesList=$activeLocales.find(".active-locale");$activeLocalesControls.find(".locales-move-up").attr("disabled",$activeLocales.hasClass("empty-list")||activeLocalesList.first().is(activeLocale));$activeLocalesControls.find(".locales-move-down").attr("disabled",$activeLocales.hasClass("empty-list")||activeLocalesList.last().is(activeLocale));$activeLocalesControls.find(".locales-remove").attr("disabled",$activeLocales.hasClass("empty-list"));$inactiveLocalesControls.find(".locales-add").attr("disabled","disabled"===$inactiveLocales.attr("disabled"))}function toggleLocale($locale){var selected=$locale.attr("aria-selected");var newState="true"!==selected;if("true"===selected){return}$selectedLocale.attr("aria-selected",false);$locale.attr("aria-selected",newState);if(true===newState){$selectedLocale=$locale;$activeLocales.attr("aria-activedescendant",$selectedLocale.attr("id"))}changeButtonState($locale)}function updateHiddenInput(){var locales=[];$activeLocales.children(".active-locale").each(function(index,el){locales.push($(el).attr("id"))});$inputField.val(locales.join(","))}function moveLocaleUp(){$selectedLocale.insertBefore($selectedLocale.prev());updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.movedUp)}function moveLocaleDown(){$selectedLocale.insertAfter($selectedLocale.next());updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.movedDown)}function toggleEmptyListMessage(){if($activeLocales.hasClass("empty-list")){$activeLocales.removeClass("empty-list");$emptyMessage.addClass("hidden")}else{$activeLocales.addClass("empty-list");$activeLocales.attr("aria-activedescendant","");$emptyMessage.removeClass("hidden");wp.a11y.speak($emptyMessage.data("a11y-message"))}}function makeLocaleInactive(){var locale=$selectedLocale.attr("id");var $successor=void 0;$successor=$selectedLocale.prevAll(":first");if(0===$successor.length){$successor=$selectedLocale.nextAll(":first")}$selectedLocale.remove();if($successor.length){toggleLocale($successor)}else{toggleEmptyListMessage()}$inactiveLocales.find('option[value="'+locale+'"]').removeClass("hidden");$inactiveLocales.attr("disabled",false);updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.localeRemoved)}function makeLocaleActive(option){var locale=option.val()||"en_US";var $newLocale=$("<li/>",{text:option.text(),role:"option","aria-selected":false,id:locale,class:"active-locale"});var $successor=void 0;option.removeAttr("selected").addClass("hidden");$successor=option.prevAll(":not(.hidden):first");if(!$successor.length){$successor=option.nextAll(":not(.hidden):first")}if(!$successor.length){$successor=$inactiveLocales.find("option:not(.hidden):first")}if(!$successor.length){$inactiveLocales.attr("disabled",true)}$successor.attr("selected",true);$inactiveLocalesControls.val($successor.val());if($activeLocales.find("#"+locale).length){return}if($activeLocales.hasClass("empty-list")){toggleEmptyListMessage()}$activeLocales.append($newLocale);toggleLocale($newLocale);$activeLocales.animate({scrollTop:$newLocale.offset().top-$activeLocales.offset().top+$activeLocales.scrollTop()});updateHiddenInput();wp.a11y.speak(settings.l10n.localeAdded)}$(".user-language-wrap").remove();$("#WPLANG").parent().parent().remove();$inactiveLocalesWrap.filter('[data-show-en_US="false"]').find('[lang="en"][value=""]').remove();changeButtonState($selectedLocale);if($inputField.val().length){$.each($inputField.val().split(","),function(index,value){value="en_US"===value?"":value;var $option=$inactiveLocales.find('[value="'+value+'"]');$option.removeAttr("selected").addClass("hidden")});var $firstInactiveLocale=$inactiveLocales.find("option:not(.hidden):first");$firstInactiveLocale.attr("selected",true);$inactiveLocalesControls.val($firstInactiveLocale.val())}$activeLocales.sortable({axis:"y",cursor:"move",items:":not(#active-locales-list-empty-message)"});$document.on("keydown",$activeLocales,function(e){switch(e.which){case KEY_UP:if(e.altKey){moveLocaleUp()}else{$selectedLocale.prev().length&&toggleLocale($selectedLocale.prev())}e.preventDefault();break;case KEY_DOWN:if(e.altKey){moveLocaleDown()}else{$selectedLocale.next().length&&toggleLocale($selectedLocale.next())}e.preventDefault();break;case KEY_BACKSPACE:makeLocaleInactive();e.preventDefault();break}});$document.on("keydown",$inactiveLocales,function(e){if(65===e.which){if(e.altKey){makeLocaleActive($inactiveLocales.find("option:selected"))}e.preventDefault()}});$inactiveLocalesControls.find(".locales-add").on("click",function(){makeLocaleActive($inactiveLocales.find("option:selected"))});$activeLocales.on("click",".active-locale",function(e){toggleLocale($(e.currentTarget))});$activeLocalesControls.find(".locales-move-up").on("click",moveLocaleUp);$activeLocalesControls.find(".locales-move-down").on("click",moveLocaleDown);$activeLocalesControls.find(".locales-remove").on("click",makeLocaleInactive)})(wp,preferredLanguages,jQuery);
1
+ "use strict";(function(wp,settings,$){var $document=$(document);var $activeLocales=$(".active-locales-list");var $activeLocalesControls=$(".active-locales-controls");var $emptyMessage=$("#active-locales-empty-message");var $inactiveLocalesWrap=$(".inactive-locales-list");var $inactiveLocales=$inactiveLocalesWrap.find("select");var $inactiveLocalesControls=$(".inactive-locales-controls");var $inputField=$('input[name="preferred_languages"]');var $selectedLocale=$activeLocales.find('li[aria-selected="true"]');var KEY_UP=38;var KEY_DOWN=40;var KEY_BACKSPACE=8;var KEY_A=65;function changeButtonState(activeLocale){var activeLocalesList=$activeLocales.find(".active-locale");$activeLocalesControls.find(".locales-move-up").attr("disabled",$activeLocales.hasClass("empty-list")||activeLocalesList.first().is(activeLocale));$activeLocalesControls.find(".locales-move-down").attr("disabled",$activeLocales.hasClass("empty-list")||activeLocalesList.last().is(activeLocale));$activeLocalesControls.find(".locales-remove").attr("disabled",$activeLocales.hasClass("empty-list"));$inactiveLocalesControls.find(".locales-add").attr("disabled","disabled"===$inactiveLocales.attr("disabled"))}function toggleLocale($locale){var selected=$locale.attr("aria-selected");var newState="true"!==selected;if("true"===selected){return}$selectedLocale.attr("aria-selected",false);$locale.attr("aria-selected",newState);if(true===newState){$selectedLocale=$locale;$activeLocales.attr("aria-activedescendant",$selectedLocale.attr("id"))}changeButtonState($locale)}function updateHiddenInput(){var locales=[];$activeLocales.children(".active-locale").each(function(index,el){locales.push($(el).attr("id"))});$inputField.val(locales.join(","))}function moveLocaleUp(){$selectedLocale.insertBefore($selectedLocale.prev());updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.movedUp)}function moveLocaleDown(){$selectedLocale.insertAfter($selectedLocale.next());updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.movedDown)}function toggleEmptyListMessage(){if($activeLocales.hasClass("empty-list")){$activeLocales.removeClass("empty-list");$emptyMessage.addClass("hidden")}else{$activeLocales.addClass("empty-list");$activeLocales.attr("aria-activedescendant","");$emptyMessage.removeClass("hidden");wp.a11y.speak($emptyMessage.data("a11y-message"))}}function makeLocaleInactive(){var locale=$selectedLocale.attr("id");var $successor;$successor=$selectedLocale.prevAll(":first");if(0===$successor.length){$successor=$selectedLocale.nextAll(":first")}$selectedLocale.remove();if($successor.length){toggleLocale($successor)}else{toggleEmptyListMessage()}$inactiveLocales.find('option[value="'.concat(locale,'"]')).removeClass("hidden");$inactiveLocales.attr("disabled",false);updateHiddenInput();changeButtonState($selectedLocale);wp.a11y.speak(settings.l10n.localeRemoved)}function makeLocaleActive(option){var locale=option.val()||"en_US";var $newLocale=$("<li/>",{text:option.text(),role:"option","aria-selected":false,id:locale,class:"active-locale"});var $successor;option.removeAttr("selected").addClass("hidden");$successor=option.prevAll(":not(.hidden):first");if(!$successor.length){$successor=option.nextAll(":not(.hidden):first")}if(!$successor.length){$successor=$inactiveLocales.find("option:not(.hidden):first")}if(!$successor.length){$inactiveLocales.attr("disabled",true)}$successor.attr("selected",true);$inactiveLocalesControls.val($successor.val());if($activeLocales.find("#".concat(locale)).length){return}if($activeLocales.hasClass("empty-list")){toggleEmptyListMessage()}$activeLocales.append($newLocale);toggleLocale($newLocale);$activeLocales.animate({scrollTop:$newLocale.offset().top-$activeLocales.offset().top+$activeLocales.scrollTop()});updateHiddenInput();wp.a11y.speak(settings.l10n.localeAdded)}$(".user-language-wrap").remove();$("#WPLANG").parent().parent().remove();$inactiveLocalesWrap.filter('[data-show-en_US="false"]').find('[lang="en"][value=""]').remove();changeButtonState($selectedLocale);if($inputField.val().length){$.each($inputField.val().split(","),function(index,value){value="en_US"===value?"":value;var $option=$inactiveLocales.find('[value="'.concat(value,'"]'));$option.removeAttr("selected").addClass("hidden")});var $firstInactiveLocale=$inactiveLocales.find("option:not(.hidden):first");$firstInactiveLocale.attr("selected",true);$inactiveLocalesControls.val($firstInactiveLocale.val())}$activeLocales.sortable({axis:"y",cursor:"move",items:":not(#active-locales-list-empty-message)"});$document.on("keydown",function(e){if(!document.querySelector(".preferred-languages").contains(document.activeElement)){return}switch(e.which){case KEY_UP:if(e.altKey){moveLocaleUp()}else if($selectedLocale.prev().length){toggleLocale($selectedLocale.prev())}else{$activeLocales.focus()}e.preventDefault();break;case KEY_DOWN:if(e.altKey){moveLocaleDown()}else if($selectedLocale.next().length){toggleLocale($selectedLocale.next())}else{$activeLocales.focus()}e.preventDefault();break;case KEY_A:if(e.altKey){makeLocaleActive($inactiveLocales.find("option:selected"))}e.preventDefault();break;case KEY_BACKSPACE:makeLocaleInactive();e.preventDefault();break}});$inactiveLocalesControls.find(".locales-add").on("click",function(){makeLocaleActive($inactiveLocales.find("option:selected"))});$activeLocales.on("click",".active-locale",function(e){toggleLocale($(e.currentTarget))});$activeLocalesControls.find(".locales-move-up").on("click",moveLocaleUp);$activeLocalesControls.find(".locales-move-down").on("click",moveLocaleDown);$activeLocalesControls.find(".locales-remove").on("click",makeLocaleInactive)})(wp,preferredLanguages,jQuery);
preferred-languages.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Preferred Languages
4
  * Plugin URI: https://github.com/swissspidy/preferred-languages/
5
  * Description: Choose languages for displaying WordPress in, in order of preference.
6
- * Version: 1.4.0
7
  * Author: Pascal Birchler
8
  * Author URI: https://pascalbirchler.com
9
  * License: GPL-2.0+
3
  * Plugin Name: Preferred Languages
4
  * Plugin URI: https://github.com/swissspidy/preferred-languages/
5
  * Description: Choose languages for displaying WordPress in, in order of preference.
6
+ * Version: 1.5.0
7
  * Author: Pascal Birchler
8
  * Author URI: https://pascalbirchler.com
9
  * License: GPL-2.0+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: internationalization, i18n, localization, l10n, language, locale, translat
4
  Requires at least: 4.9
5
  Tested up to: 4.9
6
  Requires PHP: 5.2
7
- Stable tag: 1.4.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -31,6 +31,12 @@ If you want to get involved, check out [open issues](https://github.com/swissspi
31
 
32
  == Changelog ==
33
 
 
 
 
 
 
 
34
  = 1.4.0 =
35
 
36
  * New: Keyboard navigation improvements.
@@ -69,6 +75,10 @@ If you want to get involved, check out [open issues](https://github.com/swissspi
69
 
70
  == Upgrade Notice ==
71
 
 
 
 
 
72
  = 1.4.0 =
73
 
74
  This release contains improvements regarding translation downloads upon saving.
4
  Requires at least: 4.9
5
  Tested up to: 4.9
6
  Requires PHP: 5.2
7
+ Stable tag: 1.5.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
31
 
32
  == Changelog ==
33
 
34
+ = 1.5.0 =
35
+
36
+ * Enhancement: Improved compatibility with multilingual plugins like Polylang.
37
+ * Fixed: Fixes an issue with keyboard navigation.
38
+ * Fixed: Make sure the correct languages are retrieved when updating the settings.
39
+
40
  = 1.4.0 =
41
 
42
  * New: Keyboard navigation improvements.
75
 
76
  == Upgrade Notice ==
77
 
78
+ = 1.5.0 =
79
+
80
+ This release addresses an issue with keyboard navigation.
81
+
82
  = 1.4.0 =
83
 
84
  This release contains improvements regarding translation downloads upon saving.