GithubHelp home page GithubHelp logo

Comments (2)

imdpk avatar imdpk commented on July 27, 2024

The way I resolved this error is by setting a initial view for the global view variable. It looks like DOMContentLoaded is not updating the view variable fast enough which results is isDesktop(), isLandscape() etc... on page load acting on an undefined variable. I have added a function which just returns the logic to get the current size. I made a few more updates i can request a merge if you would like.

Here is what I have done:

  var view = currentView(),
      sizes = ['xs', 's', 'm', 'l', 'xl'];

  function currentView() {
    try {
      var currentView = window.getComputedStyle(document.querySelector('body'), ':after').getPropertyValue('content').replace(/["']/g, '');
      return currentView;
    } catch(exception) {
      console.error(exception);
      return 'l landscape'; // assume 1024px wide landscape screen if computed style query fails
    }
  }

  /**
   * Get the current view and trigger viewchange event if it changed since last query
   *
   * @return {string} string from body:after CSS content property
   */
  function getView() {
    var oldView = view;
    view = currentView();

    if (oldView !== view && window.hasCustomEvents) {
      var event = new window.CustomEvent('viewchange', {'detail': {
        'originalView': oldView,
        'currentView': view
      }});
      document.dispatchEvent(event);
    }

    return view;
  }

from anzeixer.

tschuems avatar tschuems commented on July 27, 2024

Hi @imdpk
Thank you very much for your suggestion. We merged the changes into the master branch. Sorry for the delay, we missed it 🎉

from anzeixer.

Related Issues (2)

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.