github.com/kayoticsully/syncthing@v0.8.9-0.20140724133906-c45a2fdc03f8/assets/bootstrap-3.1.1/js/tests/unit/affix.js (about)

     1  $(function () {
     2  
     3      module('affix')
     4  
     5        test('should provide no conflict', function () {
     6          var affix = $.fn.affix.noConflict()
     7          ok(!$.fn.affix, 'affix was set back to undefined (org value)')
     8          $.fn.affix = affix
     9        })
    10  
    11        test('should be defined on jquery object', function () {
    12          ok($(document.body).affix, 'affix method is defined')
    13        })
    14  
    15        test('should return element', function () {
    16          ok($(document.body).affix()[0] == document.body, 'document.body returned')
    17        })
    18  
    19        test('should exit early if element is not visible', function () {
    20          var $affix = $('<div style="display: none"></div>').affix()
    21          $affix.data('bs.affix').checkPosition()
    22          ok(!$affix.hasClass('affix'), 'affix class was not added')
    23        })
    24  
    25        test('should trigger affixed event after affix', function () {
    26          stop()
    27  
    28          var template = $('<div id="affixTarget"><ul><li>Please affix</li><li>And unaffix</li></ul></div><div id="affixAfter" style="height: 20000px; display:block;"></div>')
    29          template.appendTo('body')
    30  
    31          var affixer = $('#affixTarget').affix({
    32            offset: $('#affixTarget ul').position()
    33          })
    34  
    35          $('#affixTarget')
    36            .on('affix.bs.affix', function (e) {
    37              ok(true, 'affix event triggered')
    38            }).on('affixed.bs.affix', function (e) {
    39              ok(true,'affixed event triggered')
    40              $('#affixTarget').remove()
    41              $('#affixAfter').remove()
    42              start()
    43            })
    44  
    45          setTimeout(function () {
    46            window.scrollTo(0, document.body.scrollHeight)
    47            setTimeout(function () { window.scroll(0,0) }, 0)
    48          },0)
    49        })
    50  })