Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 1.76 KB

EXAMPLES.md

File metadata and controls

53 lines (40 loc) · 1.76 KB

Requested features - immediately brought to life by a bit of code

Allowing the user to scroll with two fingers (#70)

selection.on('beforestart', (() => {
    let timeout = null;

    return ({oe}) => {

        // Check if user already tapped inside of a selection-area.
        if (timeout !== null) {

            // A second pointer-event occured, ignore that one.
            clearTimeout(timeout);
            timeout = null;
        } else {

            // Wait 50ms in case the user uses two fingers to scroll.
            timeout = setTimeout(() => {

                // OK User used only one finger, we can safely initiate a selection and reset the timer.
                selection.trigger(oe);
                timeout = null;
            }, 50);
        }

        // Never start automatically.
        return false;
    };
})());

Preventing the start of a selection based on certain conditions (#73)

selection.on('beforestart', evt => {
    return !evt.oe.path.some(item => {

        // item is in this case an element affected by the event-bubbeling.
        // To exclude elements with class "blocked" you could do the following (#73):
        return item.classList.contains('blocked');

        // If the areas you're using contains input elements you might want to prevent
        // any out-going selections from these elements (#72):
        return oe.target.tagName !== 'INPUT';
    });
});

Feel free to submit a PR or create an issue if you got any ideas for more examples!