codecombat/app/views/play/level/tome/spell_palette_entry_view.coffee

60 lines
2 KiB
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
View = require 'views/kinds/CocoView'
template = require 'templates/play/level/tome/spell_palette_entry'
{me} = require 'lib/auth'
filters = require 'lib/image_filter'
Docs = require 'lib/world/docs'
module.exports = class SpellPaletteEntryView extends View
tagName: 'div' # Could also try <code> instead of <div>, but would need to adjust colors
className: 'spell-palette-entry-view'
template: template
subscriptions:
'surface:frame-changed': "onFrameChanged"
events:
'mouseover': 'onMouseOver'
'click': 'onClick'
constructor: (options) ->
super options
@thang = options.thang
@doc = options.doc
@shortenize = options.shortenize
afterRender: ->
super()
text = if @shortenize then @doc.shorterName else @doc.shortName
@$el.text(text).addClass(@doc.type)
@$el.attr('title', @doc.title()).popover(
animation: true
html: true
placement: 'top'
trigger: 'hover'
content: @doc.html()
container: @$el.parent().parent().parent()
)
2014-01-30 19:36:36 -05:00
@$el.on 'show.bs.popover', =>
2014-01-03 13:32:13 -05:00
# New, good event
Backbone.Mediator.publish 'tome:palette-hovered', thang: @thang, prop: @doc.prop
# Bad, old one for old scripts (TODO)
Backbone.Mediator.publish 'editor:palette-hovered', thang: @thang, prop: @doc.prop
onMouseOver: (e) ->
# Make sure the doc has the updated Thang so it can regenerate its prop value
@doc.thang = @thang
@$el.data('bs.popover').options.content = @doc.html()
2014-01-03 13:32:13 -05:00
@$el.popover('setContent')
onClick: (e) ->
Backbone.Mediator.publish 'tome:palette-clicked', thang: @thang, prop: @doc.prop
onFrameChanged: (e) ->
return unless e.selectedThang?.id is @thang.id
@options.thang = @thang = e.selectedThang # Update our thang to the current version
@options.doc = @doc = Docs.getDocsFor(@thang, [@doc.prop])[0]
2014-01-03 13:32:13 -05:00
@$el.find("code.current-value").text(@doc.formatValue()) # Don't call any functions. (?? What does this mean?)
2014-02-11 14:31:02 -05:00
destroy: ->
@$el.off()
super()