mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-14 05:55:00 -04:00
Fixes for ThangListEntryView popover hover states.
This commit is contained in:
parent
3a0ed0af9b
commit
af965ccb93
1 changed files with 20 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue