Sha256: 36b7bd237c86488b1fe01a48dafcf19408bcf013e0373742c16df34bea931115

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

/*
 * enables jsdom globally.
 */

var KEYS = require('./keys')

var defaultHtml = '<!doctype html><html><head><meta charset="utf-8">' +
  '</head><body></body></html>'

module.exports = function globalJsdom (html, options) {
  if (html === undefined) {
    html = defaultHtml
  }

  if (options === undefined) {
    options = {}
  }

  // Idempotency
  if (global.navigator &&
    global.navigator.userAgent &&
    global.navigator.userAgent.indexOf('Node.js') > -1 &&
    global.document &&
    typeof global.document.destroy === 'function') {
    return global.document.destroy
  }

  var jsdom = require('jsdom')
  var document = jsdom.jsdom(html, options)
  var window = document.defaultView

  KEYS.forEach(function (key) {
    global[key] = window[key]
  })

  global.document = document
  global.window = window
  window.console = global.console
  document.destroy = cleanup

  function cleanup () {
    KEYS.forEach(function (key) { delete global[key] })
  }

  return cleanup
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
select_all-rails-0.3.1 node_modules/jsdom-global/index.js