aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorF A T <[email protected]>2015-02-11 11:41:26 -0800
committerF A T <[email protected]>2015-02-11 11:41:26 -0800
commita5580360ba423aba214fe7c58dd49793b0b8e215 (patch)
tree0b1e7c0d87766742af9fd5100f9475670214078c /js
parentd71ccaefbce5f21ad2552685999074537e25b65a (diff)
parent1e9e3316b6718af09bfe473f5eb364e4f9475731 (diff)
downloadbootstrap-a5580360ba423aba214fe7c58dd49793b0b8e215.tar.xz
bootstrap-a5580360ba423aba214fe7c58dd49793b0b8e215.zip
Merge pull request #93 from twbs/fat-removeAffix
kill affix
Diffstat (limited to 'js')
-rw-r--r--js/affix.js162
-rw-r--r--js/tests/unit/affix.js101
2 files changed, 0 insertions, 263 deletions
diff --git a/js/affix.js b/js/affix.js
deleted file mode 100644
index aaebc8c0f..000000000
--- a/js/affix.js
+++ /dev/null
@@ -1,162 +0,0 @@
-/* ========================================================================
- * Bootstrap: affix.js v3.3.2
- * http://getbootstrap.com/javascript/#affix
- * ========================================================================
- * Copyright 2011-2015 Twitter, Inc.
- * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
- * ======================================================================== */
-
-
-+function ($) {
- 'use strict';
-
- // AFFIX CLASS DEFINITION
- // ======================
-
- var Affix = function (element, options) {
- this.options = $.extend({}, Affix.DEFAULTS, options)
-
- this.$target = $(this.options.target)
- .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
- .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this))
-
- this.$element = $(element)
- this.affixed =
- this.unpin =
- this.pinnedOffset = null
-
- this.checkPosition()
- }
-
- Affix.VERSION = '3.3.2'
-
- Affix.RESET = 'affix affix-top affix-bottom'
-
- Affix.DEFAULTS = {
- offset: 0,
- target: window
- }
-
- Affix.prototype.getState = function (scrollHeight, height, offsetTop, offsetBottom) {
- var scrollTop = this.$target.scrollTop()
- var position = this.$element.offset()
- var targetHeight = this.$target.height()
-
- if (offsetTop != null && this.affixed == 'top') return scrollTop < offsetTop ? 'top' : false
-
- if (this.affixed == 'bottom') {
- if (offsetTop != null) return (scrollTop + this.unpin <= position.top) ? false : 'bottom'
- return (scrollTop + targetHeight <= scrollHeight - offsetBottom) ? false : 'bottom'
- }
-
- var initializing = this.affixed == null
- var colliderTop = initializing ? scrollTop : position.top
- var colliderHeight = initializing ? targetHeight : height
-
- if (offsetTop != null && scrollTop <= offsetTop) return 'top'
- if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom'
-
- return false
- }
-
- Affix.prototype.getPinnedOffset = function () {
- if (this.pinnedOffset) return this.pinnedOffset
- this.$element.removeClass(Affix.RESET).addClass('affix')
- var scrollTop = this.$target.scrollTop()
- var position = this.$element.offset()
- return (this.pinnedOffset = position.top - scrollTop)
- }
-
- Affix.prototype.checkPositionWithEventLoop = function () {
- setTimeout($.proxy(this.checkPosition, this), 1)
- }
-
- Affix.prototype.checkPosition = function () {
- if (!this.$element.is(':visible')) return
-
- var height = this.$element.height()
- var offset = this.options.offset
- var offsetTop = offset.top
- var offsetBottom = offset.bottom
- var scrollHeight = $('body').height()
-
- if (typeof offset != 'object') offsetBottom = offsetTop = offset
- if (typeof offsetTop == 'function') offsetTop = offset.top(this.$element)
- if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element)
-
- var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
-
- if (this.affixed != affix) {
- if (this.unpin != null) this.$element.css('top', '')
-
- var affixType = 'affix' + (affix ? '-' + affix : '')
- var e = $.Event(affixType + '.bs.affix')
-
- this.$element.trigger(e)
-
- if (e.isDefaultPrevented()) return
-
- this.affixed = affix
- this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
-
- this.$element
- .removeClass(Affix.RESET)
- .addClass(affixType)
- .trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
- }
-
- if (affix == 'bottom') {
- this.$element.offset({
- top: scrollHeight - height - offsetBottom
- })
- }
- }
-
-
- // AFFIX PLUGIN DEFINITION
- // =======================
-
- function Plugin(option) {
- 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]()
- })
- }
-
- var old = $.fn.affix
-
- $.fn.affix = Plugin
- $.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 != null) data.offset.bottom = data.offsetBottom
- if (data.offsetTop != null) data.offset.top = data.offsetTop
-
- Plugin.call($spy, data)
- })
- })
-
-}(jQuery);
diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js
deleted file mode 100644
index 040fe9803..000000000
--- a/js/tests/unit/affix.js
+++ /dev/null
@@ -1,101 +0,0 @@
-$(function () {
- 'use strict';
-
- module('affix plugin')
-
- test('should be defined on jquery object', function () {
- ok($(document.body).affix, 'affix method is defined')
- })
-
- module('affix', {
- setup: function () {
- // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
- $.fn.bootstrapAffix = $.fn.affix.noConflict()
- },
- teardown: function () {
- $.fn.affix = $.fn.bootstrapAffix
- delete $.fn.bootstrapAffix
- }
- })
-
- test('should provide no conflict', function () {
- strictEqual($.fn.affix, undefined, 'affix was set back to undefined (org value)')
- })
-
- test('should return jquery collection containing the element', function () {
- var $el = $('<div/>')
- var $affix = $el.bootstrapAffix()
- ok($affix instanceof $, 'returns jquery collection')
- strictEqual($affix[0], $el[0], 'collection contains element')
- })
-
- test('should exit early if element is not visible', function () {
- var $affix = $('<div style="display: none"/>').bootstrapAffix()
- $affix.data('bs.affix').checkPosition()
- ok(!$affix.hasClass('affix'), 'affix class was not added')
- })
-
- test('should trigger affixed event after affix', function (assert) {
- var done = assert.async()
-
- var templateHTML = '<div id="affixTarget">'
- + '<ul>'
- + '<li>Please affix</li>'
- + '<li>And unaffix</li>'
- + '</ul>'
- + '</div>'
- + '<div id="affixAfter" style="height: 20000px; display: block;"/>'
- $(templateHTML).appendTo(document.body)
-
- $('#affixTarget').bootstrapAffix({
- offset: $('#affixTarget ul').position()
- })
-
- $('#affixTarget')
- .on('affix.bs.affix', function () {
- ok(true, 'affix event fired')
- }).on('affixed.bs.affix', function () {
- ok(true, 'affixed event fired')
- $('#affixTarget, #affixAfter').remove()
- done()
- })
-
- setTimeout(function () {
- window.scrollTo(0, document.body.scrollHeight)
-
- setTimeout(function () {
- window.scroll(0, 0)
- }, 16) // for testing in a browser
- }, 0)
- })
-
- test('should affix-top when scrolling up to offset when parent has padding', function (assert) {
- var done = assert.async()
-
- var templateHTML = '<div id="padding-offset" style="padding-top: 20px;">'
- + '<div id="affixTopTarget">'
- + '<p>Testing affix-top class is added</p>'
- + '</div>'
- + '<div style="height: 1000px; display: block;"/>'
- + '</div>'
- $(templateHTML).appendTo(document.body)
-
- $('#affixTopTarget')
- .bootstrapAffix({
- offset: { top: 120, bottom: 0 }
- })
- .on('affixed-top.bs.affix', function () {
- ok($('#affixTopTarget').hasClass('affix-top'), 'affix-top class applied')
- $('#padding-offset').remove()
- done()
- })
-
- setTimeout(function () {
- window.scrollTo(0, document.body.scrollHeight)
-
- setTimeout(function () {
- window.scroll(0, 119)
- }, 250)
- }, 250)
- })
-})