mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
Tooltips fires show, shown, hide, hidden events
It is re-worked from #3691.
This commit is contained in:
parent
48211ad9f5
commit
7a3a88acc6
2 changed files with 88 additions and 0 deletions
11
js/bootstrap-tooltip.js
vendored
11
js/bootstrap-tooltip.js
vendored
|
@ -110,8 +110,11 @@
|
||||||
, actualHeight
|
, actualHeight
|
||||||
, placement
|
, placement
|
||||||
, tp
|
, tp
|
||||||
|
, e
|
||||||
|
|
||||||
if (this.hasContent() && this.enabled) {
|
if (this.hasContent() && this.enabled) {
|
||||||
|
this.$element.trigger(e = $.Event('show'))
|
||||||
|
if (e.isDefaultPrevented()) return
|
||||||
$tip = this.tip()
|
$tip = this.tip()
|
||||||
this.setContent()
|
this.setContent()
|
||||||
|
|
||||||
|
@ -152,6 +155,8 @@
|
||||||
.offset(tp)
|
.offset(tp)
|
||||||
.addClass(placement)
|
.addClass(placement)
|
||||||
.addClass('in')
|
.addClass('in')
|
||||||
|
|
||||||
|
this.$element.trigger('shown')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +171,10 @@
|
||||||
, hide: function () {
|
, hide: function () {
|
||||||
var that = this
|
var that = this
|
||||||
, $tip = this.tip()
|
, $tip = this.tip()
|
||||||
|
, e
|
||||||
|
|
||||||
|
this.$element.trigger(e = $.Event('hide'))
|
||||||
|
if (e.isDefaultPrevented()) return
|
||||||
|
|
||||||
$tip.removeClass('in')
|
$tip.removeClass('in')
|
||||||
|
|
||||||
|
@ -184,6 +193,8 @@
|
||||||
removeWithAnimation() :
|
removeWithAnimation() :
|
||||||
$tip.detach()
|
$tip.detach()
|
||||||
|
|
||||||
|
this.$element.trigger('hidden')
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
77
js/tests/unit/bootstrap-tooltip.js
vendored
77
js/tests/unit/bootstrap-tooltip.js
vendored
|
@ -66,6 +66,83 @@ $(function () {
|
||||||
ok(!$(".tooltip").length, 'tooltip removed')
|
ok(!$(".tooltip").length, 'tooltip removed')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("should fire show event", function () {
|
||||||
|
stop()
|
||||||
|
var tooltip = $('<div title="tooltip title"></div>')
|
||||||
|
.bind("show", function() {
|
||||||
|
ok(true, "show was called")
|
||||||
|
start()
|
||||||
|
})
|
||||||
|
.tooltip('show')
|
||||||
|
})
|
||||||
|
|
||||||
|
test("should fire shown event", function () {
|
||||||
|
stop()
|
||||||
|
var tooltip = $('<div title="tooltip title"></div>')
|
||||||
|
.bind("shown", function() {
|
||||||
|
ok(true, "shown was called")
|
||||||
|
start()
|
||||||
|
})
|
||||||
|
.tooltip('show')
|
||||||
|
})
|
||||||
|
|
||||||
|
test("should not fire shown event when default prevented", function () {
|
||||||
|
stop()
|
||||||
|
var tooltip = $('<div title="tooltip title"></div>')
|
||||||
|
.bind("show", function(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
ok(true, "show was called")
|
||||||
|
start()
|
||||||
|
})
|
||||||
|
.bind("shown", function() {
|
||||||
|
ok(false, "shown was called")
|
||||||
|
})
|
||||||
|
.tooltip('show')
|
||||||
|
})
|
||||||
|
|
||||||
|
test("should fire hide event", function () {
|
||||||
|
stop()
|
||||||
|
var tooltip = $('<div title="tooltip title"></div>')
|
||||||
|
.bind("shown", function() {
|
||||||
|
$(this).tooltip('hide')
|
||||||
|
})
|
||||||
|
.bind("hide", function() {
|
||||||
|
ok(true, "hide was called")
|
||||||
|
start()
|
||||||
|
})
|
||||||
|
.tooltip('show')
|
||||||
|
})
|
||||||
|
|
||||||
|
test("should fire hidden event", function () {
|
||||||
|
stop()
|
||||||
|
var tooltip = $('<div title="tooltip title"></div>')
|
||||||
|
.bind("shown", function() {
|
||||||
|
$(this).tooltip('hide')
|
||||||
|
})
|
||||||
|
.bind("hidden", function() {
|
||||||
|
ok(true, "hidden was called")
|
||||||
|
start()
|
||||||
|
})
|
||||||
|
.tooltip('show')
|
||||||
|
})
|
||||||
|
|
||||||
|
test("should not fire hidden event when default prevented", function () {
|
||||||
|
stop()
|
||||||
|
var tooltip = $('<div title="tooltip title"></div>')
|
||||||
|
.bind("shown", function() {
|
||||||
|
$(this).tooltip('hide')
|
||||||
|
})
|
||||||
|
.bind("hide", function(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
ok(true, "hide was called")
|
||||||
|
start()
|
||||||
|
})
|
||||||
|
.bind("hidden", function() {
|
||||||
|
ok(false, "hidden was called")
|
||||||
|
})
|
||||||
|
.tooltip('show')
|
||||||
|
})
|
||||||
|
|
||||||
test("should not show tooltip if leave event occurs before delay expires", function () {
|
test("should not show tooltip if leave event occurs before delay expires", function () {
|
||||||
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
|
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
|
||||||
.appendTo('#qunit-fixture')
|
.appendTo('#qunit-fixture')
|
||||||
|
|
Loading…
Add table
Reference in a new issue