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

Error: ReferenceError: window is not defined #2

Open
oppianmatt opened this issue Jul 31, 2015 · 1 comment
Open

Error: ReferenceError: window is not defined #2

oppianmatt opened this issue Jul 31, 2015 · 1 comment

Comments

@oppianmatt
Copy link

Tracing dependencies for: search
ReferenceError: window is not defined
In module tree:
    search
      pupriceslider

Error: ReferenceError: window is not defined
In module tree:
    search
      pupriceslider
@oppianmatt
Copy link
Author

rewrote it to this and it works:

define(function() {
  "use strict";
  if (typeof window == 'undefined')
    return { load: function(n, r, load){ load() } };
  var doc = window.document,
      docBody = doc.body,
      createLink = function (src) {
        var link = doc.createElement('link');
        link.type = 'text/css';
        link.rel = 'stylesheet';
        link.href = src;
        return link;
      },
      resolveClassName = function (moduleName) {
        var parts = moduleName.split('/');
        return parts[parts.length - 1].replace('.', '-') + '-loaded';
      };
  var cssAPI = {};
  cssAPI.load = function (name, req, load) {
    var head = doc.getElementsByTagName('head')[0],
        test,
        interval,
        link;

    test = doc.createElement('div');
    test.className = resolveClassName(name);
    test.style.cssText = 'position: absolute;left:-9999px;top:-9999px;';
    docBody.appendChild(test);

    if (test.offsetHeight > 0) {
      docBody.removeChild(test);
      load();
    } else {
      link = createLink(name);
      head.appendChild(link);
      interval = window.setInterval(function () {
        if (test.offsetHeight > 0) {
          clearInterval(interval);
          docBody.removeChild(test);
          load();
        }
      }, 50);
    }
  };

  return cssAPI;
});

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

1 participant