aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2020-07-23 15:54:16 +0200
committerGitHub <noreply@github.com>2020-07-23 15:54:16 +0200
commit5e2fc44c0cf50e9bcb4f11a23ea5782653ab7eba (patch)
treefaef7b49bd2ccad7a127a7ea0ba9d2cc074a060d
parent91037d66b0ea8dd7db0b6083721d0d1b2106cd16 (diff)
downloadjquery-ui-5e2fc44c0cf50e9bcb4f11a23ea5782653ab7eba.tar.gz
jquery-ui-5e2fc44c0cf50e9bcb4f11a23ea5782653ab7eba.zip
Tests: Account for extra focus/blur listeners in jQuery >=3.4
jQuery >=3.4.0 uses a special focus/blur handler pair needed to fix various issues with checkboxes/radio buttons as well as being able to pass data in focus triggers. However, this leaves dummy focus & blur events if any of these events were ever listened to at a particular element. There's not a lot UI can do to fix this so we now just skip these handlers for data comparisons in tests. Ref jquery/jquery#4496 Closes gh-1930 Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
-rw-r--r--tests/lib/qunit-assert-domequal.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/lib/qunit-assert-domequal.js b/tests/lib/qunit-assert-domequal.js
index 35695c4f1..83ac60b97 100644
--- a/tests/lib/qunit-assert-domequal.js
+++ b/tests/lib/qunit-assert-domequal.js
@@ -93,6 +93,28 @@ function getElementStyles( elem ) {
return styles;
}
+// Returns 0 if v1 == v2, -1 if v1 < v2, 1 if v1 > v2
+function compareVersions( v1, v2 ) {
+ var i,
+ rVersionParts = /^(\d+)\.(\d+)\.(\d+)/,
+ v1p = rVersionParts.exec( v1 ) || [ ],
+ v2p = rVersionParts.exec( v2 ) || [ ];
+
+ for ( i = 1; i <= 3; i++ ) {
+ if ( +v1p[ i ] > +v2p[ i ] ) {
+ return 1;
+ }
+ if ( +v1p[ i ] < +v2p[ i ] ) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+function jQueryVersionSince( version ) {
+ return compareVersions( $.fn.jquery, version ) >= 0;
+}
+
function extract( selector, message ) {
var elem = $( selector );
if ( !elem.length ) {
@@ -113,6 +135,54 @@ function extract( selector, message ) {
} );
result.style = getElementStyles( elem[ 0 ] );
result.events = $._data( elem[ 0 ], "events" );
+
+ // jQuery >=3.4.0 uses a special focus/blur handler pair
+ // needed to fix various issues with checkboxes/radio buttons
+ // as well as being able to pass data in focus triggers.
+ // However, this leaves dummy focus & blur events if any of these
+ // events were ever listened to at a particular element. There's not
+ // a lot UI can do to fix this so just skip these handlers for
+ // data comparisons in tests.
+ // See https://github.com/jquery/jquery/issues/4496
+ if ( result.events && jQueryVersionSince( "3.4.0" ) ) {
+ var i, eventDataList, eventData;
+ $.each( [ "focus", "blur" ], function( index, eventType ) {
+ if ( !result.events[ eventType ] ) {
+ return;
+ }
+
+ // Only the special internal handlers
+ // have the namespace field set to boolean `false`;
+ // filter them out.
+ result.events[ eventType ] = result.events[ eventType ].filter( function( eventData ) {
+ return eventData.namespace !== false;
+ } );
+
+ eventDataList = result.events[ eventType ];
+ for ( i = eventDataList.length - 1; i > -1; i-- ) {
+ eventData = eventDataList[ i ];
+
+ // Only these special jQuery internal handlers
+ // have the `namespace` field set to `false`;
+ // all other events use a string value, possibly
+ // an empty string if no namespace was set.
+ if ( eventData.namespace === false ) {
+ eventDataList.splice( i, 1 );
+ }
+ }
+
+ // Remove empty eventData collections to follow jQuery behavior.
+ if ( !eventDataList.length ) {
+ delete result.events[ eventType ];
+ }
+ } );
+
+ // Simulate empty events collections removal to follow jQuery behavior.
+ if ( !Object.keys( result.events ).length ) {
+ result.events = undefined;
+ }
+ }
+
result.data = $.extend( {}, elem.data() );
delete result.data[ $.expando ];
children = elem.children();
color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * Copyright 2000-2021 Vaadin Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.vaadin.ui;

/**
 * Interface implemented by {@link HasComponents} implementors that wish to
 * dynamically be able to prevent given child components from reaching the
 * client side.
 *
 * @author Vaadin Ltd
 * @since 7.0
 *
 */
public interface SelectiveRenderer extends HasComponents {
    /**
     * Checks if the child component should be rendered (sent to the client
     * side). This method allows hiding a child component from updates and
     * communication to and from the client. It is mostly useful for parents
     * which show only a limited number of their children at any given time and
     * want to allow updates only for the visible children (e.g. TabSheet has
     * one tab open at a time).
     * <p>
     * This method can only prevent updates from reaching the client, not force
     * child components to reach the client. If the child is set to visible,
     * returning false will prevent the child from being sent to the client. If
     * a child is set to invisible, this method has no effect.
     * </p>
     *
     * @param childComponent
     *            The child component to check
     * @return true if the child component may be sent to the client, false
     *         otherwise
     */
    public boolean isRendered(Component childComponent);

}