Skip to content

Commit

Permalink
Allow to attach the minimap to any node using the attach method
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Aug 14, 2015
1 parent 1f48b89 commit 225293f
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MinimapElement extends HTMLElement
swapPosition = @minimap? and displayMinimapOnLeft isnt @displayMinimapOnLeft
@displayMinimapOnLeft = displayMinimapOnLeft

@swapMinimapPosition()
@updateMinimapFlexPosition()

'minimap.minimapScrollIndicator': (@minimapScrollIndicator) =>
if @minimapScrollIndicator and not @scrollIndicator?
Expand Down Expand Up @@ -88,6 +88,7 @@ class MinimapElement extends HTMLElement
attachedCallback: ->
@subscriptions.add atom.views.pollDocument => @pollDOM()
@measureHeightAndWidth()
@updateMinimapFlexPosition()
@attached = true

# Uses of `atom.styles.onDidAddStyleElement` instead of
Expand Down Expand Up @@ -121,35 +122,21 @@ class MinimapElement extends HTMLElement
#
# The position at which the element is attached is defined by the
# `displayMinimapOnLeft` setting.
attach: ->
attach: (parent) ->
return if @attached
@getTextEditorElementRoot().appendChild(this)
@swapMinimapPosition()
@attached = true

# Attaches the {MinimapElement} to the left of the target {TextEditorElement}.
attachToLeft: ->
@classList.add('left')

# Attaches the {MinimapElement} to the right of the target
# {TextEditorElement}.
attachToRight: ->
@classList.remove('left')

# Swaps the {MinimapElement} position based on the value of the
# `displayMinimapOnLeft` setting.
swapMinimapPosition: ->
if @displayMinimapOnLeft
@attachToLeft()
else
@attachToRight()
(parent ? @getTextEditorElementRoot()).appendChild(this)

# Detaches the {MinimapElement} from the DOM.
detach: ->
return unless @attached
return unless @parentNode?
@parentNode.removeChild(this)

# Toggles the minimap left/right position based on the value of the
# `displayMinimapOnLeft` setting.
updateMinimapFlexPosition: ->
@classList.toggle('left', @displayMinimapOnLeft)

# Destroys this {MinimapElement}.
destroy: ->
@subscriptions.dispose()
Expand Down

0 comments on commit 225293f

Please sign in to comment.