Adam Shaw 8 rokov pred
rodič
commit
a509950caf

+ 4 - 2
src/Calendar.js

@@ -247,9 +247,11 @@ var Calendar = FC.Calendar = Class.extend(EmitterMixin, {
 	Called before initialize()
 	*/
 	initCurrentDate: function() {
+		var defaultDateInput = this.opt('defaultDate');
+
 		// compute the initial ambig-timezone date
-		if (this.options.defaultDate != null) {
-			this.currentDate = this.moment(this.options.defaultDate).stripZone();
+		if (defaultDateInput != null) {
+			this.currentDate = this.moment(defaultDateInput).stripZone();
 		}
 		else {
 			this.currentDate = this.getNow(); // getNow already returns unzoned

+ 7 - 7
src/Calendar.moment.js

@@ -9,8 +9,8 @@ Calendar.mixin({
 	initMomentInternals: function() {
 		var _this = this;
 
-		this.defaultAllDayEventDuration = moment.duration(this.options.defaultAllDayEventDuration);
-		this.defaultTimedEventDuration = moment.duration(this.options.defaultTimedEventDuration);
+		this.defaultAllDayEventDuration = moment.duration(this.opt('defaultAllDayEventDuration'));
+		this.defaultTimedEventDuration = moment.duration(this.opt('defaultTimedEventDuration'));
 
 		// Called immediately, and when any of the options change.
 		// Happens before any internal objects rebuild or rerender, because this is very core.
@@ -73,7 +73,7 @@ Calendar.mixin({
 	moment: function() {
 		var mom;
 
-		if (this.options.timezone === 'local') {
+		if (this.opt('timezone') === 'local') {
 			mom = FC.moment.apply(null, arguments);
 
 			// Force the moment to be local, because FC.moment doesn't guarantee it.
@@ -81,7 +81,7 @@ Calendar.mixin({
 				mom.local();
 			}
 		}
-		else if (this.options.timezone === 'UTC') {
+		else if (this.opt('timezone') === 'UTC') {
 			mom = FC.moment.utc.apply(null, arguments); // process as UTC
 		}
 		else {
@@ -103,7 +103,7 @@ Calendar.mixin({
 	// Returns a boolean about whether or not the calendar knows how to calculate
 	// the timezone offset of arbitrary dates in the current timezone.
 	getIsAmbigTimezone: function() {
-		return this.options.timezone !== 'local' && this.options.timezone !== 'UTC';
+		return this.opt('timezone') !== 'local' && this.opt('timezone') !== 'UTC';
 	},
 
 
@@ -132,7 +132,7 @@ Calendar.mixin({
 	// Returns a moment for the current date, as defined by the client's computer or from the `now` option.
 	// Will return an moment with an ambiguous timezone.
 	getNow: function() {
-		var now = this.options.now;
+		var now = this.opt('now');
 		if (typeof now === 'function') {
 			now = now();
 		}
@@ -143,7 +143,7 @@ Calendar.mixin({
 	// Produces a human-readable string for the given duration.
 	// Side-effect: changes the locale of the given duration.
 	humanizeDuration: function(duration) {
-		return duration.locale(this.options.locale).humanize();
+		return duration.locale(this.opt('locale')).humanize();
 	},
 
 

+ 6 - 0
src/Calendar.options.js

@@ -39,6 +39,12 @@ Calendar.mixin({
 	},
 
 
+	// private getter
+	opt: function(name) {
+		return this.options[name];
+	},
+
+
 	setOptions: function(newOptionHash) {
 		var optionCnt = 0;
 		var optionName;

+ 10 - 7
src/Calendar.render.js

@@ -65,13 +65,13 @@ Calendar.mixin({
 		this.initToolbars();
 		this.renderHeader();
 		this.renderFooter();
-		this.renderView(this.options.defaultView);
+		this.renderView(this.opt('defaultView'));
 
-		if (this.options.handleWindowResize) {
+		if (this.opt('handleWindowResize')) {
 			$(window).resize(
 				this.windowResizeProxy = debounce( // prevents rapid calls
 					this.windowResize.bind(this),
-					this.options.windowResizeDelay
+					this.opt('windowResizeDelay')
 				)
 			);
 		}
@@ -198,7 +198,7 @@ Calendar.mixin({
 
 
 	isHeightAuto: function() {
-		return this.options.contentHeight === 'auto' || this.options.height === 'auto';
+		return this.opt('contentHeight') === 'auto' || this.opt('height') === 'auto';
 	},
 
 
@@ -226,8 +226,8 @@ Calendar.mixin({
 
 
 	_calcSize: function() { // assumes elementVisible
-		var contentHeightInput = this.options.contentHeight;
-		var heightInput = this.options.height;
+		var contentHeightInput = this.opt('contentHeight');
+		var heightInput = this.opt('height');
 
 		if (typeof contentHeightInput === 'number') { // exists and not 'auto'
 			this.suggestedViewHeight = contentHeightInput;
@@ -245,7 +245,10 @@ Calendar.mixin({
 			this.suggestedViewHeight = this.el.parent().height() - this.queryToolbarsHeight();
 		}
 		else {
-			this.suggestedViewHeight = Math.round(this.contentEl.width() / Math.max(this.options.aspectRatio, .5));
+			this.suggestedViewHeight = Math.round(
+				this.contentEl.width() /
+				Math.max(this.opt('aspectRatio'), .5)
+			);
 		}
 	},
 

+ 2 - 2
src/Calendar.toolbar.js

@@ -16,7 +16,7 @@ Calendar.mixin({
 	computeHeaderOptions: function() {
 		return {
 			extraClasses: 'fc-header-toolbar',
-			layout: this.options.header
+			layout: this.opt('header')
 		};
 	},
 
@@ -24,7 +24,7 @@ Calendar.mixin({
 	computeFooterOptions: function() {
 		return {
 			extraClasses: 'fc-footer-toolbar',
-			layout: this.options.footer
+			layout: this.opt('footer')
 		};
 	},
 

+ 23 - 19
src/EventManager.js

@@ -48,7 +48,7 @@ function EventManager() { // assumed to be a calendar
 
 
 	$.each(
-		(t.options.events ? [ t.options.events ] : []).concat(t.options.eventSources || []),
+		(t.opt('events') ? [ t.opt('events') ] : []).concat(t.opt('eventSources') || []),
 		function(i, sourceInput) {
 			var source = buildEventSource(sourceInput);
 			if (source) {
@@ -60,7 +60,7 @@ function EventManager() { // assumed to be a calendar
 
 
 	function requestEvents(start, end) {
-		if (!t.options.lazyFetching || isFetchNeeded(start, end)) {
+		if (!t.opt('lazyFetching') || isFetchNeeded(start, end)) {
 			return fetchEvents(start, end);
 		}
 		else {
@@ -244,7 +244,7 @@ function EventManager() { // assumed to be a calendar
 				source,
 				rangeStart.clone(),
 				rangeEnd.clone(),
-				t.options.timezone,
+				t.opt('timezone'),
 				callback
 			);
 
@@ -267,7 +267,7 @@ function EventManager() { // assumed to be a calendar
 					t, // this, the Calendar object
 					rangeStart.clone(),
 					rangeEnd.clone(),
-					t.options.timezone,
+					t.opt('timezone'),
 					function(events) {
 						callback(events);
 						t.popLoading();
@@ -302,9 +302,9 @@ function EventManager() { // assumed to be a calendar
 				// and not affect the passed-in object.
 				var data = $.extend({}, customData || {});
 
-				var startParam = firstDefined(source.startParam, t.options.startParam);
-				var endParam = firstDefined(source.endParam, t.options.endParam);
-				var timezoneParam = firstDefined(source.timezoneParam, t.options.timezoneParam);
+				var startParam = firstDefined(source.startParam, t.opt('startParam'));
+				var endParam = firstDefined(source.endParam, t.opt('endParam'));
+				var timezoneParam = firstDefined(source.timezoneParam, t.opt('timezoneParam'));
 
 				if (startParam) {
 					data[startParam] = rangeStart.format();
@@ -312,8 +312,8 @@ function EventManager() { // assumed to be a calendar
 				if (endParam) {
 					data[endParam] = rangeEnd.format();
 				}
-				if (t.options.timezone && t.options.timezone != 'local') {
-					data[timezoneParam] = t.options.timezone;
+				if (t.opt('timezone') && t.opt('timezone') != 'local') {
+					data[timezoneParam] = t.opt('timezone');
 				}
 
 				t.pushLoading();
@@ -722,12 +722,13 @@ function EventManager() { // assumed to be a calendar
 	// Will return `false` when input is invalid.
 	// `source` is optional
 	function buildEventFromInput(input, source) {
+		var calendarEventDataTransform = t.opt('eventDataTransform');
 		var out = {};
 		var start, end;
 		var allDay;
 
-		if (t.options.eventDataTransform) {
-			input = t.options.eventDataTransform(input);
+		if (calendarEventDataTransform) {
+			input = calendarEventDataTransform(input);
 		}
 		if (source && source.eventDataTransform) {
 			input = source.eventDataTransform(input);
@@ -793,7 +794,7 @@ function EventManager() { // assumed to be a calendar
 			if (allDay === undefined) { // still undefined? fallback to default
 				allDay = firstDefined(
 					source ? source.allDayDefault : undefined,
-					t.options.allDayDefault
+					t.opt('allDayDefault')
 				);
 				// still undefined? normalizeEventDates will calculate it
 			}
@@ -830,7 +831,7 @@ function EventManager() { // assumed to be a calendar
 		}
 
 		if (!eventProps.end) {
-			if (t.options.forceEventDuration) {
+			if (t.opt('forceEventDuration')) {
 				eventProps.end = t.getDefaultEventEnd(eventProps.allDay, eventProps.start);
 			}
 			else {
@@ -1183,21 +1184,22 @@ function backupEventDates(event) {
 // Determines if the given event can be relocated to the given span (unzoned start/end with other misc data)
 Calendar.prototype.isEventSpanAllowed = function(span, event) {
 	var source = event.source || {};
+	var eventAllowFunc = this.opt('eventAllow');
 
 	var constraint = firstDefined(
 		event.constraint,
 		source.constraint,
-		this.options.eventConstraint
+		this.opt('eventConstraint')
 	);
 
 	var overlap = firstDefined(
 		event.overlap,
 		source.overlap,
-		this.options.eventOverlap
+		this.opt('eventOverlap')
 	);
 
 	return this.isSpanAllowed(span, constraint, overlap, event) &&
-		(!this.options.eventAllow || this.options.eventAllow(span, event) !== false);
+		(!eventAllowFunc || eventAllowFunc(span, event) !== false);
 };
 
 
@@ -1226,8 +1228,10 @@ Calendar.prototype.isExternalSpanAllowed = function(eventSpan, eventLocation, ev
 
 // Determines the given span (unzoned start/end with other misc data) can be selected.
 Calendar.prototype.isSelectionSpanAllowed = function(span) {
-	return this.isSpanAllowed(span, this.options.selectConstraint, this.options.selectOverlap) &&
-		(!this.options.selectAllow || this.options.selectAllow(span) !== false);
+	var selectAllowFunc = this.opt('selectAllow');
+
+	return this.isSpanAllowed(span, this.opt('selectConstraint'), this.opt('selectOverlap')) &&
+		(!selectAllowFunc || selectAllowFunc(span) !== false);
 };
 
 
@@ -1351,7 +1355,7 @@ var BUSINESS_HOUR_EVENT_DEFAULTS = {
 // Return events objects for business hours within the current view.
 // Abuse of our event system :(
 Calendar.prototype.getCurrentBusinessHourEvents = function(wholeDay) {
-	return this.computeBusinessHourEvents(wholeDay, this.options.businessHours);
+	return this.computeBusinessHourEvents(wholeDay, this.opt('businessHours'));
 };
 
 // Given a raw input value from options, return events objects for business hours within the current view.

+ 9 - 7
src/Toolbar.js

@@ -31,7 +31,7 @@ function Toolbar(calendar, toolbarOptions) {
 	function render() {
 		var sections = toolbarOptions.layout;
 
-		tm = calendar.options.theme ? 'ui' : 'fc';
+		tm = calendar.opt('theme') ? 'ui' : 'fc';
 
 		if (sections) {
 			if (!el) {
@@ -62,6 +62,8 @@ function Toolbar(calendar, toolbarOptions) {
 	function renderSection(position) {
 		var sectionEl = $('<div class="fc-' + position + '"/>');
 		var buttonStr = toolbarOptions.layout[position];
+		var calendarCustomButtons = calendar.opt('customButtons') || {};
+		var calendarButtonText = calendar.opt('buttonText') || {};
 
 		if (buttonStr) {
 			$.each(buttonStr.split(' '), function(i) {
@@ -86,7 +88,7 @@ function Toolbar(calendar, toolbarOptions) {
 						isOnlyButtons = false;
 					}
 					else {
-						if ((customButtonProps = (calendar.options.customButtons || {})[buttonName])) {
+						if ((customButtonProps = calendarCustomButtons[buttonName])) {
 							buttonClick = function(ev) {
 								if (customButtonProps.click) {
 									customButtonProps.click.call(button[0], ev);
@@ -108,7 +110,7 @@ function Toolbar(calendar, toolbarOptions) {
 								calendar[buttonName]();
 							};
 							overrideText = (calendar.overrides.buttonText || {})[buttonName];
-							defaultText = calendar.options.buttonText[buttonName]; // everything else is considered default
+							defaultText = calendarButtonText[buttonName]; // everything else is considered default
 						}
 
 						if (buttonClick) {
@@ -116,20 +118,20 @@ function Toolbar(calendar, toolbarOptions) {
 							themeIcon =
 								customButtonProps ?
 									customButtonProps.themeIcon :
-									calendar.options.themeButtonIcons[buttonName];
+									calendar.opt('themeButtonIcons')[buttonName];
 
 							normalIcon =
 								customButtonProps ?
 									customButtonProps.icon :
-									calendar.options.buttonIcons[buttonName];
+									calendar.opt('buttonIcons')[buttonName];
 
 							if (overrideText) {
 								innerHtml = htmlEscape(overrideText);
 							}
-							else if (themeIcon && calendar.options.theme) {
+							else if (themeIcon && calendar.opt('theme')) {
 								innerHtml = "<span class='ui-icon ui-icon-" + themeIcon + "'></span>";
 							}
-							else if (normalIcon && !calendar.options.theme) {
+							else if (normalIcon && !calendar.opt('theme')) {
 								innerHtml = "<span class='fc-icon fc-icon-" + normalIcon + "'></span>";
 							}
 							else {

+ 1 - 1
src/common/Grid.events.js

@@ -207,7 +207,7 @@ Grid.mixin({
 		if (businessHours == null) {
 			// fallback
 			// access from calendawr. don't access from view. doesn't update with dynamic options.
-			businessHours = calendar.options.businessHours;
+			businessHours = calendar.opt('businessHours');
 		}
 
 		events = calendar.computeBusinessHourEvents(wholeDay, businessHours);

+ 2 - 2
src/gcal/gcal.js

@@ -73,7 +73,7 @@ FC.sourceFetchers.push(function(sourceOptions, start, end, timezone) {
 
 function transformOptions(sourceOptions, start, end, timezone, calendar) {
 	var url = API_BASE + '/' + encodeURIComponent(sourceOptions.googleCalendarId) + '/events?callback=?'; // jsonp
-	var apiKey = sourceOptions.googleCalendarApiKey || calendar.options.googleCalendarApiKey;
+	var apiKey = sourceOptions.googleCalendarApiKey || calendar.opt('googleCalendarApiKey');
 	var success = sourceOptions.success;
 	var data;
 	var timezoneArg; // populated when a specific timezone. escaped to Google's liking
@@ -83,7 +83,7 @@ function transformOptions(sourceOptions, start, end, timezone, calendar) {
 
 		// call error handlers
 		(sourceOptions.googleCalendarError || $.noop).apply(calendar, errorObjs);
-		(calendar.options.googleCalendarError || $.noop).apply(calendar, errorObjs);
+		(calendar.opt('googleCalendarError') || $.noop).apply(calendar, errorObjs);
 
 		// print error to debug console
 		FC.warn.apply(null, [ message ].concat(apiErrorObjs || []));