Sha256: 04605757ea8f338372df2daa39e8a6a214b53046767ea397baa6a2e482956b21

Contents?: true

Size: 1.44 KB

Versions: 10

Compression:

Stored size: 1.44 KB

Contents

# Override exported methods for non-Node.js engines.

CoffeeScript = require './coffee-script'
CoffeeScript.require = require

# Use standard JavaScript `eval` to eval code.
CoffeeScript.eval = (code, options) ->
  eval CoffeeScript.compile code, options

# Running code does not provide access to this scope.
CoffeeScript.run = (code, options = {}) ->
  options.bare = on
  Function(CoffeeScript.compile code, options)()

# If we're not in a browser environment, we're finished with the public API.
return unless window?

# Load a remote script from the current domain via XHR.
CoffeeScript.load = (url, options) ->
  xhr = new (window.ActiveXObject or XMLHttpRequest)('Microsoft.XMLHTTP')
  xhr.open 'GET', url, true
  xhr.overrideMimeType 'text/plain' if 'overrideMimeType' of xhr
  xhr.onreadystatechange = ->
    CoffeeScript.run xhr.responseText, options if xhr.readyState is 4
  xhr.send null

# Activate CoffeeScript in the browser by having it compile and evaluate
# all script tags with a content-type of `text/coffeescript`.
# This happens on page load.
runScripts = ->
  for script in document.getElementsByTagName 'script'
    if script.type is 'text/coffeescript'
      if script.src
        CoffeeScript.load script.src
      else
        CoffeeScript.run script.innerHTML
  null

# Listen for window load, both in browsers and in IE.
if window.addEventListener
  addEventListener 'DOMContentLoaded', runScripts, no
else
  attachEvent 'onload', runScripts

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
spade-packager-0.1.0.1 packages/coffee-script/src/browser.coffee
spade-packager-0.1.0 packages/coffee-script/src/browser.coffee
spade-0.0.8.1 packages/coffee-script/src/browser.coffee
spade-0.0.7 packages/coffee-script/src/browser.coffee
spade-0.0.6 packages/coffee-script/src/browser.coffee
spade-0.0.5 packages/coffee-script/src/browser.coffee
spade-0.0.4 packages/coffee-script/src/browser.coffee
spade-0.0.3 packages/coffee-script/src/browser.coffee
spade-0.0.2 packages/coffee-script/src/browser.coffee
spade-0.0.1 packages/coffee-script/src/browser.coffee