diff --git a/docs/assets/bootstrap.zip b/docs/assets/bootstrap.zip index 8ad9a0695f..594fb24db8 100644 Binary files a/docs/assets/bootstrap.zip and b/docs/assets/bootstrap.zip differ diff --git a/docs/assets/js/bootstrap-alert.js b/docs/assets/js/bootstrap-alert.js index d17f44e150..7a1607da15 100644 --- a/docs/assets/js/bootstrap-alert.js +++ b/docs/assets/js/bootstrap-alert.js @@ -45,15 +45,16 @@ } $parent = $(selector) - $parent.trigger('close') e && e.preventDefault() $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) - $parent - .trigger('close') - .removeClass('in') + $parent.trigger(e = $.Event('close')) + + if (e.isDefaultPrevented()) return + + $parent.removeClass('in') function removeElement() { $parent diff --git a/docs/assets/js/bootstrap-carousel.js b/docs/assets/js/bootstrap-carousel.js index 7db5bea333..8ce7418d22 100644 --- a/docs/assets/js/bootstrap-carousel.js +++ b/docs/assets/js/bootstrap-carousel.js @@ -86,6 +86,7 @@ , direction = type == 'next' ? 'left' : 'right' , fallback = type == 'next' ? 'first' : 'last' , that = this + , e = $.Event('slide') this.sliding = true @@ -96,11 +97,12 @@ if ($next.hasClass('active')) return if ($.support.transition && this.$element.hasClass('slide')) { + this.$element.trigger(e) + if (e.isDefaultPrevented()) return $next.addClass(type) $next[0].offsetWidth // force reflow $active.addClass(direction) $next.addClass(direction) - this.$element.trigger('slide') this.$element.one($.support.transition.end, function () { $next.removeClass([type, direction].join(' ')).addClass('active') $active.removeClass(['active', direction].join(' ')) @@ -108,7 +110,8 @@ setTimeout(function () { that.$element.trigger('slid') }, 0) }) } else { - this.$element.trigger('slide') + this.$element.trigger(e) + if (e.isDefaultPrevented()) return $active.removeClass('active') $next.addClass('active') this.sliding = false diff --git a/docs/assets/js/bootstrap-collapse.js b/docs/assets/js/bootstrap-collapse.js index 16b91eb244..478eea3912 100644 --- a/docs/assets/js/bootstrap-collapse.js +++ b/docs/assets/js/bootstrap-collapse.js @@ -61,7 +61,7 @@ } this.$element[dimension](0) - this.transition('addClass', 'show', 'shown') + this.transition('addClass', $.Event('show'), 'shown') this.$element[dimension](this.$element[0][scroll]) } @@ -70,7 +70,7 @@ if (this.transitioning) return dimension = this.dimension() this.reset(this.$element[dimension]()) - this.transition('removeClass', 'hide', 'hidden') + this.transition('removeClass', $.Event('hide'), 'hidden') this.$element[dimension](0) } @@ -95,11 +95,13 @@ that.$element.trigger(completeEvent) } + this.$element.trigger(startEvent) + + if (startEvent.isDefaultPrevented()) return + this.transitioning = 1 - this.$element - .trigger(startEvent) - [method]('in') + this.$element[method]('in') $.support.transition && this.$element.hasClass('collapse') ? this.$element.one($.support.transition.end, complete) : diff --git a/docs/assets/js/bootstrap-scrollspy.js b/docs/assets/js/bootstrap-scrollspy.js index bd3f106044..c02e263b0e 100644 --- a/docs/assets/js/bootstrap-scrollspy.js +++ b/docs/assets/js/bootstrap-scrollspy.js @@ -46,8 +46,8 @@ var self = this , $targets - this.offsets = [] - this.targets = [] + this.offsets = $([]) + this.targets = $([]) $targets = this.$body .find(this.selector) diff --git a/docs/assets/js/bootstrap-tab.js b/docs/assets/js/bootstrap-tab.js index b3938f6714..974cc0aca2 100644 --- a/docs/assets/js/bootstrap-tab.js +++ b/docs/assets/js/bootstrap-tab.js @@ -39,6 +39,7 @@ , selector = $this.attr('data-target') , previous , $target + , e if (!selector) { selector = $this.attr('href') @@ -49,11 +50,14 @@ previous = $ul.find('.active a').last()[0] - $this.trigger({ - type: 'show' - , relatedTarget: previous + e = $.Event('show', { + relatedTarget: previous }) + $this.trigger(e) + + if (e.isDefaultPrevented()) return + $target = $(selector) this.activate($this.parent('li'), $ul) diff --git a/js/bootstrap-alert.js b/js/bootstrap-alert.js index d17f44e150..7a1607da15 100644 --- a/js/bootstrap-alert.js +++ b/js/bootstrap-alert.js @@ -45,15 +45,16 @@ } $parent = $(selector) - $parent.trigger('close') e && e.preventDefault() $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent()) - $parent - .trigger('close') - .removeClass('in') + $parent.trigger(e = $.Event('close')) + + if (e.isDefaultPrevented()) return + + $parent.removeClass('in') function removeElement() { $parent diff --git a/js/bootstrap-carousel.js b/js/bootstrap-carousel.js index 7db5bea333..8ce7418d22 100644 --- a/js/bootstrap-carousel.js +++ b/js/bootstrap-carousel.js @@ -86,6 +86,7 @@ , direction = type == 'next' ? 'left' : 'right' , fallback = type == 'next' ? 'first' : 'last' , that = this + , e = $.Event('slide') this.sliding = true @@ -96,11 +97,12 @@ if ($next.hasClass('active')) return if ($.support.transition && this.$element.hasClass('slide')) { + this.$element.trigger(e) + if (e.isDefaultPrevented()) return $next.addClass(type) $next[0].offsetWidth // force reflow $active.addClass(direction) $next.addClass(direction) - this.$element.trigger('slide') this.$element.one($.support.transition.end, function () { $next.removeClass([type, direction].join(' ')).addClass('active') $active.removeClass(['active', direction].join(' ')) @@ -108,7 +110,8 @@ setTimeout(function () { that.$element.trigger('slid') }, 0) }) } else { - this.$element.trigger('slide') + this.$element.trigger(e) + if (e.isDefaultPrevented()) return $active.removeClass('active') $next.addClass('active') this.sliding = false diff --git a/js/bootstrap-collapse.js b/js/bootstrap-collapse.js index 16b91eb244..478eea3912 100644 --- a/js/bootstrap-collapse.js +++ b/js/bootstrap-collapse.js @@ -61,7 +61,7 @@ } this.$element[dimension](0) - this.transition('addClass', 'show', 'shown') + this.transition('addClass', $.Event('show'), 'shown') this.$element[dimension](this.$element[0][scroll]) } @@ -70,7 +70,7 @@ if (this.transitioning) return dimension = this.dimension() this.reset(this.$element[dimension]()) - this.transition('removeClass', 'hide', 'hidden') + this.transition('removeClass', $.Event('hide'), 'hidden') this.$element[dimension](0) } @@ -95,11 +95,13 @@ that.$element.trigger(completeEvent) } + this.$element.trigger(startEvent) + + if (startEvent.isDefaultPrevented()) return + this.transitioning = 1 - this.$element - .trigger(startEvent) - [method]('in') + this.$element[method]('in') $.support.transition && this.$element.hasClass('collapse') ? this.$element.one($.support.transition.end, complete) : diff --git a/js/bootstrap-scrollspy.js b/js/bootstrap-scrollspy.js index bd3f106044..c02e263b0e 100644 --- a/js/bootstrap-scrollspy.js +++ b/js/bootstrap-scrollspy.js @@ -46,8 +46,8 @@ var self = this , $targets - this.offsets = [] - this.targets = [] + this.offsets = $([]) + this.targets = $([]) $targets = this.$body .find(this.selector) diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js index b3938f6714..974cc0aca2 100644 --- a/js/bootstrap-tab.js +++ b/js/bootstrap-tab.js @@ -39,6 +39,7 @@ , selector = $this.attr('data-target') , previous , $target + , e if (!selector) { selector = $this.attr('href') @@ -49,11 +50,14 @@ previous = $ul.find('.active a').last()[0] - $this.trigger({ - type: 'show' - , relatedTarget: previous + e = $.Event('show', { + relatedTarget: previous }) + $this.trigger(e) + + if (e.isDefaultPrevented()) return + $target = $(selector) this.activate($this.parent('li'), $ul) diff --git a/js/tests/index.html b/js/tests/index.html index 2d59ab0321..3e6cb9777c 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -15,6 +15,7 @@ + @@ -28,6 +29,7 @@ + diff --git a/js/tests/unit/bootstrap-alert.js b/js/tests/unit/bootstrap-alert.js index e607f43402..7f24e0e6be 100644 --- a/js/tests/unit/bootstrap-alert.js +++ b/js/tests/unit/bootstrap-alert.js @@ -38,4 +38,19 @@ $(function () { ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom') }) + test("should not fire closed when close is prevented", function () { + $.support.transition = false + stop(); + $('
') + .bind('close', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('closed', function () { + ok(false); + }) + .alert('close') + }) + }) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-carousel.js b/js/tests/unit/bootstrap-carousel.js new file mode 100644 index 0000000000..92c23e227c --- /dev/null +++ b/js/tests/unit/bootstrap-carousel.js @@ -0,0 +1,28 @@ +$(function () { + + module("bootstrap-carousel") + + test("should be defined on jquery object", function () { + ok($(document.body).carousel, 'carousel method is defined') + }) + + test("should return element", function () { + ok($(document.body).carousel()[0] == document.body, 'document.body returned') + }) + + test("should not fire sliden when slide is prevented", function () { + $.support.transition = false + stop(); + $('') + .bind('slide', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('slid', function () { + ok(false); + }) + .carousel('next') + }) + +}) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-collapse.js b/js/tests/unit/bootstrap-collapse.js index 698238d96b..8e52898b5d 100644 --- a/js/tests/unit/bootstrap-collapse.js +++ b/js/tests/unit/bootstrap-collapse.js @@ -22,4 +22,19 @@ $(function () { ok(/height/.test(el.attr('style')), 'has height set') }) + test("should not fire shown when show is prevented", function () { + $.support.transition = false + stop(); + $('') + .bind('show', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('shown', function () { + ok(false); + }) + .collapse('show') + }) + }) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-tab.js b/js/tests/unit/bootstrap-tab.js index 18f490fa5e..9878047810 100644 --- a/js/tests/unit/bootstrap-tab.js +++ b/js/tests/unit/bootstrap-tab.js @@ -42,4 +42,20 @@ $(function () { equals($("#qunit-fixture").find('.active').attr('id'), "home") }) + + test("should not fire closed when close is prevented", function () { + $.support.transition = false + stop(); + $('') + .bind('show', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('shown', function () { + ok(false); + }) + .tab('show') + }) + }) \ No newline at end of file