2014-08-06 05:05:31 +08:00
|
|
|
Template.slide.rendered = ->
|
2015-12-04 01:03:04 +08:00
|
|
|
reactOnSlideChange(@)
|
|
|
|
|
|
|
|
@reactOnSlideChange = =>
|
|
|
|
currentSlide = BBB.getCurrentSlide("slide.rendered")
|
2015-11-18 01:01:27 +08:00
|
|
|
|
2014-12-23 03:11:09 +08:00
|
|
|
pic = new Image()
|
|
|
|
pic.onload = ->
|
2015-12-04 01:03:04 +08:00
|
|
|
setInSession 'slideOriginalWidth', @width
|
|
|
|
setInSession 'slideOriginalHeight', @height
|
2015-01-07 01:42:37 +08:00
|
|
|
$(window).resize( ->
|
2015-02-25 05:29:32 +08:00
|
|
|
# redraw the whiteboard to adapt to the resized window
|
2015-07-20 08:34:07 +08:00
|
|
|
if !$('.panel-footer').hasClass('ui-resizable-resizing') # not in the middle of resizing the message input
|
2015-09-10 01:24:57 +08:00
|
|
|
scaleWhiteboard()
|
2015-01-07 01:42:37 +08:00
|
|
|
)
|
2015-08-18 04:55:28 +08:00
|
|
|
if currentSlide?.slide?.img_uri?
|
2014-12-23 03:11:09 +08:00
|
|
|
createWhiteboardPaper (wpm) ->
|
|
|
|
displaySlide wpm
|
2015-08-18 04:55:28 +08:00
|
|
|
pic.src = currentSlide?.slide?.img_uri
|
2015-12-04 01:03:04 +08:00
|
|
|
return ""
|
2014-08-06 05:05:31 +08:00
|
|
|
|
2014-10-16 21:24:31 +08:00
|
|
|
@createWhiteboardPaper = (callback) =>
|
2015-12-04 01:03:04 +08:00
|
|
|
# console.log "CREATING WPM"
|
2014-10-16 21:24:31 +08:00
|
|
|
@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) ->
|
2015-12-04 01:03:04 +08:00
|
|
|
currentSlide = BBB.getCurrentSlide("displaySlide")
|
2015-11-11 11:44:48 +08:00
|
|
|
|
2014-10-17 02:18:46 +08:00
|
|
|
wpm.create()
|
2015-01-07 01:42:37 +08:00
|
|
|
adjustedDimensions = scaleSlide(getInSession('slideOriginalWidth'), getInSession('slideOriginalHeight'))
|
2015-08-18 04:55:28 +08:00
|
|
|
wpm._displayPage(currentSlide?.slide?.img_uri, getInSession('slideOriginalWidth'), getInSession('slideOriginalHeight'))
|
2015-01-07 01:42:37 +08:00
|
|
|
manuallyDisplayShapes()
|
2015-02-03 00:10:40 +08:00
|
|
|
wpm.scale(adjustedDimensions.width, adjustedDimensions.height)
|
2014-08-15 23:04:35 +08:00
|
|
|
|
2014-10-16 06:28:54 +08:00
|
|
|
@manuallyDisplayShapes = ->
|
2015-03-07 03:47:07 +08:00
|
|
|
|
|
|
|
return if Meteor.WhiteboardCleanStatus.findOne({in_progress: true})?
|
|
|
|
|
2015-12-04 01:03:04 +08:00
|
|
|
currentSlide = BBB.getCurrentSlide("manuallyDisplayShapes")
|
2014-10-16 06:28:54 +08:00
|
|
|
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
|
|
|
|
2015-01-07 05:53:07 +08:00
|
|
|
|
|
|
|
# calculates and returns the best fitting {width, height} pair
|
|
|
|
# based on the image's original width and height
|
2014-11-01 06:27:27 +08:00
|
|
|
@scaleSlide = (originalWidth, originalHeight) ->
|
2015-01-07 05:53:07 +08:00
|
|
|
|
2015-02-25 05:29:32 +08:00
|
|
|
# set the size of the whiteboard space (frame) where the slide will be displayed
|
2015-02-03 00:34:37 +08:00
|
|
|
if window.matchMedia('(orientation: landscape)').matches
|
2015-02-25 05:29:32 +08:00
|
|
|
# for landscape orientation we want "fit to height" so that we can
|
|
|
|
# minimize the empty space above and below the slide (for best readability)
|
2015-05-29 01:06:57 +08:00
|
|
|
boardWidth = $("#whiteboard-container").width()
|
|
|
|
boardHeight = $("#whiteboard-container").height()
|
2015-02-25 05:29:32 +08:00
|
|
|
else
|
|
|
|
# for portrait orientation we want "fit to width" so that we can
|
|
|
|
# minimize the empty space on the sides of the slide (for best readability)
|
2015-05-29 01:06:57 +08:00
|
|
|
boardWidth = $("#whiteboard-container").width()
|
|
|
|
boardHeight = 1.4 * $("#whiteboard-container").width() # A4 paper size
|
2014-11-01 06:27:27 +08:00
|
|
|
|
2015-01-07 05:53:07 +08:00
|
|
|
# this is the best fitting pair
|
|
|
|
adjustedWidth = null
|
|
|
|
adjustedHeight = null
|
|
|
|
|
|
|
|
|
|
|
|
# the slide image is in portrait orientation
|
2014-11-01 06:27:27 +08:00
|
|
|
if originalWidth <= originalHeight
|
|
|
|
adjustedWidth = boardHeight * originalWidth / originalHeight
|
|
|
|
if boardWidth < adjustedWidth
|
|
|
|
adjustedHeight = boardHeight * boardWidth / adjustedWidth
|
|
|
|
adjustedWidth = boardWidth
|
|
|
|
else
|
|
|
|
adjustedHeight = boardHeight
|
2015-01-07 05:53:07 +08:00
|
|
|
|
|
|
|
# ths slide image is in landscape orientation
|
2014-11-01 06:27:27 +08:00
|
|
|
else
|
|
|
|
adjustedHeight = boardWidth * originalHeight / originalWidth
|
|
|
|
if boardHeight < adjustedHeight
|
|
|
|
adjustedWidth = boardWidth * boardHeight / adjustedHeight
|
|
|
|
adjustedHeight = boardHeight
|
|
|
|
else
|
|
|
|
adjustedWidth = boardWidth
|
2015-01-07 05:53:07 +08:00
|
|
|
|
2015-11-11 11:44:48 +08:00
|
|
|
{ width: adjustedWidth, height: adjustedHeight, boardWidth: boardWidth, boardHeight: boardHeight }
|
2014-11-01 06:27:27 +08:00
|
|
|
|
2014-10-16 06:26:27 +08:00
|
|
|
Template.slide.helpers
|
|
|
|
updatePointerLocation: (pointer) ->
|
2015-12-04 04:01:27 +08:00
|
|
|
whiteboardPaperModel?.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()
|