From 0037fd4346d0f9bff2d99e4784f58962a6fb7072 Mon Sep 17 00:00:00 2001 From: Lucas Galfaso Date: Wed, 29 Jul 2015 11:45:58 +0200 Subject: [PATCH] refactor($locale): use en-us as generic built-in locale Previously there was a custom built en-us locale that was included with angular.js. This made likely that it would get out of sync with the real en-us locale that is generated from the closure library. This change removes that custom one and uses the generated one instead. This also has the benefit of preventing the unwanted caught error on trying to load `ngLocale` during angular bootstrap. Closes #12134 Closes #8174 --- Gruntfile.js | 2 +- angularFiles.js | 11 +++---- src/AngularPublic.js | 6 ---- src/angular.bind | 10 +++++++ src/angular.suffix | 12 -------- src/ng/locale.js | 70 +------------------------------------------ test/ng/localeSpec.js | 5 +++- 7 files changed, 22 insertions(+), 94 deletions(-) create mode 100644 src/angular.bind diff --git a/Gruntfile.js b/Gruntfile.js index db263ea911bc..410ca100825b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -115,7 +115,7 @@ module.exports = function(grunt) { files: { src: 'test/**/*.js' }, }, ng: { - files: { src: files['angularSrc'] }, + files: { src: files['angularSrc'].concat('!src/angular.bind') }, }, ngAnimate: { files: { src: 'src/ngAnimate/**/*.js' }, diff --git a/angularFiles.js b/angularFiles.js index 3cc8d1ec70b7..290f1e7354a3 100755 --- a/angularFiles.js +++ b/angularFiles.js @@ -25,7 +25,6 @@ var angularFiles = { 'src/ng/httpBackend.js', 'src/ng/interpolate.js', 'src/ng/interval.js', - 'src/ng/locale.js', 'src/ng/location.js', 'src/ng/log.js', 'src/ng/parse.js', @@ -76,7 +75,10 @@ var angularFiles = { 'src/ng/directive/script.js', 'src/ng/directive/select.js', 'src/ng/directive/style.js', - 'src/ng/directive/validators.js' + 'src/ng/directive/validators.js', + 'src/angular.bind', + 'src/publishExternalApis.js', + 'src/ngLocale/angular-locale_en-us.js' ], 'angularLoader': [ @@ -179,7 +181,6 @@ var angularFiles = { 'bower_components/jquery/dist/jquery.js', 'test/jquery_remove.js', '@angularSrc', - 'src/publishExternalApis.js', '@angularSrcModules', '@angularScenario', '@angularTest' @@ -188,7 +189,8 @@ var angularFiles = { 'karmaExclude': [ 'test/jquery_alias.js', 'src/angular-bootstrap.js', - 'src/ngScenario/angular-bootstrap.js' + 'src/ngScenario/angular-bootstrap.js', + 'src/angular.bind' ], 'karmaScenario': [ @@ -215,7 +217,6 @@ var angularFiles = { 'bower_components/jquery/dist/jquery.js', 'test/jquery_alias.js', '@angularSrc', - 'src/publishExternalApis.js', '@angularSrcModules', '@angularScenario', '@angularTest' diff --git a/src/AngularPublic.js b/src/AngularPublic.js index d608407f0ba7..78901de03cda 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -3,7 +3,6 @@ /* global angularModule: true, version: true, - $LocaleProvider, $CompileProvider, htmlAnchorDirective, @@ -151,11 +150,6 @@ function publishExternalAPI(angular) { }); angularModule = setupModuleLoader(window); - try { - angularModule('ngLocale'); - } catch (e) { - angularModule('ngLocale', []).provider('$locale', $LocaleProvider); - } angularModule('ng', ['ngLocale'], ['$provide', function ngModule($provide) { diff --git a/src/angular.bind b/src/angular.bind new file mode 100644 index 000000000000..33bc710d4342 --- /dev/null +++ b/src/angular.bind @@ -0,0 +1,10 @@ +if (window.angular.bootstrap) { + //AngularJS is already loaded, so we can return here... + console.log('WARNING: Tried to load angular more than once.'); + return; +} + +//try to bind to jquery now so that one can write jqLite(document).ready() +//but we will rebind on bootstrap again. +bindJQuery(); + diff --git a/src/angular.suffix b/src/angular.suffix index 4baa20e1b0b6..a79a3fb67841 100644 --- a/src/angular.suffix +++ b/src/angular.suffix @@ -1,15 +1,3 @@ - if (window.angular.bootstrap) { - //AngularJS is already loaded, so we can return here... - console.log('WARNING: Tried to load angular more than once.'); - return; - } - - //try to bind to jquery now so that one can write jqLite(document).ready() - //but we will rebind on bootstrap again. - bindJQuery(); - - publishExternalAPI(angular); - jqLite(document).ready(function() { angularInit(document, bootstrap); }); diff --git a/src/ng/locale.js b/src/ng/locale.js index 4a2d64c7a1db..f98281f70228 100644 --- a/src/ng/locale.js +++ b/src/ng/locale.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; /** * @ngdoc service @@ -10,72 +10,4 @@ * * * `id` – `{string}` – locale id formatted as `languageId-countryId` (e.g. `en-us`) */ -function $LocaleProvider() { - this.$get = function() { - return { - id: 'en-us', - NUMBER_FORMATS: { - DECIMAL_SEP: '.', - GROUP_SEP: ',', - PATTERNS: [ - { // Decimal Pattern - minInt: 1, - minFrac: 0, - maxFrac: 3, - posPre: '', - posSuf: '', - negPre: '-', - negSuf: '', - gSize: 3, - lgSize: 3 - },{ //Currency Pattern - minInt: 1, - minFrac: 2, - maxFrac: 2, - posPre: '\u00A4', - posSuf: '', - negPre: '-\u00A4', - negSuf: '', - gSize: 3, - lgSize: 3 - } - ], - CURRENCY_SYM: '$' - }, - - DATETIME_FORMATS: { - MONTH: - 'January,February,March,April,May,June,July,August,September,October,November,December' - .split(','), - SHORTMONTH: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','), - DAY: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','), - SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','), - AMPMS: ['AM','PM'], - medium: 'MMM d, y h:mm:ss a', - 'short': 'M/d/yy h:mm a', - fullDate: 'EEEE, MMMM d, y', - longDate: 'MMMM d, y', - mediumDate: 'MMM d, y', - shortDate: 'M/d/yy', - mediumTime: 'h:mm:ss a', - shortTime: 'h:mm a', - ERANAMES: [ - "Before Christ", - "Anno Domini" - ], - ERAS: [ - "BC", - "AD" - ] - }, - - pluralCat: function(num) { - if (num === 1) { - return 'one'; - } - return 'other'; - } - }; - }; -} diff --git a/test/ng/localeSpec.js b/test/ng/localeSpec.js index 1da9cf611062..a811de51fbad 100644 --- a/test/ng/localeSpec.js +++ b/test/ng/localeSpec.js @@ -3,7 +3,10 @@ describe('$locale', function() { /* global $LocaleProvider: false */ - var $locale = new $LocaleProvider().$get(); + var $locale; + beforeEach(inject(function(_$locale_) { + $locale = _$locale_; + })); it('should have locale id set to en-us', function() { expect($locale.id).toBe('en-us');