diff options
author | Jacob Thornton <jacobthornton@gmail.com> | 2013-05-25 10:15:04 +0400 |
---|---|---|
committer | Jacob Thornton <jacobthornton@gmail.com> | 2013-05-25 10:15:04 +0400 |
commit | f3e45c37780b12a3fa96e7d4578f38a883cba9a0 (patch) | |
tree | 935a3cf3c892f2db38842e351cd9ddd53ff37c36 /docs/assets/js/bootstrap.js | |
parent | f820de4b325c4a9049c822374701efd2bcb7e26e (diff) |
add show/shown hide/hidden events to dropdown + update dropdown links for testing + catch a few missed namespace things
Diffstat (limited to 'docs/assets/js/bootstrap.js')
-rw-r--r-- | docs/assets/js/bootstrap.js | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/docs/assets/js/bootstrap.js b/docs/assets/js/bootstrap.js index f19a123a4a..b2b4086726 100644 --- a/docs/assets/js/bootstrap.js +++ b/docs/assets/js/bootstrap.js @@ -433,7 +433,7 @@ // CAROUSEL DATA-API // ================= - $(document).on('click.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { + $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { var $this = $(this), href var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 var options = $.extend({}, $target.data(), $this.data()) @@ -590,7 +590,7 @@ // COLLAPSE DATA-API // ================= - $(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) { + $(document).on('click.bs.collapse.data-api', '[data-toggle=collapse]', function (e) { var $this = $(this), href var target = $this.attr('data-target') || e.preventDefault() @@ -630,10 +630,7 @@ var backdrop = '.dropdown-backdrop' var toggle = '[data-toggle=dropdown]' var Dropdown = function (element) { - var $el = $(element).on('click.dropdown.data-api', this.toggle) - $('html').on('click.dropdown.data-api', function () { - $el.parent().removeClass('open') - }) + var $el = $(element).on('click.bs.dropdown', this.toggle) } Dropdown.prototype.toggle = function (e) { @@ -651,7 +648,14 @@ // if mobile we we use a backdrop because click events don't delegate $('<div class="dropdown-backdrop"/>').insertBefore($(this)).on('click', clearMenus) } - $parent.toggleClass('open') + + $parent.trigger(e = $.Event('show.bs.dropdown')) + + if (e.isDefaultPrevented()) return + + $parent + .toggleClass('open') + .trigger('shown.bs.dropdown') } $this.focus() @@ -692,7 +696,13 @@ function clearMenus() { $(backdrop).remove() - $(toggle).each(function () { getParent($(this)).removeClass('open') }) + $(toggle).each(function (e) { + var $parent = getParent($(this)) + if (!$parent.hasClass('open')) return + $parent.trigger(e = $.Event('hide.bs.dropdown')) + if (e.isDefaultPrevented()) return + $parent.removeClass('open').trigger('hidden.bs.dropdown') + }) } function getParent($this) { @@ -741,10 +751,10 @@ $(document) - .on('click.dropdown.data-api', clearMenus) - .on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) - .on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle) - .on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) + .on('click.bs.dropdown.data-api', clearMenus) + .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) + .on('click.bs.dropdown.data-api' , toggle, Dropdown.prototype.toggle) + .on('keydown.bs.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) }(window.jQuery); /* ======================================================================== @@ -1482,7 +1492,7 @@ var $element = $(element).is('body') ? $(window) : $(element) this.$body = $('body') - this.$scrollElement = $element.on('scroll.scroll-spy.data-api', process) + this.$scrollElement = $element.on('scroll.bs.scroll-spy.data-api', process) this.options = $.extend({}, ScrollSpy.DEFAULTS, options) this.selector = (this.options.target || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 |