Pārlūkot izejas kodu

use our own version of jQuery.proxy to avoid undesired behavior

Adam Shaw 11 gadi atpakaļ
vecāks
revīzija
4921ae94e8

+ 4 - 4
src/common/DragListener.js

@@ -63,14 +63,14 @@ var DragListener = fc.DragListener = Class.extend({
 					this.scrollEl = scrollParent;
 
 					// scope to `this`, and use `debounce` to make sure rapid calls don't happen
-					this.scrollHandlerProxy = debounce($.proxy(this, 'scrollHandler'), 100);
+					this.scrollHandlerProxy = debounce(proxy(this, 'scrollHandler'), 100);
 					this.scrollEl.on('scroll', this.scrollHandlerProxy);
 				}
 			}
 
 			$(document)
-				.on('mousemove', this.mousemoveProxy = $.proxy(this, 'mousemove'))
-				.on('mouseup', this.mouseupProxy = $.proxy(this, 'mouseup'))
+				.on('mousemove', this.mousemoveProxy = proxy(this, 'mousemove'))
+				.on('mouseup', this.mouseupProxy = proxy(this, 'mouseup'))
 				.on('selectstart', this.preventDefault); // prevents native selection in IE<=8
 
 			if (ev) {
@@ -278,7 +278,7 @@ var DragListener = fc.DragListener = Class.extend({
 		// if there is non-zero velocity, and an animation loop hasn't already started, then START
 		if ((this.scrollTopVel || this.scrollLeftVel) && !this.scrollIntervalId) {
 			this.scrollIntervalId = setInterval(
-				$.proxy(this, 'scrollIntervalFunc'), // scope to `this`
+				proxy(this, 'scrollIntervalFunc'), // scope to `this`
 				this.scrollIntervalMs
 			);
 		}

+ 1 - 1
src/common/Grid.js

@@ -38,7 +38,7 @@ var Grid = fc.Grid = RowRenderer.extend({
 
 		this.coordMap = new GridCoordMap(this);
 		this.elsByFill = {};
-		this.documentDragStartProxy = $.proxy(this, 'documentDragStart');
+		this.documentDragStartProxy = proxy(this, 'documentDragStart');
 	},
 
 

+ 1 - 1
src/common/MouseFollower.js

@@ -49,7 +49,7 @@ var MouseFollower = Class.extend({
 				this.updatePosition();
 			}
 
-			$(document).on('mousemove', this.mousemoveProxy = $.proxy(this, 'mousemove'));
+			$(document).on('mousemove', this.mousemoveProxy = proxy(this, 'mousemove'));
 		}
 	},
 

+ 1 - 1
src/common/Popover.js

@@ -72,7 +72,7 @@ var Popover = Class.extend({
 		});
 
 		if (options.autoHide) {
-			$(document).on('mousedown', this.documentMousedownProxy = $.proxy(this, 'documentMousedown'));
+			$(document).on('mousedown', this.documentMousedownProxy = proxy(this, 'documentMousedown'));
 		}
 	},
 

+ 1 - 1
src/common/View.js

@@ -58,7 +58,7 @@ var View = fc.View = Class.extend({
 		this.initThemingProps();
 		this.initHiddenDays();
 
-		this.documentMousedownProxy = $.proxy(this, 'documentMousedown');
+		this.documentMousedownProxy = proxy(this, 'documentMousedown');
 
 		this.initialize();
 	},

+ 13 - 0
src/util.js

@@ -6,6 +6,7 @@ fc.debounce = debounce;
 fc.isInt = isInt;
 fc.htmlEscape = htmlEscape;
 fc.cssToStr = cssToStr;
+fc.proxy = proxy;
 
 
 /* FullCalendar-specific DOM Utilities
@@ -596,6 +597,18 @@ function isInt(n) {
 }
 
 
+// Returns a method bound to the given object context.
+// Just like one of the jQuery.proxy signatures, but without the undesired behavior of treating the same method with
+// different contexts as identical when binding/unbinding events.
+function proxy(obj, methodName) {
+	var method = obj[methodName];
+
+	return function() {
+		return method.apply(obj, arguments);
+	};
+}
+
+
 // Returns a function, that, as long as it continues to be invoked, will not
 // be triggered. The function will be called after it stops being called for
 // N milliseconds.