Skip to content

Commit

Permalink
Added more CoffeeScript sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonidas-from-XIV committed Sep 14, 2011
1 parent 9d479f1 commit e10a868
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions src/jquery.floatinghands.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
onUpdate = (bitmap) -> ->
# calculate the degree by passing the function to the degree calculator
# function and set this degree
bitmap.rotation = bitmap.updateFn(bitmap.timeFn)
bitmap.rotation = bitmap.updateFn bitmap.timeFn
# return `true` so it will be called again
true

Expand All @@ -24,7 +24,7 @@

layerLoaded = (stage, layer) -> (event) ->
image = event.target
bitmap = new Bitmap(image)
bitmap = new Bitmap image
delete layer.image

if !layer.z?
Expand All @@ -39,13 +39,11 @@
if !bitmap.timeFn?
bitmap.timeFn = now
# get the specialized updater function
updaterFn = onUpdate(bitmap)
updaterFn = onUpdate bitmap
# call it once, so we start with the newest coordinates
updaterFn()
# add the bitmap to the Ticker so it recalculates every tick
recalculateRotation =
tick: updaterFn
Ticker.addListener recalculateRotation
Ticker.addListener tick: updaterFn

# deactivate mouse events on layers, because they are not clickable
bitmap.mouseEnabled = false
Expand Down Expand Up @@ -88,7 +86,6 @@
button.click callback
$(stage.canvas).before button


objectOnPoint = (hotspots, x, y) ->
for key, obj of hotspots
# need to convert these out of a string, because JS dictionaries are a joke
Expand Down Expand Up @@ -155,7 +152,7 @@

# define the plugin callback for jQuery
jQuery.fn.floatinghands = ->
attach: => attach.apply(this, arguments)
attach: => attach.apply this, arguments
Stopwatch: Stopwatch

attach = (layers, pusher) ->
Expand All @@ -164,7 +161,7 @@
return this

# get the <img> and harvest it for width and height and replace by canvas
candidate = $(this[0])
candidate = $ this[0]
width = candidate.width()
height = candidate.height()
# we set the attribute on the element and not using jquery, because
Expand All @@ -178,7 +175,7 @@
G_vmlCanvasManager?.initElement widget

# we got a canvas, start initialization
stage = new Stage(widget)
stage = new Stage widget
# extend the stage with helpers
stage.updateElements = updateElements

Expand All @@ -190,7 +187,7 @@
mouseX = event.pageX - $(widget).offset().left
mouseY = event.pageY - $(widget).offset().top

item = objectOnPoint(hotspots, mouseX, mouseY)
item = objectOnPoint hotspots, mouseX, mouseY
if item?
# call callback if defined
if item.pushed?
Expand All @@ -214,7 +211,7 @@
mouseX = event.pageX - $(widget).offset().left
mouseY = event.pageY - $(widget).offset().top

item = objectOnPoint(hotspots, mouseX, mouseY)
item = objectOnPoint hotspots, mouseX, mouseY
if item?
# re-display stage immediately
stage.update()
Expand All @@ -224,11 +221,8 @@
mouseY = event.pageY - $(widget).offset().top
#console.log mouseX, mouseY

item = objectOnPoint(hotspots, mouseX, mouseY)
style = 'auto'
if item?
style = 'pointer'
$(this).css('cursor', style)
item = objectOnPoint hotspots, mouseX, mouseY
$(this).css 'cursor', if item? then 'pointer' else 'auto'

# add all images to the stage
initButton(stage) element for element in pusher
Expand All @@ -237,14 +231,9 @@
initPusher = initialize stage, pusherLoaded
initPusher element for element in pusher

# create an object so addListener has something to call on.
listener =
tick: () ->
stage.update()

# adjust ticks / FPS at will
Ticker.setInterval 125
Ticker.addListener listener
Ticker.addListener tick: -> stage.update()

# return 'this' so the plugin call can be chained
this
Expand Down

0 comments on commit e10a868

Please sign in to comment.