Bladeren bron

Merge branch 'master' into weeknr-in-daycell

Peter Nowee 10 jaren geleden
bovenliggende
commit
a638c9a224
10 gewijzigde bestanden met toevoegingen van 94 en 74 verwijderingen
  1. 9 0
      .github/ISSUE_TEMPLATE.md
  2. 6 0
      CHANGELOG.md
  3. 1 1
      bower.json
  4. 1 1
      package.json
  5. 22 0
      src/common/CoordCache.js
  6. 1 1
      src/common/DayGrid.events.js
  7. 3 13
      src/common/Grid.events.js
  8. 1 1
      src/common/TimeGrid.events.js
  9. 49 56
      src/common/View.js
  10. 1 1
      src/main.js

+ 9 - 0
.github/ISSUE_TEMPLATE.md

@@ -0,0 +1,9 @@
+### Bug Reports
+You MUST have a JSBin recreation, or else your issue will be CLOSED without explanation.
+Instructions: http://fullcalendar.io/wiki/Reporting-Bugs/
+
+### Feature Requests
+Search the issue tracker for an existing ticket before creating a new one.
+Instructions: http://fullcalendar.io/wiki/Requesting-Features/
+
+(Please erase the above text and begin typing. Thanks!)

+ 6 - 0
CHANGELOG.md

@@ -1,4 +1,10 @@
 
+v2.6.1 (2016-02-17)
+-------------------
+
+- make nowIndicator positioning refresh on window resize
+
+
 v2.6.0 (2016-01-07)
 -------------------
 

+ 1 - 1
bower.json

@@ -1,7 +1,7 @@
 {
   "name": "fullcalendar",
   "title": "FullCalendar",
-  "version": "2.5.0",
+  "version": "0.0.0",
   "description": "Full-sized drag & drop event calendar",
   "keywords": [
     "calendar",

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
   "name": "fullcalendar",
   "title": "FullCalendar",
-  "version": "2.5.0",
+  "version": "0.0.0",
   "description": "Full-sized drag & drop event calendar",
   "keywords": [
     "calendar",

+ 22 - 0
src/common/CoordCache.js

@@ -60,6 +60,14 @@ var CoordCache = FC.CoordCache = Class.extend({
 	},
 
 
+	// When called, if coord caches aren't built, builds them
+	ensureBuilt: function() {
+		if (!this.origin) {
+			this.build();
+		}
+	},
+
+
 	// Compute and return what the elements' bounding rectangle is, from the user's perspective.
 	// Right now, only returns a rectangle if constrained by an overflow:scroll element.
 	queryBoundingRect: function() {
@@ -112,6 +120,8 @@ var CoordCache = FC.CoordCache = Class.extend({
 	// Given a left offset (from document left), returns the index of the el that it horizontally intersects.
 	// If no intersection is made, or outside of the boundingRect, returns undefined.
 	getHorizontalIndex: function(leftOffset) {
+		this.ensureBuilt();
+
 		var boundingRect = this.boundingRect;
 		var lefts = this.lefts;
 		var rights = this.rights;
@@ -131,6 +141,8 @@ var CoordCache = FC.CoordCache = Class.extend({
 	// Given a top offset (from document top), returns the index of the el that it vertically intersects.
 	// If no intersection is made, or outside of the boundingRect, returns undefined.
 	getVerticalIndex: function(topOffset) {
+		this.ensureBuilt();
+
 		var boundingRect = this.boundingRect;
 		var tops = this.tops;
 		var bottoms = this.bottoms;
@@ -149,12 +161,14 @@ var CoordCache = FC.CoordCache = Class.extend({
 
 	// Gets the left offset (from document left) of the element at the given index
 	getLeftOffset: function(leftIndex) {
+		this.ensureBuilt();
 		return this.lefts[leftIndex];
 	},
 
 
 	// Gets the left position (from offsetParent left) of the element at the given index
 	getLeftPosition: function(leftIndex) {
+		this.ensureBuilt();
 		return this.lefts[leftIndex] - this.origin.left;
 	},
 
@@ -162,6 +176,7 @@ var CoordCache = FC.CoordCache = Class.extend({
 	// Gets the right offset (from document left) of the element at the given index.
 	// This value is NOT relative to the document's right edge, like the CSS concept of "right" would be.
 	getRightOffset: function(leftIndex) {
+		this.ensureBuilt();
 		return this.rights[leftIndex];
 	},
 
@@ -169,30 +184,35 @@ var CoordCache = FC.CoordCache = Class.extend({
 	// Gets the right position (from offsetParent left) of the element at the given index.
 	// This value is NOT relative to the offsetParent's right edge, like the CSS concept of "right" would be.
 	getRightPosition: function(leftIndex) {
+		this.ensureBuilt();
 		return this.rights[leftIndex] - this.origin.left;
 	},
 
 
 	// Gets the width of the element at the given index
 	getWidth: function(leftIndex) {
+		this.ensureBuilt();
 		return this.rights[leftIndex] - this.lefts[leftIndex];
 	},
 
 
 	// Gets the top offset (from document top) of the element at the given index
 	getTopOffset: function(topIndex) {
+		this.ensureBuilt();
 		return this.tops[topIndex];
 	},
 
 
 	// Gets the top position (from offsetParent top) of the element at the given position
 	getTopPosition: function(topIndex) {
+		this.ensureBuilt();
 		return this.tops[topIndex] - this.origin.top;
 	},
 
 	// Gets the bottom offset (from the document top) of the element at the given index.
 	// This value is NOT relative to the offsetParent's bottom edge, like the CSS concept of "bottom" would be.
 	getBottomOffset: function(topIndex) {
+		this.ensureBuilt();
 		return this.bottoms[topIndex];
 	},
 
@@ -200,12 +220,14 @@ var CoordCache = FC.CoordCache = Class.extend({
 	// Gets the bottom position (from the offsetParent top) of the element at the given index.
 	// This value is NOT relative to the offsetParent's bottom edge, like the CSS concept of "bottom" would be.
 	getBottomPosition: function(topIndex) {
+		this.ensureBuilt();
 		return this.bottoms[topIndex] - this.origin.top;
 	},
 
 
 	// Gets the height of the element at the given index
 	getHeight: function(topIndex) {
+		this.ensureBuilt();
 		return this.bottoms[topIndex] - this.tops[topIndex];
 	}
 

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

@@ -98,7 +98,7 @@ DayGrid.mixin({
 		var isResizableFromEnd = !disableResizing && event.allDay &&
 			seg.isEnd && view.isEventResizableFromEnd(event);
 		var classes = this.getSegClasses(seg, isDraggable, isResizableFromStart || isResizableFromEnd);
-		var skinCss = cssToStr(this.getEventSkinCss(event));
+		var skinCss = cssToStr(this.getSegSkinCss(seg));
 		var timeHtml = '';
 		var timeText;
 		var titleHtml;

+ 3 - 13
src/common/Grid.events.js

@@ -155,20 +155,9 @@ Grid.mixin({
 
 	// Generates a semicolon-separated CSS string to be used for the default rendering of a background event.
 	// Called by the fill system.
-	// TODO: consolidate with getEventSkinCss?
 	bgEventSegCss: function(seg) {
-		var view = this.view;
-		var event = seg.event;
-		var source = event.source || {};
-
 		return {
-			'background-color':
-				event.backgroundColor ||
-				event.color ||
-				source.backgroundColor ||
-				source.color ||
-				view.opt('eventBackgroundColor') ||
-				view.opt('eventColor')
+			'background-color': this.getSegSkinCss(seg)['background-color']
 		};
 	},
 
@@ -751,7 +740,8 @@ Grid.mixin({
 
 
 	// Utility for generating event skin-related CSS properties
-	getEventSkinCss: function(event) {
+	getSegSkinCss: function(seg) {
+		var event = seg.event;
 		var view = this.view;
 		var source = event.source || {};
 		var eventColor = event.color;

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

@@ -247,7 +247,7 @@ TimeGrid.mixin({
 		var isResizableFromStart = !disableResizing && seg.isStart && view.isEventResizableFromStart(event);
 		var isResizableFromEnd = !disableResizing && seg.isEnd && view.isEventResizableFromEnd(event);
 		var classes = this.getSegClasses(seg, isDraggable, isResizableFromStart || isResizableFromEnd);
-		var skinCss = cssToStr(this.getEventSkinCss(event));
+		var skinCss = cssToStr(this.getSegSkinCss(seg));
 		var timeText;
 		var fullTimeText; // more verbose time text. for the print stylesheet
 		var startTimeText; // just the start time text

+ 49 - 56
src/common/View.js

@@ -48,9 +48,12 @@ var View = FC.View = Class.extend({
 	// document handlers, bound to `this` object
 	documentMousedownProxy: null, // TODO: doesn't work with touch
 
-	// for refresh timing of now indicator
-	nowIndicatorTimeoutID: null,
-	nowIndicatorIntervalID: null,
+	// now indicator
+	isNowIndicatorRendered: null,
+	initialNowDate: null, // result first getNow call
+	initialNowQueriedMs: null, // ms time the getNow was called
+	nowIndicatorTimeoutID: null, // for refresh timing of now indicator
+	nowIndicatorIntervalID: null, // "
 
 
 	constructor: function(calendar, type, options, intervalDuration) {
@@ -320,22 +323,6 @@ var View = FC.View = Class.extend({
 	},
 
 
-	// If the view has already been displayed, tears it down and displays it again.
-	// Will re-render the events if necessary, which display/clear DO NOT do.
-	// TODO: make behavior more consistent.
-	redisplay: function() {
-		if (this.isSkeletonRendered) {
-			var wasEventsRendered = this.isEventsRendered;
-			this.clearEvents(); // won't trigger handlers if events never rendered
-			this.clearView();
-			this.displayView();
-			if (wasEventsRendered) { // only render and trigger handlers if events previously rendered
-				this.displayEvents(this.calendar.getEventCache());
-			}
-		}
-	},
-
-
 	// Displays the view's non-event content, such as date-related content or anything required by events.
 	// Renders the view's non-content skeleton if necessary.
 	// Can be asynchronous and return a promise.
@@ -353,10 +340,7 @@ var View = FC.View = Class.extend({
 		this.renderDates();
 		this.updateSize();
 		this.renderBusinessHours(); // might need coordinates, so should go after updateSize()
-
-		if (this.opt('nowIndicator')) {
-			this.startNowIndicator();
-		}
+		this.startNowIndicator();
 	},
 
 
@@ -458,34 +442,42 @@ var View = FC.View = Class.extend({
 	// TODO: somehow do this for the current whole day's background too
 	startNowIndicator: function() {
 		var _this = this;
-		var unit = this.getNowIndicatorUnit();
-		var initialNow; // result first getNow call
-		var initialNowQueried; // ms time of then getNow was called
+		var unit;
+		var update;
 		var delay; // ms wait value
 
-		// rerenders the now indicator, computing the new current time from the amount of time that has passed
-		// since the initial getNow call.
-		function update() {
-			_this.unrenderNowIndicator();
-			_this.renderNowIndicator(
-				initialNow.clone().add(new Date() - initialNowQueried) // add ms
-			);
+		if (this.opt('nowIndicator')) {
+			unit = this.getNowIndicatorUnit();
+			if (unit) {
+				update = proxy(this, 'updateNowIndicator'); // bind to `this`
+
+				this.initialNowDate = this.calendar.getNow();
+				this.initialNowQueriedMs = +new Date();
+				this.renderNowIndicator(this.initialNowDate);
+				this.isNowIndicatorRendered = true;
+
+				// wait until the beginning of the next interval
+				delay = this.initialNowDate.clone().startOf(unit).add(1, unit) - this.initialNowDate;
+				this.nowIndicatorTimeoutID = setTimeout(function() {
+					_this.nowIndicatorTimeoutID = null;
+					update();
+					delay = +moment.duration(1, unit);
+					delay = Math.max(100, delay); // prevent too frequent
+					_this.nowIndicatorIntervalID = setInterval(update, delay); // update every interval
+				}, delay);
+			}
 		}
+	},
 
-		if (unit) {
-			initialNow = this.calendar.getNow();
-			initialNowQueried = +new Date();
-			this.renderNowIndicator(initialNow);
 
-			// wait until the beginning of the next interval
-			delay = initialNow.clone().startOf(unit).add(1, unit) - initialNow;
-			this.nowIndicatorTimeoutID = setTimeout(function() {
-				this.nowIndicatorTimeoutID = null;
-				update();
-				delay = +moment.duration(1, unit);
-				delay = Math.max(100, delay); // prevent too frequent
-				this.nowIndicatorIntervalID = setInterval(update, delay); // update every interval
-			}, delay);
+	// rerenders the now indicator, computing the new current time from the amount of time that has passed
+	// since the initial getNow call.
+	updateNowIndicator: function() {
+		if (this.isNowIndicatorRendered) {
+			this.unrenderNowIndicator();
+			this.renderNowIndicator(
+				this.initialNowDate.clone().add(new Date() - this.initialNowQueriedMs) // add ms
+			);
 		}
 	},
 
@@ -493,19 +485,19 @@ var View = FC.View = Class.extend({
 	// Immediately unrenders the view's current time indicator and stops any re-rendering timers.
 	// Won't cause side effects if indicator isn't rendered.
 	stopNowIndicator: function() {
-		var cleared = false;
+		if (this.isNowIndicatorRendered) {
 
-		if (this.nowIndicatorTimeoutID) {
-			clearTimeout(this.nowIndicatorTimeoutID);
-			cleared = true;
-		}
-		if (this.nowIndicatorIntervalID) {
-			clearTimeout(this.nowIndicatorIntervalID);
-			cleared = true;
-		}
+			if (this.nowIndicatorTimeoutID) {
+				clearTimeout(this.nowIndicatorTimeoutID);
+				this.nowIndicatorTimeoutID = null;
+			}
+			if (this.nowIndicatorIntervalID) {
+				clearTimeout(this.nowIndicatorIntervalID);
+				this.nowIndicatorIntervalID = null;
+			}
 
-		if (cleared) { // is the indicator currently display?
 			this.unrenderNowIndicator();
+			this.isNowIndicatorRendered = false;
 		}
 	},
 
@@ -543,6 +535,7 @@ var View = FC.View = Class.extend({
 
 		this.updateHeight(isResize);
 		this.updateWidth(isResize);
+		this.updateNowIndicator();
 
 		if (isResize) {
 			this.setScroll(scrollState);

+ 1 - 1
src/main.js

@@ -1,7 +1,7 @@
 
 var FC = $.fullCalendar = {
 	version: "<%= meta.version %>",
-	internalApiVersion: 2
+	internalApiVersion: 3
 };
 var fcViews = FC.views = {};