mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-19 16:54:24 +01:00
avoid drag img
This commit is contained in:
parent
8883ccb205
commit
b1dc6b324c
@ -64,6 +64,7 @@ const Event = {
|
||||
POINTERUP : `pointerup${EVENT_KEY}`,
|
||||
POINTERLEAVE : `pointerleave${EVENT_KEY}`,
|
||||
POINTERCANCEL : `pointercancel${EVENT_KEY}`,
|
||||
DRAG_START : `dragstart${EVENT_KEY}`,
|
||||
LOAD_DATA_API : `load${EVENT_KEY}${DATA_API_KEY}`,
|
||||
CLICK_DATA_API : `click${EVENT_KEY}${DATA_API_KEY}`
|
||||
}
|
||||
@ -84,6 +85,7 @@ const Selector = {
|
||||
ACTIVE : '.active',
|
||||
ACTIVE_ITEM : '.active.carousel-item',
|
||||
ITEM : '.carousel-item',
|
||||
ITEM_IMG : '.carousel-item img',
|
||||
NEXT_PREV : '.carousel-item-next, .carousel-item-prev',
|
||||
INDICATORS : '.carousel-indicators',
|
||||
DATA_SLIDE : '[data-slide], [data-slide-to]',
|
||||
@ -323,6 +325,7 @@ class Carousel {
|
||||
}
|
||||
}
|
||||
|
||||
$(this._element.querySelectorAll(Selector.ITEM_IMG)).on(Event.DRAG_START, (e) => e.preventDefault())
|
||||
if (this._pointerEvent) {
|
||||
$(this._element).on(Event.POINTERDOWN, (event) => start(event))
|
||||
$(this._element).on(Event.POINTERUP, (event) => end(event))
|
||||
|
@ -4,17 +4,15 @@ $(function () {
|
||||
window.Carousel = typeof bootstrap !== 'undefined' ? bootstrap.Carousel : Carousel
|
||||
|
||||
var originWinPointerEvent = window.PointerEvent
|
||||
var originMsPointerEvent = window.MSPointerEvent
|
||||
window.MSPointerEvent = null
|
||||
var supportPointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent)
|
||||
|
||||
function clearPointerEvents() {
|
||||
window.PointerEvent = null
|
||||
window.MSPointerEvent = null
|
||||
}
|
||||
|
||||
function restorePointerEvents() {
|
||||
window.PointerEvent = originWinPointerEvent
|
||||
window.MSPointerEvent = originMsPointerEvent
|
||||
}
|
||||
|
||||
var stylesCarousel = [
|
||||
@ -1032,11 +1030,11 @@ $(function () {
|
||||
return
|
||||
}
|
||||
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
Simulator.setType('pointer')
|
||||
assert.expect(3)
|
||||
var $styles = $(stylesCarousel).appendTo('head')
|
||||
var done = assert.async()
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
|
||||
var carouselHTML =
|
||||
'<div class="carousel" data-interval="false">' +
|
||||
@ -1050,8 +1048,7 @@ $(function () {
|
||||
' </div>' +
|
||||
'</div>'
|
||||
|
||||
var $carousel = $(carouselHTML)
|
||||
$carousel.appendTo('#qunit-fixture')
|
||||
var $carousel = $(carouselHTML).appendTo('#qunit-fixture')
|
||||
var $item = $('#item')
|
||||
$carousel.bootstrapCarousel()
|
||||
var carousel = $carousel.data('bs.carousel')
|
||||
@ -1061,8 +1058,8 @@ $(function () {
|
||||
assert.ok(true, 'slid event fired')
|
||||
assert.ok($item.hasClass('active'))
|
||||
assert.ok(spy.called)
|
||||
delete document.documentElement.ontouchstart
|
||||
$styles.remove()
|
||||
delete document.documentElement.ontouchstart
|
||||
done()
|
||||
})
|
||||
|
||||
@ -1075,6 +1072,7 @@ $(function () {
|
||||
QUnit.test('should allow swiperight and call prev with touch events', function (assert) {
|
||||
Simulator.setType('touch')
|
||||
clearPointerEvents()
|
||||
|
||||
assert.expect(3)
|
||||
var done = assert.async()
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
@ -1119,12 +1117,12 @@ $(function () {
|
||||
return
|
||||
}
|
||||
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
assert.expect(3)
|
||||
Simulator.setType('pointer')
|
||||
|
||||
var $styles = $(stylesCarousel).appendTo('head')
|
||||
var done = assert.async()
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
|
||||
var carouselHTML =
|
||||
'<div class="carousel" data-interval="false">' +
|
||||
@ -1150,6 +1148,7 @@ $(function () {
|
||||
assert.ok(!$item.hasClass('active'))
|
||||
assert.ok(spy.called)
|
||||
$styles.remove()
|
||||
delete document.documentElement.ontouchstart
|
||||
done()
|
||||
})
|
||||
|
||||
@ -1164,9 +1163,9 @@ $(function () {
|
||||
assert.expect(3)
|
||||
clearPointerEvents()
|
||||
Simulator.setType('touch')
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
|
||||
var done = assert.async()
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
|
||||
var carouselHTML =
|
||||
'<div class="carousel" data-interval="false">' +
|
||||
@ -1192,6 +1191,7 @@ $(function () {
|
||||
assert.ok(!$item.hasClass('active'))
|
||||
assert.ok(spy.called)
|
||||
restorePointerEvents()
|
||||
delete document.documentElement.ontouchstart
|
||||
done()
|
||||
})
|
||||
|
||||
@ -1205,6 +1205,7 @@ $(function () {
|
||||
QUnit.test('should not allow pinch with touch events', function (assert) {
|
||||
assert.expect(0)
|
||||
clearPointerEvents()
|
||||
|
||||
Simulator.setType('touch')
|
||||
var done = assert.async()
|
||||
document.documentElement.ontouchstart = $.noop
|
||||
@ -1221,6 +1222,7 @@ $(function () {
|
||||
touches: 2
|
||||
}, function () {
|
||||
restorePointerEvents()
|
||||
delete document.documentElement.ontouchstart
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user