bootstrap.js 58.3 KB
Newer Older
2001
2002
2003
2004
2005
2006
    var e         = $.Event(affixType + '.bs.affix')

    this.$element.trigger(e)

    if (e.isDefaultPrevented()) return

2007
    this.affixed = affix
fat's avatar
fat committed
2008
    this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2009

2010
2011
2012
2013
    this.$element
      .removeClass(Affix.RESET)
      .addClass(affixType)
      .trigger($.Event(affixType.replace('affix', 'affixed')))
2014
2015

    if (affix == 'bottom') {
Mark Otto's avatar
Mark Otto committed
2016
      this.$element.offset({ top: scrollHeight - this.$element.height() - offsetBottom })
2017
    }
Mark Otto's avatar
Mark Otto committed
2018
2019
  }

2020
2021
2022
2023

  // AFFIX PLUGIN DEFINITION
  // =======================

Mark Otto's avatar
Mark Otto committed
2024
  function Plugin(option) {
2025
2026
2027
2028
2029
2030
2031
2032
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option

      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
2033
2034
  }

Mark Otto's avatar
Mark Otto committed
2035
2036
2037
  var old = $.fn.affix

  $.fn.affix             = Plugin
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
  $.fn.affix.Constructor = Affix


  // AFFIX NO CONFLICT
  // =================

  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }


  // AFFIX DATA-API
  // ==============

  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()

      data.offset = data.offset || {}

      if (data.offsetBottom) data.offset.bottom = data.offsetBottom
      if (data.offsetTop)    data.offset.top    = data.offsetTop

Mark Otto's avatar
Mark Otto committed
2063
      Plugin.call($spy, data)
2064
    })
Mark Otto's avatar
Mark Otto committed
2065
2066
  })

Chris Rebert's avatar
Chris Rebert committed
2067
}(jQuery);
For faster browsing, not all history is shown. View entire blame