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