Browse Source

dont mistake a jqui resize event for a window resize event

Adam Shaw 11 years ago
parent
commit
6153ac285e
3 changed files with 31 additions and 4 deletions
  1. 6 3
      src/Calendar.js
  2. 2 1
      src/defaults.js
  3. 23 0
      tests/automated/event-resize.js

+ 6 - 3
src/Calendar.js

@@ -486,8 +486,11 @@ function Calendar(element, instanceOptions) {
 	}
 	
 	
-	function windowResize() {
-		if (!ignoreWindowResize) {
+	function windowResize(ev) {
+		if (
+			!ignoreWindowResize &&
+			ev.target === window // so we don't process jqui "resize" events that have bubbled up
+		) {
 			if (currentView.start) { // view has already been rendered
 				var uid = ++resizeUID;
 				setTimeout(function() { // add a delay
@@ -499,7 +502,7 @@ function Calendar(element, instanceOptions) {
 							ignoreWindowResize--;
 						}
 					}
-				}, 200);
+				}, options.windowResizeDelay);
 			}else{
 				// calendar must have been initialized in a 0x0 iframe that has just been resized
 				lateRender();

+ 2 - 1
src/defaults.js

@@ -89,7 +89,8 @@ var defaults = {
 	
 	dropAccept: '*',
 	
-	handleWindowResize: true
+	handleWindowResize: true,
+	windowResizeDelay: 200 // milliseconds before a rerender happens
 	
 };
 

+ 23 - 0
tests/automated/event-resize.js

@@ -184,6 +184,29 @@ describe('eventResize', function() {
 					}
 				);
 			});
+
+			it('should not fire the windowResize handler', function(done) { // bug 1116
+				options.windowResize = function() { };
+				options.windowResizeDelay = 0;
+				spyOn(options, 'windowResize');
+				init(
+					function() {
+						$('.fc-event .ui-resizable-handle')
+							.simulate('mouseover') // for our dumb optimization
+							.simulate('drag-n-drop', {
+								dy: 200,
+								interpolation: {
+									stepCount: 10,
+									duration: 100
+								}
+							});
+					},
+					function() { // if an unintended rerender happened, won't get here anyway
+						expect(options.windowResize).not.toHaveBeenCalled();
+						done();
+					}
+				);
+			});
 		});
 
 		describe('when resizing a timed event without an end', function() {