Pool highlight elements

This commit is contained in:
Antonio Scandurra 2015-09-17 10:35:20 +02:00
parent f8868ffcf2
commit 8b52538213
2 changed files with 5 additions and 8 deletions

View File

@ -5,12 +5,11 @@ module.exports =
class HighlightsComponent class HighlightsComponent
oldState: null oldState: null
constructor: -> constructor: (@domElementPool) ->
@highlightNodesById = {} @highlightNodesById = {}
@regionNodesByHighlightId = {} @regionNodesByHighlightId = {}
@domNode = document.createElement('div') @domNode = @domElementPool.build("div", "highlights")
@domNode.classList.add('highlights')
getDomNode: -> getDomNode: ->
@domNode @domNode
@ -30,8 +29,7 @@ class HighlightsComponent
# add or update highlights # add or update highlights
for id, highlightState of newState for id, highlightState of newState
unless @oldState[id]? unless @oldState[id]?
highlightNode = document.createElement('div') highlightNode = @domElementPool.build("div", "highlight")
highlightNode.classList.add('highlight')
@highlightNodesById[id] = highlightNode @highlightNodesById[id] = highlightNode
@regionNodesByHighlightId[id] = {} @regionNodesByHighlightId[id] = {}
@domNode.appendChild(highlightNode) @domNode.appendChild(highlightNode)
@ -75,12 +73,11 @@ class HighlightsComponent
for newRegionState, i in newHighlightState.regions for newRegionState, i in newHighlightState.regions
unless oldHighlightState.regions[i]? unless oldHighlightState.regions[i]?
oldHighlightState.regions[i] = {} oldHighlightState.regions[i] = {}
regionNode = document.createElement('div') regionNode = @domElementPool.build("div", "region")
# This prevents highlights at the tiles boundaries to be hidden by the # This prevents highlights at the tiles boundaries to be hidden by the
# subsequent tile. When this happens, subpixel anti-aliasing gets # subsequent tile. When this happens, subpixel anti-aliasing gets
# disabled. # disabled.
regionNode.style.boxSizing = "border-box" regionNode.style.boxSizing = "border-box"
regionNode.classList.add('region')
regionNode.classList.add(newHighlightState.deprecatedRegionClass) if newHighlightState.deprecatedRegionClass? regionNode.classList.add(newHighlightState.deprecatedRegionClass) if newHighlightState.deprecatedRegionClass?
@regionNodesByHighlightId[id][i] = regionNode @regionNodesByHighlightId[id][i] = regionNode
highlightNode.appendChild(regionNode) highlightNode.appendChild(regionNode)

View File

@ -23,7 +23,7 @@ class LinesTileComponent
@domNode.style.position = "absolute" @domNode.style.position = "absolute"
@domNode.style.display = "block" @domNode.style.display = "block"
@highlightsComponent = new HighlightsComponent @highlightsComponent = new HighlightsComponent(@domElementPool)
@domNode.appendChild(@highlightsComponent.getDomNode()) @domNode.appendChild(@highlightsComponent.getDomNode())
destroy: -> destroy: ->