Skip to content

Commit 20e97f3

Browse files
AC-1975: PB Stage: Unable to locate element: {"method":"xpath","selector":"(//div[contains(@Class, "pagebuilder-content-type") and contains(@Class, "pagebuilder-dynamic-block")])[1]"}
1 parent 1024921 commit 20e97f3

File tree

3 files changed

+304
-0
lines changed

3 files changed

+304
-0
lines changed

app/code/Magento/Theme/view/adminhtml/requirejs-config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ var config = {
8888
'mage/backend/bootstrap',
8989
'mage/adminhtml/globals'
9090
],
91+
config: {
92+
mixins: {
93+
'jquery/jquery-ui': {
94+
'jquery/patches/jquery-ui-sortable': true
95+
}
96+
}
97+
},
9198
'paths': {
9299
'jquery/ui': 'jquery/jquery-ui'
93100
}

app/code/Magento/Theme/view/frontend/requirejs-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ var config = {
4040
mixins: {
4141
'Magento_Theme/js/view/breadcrumbs': {
4242
'Magento_Theme/js/view/add-home-breadcrumb': true
43+
},
44+
'jquery/ui-modules/widgets/sortable': {
45+
'jquery/patches/jquery-ui-sortable': true
4346
}
4447
}
4548
}
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery'
8+
], function ($) {
9+
'use strict';
10+
11+
/**
12+
* Patch for sortable widget.
13+
* Can safely remove only when jQuery UI is upgraded to >= 1.13.1.
14+
* Fixes:
15+
* https://github.com/jquery/jquery-ui/pull/2008
16+
* https://github.com/jquery/jquery-ui/pull/2009
17+
*/
18+
var sortablePatch = {
19+
/** @inheritdoc */
20+
_mouseDrag: function (event) {
21+
var i, item, itemElement, intersection,
22+
o = this.options;
23+
24+
//Compute the helpers position
25+
this.position = this._generatePosition(event);
26+
this.positionAbs = this._convertPositionTo("absolute");
27+
28+
//Set the helper position
29+
if (!this.options.axis || this.options.axis !== "y") {
30+
this.helper[0].style.left = this.position.left + "px";
31+
}
32+
if (!this.options.axis || this.options.axis !== "x") {
33+
this.helper[0].style.top = this.position.top + "px";
34+
}
35+
36+
//Do scrolling
37+
if (o.scroll) {
38+
if (this._scroll(event) !== false) {
39+
40+
//Update item positions used in position checks
41+
this._refreshItemPositions(true);
42+
43+
if ($.ui.ddmanager && !o.dropBehaviour) {
44+
$.ui.ddmanager.prepareOffsets(this, event);
45+
}
46+
}
47+
}
48+
49+
this.dragDirection = {
50+
vertical: this._getDragVerticalDirection(),
51+
horizontal: this._getDragHorizontalDirection()
52+
};
53+
54+
//Rearrange
55+
for (i = this.items.length - 1; i >= 0; i--) {
56+
57+
//Cache variables and intersection, continue if no intersection
58+
item = this.items[i];
59+
itemElement = item.item[0];
60+
intersection = this._intersectsWithPointer(item);
61+
if (!intersection) {
62+
continue;
63+
}
64+
65+
// Only put the placeholder inside the current Container, skip all
66+
// items from other containers. This works because when moving
67+
// an item from one container to another the
68+
// currentContainer is switched before the placeholder is moved.
69+
//
70+
// Without this, moving items in "sub-sortables" can cause
71+
// the placeholder to jitter between the outer and inner container.
72+
if (item.instance !== this.currentContainer) {
73+
continue;
74+
}
75+
76+
// Cannot intersect with itself
77+
// no useless actions that have been done before
78+
// no action if the item moved is the parent of the item checked
79+
if (itemElement !== this.currentItem[0] &&
80+
this.placeholder[intersection === 1 ?
81+
"next" : "prev"]()[0] !== itemElement &&
82+
!$.contains(this.placeholder[0], itemElement) &&
83+
(this.options.type === "semi-dynamic" ?
84+
!$.contains(this.element[0], itemElement) :
85+
true
86+
)
87+
) {
88+
89+
this.direction = intersection === 1 ? "down" : "up";
90+
91+
if (this.options.tolerance === "pointer" ||
92+
this._intersectsWithSides(item)) {
93+
this._rearrange(event, item);
94+
} else {
95+
break;
96+
}
97+
98+
this._trigger("change", event, this._uiHash());
99+
break;
100+
}
101+
}
102+
103+
//Post events to containers
104+
this._contactContainers(event);
105+
106+
//Interconnect with droppables
107+
if ($.ui.ddmanager) {
108+
$.ui.ddmanager.drag(this, event);
109+
}
110+
111+
//Call callbacks
112+
this._trigger("sort", event, this._uiHash());
113+
114+
this.lastPositionAbs = this.positionAbs;
115+
return false;
116+
117+
},
118+
119+
/** @inheritdoc */
120+
refreshPositions: function (fast) {
121+
122+
// Determine whether items are being displayed horizontally
123+
this.floating = this.items.length ?
124+
this.options.axis === "x" || this._isFloating(this.items[0].item) :
125+
false;
126+
127+
// This has to be redone because due to the item being moved out/into the offsetParent,
128+
// the offsetParent's position will change
129+
if (this.offsetParent && this.helper) {
130+
this.offset.parent = this._getParentOffset();
131+
}
132+
133+
this._refreshItemPositions(fast);
134+
135+
var i, p;
136+
137+
if (this.options.custom && this.options.custom.refreshContainers) {
138+
this.options.custom.refreshContainers.call(this);
139+
} else {
140+
for (i = this.containers.length - 1; i >= 0; i--) {
141+
p = this.containers[i].element.offset();
142+
this.containers[i].containerCache.left = p.left;
143+
this.containers[i].containerCache.top = p.top;
144+
this.containers[i].containerCache.width =
145+
this.containers[i].element.outerWidth();
146+
this.containers[i].containerCache.height =
147+
this.containers[i].element.outerHeight();
148+
}
149+
}
150+
151+
return this;
152+
},
153+
154+
/** @inheritdoc */
155+
_contactContainers: function (event) {
156+
var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, cur, nearBottom,
157+
floating, axis,
158+
innermostContainer = null,
159+
innermostIndex = null;
160+
161+
// Get innermost container that intersects with item
162+
for (i = this.containers.length - 1; i >= 0; i--) {
163+
164+
// Never consider a container that's located within the item itself
165+
if ($.contains(this.currentItem[0], this.containers[i].element[0])) {
166+
continue;
167+
}
168+
169+
if (this._intersectsWith(this.containers[i].containerCache)) {
170+
171+
// If we've already found a container and it's more "inner" than this, then continue
172+
if (innermostContainer &&
173+
$.contains(
174+
this.containers[i].element[0],
175+
innermostContainer.element[0])) {
176+
continue;
177+
}
178+
179+
innermostContainer = this.containers[i];
180+
innermostIndex = i;
181+
182+
} else {
183+
184+
// container doesn't intersect. trigger "out" event if necessary
185+
if (this.containers[i].containerCache.over) {
186+
this.containers[i]._trigger("out", event, this._uiHash(this));
187+
this.containers[i].containerCache.over = 0;
188+
}
189+
}
190+
191+
}
192+
193+
// If no intersecting containers found, return
194+
if (!innermostContainer) {
195+
return;
196+
}
197+
198+
// Move the item into the container if it's not there already
199+
if (this.containers.length === 1) {
200+
if (!this.containers[innermostIndex].containerCache.over) {
201+
this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
202+
this.containers[innermostIndex].containerCache.over = 1;
203+
}
204+
} else {
205+
206+
// When entering a new container, we will find the item with the least distance and
207+
// append our item near it
208+
dist = 10000;
209+
itemWithLeastDistance = null;
210+
floating = innermostContainer.floating || this._isFloating(this.currentItem);
211+
posProperty = floating ? "left" : "top";
212+
sizeProperty = floating ? "width" : "height";
213+
axis = floating ? "pageX" : "pageY";
214+
215+
for (j = this.items.length - 1; j >= 0; j--) {
216+
if (!$.contains(
217+
this.containers[innermostIndex].element[0], this.items[j].item[0])
218+
) {
219+
continue;
220+
}
221+
if (this.items[j].item[0] === this.currentItem[0]) {
222+
continue;
223+
}
224+
225+
cur = this.items[j].item.offset()[posProperty];
226+
nearBottom = false;
227+
if (event[axis] - cur > this.items[j][sizeProperty] / 2) {
228+
nearBottom = true;
229+
}
230+
231+
if (Math.abs(event[axis] - cur) < dist) {
232+
dist = Math.abs(event[axis] - cur);
233+
itemWithLeastDistance = this.items[j];
234+
this.direction = nearBottom ? "up" : "down";
235+
}
236+
}
237+
238+
//Check if dropOnEmpty is enabled
239+
if (!itemWithLeastDistance && !this.options.dropOnEmpty) {
240+
return;
241+
}
242+
243+
if (this.currentContainer === this.containers[innermostIndex]) {
244+
if (!this.currentContainer.containerCache.over) {
245+
this.containers[innermostIndex]._trigger("over", event, this._uiHash());
246+
this.currentContainer.containerCache.over = 1;
247+
}
248+
return;
249+
}
250+
251+
if (itemWithLeastDistance) {
252+
this._rearrange(event, itemWithLeastDistance, null, true);
253+
} else {
254+
this._rearrange(event, null, this.containers[innermostIndex].element, true);
255+
}
256+
this._trigger("change", event, this._uiHash());
257+
this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
258+
this.currentContainer = this.containers[innermostIndex];
259+
260+
//Update the placeholder
261+
this.options.placeholder.update(this.currentContainer, this.placeholder);
262+
263+
//Update scrollParent
264+
this.scrollParent = this.placeholder.scrollParent();
265+
266+
//Update overflowOffset
267+
if (this.scrollParent[0] !== this.document[0] &&
268+
this.scrollParent[0].tagName !== "HTML") {
269+
this.overflowOffset = this.scrollParent.offset();
270+
}
271+
272+
this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
273+
this.containers[innermostIndex].containerCache.over = 1;
274+
}
275+
276+
}
277+
}
278+
279+
return function () {
280+
var majorVersion = parseInt($.ui.version.split('.')[0]),
281+
minorVersion = parseInt($.ui.version.split('.')[1]),
282+
patchVersion = parseInt($.ui.version.split('.')[2])
283+
284+
if (majorVersion === 1 && minorVersion === 13 && patchVersion > 0 ||
285+
majorVersion === 1 && minorVersion >= 14 ||
286+
majorVersion >= 2
287+
) {
288+
console.warn('jQuery ui sortable patch is no longer necessary, and should be removed');
289+
}
290+
291+
$.widget('ui.sortable', $.ui.sortable, sortablePatch);
292+
};
293+
294+
});

0 commit comments

Comments
 (0)