Parcourir la source

Merge branch 'master' into skeleton

Conflicts:
	src/agenda/AgendaDayView.js
	src/agenda/AgendaEventRenderer.js
	src/agenda/AgendaView.js
	src/agenda/AgendaWeekView.js
	src/basic/BasicDayView.js
	src/basic/BasicView.js
	src/basic/BasicWeekView.js
	src/basic/MonthView.js
	src/common/DayEventRenderer.js
	src/common/SelectionManager.js
Adam Shaw il y a 11 ans
Parent
commit
c04bbba6d6

+ 1 - 1
Gruntfile.js

@@ -123,7 +123,7 @@ module.exports = function(grunt) {
 	]);
 
 	config.generateLanguages = {
-		moment: 'lib/moment/lang/',
+		moment: grunt.file.expand('lib/moment/{locale,lang}/')[0], // lang directory is pre-moment-2.8
 		datepicker: 'lib/jquery-ui/ui/i18n/',
 		fullCalendar: 'lang/',
 		dest: 'build/temp/lang/',

+ 6 - 4
build/tasks/generateLanguages.js

@@ -36,7 +36,7 @@ module.exports = function(grunt) {
 		});
 
 		// code for resetting the language back to English
-		combinedJS += '\nmoment.lang("en");';
+		combinedJS += '\n(moment.locale || moment.lang).call(moment, "en");'; // works with moment-pre-2.8
 		combinedJS += '\n$.fullCalendar.lang("en");';
 		combinedJS += '\nif ($.datepicker) $.datepicker.setDefaults($.datepicker.regional[""]);';
 
@@ -133,9 +133,11 @@ module.exports = function(grunt) {
 			}
 		);
 
-		js = js.replace( // replace the `return` statement so execution continues
-			/^(\s*)return moment\.lang\(/m,
-			'$1moment.lang('
+		// replace the `return` statement so execution continues
+		// compatible with moment-pre-2.8
+		js = js.replace(
+			/^(\s*)return moment\.(defineLocale|lang)\(/m,
+			'$1(moment.defineLocale || moment.lang).call(moment, '
 		);
 
 		return js;

+ 27 - 14
src/Calendar.js

@@ -65,26 +65,34 @@ function Calendar(element, instanceOptions) {
 	// -----------------------------------------------------------------------------------
 	// Apply overrides to the current language's data
 
-	var langData = createObject( // make a cheap clone
-		moment.langData(options.lang)
-	);
+
+	// Returns moment's internal locale data. If doesn't exist, returns English.
+	// Works with moment-pre-2.8
+	function getLocaleData(langCode) {
+		var f = moment.localeData || moment.langData;
+		return f.call(moment, langCode) ||
+			f.call(moment, 'en'); // the newer localData could return null, so fall back to en
+	}
+
+
+	var localeData = createObject(getLocaleData(options.lang)); // make a cheap copy
 
 	if (options.monthNames) {
-		langData._months = options.monthNames;
+		localeData._months = options.monthNames;
 	}
 	if (options.monthNamesShort) {
-		langData._monthsShort = options.monthNamesShort;
+		localeData._monthsShort = options.monthNamesShort;
 	}
 	if (options.dayNames) {
-		langData._weekdays = options.dayNames;
+		localeData._weekdays = options.dayNames;
 	}
 	if (options.dayNamesShort) {
-		langData._weekdaysShort = options.dayNamesShort;
+		localeData._weekdaysShort = options.dayNamesShort;
 	}
 	if (options.firstDay != null) {
-		var _week = createObject(langData._week); // _week: { dow: # }
+		var _week = createObject(localeData._week); // _week: { dow: # }
 		_week.dow = options.firstDay;
-		langData._week = _week;
+		localeData._week = _week;
 	}
 
 
@@ -117,7 +125,12 @@ function Calendar(element, instanceOptions) {
 			mom = fc.moment.parseZone.apply(null, arguments); // let the input decide the zone
 		}
 
-		mom._lang = langData;
+		if ('_locale' in mom) { // moment 2.8 and above
+			mom._locale = localeData;
+		}
+		else { // pre-moment-2.8
+			mom._lang = localeData;
+		}
 
 		return mom;
 	};
@@ -205,7 +218,7 @@ function Calendar(element, instanceOptions) {
 
 		// a function that returns a formatStr // TODO: in future, precompute this
 		if (typeof formatStr === 'function') {
-			formatStr = formatStr.call(t, options, langData);
+			formatStr = formatStr.call(t, options, localeData);
 		}
 
 		return formatRange(m1, m2, formatStr, null, options.isRTL);
@@ -217,7 +230,7 @@ function Calendar(element, instanceOptions) {
 
 		// a function that returns a formatStr // TODO: in future, precompute this
 		if (typeof formatStr === 'function') {
-			formatStr = formatStr.call(t, options, langData);
+			formatStr = formatStr.call(t, options, localeData);
 		}
 
 		return formatDate(mom, formatStr);
@@ -595,13 +608,13 @@ function Calendar(element, instanceOptions) {
 	
 	
 	function prevYear() {
-		date.add('years', -1);
+		date.add(-1, 'years');
 		renderView();
 	}
 	
 	
 	function nextYear() {
-		date.add('years', 1);
+		date.add(1, 'years');
 		renderView();
 	}
 	

+ 2 - 2
src/common/View.js

@@ -602,7 +602,7 @@ function View(calendar) {
 		while (
 			isHiddenDayHash[(out.day() + (isExclusive ? inc : 0) + 7) % 7]
 		) {
-			out.add('days', inc);
+			out.add(inc, 'days');
 		}
 		return out;
 	}
@@ -656,7 +656,7 @@ function View(calendar) {
 
 	// day offset -> date
 	function dayOffsetToDate(dayOffset) {
-		return t.start.clone().add('days', dayOffset);
+		return t.start.clone().add(dayOffset, 'days');
 	}
 
 

+ 4 - 1
src/date-formatting.js

@@ -72,12 +72,15 @@ function formatDateWithChunk(date, chunk) {
 // If the dates are the same as far as the format string is concerned, just return a single
 // rendering of one date, without any separator.
 function formatRange(date1, date2, formatStr, separator, isRTL) {
+	var localeData;
 
 	date1 = fc.moment.parseZone(date1);
 	date2 = fc.moment.parseZone(date2);
 
+	localeData = (date1.localeData || date1.lang).call(date1); // works with moment-pre-2.8
+
 	// Expand localized format strings, like "LL" -> "MMMM D YYYY"
-	formatStr = date1.lang().longDateFormat(formatStr) || formatStr;
+	formatStr = localeData.longDateFormat(formatStr) || formatStr;
 	// BTW, this is not important for `formatDate` because it is impossible to put custom tokens
 	// or non-zero areas in Moment's localized format strings.
 

+ 5 - 5
tests/automated/titleFormat.js

@@ -10,10 +10,10 @@ describe('titleFormat', function() {
 
         var viewWithFormat = [
             { view: 'month', expected: 'June 2014' },
-            { view: 'basicWeek', expected: 'Jun 8 - 14 2014' },
-            { view: 'agendaWeek', expected: 'Jun 8 - 14 2014' },
-            { view: 'basicDay', expected: 'June 12 2014' },
-            { view: 'agendaDay', expected: 'June 12 2014' }
+            { view: 'basicWeek', expected: /Jun 8 - 14,? 2014/ },  // moment changed LL defaults after 2.8
+            { view: 'agendaWeek', expected: /Jun 8 - 14,? 2014/ }, // "
+            { view: 'basicDay', expected: /June 12,? 2014/ },      // "
+            { view: 'agendaDay', expected: /June 12,? 2014/ }      // "
         ];
 
         beforeEach(function() {
@@ -28,7 +28,7 @@ describe('titleFormat', function() {
             for (var i = 0; i <  viewWithFormat.length; i++) {
                 var crtView = viewWithFormat[i];
                 cal.fullCalendar('changeView', crtView.view);
-                expect(cal.find(SELECTOR).text()).toBe(crtView.expected);
+                expect(cal.find(SELECTOR).text()).toMatch(crtView.expected);
             };
         });
     });

+ 6 - 0
tests/lib/jasmine-ext.js

@@ -1,6 +1,12 @@
 
 beforeEach(function() {
 
+	// don't show warnings about deprecated methods like `moment.lang`, etc.
+	// at some point we'll require moment version above 2.8.
+	// until then, it's too annoying to support two versions.
+	// (not the best place for this)
+	moment.suppressDeprecationWarnings = true;
+
 	jasmine.addMatchers({
 		toEqualMoment: function() {
 			return {