Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
fix(i18n): rename the amMoment:languageChange event to `amMoment:lo…
Browse files Browse the repository at this point in the history
…caleChanged` .
  • Loading branch information
urish committed Sep 7, 2014
1 parent dbcb063 commit d5a0f03
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
16 changes: 10 additions & 6 deletions angular-moment.js
Expand Up @@ -226,7 +226,7 @@
cancelTimer();
});

scope.$on('amMoment:languageChange', function () {
scope.$on('amMoment:localeChanged', function () {
updateMoment();
});
};
Expand Down Expand Up @@ -260,13 +260,17 @@
*
* @description
* Changes the locale for moment.js and updates all the am-time-ago directive instances
* with the new locale.
* with the new locale. Also broadcasts a `amMoment:localeChanged` event on $rootScope.
*
* @param {string} lang 2-letter language code (e.g. en, es, ru, etc.)
* @param {string} locale 2-letter language code (e.g. en, es, ru, etc.)
*/
this.changeLocale = function (lang) {
var result = (moment.locale||moment.lang)(lang);
if (angular.isDefined(lang)) {
this.changeLocale = function (locale) {
var result = (moment.locale||moment.lang)(locale);
if (angular.isDefined(locale)) {
$rootScope.$broadcast('amMoment:localeChanged');

// The following event is deprecated and will be removed in an upcoming
// major release.
$rootScope.$broadcast('amMoment:languageChange');
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion angular-moment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion angular-moment.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests.js
Expand Up @@ -481,18 +481,18 @@ describe('module angularMoment', function () {
expect(amMoment.changeLocale()).toBe('en');
});

it('should broadcast an angularMoment:languageChange event on the root scope if a locale is specified', function () {
it('should broadcast an angularMoment:localeChanged event on the root scope if a locale is specified', function () {
var eventBroadcasted = false;
$rootScope.$on('amMoment:languageChange', function () {
$rootScope.$on('amMoment:localeChanged', function () {
eventBroadcasted = true;
});
amMoment.changeLocale('fr');
expect(eventBroadcasted).toBe(true);
});

it('should not broadcast an angularMoment:languageChange event on the root scope if no locale is specified', function () {
it('should not broadcast an angularMoment:localeChanged event on the root scope if no locale is specified', function () {
var eventBroadcasted = false;
$rootScope.$on('amMoment:languageChange', function () {
$rootScope.$on('amMoment:localeChanged', function () {
eventBroadcasted = true;
});
amMoment.changeLocale();
Expand Down

0 comments on commit d5a0f03

Please sign in to comment.