Giter VIP home page Giter VIP logo

Comments (2)

rodneyrehm avatar rodneyrehm commented on May 31, 2024

To solve this issue the script must be able to run before DOMContentLoaded - that is something we cannot guarantee as of now, thus leaving this issue open.

Here's the thing that might've worked, could it run synchronously:

define(function defineFixBrowserAutofocusTarget(require) {
  'use strict';

  /*
      Working around an issue at page-load when the URI-fragment should make the document
      scroll to an element, but another element with [autofocus] interferes.

      https://code.google.com/p/chromium/issues/detail?id=382901
      https://bugzilla.mozilla.org/show_bug.cgi?id=840187
   */

  var isVisible = require('../dom/is-visible');
  var supportsCssShadow = require('../supports/css-shadow');

  if (document.readyState === 'complete') {
    window.console && window.console.warn && console.warn('fix-browser/autofocus-target needs to be executed before the DOM is ready');
    return;
  }

  function disableAutofocus() {
    var id = window.location.hash.replace(/^#/, '');
    if (!id) {
      return;
    }

    // NOTE: using the <a> element to define anchros (e.g. <a name="target-id">)
    // is obsolete since HTML5 and is thus not being supported here
    // see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-name
    var target = document.getElementById(id);
    // target must exist and must be painted
    if (!target || !isVisible(target)) {
      return;
    }

    // [autofocus] in ShadowDOM will acquire focus like it were in the document itself
    var selector = supportsCssShadow ? '[autofocus], ::shadow [autofocus]' : '[autofocus]';
    var autofocusElements = document.querySelectorAll(selector);
    // remove all [autofocus] from the document will prevent scrollElementIntoView() from happening
    var disabledAutofocusElements = [].map.call(autofocusElements, function(element) {
      element.removeAttribute('autofocus');
      return element;
    });

    // restore [autofocus] elements after initial focus/positioning is done
    (window.setImmediate || window.setTimeout)(function() {
      disabledAutofocusElements.forEach(function(element) {
        element.setAttribute('autofocus', '');
      });
    });
  }

  window.addEventListener('DOMContentLoaded', disableAutofocus, true);

});

from ally.js.

rodneyrehm avatar rodneyrehm commented on May 31, 2024

not providing this fix for now

from ally.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.