Unverified Commit 199f2b4b authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3101922 by bnjmnm, nod_, lauriii: Find replacement for Modernizr...

Issue #3101922 by bnjmnm, nod_, lauriii: Find replacement for Modernizr touchevent test and deprecate
parent e36f0406
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -682,6 +682,7 @@ drupal.tabledrag:
    - core/drupal
    - core/drupalSettings
    - core/once
    - core/drupal.touchevents-test

drupal.tableheader:
  version: VERSION
@@ -723,6 +724,14 @@ drupal.timezone:
    - core/once
    - core/drupal

drupal.touchevents-test:
  header: true
  version: VERSION
  js:
    # Set weight to -21 so it loads alongside Modernizr, the library previously
    # responsible for this detection.
    misc/touchevents-test.js: { weight: -21 }

drupal.vertical-tabs:
  version: VERSION
  js:
@@ -990,7 +999,6 @@ modernizr:
  version: "3.11.7"
  js:
    assets/vendor/modernizr/modernizr.min.js: { preprocess: 0, weight: -21, minified: true }
    misc/modernizr-additional-tests.js: { preprocess: 0, weight: -20 }

normalize:
  remote: https://github.com/necolas/normalize.css
@@ -1116,6 +1124,7 @@ drupal.dialog.off_canvas:
    - core/drupal.announce
    - core/drupal.dialog
    - core/drupal.dialog.ajax
    - core/drupal.touchevents-test

js-cookie:
  remote: https://github.com/js-cookie/js-cookie
+0 −43
Original line number Diff line number Diff line
/**
 * @file
 * Provides additional Modernizr tests.
 */
((Modernizr) => {
  // This is a copy of Modernizr's touchevents test from version 3.3.1. Drupal
  // core has updated Modernizr to a version newer than 3.3.1, but this newer
  // version does not include the touchevents test in its build. Modernizr's
  // touchevents test is deprecated, and newer versions of this test do not work
  // properly with Drupal as it significantly changes the criteria used for
  // determining if touchevents are supported.
  // The most recent known-to-work version, 3.3.1 is provided here. The only
  // changes are refactoring the code to meet Drupal's JavaScript coding
  // standards and calling prefixes and testStyles() via the Modernizr object
  // as they are not in scope when adding a test via Modernizr.addTest();
  // @todo find alternative to Modernizr's deprecated touchevent test in
  //   http://drupal.org/node/3101922
  // @see https://github.com/Modernizr/Modernizr/blob/v3.3.1/feature-detects/touchevents.js
  Modernizr.addTest('touchevents', () => {
    let bool;

    if (
      'ontouchstart' in window ||
      (window.DocumentTouch && document instanceof window.DocumentTouch)
    ) {
      bool = true;
    } else {
      // include the 'heartz' as a way to have a non matching MQ to help
      // terminate the join https://git.io/vznFH
      const query = [
        '@media (',
        Modernizr._prefixes.join('touch-enabled),('),
        'heartz',
        ')',
        '{#modernizr{top:9px;position:absolute}}',
      ].join('');
      Modernizr.testStyles(query, (node) => {
        bool = node.offsetTop === 9;
      });
    }
    return bool;
  });
})(Modernizr);
+0 −23
Original line number Diff line number Diff line
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/

(Modernizr => {
  Modernizr.addTest('touchevents', () => {
    let bool;

    if ('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch) {
      bool = true;
    } else {
      const query = ['@media (', Modernizr._prefixes.join('touch-enabled),('), 'heartz', ')', '{#modernizr{top:9px;position:absolute}}'].join('');
      Modernizr.testStyles(query, node => {
        bool = node.offsetTop === 9;
      });
    }

    return bool;
  });
})(Modernizr);
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
/**
 * @file
 * A replacement for Modernizr touch events detection.
 */

document.documentElement.classList.add(
  'ontouchstart' in window ||
    (window.DocumentTouch && document instanceof window.DocumentTouch)
    ? 'touchevents'
    : 'no-touchevents',
);
+8 −0
Original line number Diff line number Diff line
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/

document.documentElement.classList.add('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch ? 'touchevents' : 'no-touchevents');
 No newline at end of file
Loading