aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2013-05-27 19:23:17 -0700
committerMark Otto <[email protected]>2013-05-27 19:23:17 -0700
commit8899c30f16a32f1c3237242abf5e1bde5d88d0ca (patch)
tree47b8b4f0e38af1f48c1c632982aed23e799d4e03 /js
parent60575dfb461d5e01d36b564dccc55ef260982081 (diff)
parenta7a87c8e8c3343f6d9dea868d578178de8907f98 (diff)
downloadbootstrap-8899c30f16a32f1c3237242abf5e1bde5d88d0ca.tar.xz
bootstrap-8899c30f16a32f1c3237242abf5e1bde5d88d0ca.zip
Merge branch '3.0.0-wip' of github.com:twitter/bootstrap into 3.0.0-wip
Diffstat (limited to 'js')
-rw-r--r--js/carousel.js11
-rw-r--r--js/collapse.js2
-rw-r--r--js/dropdown.js30
-rw-r--r--js/modal.js7
-rw-r--r--js/scrollspy.js2
-rw-r--r--js/tests/unit/dropdown.js67
-rw-r--r--js/tooltip.js19
7 files changed, 113 insertions, 25 deletions
diff --git a/js/carousel.js b/js/carousel.js
index f1d035e9a..0da8e41ca 100644
--- a/js/carousel.js
+++ b/js/carousel.js
@@ -185,8 +185,8 @@
// CAROUSEL DATA-API
// =================
- $(document).on('click.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
- var $this = $(this), href
+ $(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())
var slideIndex
@@ -200,4 +200,11 @@
e.preventDefault()
})
+ $(window).on('load', function () {
+ $('[data-ride="carousel"]').each(function () {
+ var $carousel = $(this)
+ $carousel.carousel($carousel.data())
+ })
+ })
+
}(window.jQuery);
diff --git a/js/collapse.js b/js/collapse.js
index e37f25592..f8b65b393 100644
--- a/js/collapse.js
+++ b/js/collapse.js
@@ -139,7 +139,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()
diff --git a/js/dropdown.js b/js/dropdown.js
index 39c4ad258..2bb789a79 100644
--- a/js/dropdown.js
+++ b/js/dropdown.js
@@ -26,10 +26,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) {
@@ -47,7 +44,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()
@@ -88,7 +92,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) {
@@ -137,9 +147,9 @@
$(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);
diff --git a/js/modal.js b/js/modal.js
index 9d6bf7339..07b508124 100644
--- a/js/modal.js
+++ b/js/modal.js
@@ -58,7 +58,7 @@
var transition = $.support.transition && that.$element.hasClass('fade')
if (!that.$element.parent().length) {
- that.$element.appendTo(document.body) //don't move modals dom position
+ that.$element.appendTo(document.body) // don't move modals dom position
}
that.$element.show()
@@ -76,7 +76,6 @@
transition ?
that.$element.one($.support.transition.end, function () { that.$element.focus().trigger('shown.bs.modal') }) :
that.$element.focus().trigger('shown.bs.modal')
-
})
}
@@ -105,7 +104,9 @@
}
Modal.prototype.enforceFocus = function () {
- $(document).on('focusin.bs.modal', function (e) {
+ $(document)
+ .off('focusin.bs.modal') // guard against infinite focus loop
+ .on('focusin.bs.modal', function (e) {
if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
this.$element.focus()
}
diff --git a/js/scrollspy.js b/js/scrollspy.js
index 41c17822c..8d1e72a87 100644
--- a/js/scrollspy.js
+++ b/js/scrollspy.js
@@ -29,7 +29,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
diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js
index 09b5673a4..e45bd0a46 100644
--- a/js/tests/unit/dropdown.js
+++ b/js/tests/unit/dropdown.js
@@ -149,4 +149,71 @@ $(function () {
$("#qunit-fixture").html("")
})
+ test("should fire show and hide event", function () {
+ var dropdownHTML = '<ul class="tabs">'
+ + '<li class="dropdown">'
+ + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
+ + '<ul class="dropdown-menu">'
+ + '<li><a href="#">Secondary link</a></li>'
+ + '<li><a href="#">Something else here</a></li>'
+ + '<li class="divider"></li>'
+ + '<li><a href="#">Another link</a></li>'
+ + '</ul>'
+ + '</li>'
+ + '</ul>'
+ , dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .dropdown()
+
+ stop()
+
+ dropdown
+ .parent('.dropdown')
+ .bind('show.bs.dropdown', function () {
+ ok(true, 'show was called')
+ })
+ .bind('hide.bs.dropdown', function () {
+ ok(true, 'hide was called')
+ start()
+ })
+
+ dropdown.click()
+ $(document.body).click()
+ })
+
+
+ test("should fire shown and hiden event", function () {
+ var dropdownHTML = '<ul class="tabs">'
+ + '<li class="dropdown">'
+ + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
+ + '<ul class="dropdown-menu">'
+ + '<li><a href="#">Secondary link</a></li>'
+ + '<li><a href="#">Something else here</a></li>'
+ + '<li class="divider"></li>'
+ + '<li><a href="#">Another link</a></li>'
+ + '</ul>'
+ + '</li>'
+ + '</ul>'
+ , dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .dropdown()
+
+ stop()
+
+ dropdown
+ .parent('.dropdown')
+ .bind('shown.bs.dropdown', function () {
+ ok(true, 'show was called')
+ })
+ .bind('hidden.bs.dropdown', function () {
+ ok(true, 'hide was called')
+ start()
+ })
+
+ dropdown.click()
+ $(document.body).click()
+ })
+
})
diff --git a/js/tooltip.js b/js/tooltip.js
index 80bdf7266..d95624bdc 100644
--- a/js/tooltip.js
+++ b/js/tooltip.js
@@ -91,7 +91,7 @@
return options
}
- Tooltip.prototype.enter = function (e) {
+ Tooltip.prototype.enter = function (obj) {
var defaults = this.getDefaults()
var options = {}
@@ -99,26 +99,29 @@
if (defaults[key] != value) options[key] = value
})
- var self = $(e.currentTarget)[this.type](options).data('bs.' + this.type)
+ var self = obj instanceof this.constructor ?
+ obj : $(obj.currentTarget)[this.type](options).data('bs.' + this.type)
if (!self.options.delay || !self.options.delay.show) return self.show()
clearTimeout(this.timeout)
self.hoverState = 'in'
- this.timeout = setTimeout(function() {
+ this.timeout = setTimeout(function () {
if (self.hoverState == 'in') self.show()
}, self.options.delay.show)
}
- Tooltip.prototype.leave = function (e) {
- var self = $(e.currentTarget)[this.type](this._options).data('bs.' + this.type)
+ Tooltip.prototype.leave = function (obj) {
+ var self = obj instanceof this.constructor ?
+ obj : $(obj.currentTarget)[this.type](this._options).data('bs.' + this.type)
+
+ clearTimeout(this.timeout)
- if (this.timeout) clearTimeout(this.timeout)
if (!self.options.delay || !self.options.delay.hide) return self.hide()
self.hoverState = 'out'
- this.timeout = setTimeout(function() {
+ this.timeout = setTimeout(function () {
if (self.hoverState == 'out') self.hide()
}, self.options.delay.hide)
}
@@ -315,7 +318,7 @@
Tooltip.prototype.toggle = function (e) {
var self = e ? $(e.currentTarget)[this.type](this._options).data('bs.' + this.type) : this
- self.tip().hasClass('in') ? self.hide() : self.show()
+ self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
}
Tooltip.prototype.destroy = function () {