decide.nolog.cz/app/components/language-select.js
jelhan 08f2a81ac1
Drop jQuery (#196)
Drops ember-radio-buttons addon and uses a plain input element instead. ember-radio-buttons doesn't seem to be maintained anymore and required jQuery. Also plain input element seems to be much easier to maintain.

Replaces ember-ajax by ember-fetch as ember-ajax is build on top of jQuery.ajax().

This reduces the bundle size by 25 KB (JavaScript) after gzip. Updating the size limit accordingly.
2019-05-22 12:29:29 +02:00

40 lines
1 KiB
JavaScript

import { inject as service } from '@ember/service';
import { readOnly } from '@ember/object/computed';
import Component from '@ember/component';
import { computed } from '@ember/object';
import localesMeta from 'croodle/locales/meta';
export default Component.extend({
tagName: 'select',
classNames: [ 'language-select' ],
i18n: service(),
moment: service(),
powerCalendar: service(),
current: readOnly('i18n.locale'),
locales: computed('i18n.locales', function() {
let currentLocale = this.get('i18n.locale');
return this.get('i18n.locales').map(function(locale) {
return {
id: locale,
selected: locale === currentLocale,
text: localesMeta[locale]
};
});
}),
change() {
let locale = this.element.options[this.element.selectedIndex].value;
this.i18n.set('locale', locale);
this.moment.changeLocale(locale);
this.powerCalendar.set('locale', locale);
if (window.localStorage) {
window.localStorage.setItem('locale', locale);
}
}
});