2014-08-06 05:05:31 +08:00
|
|
|
Template.slide.rendered = ->
|
2014-09-16 00:46:02 +08:00
|
|
|
currentSlide = getCurrentSlideDoc()
|
2014-10-15 09:36:30 +08:00
|
|
|
if currentSlide?.slide?.png_uri?
|
2014-10-16 06:26:27 +08:00
|
|
|
createWhiteboardPaper (wpm) ->
|
|
|
|
displaySlide wpm
|
2014-08-06 05:05:31 +08:00
|
|
|
|
2014-10-16 21:24:31 +08:00
|
|
|
@createWhiteboardPaper = (callback) =>
|
|
|
|
@whiteboardPaperModel = new Meteor.WhiteboardPaperModel('whiteboard-paper')
|
|
|
|
callback(@whiteboardPaperModel)
|
2014-08-06 05:05:31 +08:00
|
|
|
|
2014-10-17 04:45:42 +08:00
|
|
|
@displaySlide = (wpm) ->
|
2014-10-16 06:28:54 +08:00
|
|
|
currentSlide = getCurrentSlideDoc()
|
2014-10-17 02:18:46 +08:00
|
|
|
wpm.create()
|
2014-10-16 06:28:54 +08:00
|
|
|
pic = new Image()
|
|
|
|
pic.onload = ->
|
2014-11-01 06:27:27 +08:00
|
|
|
adjustedDimensions = scaleSlide(this.width, this.height)
|
|
|
|
wpm._displayPage(currentSlide?.slide?.png_uri, this.width, this.height)
|
2014-10-16 06:28:54 +08:00
|
|
|
manuallyDisplayShapes()
|
2014-11-01 06:27:27 +08:00
|
|
|
wpm.scale(adjustedDimensions.width, adjustedDimensions.height)
|
2014-10-17 02:18:46 +08:00
|
|
|
|
2014-10-16 06:28:54 +08:00
|
|
|
pic.src = currentSlide?.slide?.png_uri
|
2014-08-15 23:04:35 +08:00
|
|
|
|
2014-10-16 06:28:54 +08:00
|
|
|
@manuallyDisplayShapes = ->
|
|
|
|
currentSlide = getCurrentSlideDoc()
|
|
|
|
wpm = @whiteboardPaperModel
|
|
|
|
shapes = Meteor.Shapes.find({whiteboardId: currentSlide?.slide?.id}).fetch()
|
|
|
|
for s in shapes
|
|
|
|
shapeInfo = s.shape?.shape or s?.shape
|
|
|
|
shapeType = shapeInfo?.type
|
2014-10-16 06:26:27 +08:00
|
|
|
|
2014-10-16 06:28:54 +08:00
|
|
|
if shapeType isnt "text"
|
|
|
|
len = shapeInfo.points.length
|
|
|
|
for num in [0..len] # the coordinates must be in the range 0 to 1
|
|
|
|
shapeInfo?.points[num] = shapeInfo?.points[num] / 100
|
|
|
|
wpm?.makeShape(shapeType, shapeInfo)
|
|
|
|
wpm?.updateShape(shapeType, shapeInfo)
|
2014-08-15 23:04:35 +08:00
|
|
|
|
2014-11-01 06:27:27 +08:00
|
|
|
@scaleSlide = (originalWidth, originalHeight) ->
|
|
|
|
boardWidth = $("#whiteboard").width()
|
|
|
|
|
|
|
|
whiteboardBottom = $("#whiteboard").offset().top + $("#whiteboard").height()
|
|
|
|
footerTop = $(".myFooter").offset().top
|
|
|
|
if footerTop < whiteboardBottom
|
|
|
|
boardHeight = footerTop - $("#whiteboard").offset().top - $("#whiteboard-navbar").height() - 10
|
|
|
|
else
|
|
|
|
boardHeight = $("#whiteboard").height() - $("#whiteboard-navbar").height() - 10
|
|
|
|
|
|
|
|
if originalWidth <= originalHeight
|
|
|
|
adjustedWidth = boardHeight * originalWidth / originalHeight
|
|
|
|
$('#whiteboard-paper').width(adjustedWidth)
|
|
|
|
if boardWidth < adjustedWidth
|
|
|
|
adjustedHeight = boardHeight * boardWidth / adjustedWidth
|
|
|
|
adjustedWidth = boardWidth
|
|
|
|
else
|
|
|
|
adjustedHeight = boardHeight
|
|
|
|
$("#whiteboard-paper").height(adjustedHeight)
|
|
|
|
else
|
|
|
|
adjustedHeight = boardWidth * originalHeight / originalWidth
|
|
|
|
$('#whiteboard-paper').height(adjustedHeight)
|
|
|
|
if boardHeight < adjustedHeight
|
|
|
|
adjustedWidth = boardWidth * boardHeight / adjustedHeight
|
|
|
|
adjustedHeight = boardHeight
|
|
|
|
else
|
|
|
|
adjustedWidth = boardWidth
|
|
|
|
$("#whiteboard-paper").width(adjustedWidth)
|
|
|
|
|
|
|
|
{ width: adjustedWidth, height: adjustedHeight }
|
|
|
|
|
2014-10-16 06:26:27 +08:00
|
|
|
Template.slide.helpers
|
|
|
|
updatePointerLocation: (pointer) ->
|
2014-10-21 23:36:53 +08:00
|
|
|
if whiteboardPaperModel?
|
|
|
|
wpm = whiteboardPaperModel
|
|
|
|
wpm?.moveCursor(pointer.x, pointer.y)
|
2014-08-15 23:04:35 +08:00
|
|
|
|
2014-08-11 23:56:46 +08:00
|
|
|
#### SHAPE ####
|
2014-08-12 02:41:03 +08:00
|
|
|
Template.shape.rendered = ->
|
2014-08-12 02:46:10 +08:00
|
|
|
# @data is the shape object coming from the {{#each}} in the html file
|
2014-08-20 00:54:01 +08:00
|
|
|
shapeInfo = @data.shape?.shape or @data.shape
|
2014-08-12 02:46:10 +08:00
|
|
|
shapeType = shapeInfo?.type
|
2014-08-12 02:41:03 +08:00
|
|
|
|
2014-08-20 00:54:01 +08:00
|
|
|
if shapeType isnt "text"
|
2014-09-18 04:04:30 +08:00
|
|
|
len = shapeInfo.points.length
|
|
|
|
for num in [0..len] # the coordinates must be in the range 0 to 1
|
2014-08-20 00:54:01 +08:00
|
|
|
shapeInfo.points[num] = shapeInfo.points[num] / 100
|
2014-08-12 02:41:03 +08:00
|
|
|
|
2014-10-21 23:36:53 +08:00
|
|
|
if whiteboardPaperModel?
|
|
|
|
wpm = whiteboardPaperModel
|
|
|
|
wpm?.makeShape(shapeType, shapeInfo)
|
|
|
|
wpm?.updateShape(shapeType, shapeInfo)
|
2014-08-12 04:54:16 +08:00
|
|
|
|
2014-08-15 23:04:35 +08:00
|
|
|
Template.shape.destroyed = ->
|
2014-10-21 23:36:53 +08:00
|
|
|
if whiteboardPaperModel?
|
|
|
|
wpm = whiteboardPaperModel
|
|
|
|
wpm.clearShapes()
|
|
|
|
manuallyDisplayShapes()
|