Fixes for ThangListEntryView popover hover states.

This commit is contained in:
Nick Winter 2014-02-23 17:11:27 -08:00
parent 3a0ed0af9b
commit af965ccb93

View file

@ -21,6 +21,7 @@ module.exports = class ThangListEntryView extends View
'surface:frame-changed': "onFrameChanged"
'level-set-letterbox': 'onSetLetterbox'
'tome:thang-list-entry-popover-shown': 'onThangListEntryPopoverShown'
'surface:coordinates-shown': 'onSurfaceCoordinatesShown'
events:
'click': 'onClick'
@ -86,38 +87,47 @@ module.exports = class ThangListEntryView extends View
onMouseEnter: (e) ->
return unless @controlsEnabled and @spells.length
@showSpells()
@clearTimeouts()
@showSpellsTimeout = _.delay @showSpells, 100
onMouseLeave: (e) ->
return unless @controlsEnabled and @spells.length
clearTimeout @hideSpellsTimeout if @hideSpellsTimeout
@clearTimeouts()
@hideSpellsTimeout = _.delay @hideSpells, 100
clearTimeouts: ->
clearTimeout @showSpellsTimeout if @showSpellsTimeout
clearTimeout @hideSpellsTimeout if @hideSpellsTimeout
@showSpellsTimeout = @hideSpellsTimeout = null
onThangListEntryPopoverShown: (e) ->
# I couldn't figure out how to get the mouseenter / mouseleave to always work, so this is a fallback
# to hide our popover is another Thang's popover gets shown.
return if e.entry is @
@hideSpells()
onSurfaceCoordinatesShown: (e) ->
# Definitely aren't hovering over this.
@hideSpells()
showSpells: =>
@clearTimeouts()
@sortSpells()
@$el.data('bs.popover').options.content = @getSpellListHTML()
@$el.popover('setContent').popover('show')
@$el.parent().parent().parent().i18n()
clearTimeout @hideSpellsTimeout if @hideSpellsTimeout
@hideSpellsTimeout = null
@popover = @$el.parent().parent().parent().find('.popover')
@popover.off 'mouseenter mouseleave'
@popover.mouseenter (e) => @onMouseEnter()
@popover.mouseleave (e) => @onMouseLeave()
@popover.mouseenter (e) => @showSpells() if @controlsEnabled
@popover.mouseleave (e) => @hideSpells()
thangID = @thang.id
@popover.find('code').click (e) ->
Backbone.Mediator.publish "level-select-sprite", thangID: thangID, spellName: $(@).data 'spell-name'
Backbone.Mediator.publish 'tome:thang-list-entry-popover-shown', entry: @
hideSpells: =>
@clearTimeouts()
@$el.popover('hide')
@hideSpellsTimeout = null
getSpellListHTML: ->
spellsPopoverTemplate {spells: @spells}
@ -129,13 +139,16 @@ module.exports = class ThangListEntryView extends View
onSetLetterbox: (e) ->
if e.on then @reasonsToBeDisabled.letterbox = true else delete @reasonsToBeDisabled.letterbox
@updateControls()
onDisableControls: (e) ->
return if e.controls and not ('surface' in e.controls) # disable selection?
@reasonsToBeDisabled.controls = true
@updateControls()
onEnableControls: (e) ->
delete @reasonsToBeDisabled.controls
@updateControls()
updateControls: ->
enabled = _.keys(@reasonsToBeDisabled).length is 0
return if enabled is @controlsEnabled