         @$tip.css offset
         @debugLog '_onTriggerMouseMove', @_state, offset
 
-    # - Auto-direction support. Given the context boundary, choose the best
-    #   direction. The data is stored with the trigger and gets accessed elsewhere.
+    # `_updateDirectionByTrigger` is the main provider of auto-direction
+    # support. Given the `$context`'s `_bounds`, it changes to the best
+    # direction as needed. The current `direction` is stored as jQuery data with
+    # trigger.
     _updateDirectionByTrigger: ($trigger) ->
       return no if @autoDirection is off
       triggerPosition = $trigger.position()

      containerClass = $.trim [@classNames.tip, @classNames.follow, directionClass].join ' '
      html = @tipTemplate containerClass

    _saveTriggerContent: ($trigger) ->
      title = $trigger.attr 'title'
      if title?


  # SnapTip API
  # -----------
  # With such a complete base API, extending it with an implementation with
  # snapping becomes almost trivial.
  class SnapTip extends Tip

    # Continue setting up `$tip` and other properties.
    constructor: ($triggers, options, $context) ->
      super $triggers, options, $context
      # Infer `snap.toTrigger`.
      if @snap.toTrigger is off
        @snap.toTrigger = @snap.toXAxis is on or @snap.toYAxis is on
      # Tweak `cursorHeight`.
      if @snap.toXAxis is on then @cursorHeight = 0
      if @snap.toYAxis is on then @cursorHeight = 2
      # `_offsetStart` stores the original offset, which is used for snapping.
      @_offsetStart = null
      # Add snapping config as classes.
      @$tip.addClass @classNames.snap[key] for key, active of @snap when active

    # `_moveToTrigger` is the main positioner. The `baseOffset` given is
    # expected to be the trigger offset.  
    # TODO: Still needs to support all the directions.
    _moveToTrigger: ($trigger, baseOffset) ->
      #@debugLog baseOffset
      offset = $trigger.offset()
      if @snap.toXAxis is on
        if @isDirection 'south' then offset.top += $trigger.outerHeight()
        if @snap.toYAxis is off
          # Note arbitrary buffer offset.
          offset.left = baseOffset.left - (@$tip.outerWidth() - 12)/ 2
      if @snap.toYAxis is on
        if @isDirection 'east' then offset.left += $trigger.outerWidth()
        if @snap.toXAxis is off
          offset.top = baseOffset.top - @$tip.outerHeight() / 2
      offset

    # Extend `_bindTrigger` to get initial position for snapping. This is only
    # for snapping without snapping to the trigger, which is only what's
    # currently supported. See `afterShow` hook.
    _bindTrigger: ($trigger) ->
      super $trigger
      $trigger.on @evt('truemouseleave'), (event) => @_offsetStart = null

    # `onShow` and `afterShow` are implemented such that they make the tip
    # invisible while it's being positioned and then reveal it.
    onShow: (triggerChanged, event) ->
      if triggerChanged is yes
        @$tip.css 'visibility', 'hidden'
    afterShow: (triggerChanged, event) ->
      if triggerChanged is yes
        @$tip.css 'visibility', 'visible'
