From 225293f48bed0808da3ccd40fd79a98ae7a278f2 Mon Sep 17 00:00:00 2001 From: abe33 Date: Sat, 15 Aug 2015 01:41:55 +0200 Subject: [PATCH] Allow to attach the minimap to any node using the `attach` method --- lib/minimap-element.coffee | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/minimap-element.coffee b/lib/minimap-element.coffee index 7b1de26b..a60f85fc 100644 --- a/lib/minimap-element.coffee +++ b/lib/minimap-element.coffee @@ -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? @@ -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 @@ -121,28 +122,9 @@ 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: -> @@ -150,6 +132,11 @@ class MinimapElement extends HTMLElement 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()