Skip to content
Snippets Groups Projects
Verified Commit 89582dc5 authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3500564 by tom konda, catch: Remove the test-only jQuery key event polyfill

parent 91faaba1
No related branches found
No related tags found
1 merge request!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes
Pipeline #450091 passed with warnings
Pipeline: drupal

#450102

    name: 'jQuery key event polyfill test'
    type: module
    description: 'Polyfills the event.which property, needed for tests'
    package: Testing
    version: VERSION
    jquery.key_event.polyfill:
    version: VERSION
    js:
    js/jquery.key_event.polyfill.js: { }
    /**
    * @file
    * Adds a jQuery polyfill for event.which.
    *
    * In jQuery 3.6, the event.which polyfill was removed, which is not needed for
    * any supported browsers, but is still necessary to trigger keyboard events in
    * FunctionalJavaScript tests.
    *
    * @todo: This polyfill may be removed if MinkSelenium2Driver updates its use of
    * syn.js, https://github.com/minkphp/MinkSelenium2Driver/pull/333
    *
    * @see https://github.com/jquery/jquery/issues/4755
    * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/which
    */
    (($) => {
    // This is the polyfill implementation from jQuery 3.5.1, modified only to
    // meet Drupal coding standards.
    jQuery.event.addProp('which', function (event) {
    const keyEventRegex = /^key/;
    const mouseEventRegex = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
    const button = event.button;
    // Add which for key events
    if (event.which == null && keyEventRegex.test(event.type)) {
    return event.charCode != null ? event.charCode : event.keyCode;
    }
    // Add which for click: 1 === left; 2 === middle; 3 === right
    if (
    !event.which &&
    button !== undefined &&
    mouseEventRegex.test(event.type)
    ) {
    if (button && 1) {
    return 1;
    }
    if (button && 2) {
    return 3;
    }
    if (button && 4) {
    return 2;
    }
    return 0;
    }
    return event.which;
    });
    })(jQuery);
    <?php
    declare(strict_types=1);
    namespace Drupal\jquery_keyevent_polyfill_test\Hook;
    use Drupal\Core\Hook\Attribute\Hook;
    /**
    * Hook implementations for jquery_keyevent_polyfill_test.
    */
    class JqueryKeyeventPolyfillTestHooks {
    /**
    * Implements hook_library_info_alter().
    */
    #[Hook('library_info_alter')]
    public function libraryInfoAlter(&$libraries, $module): void {
    if ($module == 'core' && isset($libraries['jquery'])) {
    $libraries['jquery']['dependencies'][] = 'jquery_keyevent_polyfill_test/jquery.keyevent.polyfill';
    }
    }
    }
    ......@@ -75,7 +75,6 @@ protected function installModulesFromClassProperty(ContainerInterface $container
    self::$modules = [
    'js_testing_ajax_request_test',
    'js_testing_log_test',
    'jquery_key_event_polyfill_test',
    ];
    if ($this->disableCssAnimations) {
    self::$modules[] = 'css_disable_transitions_test';
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment