Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorMark Otto <otto@github.com>2012-12-26 19:21:34 +0400
committerMark Otto <otto@github.com>2012-12-26 19:21:34 +0400
commit9749d6afc2730d41cab0111e1cc19bba7c5c3676 (patch)
tree5420af50b680ac608d6ed177d24d79870dcad544 /js
parentf74990d898b08be61f0f8b514378adf223d55a4b (diff)
parentb9c7f29134f2fa81931fa4663fc40ef7a0e363d1 (diff)
Merge branch '2.3.0-wip' of github.com:twitter/bootstrap into 2.3.0-wip
Diffstat (limited to 'js')
-rw-r--r--js/bootstrap-carousel.js9
-rw-r--r--js/bootstrap-collapse.js2
-rw-r--r--js/bootstrap-dropdown.js7
-rw-r--r--js/bootstrap-scrollspy.js2
-rw-r--r--js/bootstrap-tooltip.js45
-rw-r--r--js/tests/unit/bootstrap-tooltip.js97
6 files changed, 144 insertions, 18 deletions
diff --git a/js/bootstrap-carousel.js b/js/bootstrap-carousel.js
index cb006cfdbc..5d14e7c711 100644
--- a/js/bootstrap-carousel.js
+++ b/js/bootstrap-carousel.js
@@ -188,11 +188,18 @@
/* 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
, $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
, options = $.extend({}, $target.data(), $this.data())
+ , slideIndex
+
$target.carousel(options)
+
+ if (slideIndex = $this.attr('data-slide-to')) {
+ $target.data('carousel').pause().to(slideIndex).cycle()
+ }
+
e.preventDefault()
})
diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js
index 9f0a3f622d..20b2eb90a8 100644
--- a/js/bootstrap-collapse.js
+++ b/js/bootstrap-collapse.js
@@ -129,7 +129,7 @@
return this.each(function () {
var $this = $(this)
, 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 (typeof option == 'string') data[option]()
})
diff --git a/js/bootstrap-dropdown.js b/js/bootstrap-dropdown.js
index bc421884fe..b8c5852830 100644
--- a/js/bootstrap-dropdown.js
+++ b/js/bootstrap-dropdown.js
@@ -81,7 +81,10 @@
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)
@@ -154,7 +157,7 @@
$(document)
.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('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)
diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js
index 54647277fe..dff9a3b375 100644
--- a/js/bootstrap-scrollspy.js
+++ b/js/bootstrap-scrollspy.js
@@ -59,7 +59,7 @@
, $href = /^#\w/.test(href) && $(href)
return ( $href
&& $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] })
.each(function () {
diff --git a/js/bootstrap-tooltip.js b/js/bootstrap-tooltip.js
index e08604940d..c23d8267a8 100644
--- a/js/bootstrap-tooltip.js
+++ b/js/bootstrap-tooltip.js
@@ -38,19 +38,27 @@
, init: function (type, element, options) {
var eventIn
, eventOut
+ , triggers
+ , trigger
+ , i
this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.enabled = true
- if (this.options.trigger == 'click') {
- this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
- } else if (this.options.trigger != 'manual') {
- eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
- eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
- 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))
+ 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))
+ } else if (trigger != 'manual') {
+ eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
+ eventOut = trigger == 'hover' ? 'mouseleave' : 'blur'
+ 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.options.selector ?
@@ -102,8 +110,11 @@
, actualHeight
, placement
, tp
+ , e = $.Event('show')
if (this.hasContent() && this.enabled) {
+ this.$element.trigger(e)
+ if (e.isDefaultPrevented()) return
$tip = this.tip()
this.setContent()
@@ -118,7 +129,8 @@
$tip
.detach()
.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()
@@ -144,6 +156,8 @@
.offset(tp)
.addClass(placement)
.addClass('in')
+
+ this.$element.trigger('shown')
}
}
@@ -158,6 +172,10 @@
, hide: function () {
var that = this
, $tip = this.tip()
+ , e = $.Event('hide')
+
+ this.$element.trigger(e)
+ if (e.isDefaultPrevented()) return
$tip.removeClass('in')
@@ -176,6 +194,8 @@
removeWithAnimation() :
$tip.detach()
+ this.$element.trigger('hidden')
+
return this
}
@@ -234,8 +254,8 @@
}
, toggle: function (e) {
- var self = $(e.currentTarget)[this.type](this._options).data(this.type)
- self[self.tip().hasClass('in') ? 'hide' : 'show']()
+ var self = e ? $(e.currentTarget)[this.type](this._options).data(this.type) : this
+ self.tip().hasClass('in') ? self.hide() : self.show()
}
, destroy: function () {
@@ -267,10 +287,11 @@
, placement: 'top'
, selector: false
, template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
- , trigger: 'hover'
+ , trigger: 'hover focus'
, title: ''
, delay: 0
, html: false
+ , container: false
}
@@ -282,4 +303,4 @@
return this
}
-}(window.jQuery); \ No newline at end of file
+}(window.jQuery);
diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js
index ba51347433..ef21bd96b4 100644
--- a/js/tests/unit/bootstrap-tooltip.js
+++ b/js/tests/unit/bootstrap-tooltip.js
@@ -66,6 +66,83 @@ $(function () {
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 () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
@@ -156,4 +233,22 @@ $(function () {
div.find('a').trigger('click')
ok($(".tooltip").is('.fade.in'), 'tooltip is faded in')
})
-}) \ No newline at end of file
+
+ 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')
+ })
+})