mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-11 08:04:59 +02:00
add preventDefault support for all inital event types (show, close, hide, etc.) + fix small bug with scrollspy.last
This commit is contained in:
Binary file not shown.
9
docs/assets/js/bootstrap-alert.js
vendored
9
docs/assets/js/bootstrap-alert.js
vendored
@@ -45,15 +45,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$parent = $(selector)
|
$parent = $(selector)
|
||||||
$parent.trigger('close')
|
|
||||||
|
|
||||||
e && e.preventDefault()
|
e && e.preventDefault()
|
||||||
|
|
||||||
$parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
|
$parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
|
||||||
|
|
||||||
$parent
|
$parent.trigger(e = $.Event('close'))
|
||||||
.trigger('close')
|
|
||||||
.removeClass('in')
|
if (e.isDefaultPrevented()) return
|
||||||
|
|
||||||
|
$parent.removeClass('in')
|
||||||
|
|
||||||
function removeElement() {
|
function removeElement() {
|
||||||
$parent
|
$parent
|
||||||
|
7
docs/assets/js/bootstrap-carousel.js
vendored
7
docs/assets/js/bootstrap-carousel.js
vendored
@@ -86,6 +86,7 @@
|
|||||||
, direction = type == 'next' ? 'left' : 'right'
|
, direction = type == 'next' ? 'left' : 'right'
|
||||||
, fallback = type == 'next' ? 'first' : 'last'
|
, fallback = type == 'next' ? 'first' : 'last'
|
||||||
, that = this
|
, that = this
|
||||||
|
, e = $.Event('slide')
|
||||||
|
|
||||||
this.sliding = true
|
this.sliding = true
|
||||||
|
|
||||||
@@ -96,11 +97,12 @@
|
|||||||
if ($next.hasClass('active')) return
|
if ($next.hasClass('active')) return
|
||||||
|
|
||||||
if ($.support.transition && this.$element.hasClass('slide')) {
|
if ($.support.transition && this.$element.hasClass('slide')) {
|
||||||
|
this.$element.trigger(e)
|
||||||
|
if (e.isDefaultPrevented()) return
|
||||||
$next.addClass(type)
|
$next.addClass(type)
|
||||||
$next[0].offsetWidth // force reflow
|
$next[0].offsetWidth // force reflow
|
||||||
$active.addClass(direction)
|
$active.addClass(direction)
|
||||||
$next.addClass(direction)
|
$next.addClass(direction)
|
||||||
this.$element.trigger('slide')
|
|
||||||
this.$element.one($.support.transition.end, function () {
|
this.$element.one($.support.transition.end, function () {
|
||||||
$next.removeClass([type, direction].join(' ')).addClass('active')
|
$next.removeClass([type, direction].join(' ')).addClass('active')
|
||||||
$active.removeClass(['active', direction].join(' '))
|
$active.removeClass(['active', direction].join(' '))
|
||||||
@@ -108,7 +110,8 @@
|
|||||||
setTimeout(function () { that.$element.trigger('slid') }, 0)
|
setTimeout(function () { that.$element.trigger('slid') }, 0)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.$element.trigger('slide')
|
this.$element.trigger(e)
|
||||||
|
if (e.isDefaultPrevented()) return
|
||||||
$active.removeClass('active')
|
$active.removeClass('active')
|
||||||
$next.addClass('active')
|
$next.addClass('active')
|
||||||
this.sliding = false
|
this.sliding = false
|
||||||
|
12
docs/assets/js/bootstrap-collapse.js
vendored
12
docs/assets/js/bootstrap-collapse.js
vendored
@@ -61,7 +61,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.$element[dimension](0)
|
this.$element[dimension](0)
|
||||||
this.transition('addClass', 'show', 'shown')
|
this.transition('addClass', $.Event('show'), 'shown')
|
||||||
this.$element[dimension](this.$element[0][scroll])
|
this.$element[dimension](this.$element[0][scroll])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
if (this.transitioning) return
|
if (this.transitioning) return
|
||||||
dimension = this.dimension()
|
dimension = this.dimension()
|
||||||
this.reset(this.$element[dimension]())
|
this.reset(this.$element[dimension]())
|
||||||
this.transition('removeClass', 'hide', 'hidden')
|
this.transition('removeClass', $.Event('hide'), 'hidden')
|
||||||
this.$element[dimension](0)
|
this.$element[dimension](0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,11 +95,13 @@
|
|||||||
that.$element.trigger(completeEvent)
|
that.$element.trigger(completeEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$element.trigger(startEvent)
|
||||||
|
|
||||||
|
if (startEvent.isDefaultPrevented()) return
|
||||||
|
|
||||||
this.transitioning = 1
|
this.transitioning = 1
|
||||||
|
|
||||||
this.$element
|
this.$element[method]('in')
|
||||||
.trigger(startEvent)
|
|
||||||
[method]('in')
|
|
||||||
|
|
||||||
$.support.transition && this.$element.hasClass('collapse') ?
|
$.support.transition && this.$element.hasClass('collapse') ?
|
||||||
this.$element.one($.support.transition.end, complete) :
|
this.$element.one($.support.transition.end, complete) :
|
||||||
|
4
docs/assets/js/bootstrap-scrollspy.js
vendored
4
docs/assets/js/bootstrap-scrollspy.js
vendored
@@ -46,8 +46,8 @@
|
|||||||
var self = this
|
var self = this
|
||||||
, $targets
|
, $targets
|
||||||
|
|
||||||
this.offsets = []
|
this.offsets = $([])
|
||||||
this.targets = []
|
this.targets = $([])
|
||||||
|
|
||||||
$targets = this.$body
|
$targets = this.$body
|
||||||
.find(this.selector)
|
.find(this.selector)
|
||||||
|
10
docs/assets/js/bootstrap-tab.js
vendored
10
docs/assets/js/bootstrap-tab.js
vendored
@@ -39,6 +39,7 @@
|
|||||||
, selector = $this.attr('data-target')
|
, selector = $this.attr('data-target')
|
||||||
, previous
|
, previous
|
||||||
, $target
|
, $target
|
||||||
|
, e
|
||||||
|
|
||||||
if (!selector) {
|
if (!selector) {
|
||||||
selector = $this.attr('href')
|
selector = $this.attr('href')
|
||||||
@@ -49,11 +50,14 @@
|
|||||||
|
|
||||||
previous = $ul.find('.active a').last()[0]
|
previous = $ul.find('.active a').last()[0]
|
||||||
|
|
||||||
$this.trigger({
|
e = $.Event('show', {
|
||||||
type: 'show'
|
relatedTarget: previous
|
||||||
, relatedTarget: previous
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$this.trigger(e)
|
||||||
|
|
||||||
|
if (e.isDefaultPrevented()) return
|
||||||
|
|
||||||
$target = $(selector)
|
$target = $(selector)
|
||||||
|
|
||||||
this.activate($this.parent('li'), $ul)
|
this.activate($this.parent('li'), $ul)
|
||||||
|
9
js/bootstrap-alert.js
vendored
9
js/bootstrap-alert.js
vendored
@@ -45,15 +45,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$parent = $(selector)
|
$parent = $(selector)
|
||||||
$parent.trigger('close')
|
|
||||||
|
|
||||||
e && e.preventDefault()
|
e && e.preventDefault()
|
||||||
|
|
||||||
$parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
|
$parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
|
||||||
|
|
||||||
$parent
|
$parent.trigger(e = $.Event('close'))
|
||||||
.trigger('close')
|
|
||||||
.removeClass('in')
|
if (e.isDefaultPrevented()) return
|
||||||
|
|
||||||
|
$parent.removeClass('in')
|
||||||
|
|
||||||
function removeElement() {
|
function removeElement() {
|
||||||
$parent
|
$parent
|
||||||
|
7
js/bootstrap-carousel.js
vendored
7
js/bootstrap-carousel.js
vendored
@@ -86,6 +86,7 @@
|
|||||||
, direction = type == 'next' ? 'left' : 'right'
|
, direction = type == 'next' ? 'left' : 'right'
|
||||||
, fallback = type == 'next' ? 'first' : 'last'
|
, fallback = type == 'next' ? 'first' : 'last'
|
||||||
, that = this
|
, that = this
|
||||||
|
, e = $.Event('slide')
|
||||||
|
|
||||||
this.sliding = true
|
this.sliding = true
|
||||||
|
|
||||||
@@ -96,11 +97,12 @@
|
|||||||
if ($next.hasClass('active')) return
|
if ($next.hasClass('active')) return
|
||||||
|
|
||||||
if ($.support.transition && this.$element.hasClass('slide')) {
|
if ($.support.transition && this.$element.hasClass('slide')) {
|
||||||
|
this.$element.trigger(e)
|
||||||
|
if (e.isDefaultPrevented()) return
|
||||||
$next.addClass(type)
|
$next.addClass(type)
|
||||||
$next[0].offsetWidth // force reflow
|
$next[0].offsetWidth // force reflow
|
||||||
$active.addClass(direction)
|
$active.addClass(direction)
|
||||||
$next.addClass(direction)
|
$next.addClass(direction)
|
||||||
this.$element.trigger('slide')
|
|
||||||
this.$element.one($.support.transition.end, function () {
|
this.$element.one($.support.transition.end, function () {
|
||||||
$next.removeClass([type, direction].join(' ')).addClass('active')
|
$next.removeClass([type, direction].join(' ')).addClass('active')
|
||||||
$active.removeClass(['active', direction].join(' '))
|
$active.removeClass(['active', direction].join(' '))
|
||||||
@@ -108,7 +110,8 @@
|
|||||||
setTimeout(function () { that.$element.trigger('slid') }, 0)
|
setTimeout(function () { that.$element.trigger('slid') }, 0)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.$element.trigger('slide')
|
this.$element.trigger(e)
|
||||||
|
if (e.isDefaultPrevented()) return
|
||||||
$active.removeClass('active')
|
$active.removeClass('active')
|
||||||
$next.addClass('active')
|
$next.addClass('active')
|
||||||
this.sliding = false
|
this.sliding = false
|
||||||
|
12
js/bootstrap-collapse.js
vendored
12
js/bootstrap-collapse.js
vendored
@@ -61,7 +61,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.$element[dimension](0)
|
this.$element[dimension](0)
|
||||||
this.transition('addClass', 'show', 'shown')
|
this.transition('addClass', $.Event('show'), 'shown')
|
||||||
this.$element[dimension](this.$element[0][scroll])
|
this.$element[dimension](this.$element[0][scroll])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
if (this.transitioning) return
|
if (this.transitioning) return
|
||||||
dimension = this.dimension()
|
dimension = this.dimension()
|
||||||
this.reset(this.$element[dimension]())
|
this.reset(this.$element[dimension]())
|
||||||
this.transition('removeClass', 'hide', 'hidden')
|
this.transition('removeClass', $.Event('hide'), 'hidden')
|
||||||
this.$element[dimension](0)
|
this.$element[dimension](0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,11 +95,13 @@
|
|||||||
that.$element.trigger(completeEvent)
|
that.$element.trigger(completeEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$element.trigger(startEvent)
|
||||||
|
|
||||||
|
if (startEvent.isDefaultPrevented()) return
|
||||||
|
|
||||||
this.transitioning = 1
|
this.transitioning = 1
|
||||||
|
|
||||||
this.$element
|
this.$element[method]('in')
|
||||||
.trigger(startEvent)
|
|
||||||
[method]('in')
|
|
||||||
|
|
||||||
$.support.transition && this.$element.hasClass('collapse') ?
|
$.support.transition && this.$element.hasClass('collapse') ?
|
||||||
this.$element.one($.support.transition.end, complete) :
|
this.$element.one($.support.transition.end, complete) :
|
||||||
|
4
js/bootstrap-scrollspy.js
vendored
4
js/bootstrap-scrollspy.js
vendored
@@ -46,8 +46,8 @@
|
|||||||
var self = this
|
var self = this
|
||||||
, $targets
|
, $targets
|
||||||
|
|
||||||
this.offsets = []
|
this.offsets = $([])
|
||||||
this.targets = []
|
this.targets = $([])
|
||||||
|
|
||||||
$targets = this.$body
|
$targets = this.$body
|
||||||
.find(this.selector)
|
.find(this.selector)
|
||||||
|
10
js/bootstrap-tab.js
vendored
10
js/bootstrap-tab.js
vendored
@@ -39,6 +39,7 @@
|
|||||||
, selector = $this.attr('data-target')
|
, selector = $this.attr('data-target')
|
||||||
, previous
|
, previous
|
||||||
, $target
|
, $target
|
||||||
|
, e
|
||||||
|
|
||||||
if (!selector) {
|
if (!selector) {
|
||||||
selector = $this.attr('href')
|
selector = $this.attr('href')
|
||||||
@@ -49,11 +50,14 @@
|
|||||||
|
|
||||||
previous = $ul.find('.active a').last()[0]
|
previous = $ul.find('.active a').last()[0]
|
||||||
|
|
||||||
$this.trigger({
|
e = $.Event('show', {
|
||||||
type: 'show'
|
relatedTarget: previous
|
||||||
, relatedTarget: previous
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$this.trigger(e)
|
||||||
|
|
||||||
|
if (e.isDefaultPrevented()) return
|
||||||
|
|
||||||
$target = $(selector)
|
$target = $(selector)
|
||||||
|
|
||||||
this.activate($this.parent('li'), $ul)
|
this.activate($this.parent('li'), $ul)
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
<script src="../../js/bootstrap-transition.js"></script>
|
<script src="../../js/bootstrap-transition.js"></script>
|
||||||
<script src="../../js/bootstrap-alert.js"></script>
|
<script src="../../js/bootstrap-alert.js"></script>
|
||||||
<script src="../../js/bootstrap-button.js"></script>
|
<script src="../../js/bootstrap-button.js"></script>
|
||||||
|
<script src="../../js/bootstrap-carousel.js"></script>
|
||||||
<script src="../../js/bootstrap-collapse.js"></script>
|
<script src="../../js/bootstrap-collapse.js"></script>
|
||||||
<script src="../../js/bootstrap-dropdown.js"></script>
|
<script src="../../js/bootstrap-dropdown.js"></script>
|
||||||
<script src="../../js/bootstrap-modal.js"></script>
|
<script src="../../js/bootstrap-modal.js"></script>
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
<script src="unit/bootstrap-transition.js"></script>
|
<script src="unit/bootstrap-transition.js"></script>
|
||||||
<script src="unit/bootstrap-alert.js"></script>
|
<script src="unit/bootstrap-alert.js"></script>
|
||||||
<script src="unit/bootstrap-button.js"></script>
|
<script src="unit/bootstrap-button.js"></script>
|
||||||
|
<script src="unit/bootstrap-carousel.js"></script>
|
||||||
<script src="unit/bootstrap-collapse.js"></script>
|
<script src="unit/bootstrap-collapse.js"></script>
|
||||||
<script src="unit/bootstrap-dropdown.js"></script>
|
<script src="unit/bootstrap-dropdown.js"></script>
|
||||||
<script src="unit/bootstrap-modal.js"></script>
|
<script src="unit/bootstrap-modal.js"></script>
|
||||||
|
15
js/tests/unit/bootstrap-alert.js
vendored
15
js/tests/unit/bootstrap-alert.js
vendored
@@ -38,4 +38,19 @@ $(function () {
|
|||||||
ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom')
|
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();
|
||||||
|
$('<div class="alert"/>')
|
||||||
|
.bind('close', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
ok(true);
|
||||||
|
start();
|
||||||
|
})
|
||||||
|
.bind('closed', function () {
|
||||||
|
ok(false);
|
||||||
|
})
|
||||||
|
.alert('close')
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
28
js/tests/unit/bootstrap-carousel.js
vendored
Normal file
28
js/tests/unit/bootstrap-carousel.js
vendored
Normal file
@@ -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();
|
||||||
|
$('<div class="carousel"/>')
|
||||||
|
.bind('slide', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
ok(true);
|
||||||
|
start();
|
||||||
|
})
|
||||||
|
.bind('slid', function () {
|
||||||
|
ok(false);
|
||||||
|
})
|
||||||
|
.carousel('next')
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
15
js/tests/unit/bootstrap-collapse.js
vendored
15
js/tests/unit/bootstrap-collapse.js
vendored
@@ -22,4 +22,19 @@ $(function () {
|
|||||||
ok(/height/.test(el.attr('style')), 'has height set')
|
ok(/height/.test(el.attr('style')), 'has height set')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("should not fire shown when show is prevented", function () {
|
||||||
|
$.support.transition = false
|
||||||
|
stop();
|
||||||
|
$('<div class="collapse"/>')
|
||||||
|
.bind('show', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
ok(true);
|
||||||
|
start();
|
||||||
|
})
|
||||||
|
.bind('shown', function () {
|
||||||
|
ok(false);
|
||||||
|
})
|
||||||
|
.collapse('show')
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
16
js/tests/unit/bootstrap-tab.js
vendored
16
js/tests/unit/bootstrap-tab.js
vendored
@@ -42,4 +42,20 @@ $(function () {
|
|||||||
equals($("#qunit-fixture").find('.active').attr('id'), "home")
|
equals($("#qunit-fixture").find('.active').attr('id'), "home")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test("should not fire closed when close is prevented", function () {
|
||||||
|
$.support.transition = false
|
||||||
|
stop();
|
||||||
|
$('<div class="tab"/>')
|
||||||
|
.bind('show', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
ok(true);
|
||||||
|
start();
|
||||||
|
})
|
||||||
|
.bind('shown', function () {
|
||||||
|
ok(false);
|
||||||
|
})
|
||||||
|
.tab('show')
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
Reference in New Issue
Block a user