diff options
| author | fat <[email protected]> | 2013-12-24 16:29:51 -0800 |
|---|---|---|
| committer | fat <[email protected]> | 2013-12-24 16:29:51 -0800 |
| commit | c77740bd3abf379ba5880219fc5719eaa0e484d6 (patch) | |
| tree | 1402eaa603033c1f7983b5268b80de2564f7e758 /js | |
| parent | 073f8c049d9d669bfc57315e7b3267ab422e599c (diff) | |
| download | bootstrap-c77740bd3abf379ba5880219fc5719eaa0e484d6.tar.xz bootstrap-c77740bd3abf379ba5880219fc5719eaa0e484d6.zip | |
fixes #11720 - Add events trigger to affix
Diffstat (limited to 'js')
| -rw-r--r-- | js/affix.js | 12 | ||||
| -rw-r--r-- | js/tests/unit/affix.js | 25 |
2 files changed, 36 insertions, 1 deletions
diff --git a/js/affix.js b/js/affix.js index 94d3cc224..3ec487a78 100644 --- a/js/affix.js +++ b/js/affix.js @@ -67,10 +67,20 @@ if (this.affixed === affix) return if (this.unpin) 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('affix' + (affix ? '-' + affix : '')) + this.$element + .removeClass(Affix.RESET) + .addClass(affixType) + .trigger($.Event(affixType.replace('affix', 'affixed'))) if (affix == 'bottom') { this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() }) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index 6085a141e..3c8105bce 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -22,4 +22,29 @@ $(function () { ok(!$affix.hasClass('affix'), 'affix class was not added') }) + test('should trigger affixed event after affix', function () { + stop() + + 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>') + template.appendTo('body') + + var affixer = $('#affixTarget').affix({ + offset: $('#affixTarget ul').position() + }) + + $('#affixTarget') + .on('affix.bs.affix', function (e) { + ok(true, 'affix event triggered') + }).on('affixed.bs.affix', function (e) { + ok(true,'affixed event triggered') + $('#affixTarget').remove() + $('#affixAfter').remove() + start() + }) + + setTimeout(function () { + window.scrollTo(0, document.body.scrollHeight) + setTimeout(function () { window.scroll(0,0) }, 0) + },0) + }) }) |
