2014-11-28 20:49:41 -05:00
|
|
|
|
CocoView = require 'views/core/CocoView'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
template = require 'templates/play/level/tome/spell_palette_entry'
|
2014-11-28 20:49:41 -05:00
|
|
|
|
{me} = require 'core/auth'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
filters = require 'lib/image_filter'
|
2014-07-23 10:02:45 -04:00
|
|
|
|
DocFormatter = require './DocFormatter'
|
2014-11-26 15:33:29 -05:00
|
|
|
|
SpellView = require 'views/play/level/tome/SpellView'
|
2014-02-16 18:30:00 -05:00
|
|
|
|
|
2014-07-17 20:20:11 -04:00
|
|
|
|
module.exports = class SpellPaletteEntryView extends CocoView
|
2014-01-03 13:32:13 -05:00
|
|
|
|
tagName: 'div' # Could also try <code> instead of <div>, but would need to adjust colors
|
|
|
|
|
className: 'spell-palette-entry-view'
|
|
|
|
|
template: template
|
2014-02-16 18:30:00 -05:00
|
|
|
|
popoverPinned: false
|
2014-08-14 16:29:57 -04:00
|
|
|
|
overridePopoverTemplate: '<div class="popover spell-palette-popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
|
|
subscriptions:
|
2014-06-30 22:16:26 -04:00
|
|
|
|
'surface:frame-changed': 'onFrameChanged'
|
|
|
|
|
'tome:palette-hovered': 'onPaletteHovered'
|
|
|
|
|
'tome:palette-pin-toggled': 'onPalettePinToggled'
|
2014-02-23 19:34:03 -05:00
|
|
|
|
'tome:spell-debug-property-hovered': 'onSpellDebugPropertyHovered'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
|
|
events:
|
2014-02-16 18:30:00 -05:00
|
|
|
|
'mouseenter': 'onMouseEnter'
|
|
|
|
|
'mouseleave': 'onMouseLeave'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
'click': 'onClick'
|
|
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
|
super options
|
|
|
|
|
@thang = options.thang
|
2014-06-26 01:56:39 -04:00
|
|
|
|
@docFormatter = new DocFormatter options
|
|
|
|
|
@doc = @docFormatter.doc
|
2014-10-26 20:49:34 -04:00
|
|
|
|
@doc.initialHTML = @docFormatter.formatPopover()
|
2014-11-26 15:33:29 -05:00
|
|
|
|
@aceEditors = []
|
2014-06-25 23:19:11 -04:00
|
|
|
|
|
2014-02-12 19:42:09 -05:00
|
|
|
|
getRenderData: ->
|
|
|
|
|
c = super()
|
|
|
|
|
c.doc = @doc
|
|
|
|
|
c
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
|
super()
|
2014-02-12 19:42:09 -05:00
|
|
|
|
@$el.addClass(@doc.type)
|
2014-11-21 15:14:37 -05:00
|
|
|
|
placement = -> if $('body').hasClass('dialogue-view-active') then 'top' else 'left'
|
2014-02-12 19:42:09 -05:00
|
|
|
|
@$el.popover(
|
2014-02-16 18:30:00 -05:00
|
|
|
|
animation: false
|
2014-01-03 13:32:13 -05:00
|
|
|
|
html: true
|
2014-11-21 15:14:37 -05:00
|
|
|
|
placement: placement
|
2014-02-16 18:30:00 -05:00
|
|
|
|
trigger: 'manual' # Hover, until they click, which will then pin it until unclick.
|
2014-06-26 01:56:39 -04:00
|
|
|
|
content: @docFormatter.formatPopover()
|
2014-08-14 16:29:57 -04:00
|
|
|
|
container: 'body'
|
|
|
|
|
template: @overridePopoverTemplate
|
2014-11-23 16:26:19 -05:00
|
|
|
|
).on 'shown.bs.popover', =>
|
2014-02-20 13:39:16 -05:00
|
|
|
|
Backbone.Mediator.publish 'tome:palette-hovered', thang: @thang, prop: @doc.name, entry: @
|
2014-09-11 11:38:30 -04:00
|
|
|
|
soundIndex = Math.floor(Math.random() * 4)
|
2014-10-23 23:03:19 -04:00
|
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: "spell-palette-entry-open-#{soundIndex}", volume: 0.75
|
2014-11-23 16:26:19 -05:00
|
|
|
|
popover = @$el.data('bs.popover')
|
|
|
|
|
popover?.$tip?.i18n()
|
2014-11-26 15:33:29 -05:00
|
|
|
|
codeLanguage = @options.language
|
|
|
|
|
oldEditor.destroy() for oldEditor in @aceEditors
|
|
|
|
|
@aceEditors = []
|
|
|
|
|
aceEditors = @aceEditors
|
|
|
|
|
popover?.$tip?.find('.docs-ace').each ->
|
|
|
|
|
contents = $(@).text()
|
|
|
|
|
editor = ace.edit @
|
|
|
|
|
editor.setOptions maxLines: Infinity
|
|
|
|
|
editor.setReadOnly true
|
|
|
|
|
editor.setTheme 'ace/theme/textmate'
|
|
|
|
|
editor.setShowPrintMargin false
|
|
|
|
|
editor.setShowFoldWidgets false
|
|
|
|
|
editor.setHighlightActiveLine false
|
|
|
|
|
editor.setHighlightActiveLine false
|
|
|
|
|
editor.setBehavioursEnabled false
|
|
|
|
|
editor.renderer.setShowGutter false
|
|
|
|
|
editor.setValue contents
|
|
|
|
|
editor.clearSelection()
|
|
|
|
|
session = editor.getSession()
|
|
|
|
|
session.setUseWorker false
|
|
|
|
|
session.setMode SpellView.editModes[codeLanguage]
|
|
|
|
|
session.setWrapLimitRange null
|
|
|
|
|
session.setUseWrapMode true
|
|
|
|
|
session.setNewLineMode 'unix'
|
|
|
|
|
aceEditors.push editor
|
2014-02-12 19:42:09 -05:00
|
|
|
|
|
2014-02-16 18:30:00 -05:00
|
|
|
|
onMouseEnter: (e) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
|
# Make sure the doc has the updated Thang so it can regenerate its prop value
|
2014-06-26 01:56:39 -04:00
|
|
|
|
@$el.data('bs.popover').options.content = @docFormatter.formatPopover()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
@$el.popover('setContent')
|
2014-02-20 13:39:16 -05:00
|
|
|
|
@$el.popover 'show' unless @popoverPinned or @otherPopoverPinned
|
2014-02-16 18:30:00 -05:00
|
|
|
|
|
|
|
|
|
onMouseLeave: (e) ->
|
2014-02-20 13:39:16 -05:00
|
|
|
|
@$el.popover 'hide' unless @popoverPinned or @otherPopoverPinned
|
2014-02-16 18:30:00 -05:00
|
|
|
|
|
|
|
|
|
togglePinned: ->
|
|
|
|
|
if @popoverPinned
|
|
|
|
|
@popoverPinned = false
|
2014-08-14 16:29:57 -04:00
|
|
|
|
@$el.add('.spell-palette-popover.popover').removeClass 'pinned'
|
|
|
|
|
$('.spell-palette-popover.popover .close').remove()
|
2014-02-16 18:30:00 -05:00
|
|
|
|
@$el.popover 'hide'
|
2014-09-11 11:38:30 -04:00
|
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'spell-palette-entry-unpin', volume: 1
|
2014-02-16 18:30:00 -05:00
|
|
|
|
else
|
|
|
|
|
@popoverPinned = true
|
2014-02-20 13:39:16 -05:00
|
|
|
|
@$el.popover 'show'
|
2014-08-14 16:29:57 -04:00
|
|
|
|
@$el.add('.spell-palette-popover.popover').addClass 'pinned'
|
2014-02-20 13:39:16 -05:00
|
|
|
|
x = $('<button type="button" data-dismiss="modal" aria-hidden="true" class="close">×</button>')
|
2014-08-14 16:29:57 -04:00
|
|
|
|
$('.spell-palette-popover.popover').append x
|
2014-02-20 13:39:16 -05:00
|
|
|
|
x.on 'click', @onClick
|
2014-09-05 15:39:30 -04:00
|
|
|
|
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'spell-palette-entry-pin', volume: 1
|
2014-02-20 13:39:16 -05:00
|
|
|
|
Backbone.Mediator.publish 'tome:palette-pin-toggled', entry: @, pinned: @popoverPinned
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
2014-02-20 13:39:16 -05:00
|
|
|
|
onClick: (e) =>
|
2015-07-24 20:37:42 -04:00
|
|
|
|
if true or @options.level.get('type', true) in ['hero', 'hero-ladder', 'hero-coop', 'course', 'course-ladder']
|
2014-11-22 20:35:05 -05:00
|
|
|
|
# Jiggle instead of pin for hero levels
|
2015-03-20 12:03:36 -04:00
|
|
|
|
# Actually, do it all the time, because we recently busted the pin CSS. TODO: restore pinning
|
2014-11-22 20:35:05 -05:00
|
|
|
|
jigglyPopover = $('.spell-palette-popover.popover')
|
|
|
|
|
jigglyPopover.addClass 'jiggling'
|
|
|
|
|
pauseJiggle = =>
|
|
|
|
|
jigglyPopover.removeClass 'jiggling'
|
|
|
|
|
_.delay pauseJiggle, 1000
|
|
|
|
|
return
|
2014-08-04 17:02:54 -04:00
|
|
|
|
if key.shift
|
2014-08-05 05:19:15 -04:00
|
|
|
|
Backbone.Mediator.publish 'tome:insert-snippet', doc: @options.doc, language: @options.language, formatted: @doc
|
2014-08-04 17:02:54 -04:00
|
|
|
|
return
|
2014-02-16 18:30:00 -05:00
|
|
|
|
@togglePinned()
|
2014-02-20 13:39:16 -05:00
|
|
|
|
Backbone.Mediator.publish 'tome:palette-clicked', thang: @thang, prop: @doc.name, entry: @
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
|
|
onFrameChanged: (e) ->
|
|
|
|
|
return unless e.selectedThang?.id is @thang.id
|
2014-06-26 01:56:39 -04:00
|
|
|
|
@options.thang = @thang = @docFormatter.options.thang = e.selectedThang # Update our thang to the current version
|
2014-02-11 14:31:02 -05:00
|
|
|
|
|
2014-02-20 13:39:16 -05:00
|
|
|
|
onPaletteHovered: (e) ->
|
|
|
|
|
return if e.entry is @
|
|
|
|
|
@togglePinned() if @popoverPinned
|
|
|
|
|
|
|
|
|
|
onPalettePinToggled: (e) ->
|
|
|
|
|
return if e.entry is @
|
|
|
|
|
@otherPopoverPinned = e.pinned
|
|
|
|
|
|
2014-02-23 19:34:03 -05:00
|
|
|
|
onSpellDebugPropertyHovered: (e) ->
|
|
|
|
|
matched = e.property is @doc.name and e.owner is @doc.owner
|
|
|
|
|
if matched and not @debugHovered
|
|
|
|
|
@debugHovered = true
|
|
|
|
|
@togglePinned() unless @popoverPinned
|
|
|
|
|
else if @debugHovered and not matched
|
|
|
|
|
@debugHovered = false
|
|
|
|
|
@togglePinned() if @popoverPinned
|
|
|
|
|
null
|
|
|
|
|
|
2014-02-11 14:31:02 -05:00
|
|
|
|
destroy: ->
|
2014-02-16 18:30:00 -05:00
|
|
|
|
$('.popover.pinned').remove() if @popoverPinned # @$el.popover('destroy') doesn't work
|
|
|
|
|
@togglePinned() if @popoverPinned
|
|
|
|
|
@$el.popover 'destroy'
|
2014-02-11 14:31:02 -05:00
|
|
|
|
@$el.off()
|
2014-11-26 15:33:29 -05:00
|
|
|
|
oldEditor.destroy() for oldEditor in @aceEditors
|
2014-02-12 19:42:09 -05:00
|
|
|
|
super()
|