Skip to content

Commit

Permalink
fixes #11373 - adds related target to dropdown events
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Dec 30, 2013
1 parent 162d9e1 commit 76f0d0f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
17 changes: 9 additions & 8 deletions dist/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,13 +659,14 @@ if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery"
$('<div class="dropdown-backdrop"/>').insertAfter($(this)).on('click', clearMenus)
}

$parent.trigger(e = $.Event('show.bs.dropdown'))
var relatedTarget = { relatedTarget: this }
$parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget))

if (e.isDefaultPrevented()) return

$parent
.toggleClass('open')
.trigger('shown.bs.dropdown')
.trigger('shown.bs.dropdown', relatedTarget)

$this.focus()
}
Expand Down Expand Up @@ -704,14 +705,15 @@ if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery"
$items.eq(index).focus()
}

function clearMenus() {
function clearMenus(e) {
$(backdrop).remove()
$(toggle).each(function (e) {
$(toggle).each(function () {
var $parent = getParent($(this))
var relatedTarget = { relatedTarget: this }
if (!$parent.hasClass('open')) return
$parent.trigger(e = $.Event('hide.bs.dropdown'))
$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
if (e.isDefaultPrevented()) return
$parent.removeClass('open').trigger('hidden.bs.dropdown')
$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
})
}

Expand Down Expand Up @@ -1596,8 +1598,7 @@ if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery"
}

if (activeTarget && scrollTop <= offsets[0]) {
debugger
return activeTarget != (i = targets.first()[0]) && this.activate(i)
return activeTarget != (i = targets[0]) && this.activate(i)
}

for (i = offsets.length; i--;) {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/bootstrap.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs-assets/js/raw-files.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions javascript.html
Original file line number Diff line number Diff line change
Expand Up @@ -570,19 +570,19 @@ <h3>Events</h3>
<tbody>
<tr>
<td>show.bs.dropdown</td>
<td>This event fires immediately when the show instance method is called.</td>
<td>This event fires immediately when the show instance method is called. The toggling anchor element is available as the <code>relatedTarget</code> property of the event.</td>
</tr>
<tr>
<td>shown.bs.dropdown</td>
<td>This event is fired when the dropdown has been made visible to the user (will wait for CSS transitions, to complete).</td>
<td>This event is fired when the dropdown has been made visible to the user (will wait for CSS transitions, to complete). The toggling anchor element is available as the <code>relatedTarget</code> property of the event.</td>
</tr>
<tr>
<td>hide.bs.dropdown</td>
<td>This event is fired immediately when the hide instance method has been called.</td>
<td>This event is fired immediately when the hide instance method has been called. The toggling anchor element is available as the <code>relatedTarget</code> property of the event.</td>
</tr>
<tr>
<td>hidden.bs.dropdown</td>
<td>This event is fired when the dropdown has finished being hidden from the user (will wait for CSS transitions, to complete).</td>
<td>This event is fired when the dropdown has finished being hidden from the user (will wait for CSS transitions, to complete). The toggling anchor element is available as the <code>relatedTarget</code> property of the event.</td>
</tr>
</tbody>
</table>
Expand Down
14 changes: 8 additions & 6 deletions js/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
$('<div class="dropdown-backdrop"/>').insertAfter($(this)).on('click', clearMenus)
}

$parent.trigger(e = $.Event('show.bs.dropdown'))
var relatedTarget = { relatedTarget: this }
$parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget))

if (e.isDefaultPrevented()) return

$parent
.toggleClass('open')
.trigger('shown.bs.dropdown')
.trigger('shown.bs.dropdown', relatedTarget)

$this.focus()
}
Expand Down Expand Up @@ -79,14 +80,15 @@
$items.eq(index).focus()
}

function clearMenus() {
function clearMenus(e) {
$(backdrop).remove()
$(toggle).each(function (e) {
$(toggle).each(function () {
var $parent = getParent($(this))
var relatedTarget = { relatedTarget: this }
if (!$parent.hasClass('open')) return
$parent.trigger(e = $.Event('hide.bs.dropdown'))
$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
if (e.isDefaultPrevented()) return
$parent.removeClass('open').trigger('hidden.bs.dropdown')
$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
})
}

Expand Down

0 comments on commit 76f0d0f

Please sign in to comment.