-
-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent propagation of a click event during drag/swipe(#6).
- Loading branch information
1 parent
8478c87
commit 07b4a63
Showing
10 changed files
with
127 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* The component for handling a click event. | ||
* | ||
* @author Naotoshi Fujita | ||
* @copyright Naotoshi Fujita. All rights reserved. | ||
*/ | ||
|
||
import { FADE } from "../../constants/types"; | ||
import { subscribe } from "../../utils/dom"; | ||
|
||
|
||
/** | ||
* The component for handling a click event. | ||
* Click should be disabled during drag/swipe. | ||
* | ||
* @param {Splide} Splide - A Splide instance. | ||
* @param {Object} Components - An object containing components. | ||
* | ||
* @return {Object} - The component object. | ||
*/ | ||
export default ( Splide, Components ) => { | ||
/** | ||
* Whether click is disabled or not. | ||
* | ||
* @type {boolean} | ||
*/ | ||
let disabled = false; | ||
|
||
/** | ||
* Click component object. | ||
* | ||
* @type {Object} | ||
*/ | ||
const Click = { | ||
/** | ||
* Mount only when the drag is activated and the slide type is not "fade". | ||
* | ||
* @type {boolean} | ||
*/ | ||
required: Splide.options.drag && ! Splide.is( FADE ), | ||
|
||
/** | ||
* Called when the component is mounted. | ||
*/ | ||
mount() { | ||
subscribe( Components.Elements.track, 'click', click, { capture: true } ); | ||
|
||
Splide | ||
.on( 'drag', () => { disabled = true } ) | ||
.on( 'moved', () => { disabled = false } ); | ||
}, | ||
}; | ||
|
||
/** | ||
* Called when a track element is clicked. | ||
* | ||
* @param {Event} e - A click event. | ||
*/ | ||
function click( e ) { | ||
if ( disabled ) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
e.stopImmediatePropagation(); | ||
} | ||
} | ||
|
||
return Click; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.