Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'split' of undefined #5

Closed
imdpk opened this issue Sep 5, 2015 · 2 comments
Closed

Uncaught TypeError: Cannot read property 'split' of undefined #5

imdpk opened this issue Sep 5, 2015 · 2 comments

Comments

@imdpk
Copy link

imdpk commented Sep 5, 2015

I am receiving the following error in my console.

1.3.0 was working fine.

Here seems to be a issue:

  /**
   * Get index of the current view size
   *
   * @return {integer} zero-based index of sizes array
   */
  var getSizeIndex = function() {
    return sizes.indexOf(view.split(' ')[0]);
  };
@imdpk
Copy link
Author

imdpk commented Sep 5, 2015

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;
  }

@tschuems
Copy link
Contributor

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

tschuems added a commit that referenced this issue Jan 27, 2016
Anzeixer 2.0.1 release, merged pull request for issue #5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants