SyncButtonsView.coffee 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. define [
  2. "libs/backbone"
  3. "libs/mustache"
  4. ], () ->
  5. SyncButtonsView = Backbone.View.extend
  6. template: $("#syncButtonsTemplate").html()
  7. events:
  8. "click .sync-code-to-pdf": () -> @trigger "click:sync-code-to-pdf"
  9. "click .sync-pdf-to-code": () -> @trigger "click:sync-pdf-to-code"
  10. initialize: (options) ->
  11. @render()
  12. @ide = options.ide
  13. @ide.editor.on "resize", => @repositionLeft()
  14. @ide.editor.on "cursor:change", => @repositionTop()
  15. render: () ->
  16. @setElement($(@template))
  17. return @
  18. hide: () -> @$el.hide()
  19. show: () -> @$el.show()
  20. repositionLeft: () ->
  21. state = @ide.editor.$splitter.layout().readState()
  22. if state.east?
  23. @$el.css({right: state.east.size - 8})
  24. repositionTop: () ->
  25. # The cursor hasn't actually moved yet.
  26. setTimeout () =>
  27. cursor = @ide.editor.getCursorElement()
  28. container = @ide.editor.getContainerElement()
  29. top = cursor.offset().top - container.offset().top
  30. top = top - 6
  31. max = @ide.editor.getContainerElement().outerHeight() - @$el.outerHeight()
  32. top = 0 if top < 0
  33. top = max if top > max
  34. @$el.css({top: top})
  35. , 10