Commit 9749d6af authored by Mark Otto's avatar Mark Otto

Merge branch '2.3.0-wip' of github.com:twitter/bootstrap into 2.3.0-wip

parents f74990d8 b9c7f291
...@@ -43,14 +43,14 @@ ...@@ -43,14 +43,14 @@
// tooltip demo // tooltip demo
$('.tooltip-demo').tooltip({ $('.tooltip-demo').tooltip({
selector: "a[rel=tooltip]" selector: "a[data-toggle=tooltip]"
}) })
$('.tooltip-test').tooltip() $('.tooltip-test').tooltip()
$('.popover-test').popover() $('.popover-test').popover()
// popover demo // popover demo
$("a[rel=popover]") $("a[data-toggle=popover]")
.popover() .popover()
.click(function(e) { .click(function(e) {
e.preventDefault() e.preventDefault()
......
...@@ -188,11 +188,18 @@ ...@@ -188,11 +188,18 @@
/* CAROUSEL DATA-API /* CAROUSEL DATA-API
* ================= */ * ================= */
$(document).on('click.carousel.data-api', '[data-slide]', function (e) { $(document).on('click.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
var $this = $(this), href var $this = $(this), href
, $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
, options = $.extend({}, $target.data(), $this.data()) , options = $.extend({}, $target.data(), $this.data())
, slideIndex
$target.carousel(options) $target.carousel(options)
if (slideIndex = $this.attr('data-slide-to')) {
$target.data('carousel').pause().to(slideIndex).cycle()
}
e.preventDefault() e.preventDefault()
}) })
......
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
return this.each(function () { return this.each(function () {
var $this = $(this) var $this = $(this)
, data = $this.data('collapse') , data = $this.data('collapse')
, options = typeof option == 'object' && option , options = $.extend({}, $.fn.collapse.defaults, $this.data(), typeof option == 'object' && option)
if (!data) $this.data('collapse', (data = new Collapse(this, options))) if (!data) $this.data('collapse', (data = new Collapse(this, options)))
if (typeof option == 'string') data[option]() if (typeof option == 'string') data[option]()
}) })
......
...@@ -81,7 +81,10 @@ ...@@ -81,7 +81,10 @@
isActive = $parent.hasClass('open') isActive = $parent.hasClass('open')
if (!isActive || (isActive && e.keyCode == 27)) return $this.click() if (!isActive || (isActive && e.keyCode == 27)) {
if (e.which == 27) $parent.find(toggle).focus()
return $this.click()
}
$items = $('[role=menu] li:not(.divider):visible a', $parent) $items = $('[role=menu] li:not(.divider):visible a', $parent)
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
, $href = /^#\w/.test(href) && $(href) , $href = /^#\w/.test(href) && $(href)
return ( $href return ( $href
&& $href.length && $href.length
&& [[ $href.position().top + self.$scrollElement.scrollTop(), href ]] ) || null && [[ $href.position().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]] ) || null
}) })
.sort(function (a, b) { return a[0] - b[0] }) .sort(function (a, b) { return a[0] - b[0] })
.each(function () { .each(function () {
......
...@@ -38,20 +38,28 @@ ...@@ -38,20 +38,28 @@
, init: function (type, element, options) { , init: function (type, element, options) {
var eventIn var eventIn
, eventOut , eventOut
, triggers
, trigger
, i
this.type = type this.type = type
this.$element = $(element) this.$element = $(element)
this.options = this.getOptions(options) this.options = this.getOptions(options)
this.enabled = true this.enabled = true
if (this.options.trigger == 'click') { triggers = this.options.trigger.split(' ')
for (i = triggers.length; i--;) {
trigger = triggers[i]
if (trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (this.options.trigger != 'manual') { } else if (trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus' eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur' eventOut = trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
} }
}
this.options.selector ? this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
...@@ -267,7 +275,7 @@ ...@@ -267,7 +275,7 @@
, placement: 'top' , placement: 'top'
, selector: false , selector: false
, template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
, trigger: 'hover' , trigger: 'hover focus'
, title: '' , title: ''
, delay: 0 , delay: 0
, html: false , html: false
......
...@@ -449,11 +449,18 @@ ...@@ -449,11 +449,18 @@
/* CAROUSEL DATA-API /* CAROUSEL DATA-API
* ================= */ * ================= */
$(document).on('click.carousel.data-api', '[data-slide]', function (e) { $(document).on('click.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
var $this = $(this), href var $this = $(this), href
, $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
, options = $.extend({}, $target.data(), $this.data()) , options = $.extend({}, $target.data(), $this.data())
, slideIndex
$target.carousel(options) $target.carousel(options)
if (slideIndex = $this.attr('data-slide-to')) {
$target.data('carousel').pause().to(slideIndex).cycle()
}
e.preventDefault() e.preventDefault()
}) })
...@@ -588,7 +595,7 @@ ...@@ -588,7 +595,7 @@
return this.each(function () { return this.each(function () {
var $this = $(this) var $this = $(this)
, data = $this.data('collapse') , data = $this.data('collapse')
, options = typeof option == 'object' && option , options = $.extend({}, $.fn.collapse.defaults, $this.data(), typeof option == 'object' && option)
if (!data) $this.data('collapse', (data = new Collapse(this, options))) if (!data) $this.data('collapse', (data = new Collapse(this, options)))
if (typeof option == 'string') data[option]() if (typeof option == 'string') data[option]()
}) })
...@@ -706,7 +713,10 @@ ...@@ -706,7 +713,10 @@
isActive = $parent.hasClass('open') isActive = $parent.hasClass('open')
if (!isActive || (isActive && e.keyCode == 27)) return $this.click() if (!isActive || (isActive && e.keyCode == 27)) {
if (e.which == 27) $parent.find(toggle).focus()
return $this.click()
}
$items = $('[role=menu] li:not(.divider):visible a', $parent) $items = $('[role=menu] li:not(.divider):visible a', $parent)
...@@ -1068,20 +1078,28 @@ ...@@ -1068,20 +1078,28 @@
, init: function (type, element, options) { , init: function (type, element, options) {
var eventIn var eventIn
, eventOut , eventOut
, triggers
, trigger
, i
this.type = type this.type = type
this.$element = $(element) this.$element = $(element)
this.options = this.getOptions(options) this.options = this.getOptions(options)
this.enabled = true this.enabled = true
if (this.options.trigger == 'click') { triggers = this.options.trigger.split(' ')
for (i = triggers.length; i--;) {
trigger = triggers[i]
if (trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (this.options.trigger != 'manual') { } else if (trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus' eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur' eventOut = trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
} }
}
this.options.selector ? this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
...@@ -1297,7 +1315,7 @@ ...@@ -1297,7 +1315,7 @@
, placement: 'top' , placement: 'top'
, selector: false , selector: false
, template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
, trigger: 'hover' , trigger: 'hover focus'
, title: '' , title: ''
, delay: 0 , delay: 0
, html: false , html: false
...@@ -1486,7 +1504,7 @@ ...@@ -1486,7 +1504,7 @@
, $href = /^#\w/.test(href) && $(href) , $href = /^#\w/.test(href) && $(href)
return ( $href return ( $href
&& $href.length && $href.length
&& [[ $href.position().top + self.$scrollElement.scrollTop(), href ]] ) || null && [[ $href.position().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]] ) || null
}) })
.sort(function (a, b) { return a[0] - b[0] }) .sort(function (a, b) { return a[0] - b[0] })
.each(function () { .each(function () {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -188,11 +188,18 @@ ...@@ -188,11 +188,18 @@
/* CAROUSEL DATA-API /* CAROUSEL DATA-API
* ================= */ * ================= */
$(document).on('click.carousel.data-api', '[data-slide]', function (e) { $(document).on('click.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
var $this = $(this), href var $this = $(this), href
, $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
, options = $.extend({}, $target.data(), $this.data()) , options = $.extend({}, $target.data(), $this.data())
, slideIndex
$target.carousel(options) $target.carousel(options)
if (slideIndex = $this.attr('data-slide-to')) {
$target.data('carousel').pause().to(slideIndex).cycle()
}
e.preventDefault() e.preventDefault()
}) })
......
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
return this.each(function () { return this.each(function () {
var $this = $(this) var $this = $(this)
, data = $this.data('collapse') , data = $this.data('collapse')
, options = typeof option == 'object' && option , options = $.extend({}, $.fn.collapse.defaults, $this.data(), typeof option == 'object' && option)
if (!data) $this.data('collapse', (data = new Collapse(this, options))) if (!data) $this.data('collapse', (data = new Collapse(this, options)))
if (typeof option == 'string') data[option]() if (typeof option == 'string') data[option]()
}) })
......
...@@ -81,7 +81,10 @@ ...@@ -81,7 +81,10 @@
isActive = $parent.hasClass('open') isActive = $parent.hasClass('open')
if (!isActive || (isActive && e.keyCode == 27)) return $this.click() if (!isActive || (isActive && e.keyCode == 27)) {
if (e.which == 27) $parent.find(toggle).focus()
return $this.click()
}
$items = $('[role=menu] li:not(.divider):visible a', $parent) $items = $('[role=menu] li:not(.divider):visible a', $parent)
...@@ -154,7 +157,7 @@ ...@@ -154,7 +157,7 @@
$(document) $(document)
.on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus) .on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus)
.on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) .on('click.dropdown.data-api touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
.on('touchstart.dropdown.data-api', '.dropdown-menu', function (e) { e.stopPropagation() }) .on('touchstart.dropdown.data-api', '.dropdown-menu', function (e) { e.stopPropagation() })
.on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle) .on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
.on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) .on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
, $href = /^#\w/.test(href) && $(href) , $href = /^#\w/.test(href) && $(href)
return ( $href return ( $href
&& $href.length && $href.length
&& [[ $href.position().top + self.$scrollElement.scrollTop(), href ]] ) || null && [[ $href.position().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]] ) || null
}) })
.sort(function (a, b) { return a[0] - b[0] }) .sort(function (a, b) { return a[0] - b[0] })
.each(function () { .each(function () {
......
...@@ -38,20 +38,28 @@ ...@@ -38,20 +38,28 @@
, init: function (type, element, options) { , init: function (type, element, options) {
var eventIn var eventIn
, eventOut , eventOut
, triggers
, trigger
, i
this.type = type this.type = type
this.$element = $(element) this.$element = $(element)
this.options = this.getOptions(options) this.options = this.getOptions(options)
this.enabled = true this.enabled = true
if (this.options.trigger == 'click') { triggers = this.options.trigger.split(' ')
for (i = triggers.length; i--;) {
trigger = triggers[i]
if (trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (this.options.trigger != 'manual') { } else if (trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus' eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur' eventOut = trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
} }
}
this.options.selector ? this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
...@@ -102,8 +110,11 @@ ...@@ -102,8 +110,11 @@
, actualHeight , actualHeight
, placement , placement
, tp , tp
, e = $.Event('show')
if (this.hasContent() && this.enabled) { if (this.hasContent() && this.enabled) {
this.$element.trigger(e)
if (e.isDefaultPrevented()) return
$tip = this.tip() $tip = this.tip()
this.setContent() this.setContent()
...@@ -118,7 +129,8 @@ ...@@ -118,7 +129,8 @@
$tip $tip
.detach() .detach()
.css({ top: 0, left: 0, display: 'block' }) .css({ top: 0, left: 0, display: 'block' })
.insertAfter(this.$element)
this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
pos = this.getPosition() pos = this.getPosition()
...@@ -144,6 +156,8 @@ ...@@ -144,6 +156,8 @@
.offset(tp) .offset(tp)
.addClass(placement) .addClass(placement)
.addClass('in') .addClass('in')
this.$element.trigger('shown')
} }
} }
...@@ -158,6 +172,10 @@ ...@@ -158,6 +172,10 @@
, hide: function () { , hide: function () {
var that = this var that = this
, $tip = this.tip() , $tip = this.tip()
, e = $.Event('hide')
this.$element.trigger(e)
if (e.isDefaultPrevented()) return
$tip.removeClass('in') $tip.removeClass('in')
...@@ -176,6 +194,8 @@ ...@@ -176,6 +194,8 @@
removeWithAnimation() : removeWithAnimation() :
$tip.detach() $tip.detach()
this.$element.trigger('hidden')
return this return this
} }
...@@ -234,8 +254,8 @@ ...@@ -234,8 +254,8 @@
} }
, toggle: function (e) { , toggle: function (e) {
var self = $(e.currentTarget)[this.type](this._options).data(this.type) var self = e ? $(e.currentTarget)[this.type](this._options).data(this.type) : this
self[self.tip().hasClass('in') ? 'hide' : 'show']() self.tip().hasClass('in') ? self.hide() : self.show()
} }
, destroy: function () { , destroy: function () {
...@@ -267,10 +287,11 @@ ...@@ -267,10 +287,11 @@
, placement: 'top' , placement: 'top'
, selector: false , selector: false
, template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
, trigger: 'hover' , trigger: 'hover focus'
, title: '' , title: ''
, delay: 0 , delay: 0
, html: false , html: false
, container: false
} }
......
...@@ -66,6 +66,83 @@ $(function () { ...@@ -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')
...@@ -156,4 +233,22 @@ $(function () { ...@@ -156,4 +233,22 @@ $(function () {
div.find('a').trigger('click') div.find('a').trigger('click')
ok($(".tooltip").is('.fade.in'), 'tooltip is faded in') ok($(".tooltip").is('.fade.in'), 'tooltip is faded in')
}) })
test("should show tooltip when toggle is called", function () {
var tooltip = $('<a href="#" rel="tooltip" title="tooltip on toggle"></a>')
.appendTo('#qunit-fixture')
.tooltip({trigger: 'manual'})
.tooltip('toggle')
ok($(".tooltip").is('.fade.in'), 'tooltip should be toggled in')
})
test("should place tooltips inside the body", function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
.tooltip({container:'body'})
.tooltip('show')
ok($("body > .tooltip").length, 'inside the body')
ok(!$("#qunit-fixture > .tooltip").length, 'not found in parent')
tooltip.tooltip('hide')
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment