Просмотр исходного кода

fix bug with langs with no fc options

Adam Shaw 11 лет назад
Родитель
Сommit
94aaa264b5
2 измененных файлов с 30 добавлено и 10 удалено
  1. 16 10
      src/lang.js
  2. 14 0
      tests/automated/lang.js

+ 16 - 10
src/lang.js

@@ -50,23 +50,28 @@ fc.lang = function(langCode, newFcOptions) {
 	// get the FullCalendar internal option hash for this language. create if necessary
 	fcOptions = langOptionHash[langCode] || (langOptionHash[langCode] = {});
 
-	if (newFcOptions) { // provided new options for this language?
-
-		// this is as good a time as any to compute options based off of moment locale data
-		momOptions = getMomentLocaleData(langCode);
-		$.each(momComputableOptions, function(name, func) {
-			fcOptions[name] = func(momOptions, fcOptions);
-		});
-
-		// merge the new options on top of the old
+	// provided new options for this language? merge them in
+	if (newFcOptions) {
 		mergeOptions(fcOptions, newFcOptions);
 	}
 
+	// compute language options that weren't defined.
+	// always do this. newFcOptions can be undefined when initializing from i18n file,
+	// so no way to tell if this is an initialization or a default-setting.
+	momOptions = getMomentLocaleData(langCode); // will fall back to en
+	$.each(momComputableOptions, function(name, func) {
+		if (fcOptions[name] === undefined) {
+			fcOptions[name] = func(momOptions, fcOptions);
+		}
+	});
+
 	// set it as the default language for FullCalendar
 	defaults.lang = langCode;
 };
 
 
+// NOTE: can't guarantee any of these computations will run because not every language has datepicker
+// configs, so make sure there are English fallbacks for these in the defaults file.
 var dpComputableOptions = {
 
 	defaultButtonText: function(dpOptions) {
@@ -139,5 +144,6 @@ function getMomentLocaleData(langCode) {
 }
 
 
-// initialize the default language. forces computation of moment-derived English options.
+// Initialize English by forcing computation of moment-derived options.
+// Also, sets it as the default.
 fc.lang('en', englishDefaults);

+ 14 - 0
tests/automated/lang.js

@@ -50,4 +50,18 @@ describe('lang', function() {
 		expect(s).toEqual('Thursday May 1st 2014');
 	});
 
+	it('works when certain language has no FC settings defined', function() {
+		affix('#cal');
+		$('#cal').fullCalendar({
+			lang: 'en-ca',
+			defaultView: 'agendaWeek',
+			defaultDate: '2014-12-25',
+			events: [
+				{ title: 'Christmas', start: '2014-12-25T10:00:00' }
+			]
+		});
+		expect($('.fc-day-header:first')).toHaveText('Sun 12-21');
+		expect($('.fc-event .fc-time')).toHaveText('10:00');
+	});
+
 });