Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 881ae55

Browse files
author
Sean B. Palmer
committed
Add support for text/literate-coffeescript in the browser
1 parent c39723c commit 881ae55

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

lib/coffee-script/browser.js

Lines changed: 19 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/browser.coffee

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CoffeeScript.run = (code, options = {}) ->
1717
return unless window?
1818

1919
# Load a remote script from the current domain via XHR.
20-
CoffeeScript.load = (url, callback) ->
20+
CoffeeScript.load = (url, callback, options = {}) ->
2121
xhr = if window.ActiveXObject
2222
new window.ActiveXObject('Microsoft.XMLHTTP')
2323
else
@@ -27,7 +27,7 @@ CoffeeScript.load = (url, callback) ->
2727
xhr.onreadystatechange = ->
2828
if xhr.readyState is 4
2929
if xhr.status in [0, 200]
30-
CoffeeScript.run xhr.responseText
30+
CoffeeScript.run xhr.responseText, options
3131
else
3232
throw new Error "Could not load #{url}"
3333
callback() if callback
@@ -38,16 +38,19 @@ CoffeeScript.load = (url, callback) ->
3838
# This happens on page load.
3939
runScripts = ->
4040
scripts = document.getElementsByTagName 'script'
41-
coffees = (s for s in scripts when s.type is 'text/coffeescript')
41+
coffeetypes = ['text/coffeescript', 'text/literate-coffeescript']
42+
coffees = (s for s in scripts when s.type in coffeetypes)
4243
index = 0
4344
length = coffees.length
4445
do execute = ->
4546
script = coffees[index++]
46-
if script?.type is 'text/coffeescript'
47+
mediatype = script?.type
48+
if mediatype in coffeetypes
49+
options = {literate: mediatype is 'text/literate-coffeescript'}
4750
if script.src
48-
CoffeeScript.load script.src, execute
51+
CoffeeScript.load script.src, execute, options
4952
else
50-
CoffeeScript.run script.innerHTML
53+
CoffeeScript.run script.innerHTML, options
5154
execute()
5255
null
5356

0 commit comments

Comments
 (0)