dom.helper.js 638 B

1234567891011121314151617181920
  1. var path = require("path");
  2. var jsdom = require("jsdom");
  3. var afPath = path.join(__dirname, "../appframework.js");
  4. // html: html to load into the window
  5. // jsFiles: array of paths to js files to load into the window;
  6. // loads af core by default
  7. module.exports = function (html) {
  8. if (!("window" in global)) {
  9. global.document = jsdom.jsdom("<html><head></head><body></body></html>");
  10. global.window = document.parentWindow;
  11. global.navigator = window.navigator;
  12. require(afPath);
  13. global.$ = window.$;
  14. }
  15. if (html) {
  16. window.document.querySelector("body").innerHTML = html;
  17. }
  18. };