Skip to content

Commit

Permalink
Merge pull request #2822 from vahonc/2765-jquery-stability-and-compat…
Browse files Browse the repository at this point in the history
…ibility-enhancement-2.10-fix

#2765 WIP: jQuery 3 stability and compatibility enhancement
  • Loading branch information
romainruaud authored Jan 24, 2023
2 parents e84719c + 057b095 commit 79aa8fd
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ $hiddenTermsData = array_slice($termsData, $maxVisibleTerms);
], function($){
$(function() {

$("#<?= $block->getJsId() ?> .action-help").click(function(event) {
$("#<?= $block->getJsId() ?> .action-help").on('click', function(event) {
event.preventDefault();
$("#<?= $block->getJsId() ?> .dashboard-item-help").slideToggle();
});

$("#<?= $block->getJsId() ?>_toggle").click(function() {
$("#<?= $block->getJsId() ?>_toggle").on('click', function() {
if ($("#<?= $block->getJsId() ?>_extra").is(":hidden")) {
$(this).text('<?= $block->escapeJs(__('Show less...')) ?>');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ $hiddenTermsData = array_slice($termsData, $maxVisibleTerms);
'jquery'
], function($){
$(function() {
$("#<?= $block->getJsId() ?> .action-help").click(function(event) {
$("#<?= $block->getJsId() ?> .action-help").on('click', function(event) {
event.preventDefault();
$("#<?= $block->getJsId() ?> .dashboard-item-help").slideToggle();
});

$("#<?= $block->getJsId() ?>_toggle").click(function() {
$("#<?= $block->getJsId() ?>_toggle").on('click', function() {
if ($("#<?= $block->getJsId() ?>_extra").is(":hidden")) {
$(this).text('<?= $block->escapeJs(__('Show less...')) ?>');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ function setRowVisibility(id, isVisible)
if (isVisible) {
tr.show();
} else {
tr.blur();
tr.trigger('blur');
tr.hide();
}
}
Expand Down
192 changes: 117 additions & 75 deletions src/module-elasticsuite-catalog/view/frontend/web/js/mouse.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* jQuery UI Mouse - v1.10.4
* jQuery UI Mouse 1.13.2
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Copyright jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
Expand All @@ -15,161 +15,203 @@ define([
], function ($, undefined) {

var mouseHandled = false;
$(document).mouseup(function () {
$( document ).on( "mouseup", function() {
mouseHandled = false;
});
} );

$.widget("ui.mouse", {
version: "1.10.4",
var widgetsMouse = $.widget( "ui.mouse", {
version: "1.13.2",
options: {
cancel: "input,textarea,button,select,option",
cancel: "input, textarea, button, select, option",
distance: 1,
delay: 0
},
_mouseInit: function () {
_mouseInit: function() {
var that = this;

this.element
.bind("mousedown." + this.widgetName, function (event) {
return that._mouseDown(event);
})
.bind("click." + this.widgetName, function (event) {
if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
$.removeData(event.target, that.widgetName + ".preventClickEvent");
.on( "mousedown." + this.widgetName, function( event ) {
return that._mouseDown( event );
} )
.on( "click." + this.widgetName, function( event ) {
if ( true === $.data( event.target, that.widgetName + ".preventClickEvent" ) ) {
$.removeData( event.target, that.widgetName + ".preventClickEvent" );
event.stopImmediatePropagation();
return false;
}
});
} );

this.started = false;
},

// TODO: make sure destroying one instance of mouse doesn't mess with
// other instances of mouse
_mouseDestroy: function () {
this.element.unbind("." + this.widgetName);
if (this._mouseMoveDelegate) {
$(document)
.unbind("mousemove." + this.widgetName, this._mouseMoveDelegate)
.unbind("mouseup." + this.widgetName, this._mouseUpDelegate);
_mouseDestroy: function() {
this.element.off( "." + this.widgetName );
if ( this._mouseMoveDelegate ) {
this.document
.off( "mousemove." + this.widgetName, this._mouseMoveDelegate )
.off( "mouseup." + this.widgetName, this._mouseUpDelegate );
}
},

_mouseDown: function (event) {
_mouseDown: function( event ) {

// don't let more than one widget handle mouseStart
if (mouseHandled) {
if ( mouseHandled ) {
return;
}

// we may have missed mouseup (out of window)
(this._mouseStarted && this._mouseUp(event));
this._mouseMoved = false;

// We may have missed mouseup (out of window)
if ( this._mouseStarted ) {
this._mouseUp( event );
}

this._mouseDownEvent = event;

var that = this,
btnIsLeft = (event.which === 1),
btnIsLeft = ( event.which === 1 ),

// event.target.nodeName works around a bug in IE 8 with
// disabled inputs (#7620)
elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
elIsCancel = ( typeof this.options.cancel === "string" && event.target.nodeName ?
$( event.target ).closest( this.options.cancel ).length : false );
if ( !btnIsLeft || elIsCancel || !this._mouseCapture( event ) ) {
return true;
}

this.mouseDelayMet = !this.options.delay;
if (!this.mouseDelayMet) {
this._mouseDelayTimer = setTimeout(function () {
if ( !this.mouseDelayMet ) {
this._mouseDelayTimer = setTimeout( function() {
that.mouseDelayMet = true;
}, this.options.delay);
}, this.options.delay );
}

if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
this._mouseStarted = (this._mouseStart(event) !== false);
if (!this._mouseStarted) {
if ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) {
this._mouseStarted = ( this._mouseStart( event ) !== false );
if ( !this._mouseStarted ) {
event.preventDefault();
return true;
}
}

// Click event may never have fired (Gecko & Opera)
if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
$.removeData(event.target, this.widgetName + ".preventClickEvent");
if ( true === $.data( event.target, this.widgetName + ".preventClickEvent" ) ) {
$.removeData( event.target, this.widgetName + ".preventClickEvent" );
}

// these delegates are required to keep context
this._mouseMoveDelegate = function (event) {
return that._mouseMove(event);
// These delegates are required to keep context
this._mouseMoveDelegate = function( event ) {
return that._mouseMove( event );
};
this._mouseUpDelegate = function (event) {
return that._mouseUp(event);
this._mouseUpDelegate = function( event ) {
return that._mouseUp( event );
};
$(document)
.bind("mousemove." + this.widgetName, this._mouseMoveDelegate)
.bind("mouseup." + this.widgetName, this._mouseUpDelegate);

this.document
.on( "mousemove." + this.widgetName, this._mouseMoveDelegate )
.on( "mouseup." + this.widgetName, this._mouseUpDelegate );

event.preventDefault();

mouseHandled = true;
return true;
},

_mouseMove: function (event) {
// IE mouseup check - mouseup happened when mouse was out of window
if ($.ui.ie && (!document.documentMode || document.documentMode < 9) && !event.button) {
return this._mouseUp(event);
_mouseMove: function( event ) {

// Only check for mouseups outside the document if you've moved inside the document
// at least once. This prevents the firing of mouseup in the case of IE<9, which will
// fire a mousemove event if content is placed under the cursor. See #7778
// Support: IE <9
if ( this._mouseMoved ) {

// IE mouseup check - mouseup happened when mouse was out of window
if ( $.ui.ie && ( !document.documentMode || document.documentMode < 9 ) &&
!event.button ) {
return this._mouseUp( event );

// Iframe mouseup check - mouseup occurred in another document
} else if ( !event.which ) {

// Support: Safari <=8 - 9
// Safari sets which to 0 if you press any of the following keys
// during a drag (#14461)
if ( event.originalEvent.altKey || event.originalEvent.ctrlKey ||
event.originalEvent.metaKey || event.originalEvent.shiftKey ) {
this.ignoreMissingWhich = true;
} else if ( !this.ignoreMissingWhich ) {
return this._mouseUp( event );
}
}
}

if (this._mouseStarted) {
this._mouseDrag(event);
if ( event.which || event.button ) {
this._mouseMoved = true;
}

if ( this._mouseStarted ) {
this._mouseDrag( event );
return event.preventDefault();
}

if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
if ( this._mouseDistanceMet( event ) && this._mouseDelayMet( event ) ) {
this._mouseStarted =
(this._mouseStart(this._mouseDownEvent, event) !== false);
(this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
( this._mouseStart( this._mouseDownEvent, event ) !== false );
if ( this._mouseStarted ) {
this._mouseDrag( event );
} else {
this._mouseUp( event );
}
}

return !this._mouseStarted;
},

_mouseUp: function (event) {
$(document)
.unbind("mousemove." + this.widgetName, this._mouseMoveDelegate)
.unbind("mouseup." + this.widgetName, this._mouseUpDelegate);
_mouseUp: function( event ) {
this.document
.off( "mousemove." + this.widgetName, this._mouseMoveDelegate )
.off( "mouseup." + this.widgetName, this._mouseUpDelegate );

if (this._mouseStarted) {
if ( this._mouseStarted ) {
this._mouseStarted = false;

if (event.target === this._mouseDownEvent.target) {
$.data(event.target, this.widgetName + ".preventClickEvent", true);
if ( event.target === this._mouseDownEvent.target ) {
$.data( event.target, this.widgetName + ".preventClickEvent", true );
}

this._mouseStop(event);
this._mouseStop( event );
}

if ( this._mouseDelayTimer ) {
clearTimeout( this._mouseDelayTimer );
delete this._mouseDelayTimer;
}

return false;
this.ignoreMissingWhich = false;
mouseHandled = false;
event.preventDefault();
},

_mouseDistanceMet: function (event) {
return (Math.max(
Math.abs(this._mouseDownEvent.pageX - event.pageX),
Math.abs(this._mouseDownEvent.pageY - event.pageY)
_mouseDistanceMet: function( event ) {
return ( Math.max(
Math.abs( this._mouseDownEvent.pageX - event.pageX ),
Math.abs( this._mouseDownEvent.pageY - event.pageY )
) >= this.options.distance
);
},

_mouseDelayMet: function (/* event */) {
_mouseDelayMet: function( /* event */ ) {
return this.mouseDelayMet;
},

// These are placeholder methods, to be overridden by extending plugin
_mouseStart: function (/* event */) {
},
_mouseDrag: function (/* event */) {
},
_mouseStop: function (/* event */) {
},
_mouseCapture: function (/* event */) {
// These are placeholder methods, to be overriden by extending plugin
_mouseStart: function( /* event */ ) {},
_mouseDrag: function( /* event */ ) {},
_mouseStop: function( /* event */ ) {},
_mouseCapture: function( /* event */ ) {
return true;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ define([
options.values = [this._valueMin(), this._valueMin()];
} else if (options.values.length && options.values.length !== 2) {
options.values = [options.values[0], options.values[0]];
} else if ($.isArray(options.values)) {
} else if (Array.isArray(options.values)) {
options.values = options.values.slice(0);
}
}
Expand Down Expand Up @@ -202,7 +202,7 @@ define([

closestHandle
.addClass("ui-state-active")
.focus();
.trigger("focus");

offset = closestHandle.offset();
mouseOverHandle = !$(event.target).parents().addBack().is(".ui-slider-handle");
Expand Down Expand Up @@ -394,7 +394,7 @@ define([
}

if (arguments.length) {
if ($.isArray(arguments[0])) {
if (Array.isArray(arguments[0])) {
vals = this.options.values;
newValues = arguments[0];
for (i = 0; i < vals.length; i += 1) {
Expand Down Expand Up @@ -428,7 +428,7 @@ define([
}
}

if ($.isArray(this.options.values)) {
if (Array.isArray(this.options.values)) {
valsLength = this.options.values.length;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</li>
</ol>

<div class="no-results-message" data-bind="if: fulltextSearch() && !hasSearchResult()" class="empty">
<div class="no-results-message empty" data-bind="if: fulltextSearch() && !hasSearchResult()">
<p data-bind="html: getSearchResultMessage()"></p>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ define([
this.element.trigger('focus');
}
this.autoComplete.hide();
$('#search').blur();
$('#search').trigger('blur');
this._updateAriaHasPopup(false);
}, this),250);
}, this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@

// Simulate click on toggle button when placeholder is clicked
$(this).on('click', 'a.json-placeholder', function() {
$(this).siblings('a.json-toggle').click();
$(this).siblings('a.json-toggle').trigger('click');
return false;
});

if (options.collapsed == true) {
// Trigger click to collapse all nodes
$(this).find('a.json-toggle').click();
$(this).find('a.json-toggle').trigger('click');
}
});
};
Expand Down
Loading

0 comments on commit 79aa8fd

Please sign in to comment.