Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3898

Opening a popup and adding a page level component at the same time cause corrupted dom after ZK 3606

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 8.5.1.1
    • 8.5.0, 8.5.1
    • None
    • Security Level: Jimmy
    • None
    • None

      Steps to Reproduce

      fiddle: http://zkfiddle.org/sample/12kc9do/2-ZK-popup-dom-location-fake-parent

      • Click on do 1 button. This attach a popup to the page, and set it as context menu to the listitem.
      • Right click on the listitem. This attach another popup to the page and set it as context menu to the tg button.

      Current Result

      The 2nd popup is attached as a child of the Listitem.

      Expected Result

      The 2nd popup should be attached as a child of the page

      Debug Info

      Following ZK-3606, popup.parent is changed to the anchor when a popup is opened on a widget, or with right click

      Root Cause

      https://github.com/zkoss/zk/blob/050d1b49d2dfe8e9896cc0a77de5e855e5c2e908/zul/src/archive/web/js/zul/Widget.js#L519
      https://github.com/zkoss/zk/blob/050d1b49d2dfe8e9896cc0a77de5e855e5c2e908/zul/src/archive/web/js/zul/Widget.js#L545
      https://github.com/zkoss/zk/blob/050d1b49d2dfe8e9896cc0a77de5e855e5c2e908/zul/src/archive/web/js/zul/Widget.js#L570

      Workaround

      <script><![CDATA[ 
      zk.afterLoad('zul', function() {
      	var xWidget = {};
      	zk.override(zul.Widget.prototype, xWidget ,{
      		doClick_: function (evt, popupOnly) {
      		if (!this.shallIgnoreClick_(evt) && !evt.contextSelected) {
      			var params = this._popup ? this._parsePopParams(this._popup, evt) : {},
      				popup = this._smartFellow(params.id);
      			if (popup) {
      				//popup.parent = this; // B85-ZK-3606: fake parent
      				evt.contextSelected = true;
      
      				// to avoid a focus in IE, we have to pop up it later. for example, zksandbox/#t5
      				var self = this,
      					xy = params.x !== undefined ? [params.x, params.y]
      							: [evt.pageX, evt.pageY];
      				// F70-ZK-2007: When type=toggle, close the popup
      				if (params.type && params.type == 'toggle' && popup.isOpen()) {
      					popup.close({sendOnOpen: true});
      				} else {
      					setTimeout(function () { // F70-ZK-2007: Add the type and button number information
      						popup.open(self, xy, params.position ? params.position : null, {sendOnOpen: true, type: params.type, which: 1});
      					}, 0);
      				}
      				evt.stop({dom: true});
      			}
      		}
      		if (popupOnly !== true)
      			this.$supers('doClick_', arguments);
      	},doRightClick_: function (evt) {
      			if (!this.shallIgnoreClick_(evt) && !evt.contextSelected) {
      				var params = this._context ? this._parsePopParams(this._context, evt) : {},
      					ctx = this._smartFellow(params.id);
      				if (ctx) {
      					evt.contextSelected = true;
      	
      					// to avoid a focus in IE, we have to pop up it later. for example, zksandbox/#t5
      					var self = this,
      						xy = params.x !== undefined ? [params.x, params.y]
      								: [evt.pageX, evt.pageY];
      					// F70-ZK-2007: When type=toggle, close the popup
      					if (params.type && params.type == 'toggle' && ctx.isOpen()) {
      						ctx.close({sendOnOpen: true});
      					} else {
      						//ctx.parent = this; // B85-ZK-3606: fake parent
      						//ctx._hasFakeParent = true;
      						setTimeout(function () { // F70-ZK-2007: Add the type and button number information
      							if (self.desktop)
      								ctx.open(self, xy, params.position ? params.position : null, {sendOnOpen: true, type: params.type, which: 3}); //Bug #2870620
      						}, 0);
      					}
      					evt.stop({dom: true}); //prevent default context menu to appear
      				}
      			}
      			this.$supers('doRightClick_', arguments);
      	}
      	});//zk.override
      });//zk.afterLoad
      ]]></script>
      

            rudyhuang rudyhuang
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 5 hours Original Estimate - 5 hours
                5h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 7 hours
                7h