Examples: new coffeescript versions.

1.2
rgieseke 2011-06-16 22:56:06 +02:00
parent 1c94da0daf
commit 2c8e9bd5b4
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
page = new WebPage()
page.onConsoleMessage = (msg) -> console.log msg
page.open "http://www.phantomjs.org", (status) ->
if status is "success"
page.includeJs "http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", ->
page.evaluate ->
console.log "$(\"#intro\").text() -> " + $("#intro").text()
phantom.exit()

17
examples/sleepsort.coffee Normal file
View File

@ -0,0 +1,17 @@
###
Sort integers from the command line in a very ridiculous way: leveraging timeouts :P
###
if phantom.args < 1
console.log "Usage: phantomjs sleepsort.js PUT YOUR INTEGERS HERE SEPARATED BY SPACES"
phantom.exit()
else
sortedCount = 0
for int in phantom.args
setTimeout ((j) ->
->
console.log j
++sortedCount
phantom.exit() if sortedCount is phantom.args.length)(int),
int