Skip to content

Commit

Permalink
Add events to Canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbok committed May 1, 2016
1 parent 9fabdcd commit 9091c1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions framer/Canvas.coffee
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
{BaseClass} = require "./BaseClass" {BaseClass} = require "./BaseClass"
{Events} = require "./Events" {Events} = require "./Events"


class CanvasClass extends BaseClass class Canvas extends BaseClass


@define "width", get: -> window.innerWidth @define "width", get: -> window.innerWidth
@define "height", get: -> window.innerHeight @define "height", get: -> window.innerHeight
Expand All @@ -20,16 +20,20 @@ class CanvasClass extends BaseClass
get: -> Framer.Device.background.image get: -> Framer.Device.background.image
set: (value) -> Framer.Device.background.image = value set: (value) -> Framer.Device.background.image = value


addListener: (eventName, listener) => constructor: (options={})->
if eventName is "resize" super options
Events.wrap(window).addEventListener "resize", => Events.wrap(window).addEventListener("resize", @_handleResize)
@emit("resize")


super(eventName, listener) onResize: (cb) -> @on("resize", cb)


on: @::addListener toInspect: ->
return "<#{@constructor.name} #{@width}x#{@height}>"


onResize: (cb) -> @on("resize", cb) _handleResize: (event) =>
@emit("resize")
@emit("change:width")
@emit("change:height")
@emit("change:size")
@emit("change:frame")


# We use this as a singleton exports.Canvas = Canvas
exports.Canvas = new CanvasClass
2 changes: 1 addition & 1 deletion framer/Framer.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Framer.Gestures = (require "./Gestures").Gestures
Framer.Animation = (require "./Animation").Animation Framer.Animation = (require "./Animation").Animation
Framer.AnimationGroup = (require "./AnimationGroup").AnimationGroup Framer.AnimationGroup = (require "./AnimationGroup").AnimationGroup
Framer.Screen = (require "./Screen").Screen Framer.Screen = (require "./Screen").Screen
Framer.Canvas = (require "./Canvas").Canvas
Framer.Align = (require "./Align").Align Framer.Align = (require "./Align").Align
Framer.print = (require "./Print").print Framer.print = (require "./Print").print


Expand Down Expand Up @@ -60,5 +59,6 @@ Framer.DefaultContext = new Framer.Context(name:"Default")
Framer.DefaultContext.backgroundColor = "white" Framer.DefaultContext.backgroundColor = "white"
Framer.CurrentContext = Framer.DefaultContext Framer.CurrentContext = Framer.DefaultContext


window.Canvas = new (require "./Canvas").Canvas
Framer.Extras.MobileScrollFix.enable() if Utils.isMobile() Framer.Extras.MobileScrollFix.enable() if Utils.isMobile()
Framer.Extras.TouchEmulator.enable() if not Utils.isTouch() Framer.Extras.TouchEmulator.enable() if not Utils.isTouch()

0 comments on commit 9091c1a

Please sign in to comment.