You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2018/10/15 21:34:45 UTC

[1/2] wicket git commit: WICKET-5552 allow prevention of drags

Repository: wicket
Updated Branches:
  refs/heads/wicket-8.x efc8ceb42 -> c7be83b16


WICKET-5552 allow prevention of drags

used by ModalWindow to prevent dragging on window content

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/03412f18
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/03412f18
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/03412f18

Branch: refs/heads/wicket-8.x
Commit: 03412f18eeab8954cc60f5532585993ae1f012d0
Parents: efc8ceb
Author: Sven Meier <sv...@apache.org>
Authored: Mon Oct 15 23:15:06 2018 +0200
Committer: Sven Meier <sv...@apache.org>
Committed: Mon Oct 15 23:15:06 2018 +0200

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js    | 25 +++++++++++++-------
 .../ajax/markup/html/modal/res/modal.js         | 11 +++++++--
 2 files changed, 25 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/03412f18/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index 0969bb8..c58e502 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -2257,13 +2257,18 @@
 		Drag: {
 
 			/**
-			 * Initializes the dragging on the specified element.
-			 * Element's onmousedown will be replaced by generated handler.
-			 *
-			 * @param {Element} element - element clicking on which the drag should begin
-			 * @param {Function} onDragBegin - handler called at the begin on dragging - passed element as first parameter
-			 * @param {Function} onDragEnd - handler called at the end of dragging - passed element as first parameter
-			 * @param {Function} onDrag - handler called during dragging - passed element and mouse deltas
+			 * Initializes dragging on the specified element.
+			 * 
+			 * @param element {Element}
+			 *            element clicking on which
+			 *            the drag should begin
+			 * @param onDragBegin {Function}
+			 *            called at the begin of dragging - passed element and event as parameters,
+			 *            may return false to prevent the start
+			 * @param onDragEnd {Function}
+			 *            handler called at the end of dragging - passed element as parameter
+			 * @param onDrag {Function}
+			 *            handler called during dragging - passed element and mouse deltas as parameters
 			 */
 			init: function(element, onDragBegin, onDragEnd, onDrag) {
 
@@ -2293,14 +2298,16 @@
 
 				var element = this;
 
+				if (element.wicketOnDragBegin(element, e) === false) {
+					return;
+				}
+
 				Wicket.Event.stop(e);
 
 				if (e.preventDefault) {
 					e.preventDefault();
 				}
 
-				element.wicketOnDragBegin(element);
-
 				element.lastMouseX = e.clientX;
 				element.lastMouseY = e.clientY;
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/03412f18/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
index b00ceec..6bcebf2 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
@@ -901,11 +901,18 @@
 		/**
 		 * Called when dragging has started.
 		 */
-		onBegin: function(object) {
+		onBegin: function(element, event) {
+			// ignore anything inside the content
+			if (jQuery(event.target).closest('.w_content').size()) {
+				return false;
+			}
+
 			if (this.isIframe() && (Wicket.Browser.isGecko() || Wicket.Browser.isIELessThan11() || Wicket.Browser.isSafari())) {
 				this.revertList = [];
 				Wicket.Iframe.documentFix(document, this.revertList);
 			}
+			
+			return true;
 		},
 
 		/**
@@ -1183,7 +1190,7 @@
 					"<div class=\"w_left\" id='"+idLeft+"'>"+
 						"<div class=\"w_right_1\">"+
 							"<div class=\"w_right\" id='"+idRight+"'>"+
-								"<div class=\"w_content_1\" onmousedown=\"Wicket.Event.stop(event);\">"+
+								"<div class=\"w_content_1\">"+
 									"<div class=\"w_caption\"  id=\""+idCaption+"\">"+
 										"<a class=\"w_close\" style=\"z-index:1\" href=\"#\"></a>"+
 										"<h3 id=\""+idCaptionText+"\" class=\"w_captionText\"></h3>"+


[2/2] wicket git commit: WICKET-4423 allow dragging over iframe

Posted by sv...@apache.org.
WICKET-4423 allow dragging over iframe

with pointer-events=none

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c7be83b1
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c7be83b1
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c7be83b1

Branch: refs/heads/wicket-8.x
Commit: c7be83b16f5ef016c8d981d4b5f74bf480097868
Parents: 03412f1
Author: Sven Meier <sv...@apache.org>
Authored: Mon Oct 15 23:29:14 2018 +0200
Committer: Sven Meier <sv...@apache.org>
Committed: Mon Oct 15 23:29:14 2018 +0200

----------------------------------------------------------------------
 .../ajax/markup/html/modal/res/modal.js         | 154 +------------------
 1 file changed, 6 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/c7be83b1/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
index 6bcebf2..8b66687 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
@@ -56,142 +56,6 @@
 	}
 
 	/**
-	 * Supporting code for getting mouse move and mouse up events from iframes.
-	 * The problem when dragging a div with an iframe is that when the mouse cursor
-	 * gets over an iframe, all mouse events are received by the iframe's document. (IE and FF)
-	 *
-	 * This code can recursively traverse all iframes in document and temporarily forward
-	 * events from their documents to parent document.
-	 */
-	Wicket.Iframe = {
-
-		/**
-		 * Returns the horizontal position of given element (in pixels).
-		 */
-		findPosX: function(e) {
-			if (e.offsetParent) {
-				var c = 0;
-				while (e) {
-					c += e.offsetLeft;
-					e = e.offsetParent;
-				}
-				return c;
-			} else if (e.x) {
-				return e.x;
-			} else {
-				return 0;
-			}
-		},
-
-		/**
-		 * Returns the vertical position of given element (in pixels).
-		 */
-		findPosY: function(e) {
-			if (e.offsetParent) {
-				var c = 0;
-				while (e) {
-					c += e.offsetTop;
-					e = e.offsetParent;
-				}
-				return c;
-			} else if (e.y) {
-				return e.y;
-			} else {
-				return 0;
-			}
-		},
-
-		/**
-		 * Forwards the events from iframe to the parent document (works recursively).
-		 * @param {Document} doc - document to which the events will be forwarded
-		 * @param {HTMLElement} iframe - source iframe
-		 * @param {Array} revertList - list to which altered iframes will be added
-		 */
-		forwardEvents: function(doc, iframe, revertList) {
-			try {
-				var idoc = iframe.contentWindow.document;
-				idoc.old_onmousemove = idoc.onmousemove;
-				idoc.onmousemove = function(evt) {
-					if (!evt) {
-						evt = iframe.contentWindow.event;
-					}
-					var e = {};
-
-					var dx = 0;
-					var dy = 0;
-					if (Wicket.Browser.isIELessThan11() || Wicket.Browser.isGecko()) {
-						dx = Wicket.Window.getScrollX();
-						dy = Wicket.Window.getScrollY();
-					}
-
-					e.clientX = evt.clientX + Wicket.Iframe.findPosX(iframe) - dx;
-					e.clientY = evt.clientY + Wicket.Iframe.findPosY(iframe) - dy;
-					doc.onmousemove(e);
-				};
-				idoc.old_onmouseup = idoc.old_onmousemove;
-				idoc.onmouseup = function(evt) {
-					if (!evt) {
-						evt = iframe.contentWindow.event;
-					}
-					var e = {};
-
-					var dx = 0;
-					var dy = 0;
-					if (Wicket.Browser.isIELessThan11() || Wicket.Browser.isGecko()) {
-						dx = Wicket.Window.getScrollX();
-						dy = Wicket.Window.getScrollY();
-					}
-
-					e.clientX = evt.clientX + Wicket.Iframe.findPosX(iframe) - dx;
-					e.clientY = evt.clientY + Wicket.Iframe.findPosY(iframe) - dy;
-					doc.onmouseup(e);
-				};
-				revertList.push(iframe);
-				Wicket.Iframe.documentFix(idoc, revertList);
-			} catch (ignore) {
-			}
-		},
-
-		/**
-		 * Reverts the changes made to the given iframe.
-		 * @param {HTMLElement} iframe
-		 */
-		revertForward: function(iframe) {
-			var idoc = iframe.contentWindow.document;
-			idoc.onmousemove = idoc.old_onmousemove;
-			idoc.onmouseup = idoc.old_onmouseup;
-			idoc.old_onmousemove = null;
-			idoc.old_onmouseup = null;
-		},
-
-		/**
-		 * Forward events from all iframes of the given document (recursive)
-		 * @param {Document} doc - document to be fixed
-		 * @param {Array} revertList - all affected iframes will be stored here
-		 */
-		documentFix: function(doc, revertList) {
-			var iframes = doc.getElementsByTagName("iframe");
-			for (var i = 0; i < iframes.length; ++i) {
-				var iframe = iframes[i];
-				if (iframe.tagName) {
-					Wicket.Iframe.forwardEvents(doc, iframe, revertList);
-				}
-			}
-		},
-
-		/**
-		 * Reverts the changes made to each iframe in the given array.
-		 * @param {Array} revertList
-		 */
-		documentRevert: function(revertList) {
-			for (var i = 0; i < revertList.length; ++i) {
-				var iframe = revertList[i];
-				Wicket.Iframe.revertForward(iframe);
-			}
-		}
-	};
-
-	/**
 	 * Draggable (and optionally resizable) window that can either hold a div
 	 * or an iframe.
 	 */
@@ -907,10 +771,7 @@
 				return false;
 			}
 
-			if (this.isIframe() && (Wicket.Browser.isGecko() || Wicket.Browser.isIELessThan11() || Wicket.Browser.isSafari())) {
-				this.revertList = [];
-				Wicket.Iframe.documentFix(document, this.revertList);
-			}
+			jQuery(this.window).find('iframe').css('pointer-events', 'none');
 			
 			return true;
 		},
@@ -919,14 +780,11 @@
 		 * Called when dragging has ended.
 		 */
 		onEnd: function(object) {
-			if (this.revertList) {
-				Wicket.Iframe.documentRevert(this.revertList);
-				this.revertList = null;
-				if (Wicket.Browser.isKHTML() || this.content.style.visibility==='hidden') {
-					this.content.style.visibility='hidden';
-					window.setTimeout(Wicket.bind(function() { this.content.style.visibility='visible'; }, this),  0 );
-				}
-				this.revertList = null;
+			jQuery(this.window).find('iframe').css('pointer-events', 'auto');
+
+			if (Wicket.Browser.isKHTML() || this.content.style.visibility==='hidden') {
+				this.content.style.visibility='hidden';
+				window.setTimeout(Wicket.bind(function() { this.content.style.visibility='visible'; }, this),  0 );
 			}
 
 			this.savePosition();