<commit_before>/*
 * @license MIT License (see license.txt)
 */

'use strict';

function SwiftClick (contextEl)
{
    // if SwiftClick has already been initialised on this element then return the instance that's already in the Dictionary.
    if (typeof SwiftClick.swiftDictionary[contextEl] !== 'undefined') return SwiftClick.swiftDictionary[contextEl];

    // add this instance of SwiftClick to the dictionary using the contextEl as the key.
    SwiftClick.swiftDictionary[contextEl] = this;

    this.options =
    {
        elements: {a:'a', div:'div', span:'span', button:'button'},
        minTouchDrift: 4,
        maxTouchDrift: 16,
        useCssParser: false
    };

    var _self                           = this;
    var _swiftContextEl                 = contextEl;
    var _swiftContextElOriginalClick    = _swiftContextEl.onclick;
    var _currentlyTrackingTouch         = false;
    var _touchStartPoint                = {x:0, y:0};
    var _scrollStartPoint               = {x:0, y:0};
    var _clickedAlready                 = false;


    // SwiftClick is only initialised if both touch and orientationchange are supported.
    if ('onorientationchange' in window && 'ontouchstart' in window)
    {
        init();
    }

    function init ()
    {
        // check if the swift el already has a click handler and if so hijack it so it get's fired after SwiftClick's, instead of beforehand.
        if (typeof _swiftContextElOriginalClick === 'function')
        {
            _swiftContextEl.addEventListener('click', hijackedSwiftElClickHandler, false);
            _swiftContextEl.onclick = null;
        }

        _swiftContextEl.addEventListener('touchstart', touchStartHandler, false);
        _swiftContextEl.addEventListener('click', clickHandler, true);
    }

    function hijackedSwiftElClickHandler (event)
    {
        _swiftContextElOriginalClick(event);
    }

    function touchStartHandler (event)
    {
        var targetEl = event.target;
        var nodeName = targetEl.nodeName.toLowerCase();
        var touch = event.changedTouches[0];

        // don't synthesize an event if the node is not an acceptable type (the type isn't in the dictionary).
        if (typeof _self.options.elements[nodeName] === 'undefined')
        {
            return true;
        }

        // don't synthesize an event if we are already tracking an element.
        if (_currentlyTrackingTouch)
        {
            return true;
        }

        // check parents for 'swiftclick-ignore' class name.
        if (_self.options.useCssParser && checkIfElementShouldBeIgnored(targetEl))
        {
            _clickedAlready = false;
            return true;
        }

        event.stopPropagation();

        _currentlyTrackingTouch = true;

        // store touchstart positions so we can check for changes later (within touchend handler).
        _touchStartPoint.x = touch.pageX;
        _touchStartPoint.y = touch.pageY;
        _scrollStartPoint = getScrollPoint();

        // only add the 'touchend' listener now that we know the element should be tracked.
        targetEl.removeEventListener('touchend', touchEndHandler, false);
        targetEl.addEventListener('touchend', touchEndHandler, false);
    }

    function touchEndHandler (event)
    {
        var targetEl = event.target;
        var touchend = event.changedTouches[0];

        targetEl.removeEventListener('touchend', touchEndHandler, false);
        
        _currentlyTrackingTouch = false;

        // don't synthesize a click event if the touchpoint position has drifted significantly, as the user is not trying to click.
        if (hasTouchDriftedTooFar(touchend))
        {
            return true;
        }

        // prevent default actions and create a synthetic click event before returning false.
        event.stopPropagation();
        event.preventDefault();

        _clickedAlready = false;

        targetEl.focus();
        synthesizeClickEvent(targetEl, touchend);

        // return false in order to surpress the regular click event.
        return false;
    }

    function clickHandler (event)
    {
        var targetEl = event.target;
        var nodeName = targetEl.nodeName.toLowerCase();
<commit_msg>🐛 Handle touch cancel event just like touch end. (#9)<commit_after>/*
 * @license MIT License (see license.txt)
 */

'use strict';

function SwiftClick (contextEl)
{
    // if SwiftClick has already been initialised on this element then return the instance that's already in the Dictionary.
    if (typeof SwiftClick.swiftDictionary[contextEl] !== 'undefined') return SwiftClick.swiftDictionary[contextEl];

    // add this instance of SwiftClick to the dictionary using the contextEl as the key.
    SwiftClick.swiftDictionary[contextEl] = this;

    this.options =
    {
        elements: {a:'a', div:'div', span:'span', button:'button'},
        minTouchDrift: 4,
        maxTouchDrift: 16,
        useCssParser: false
    };

    var _self                           = this;
    var _swiftContextEl                 = contextEl;
    var _swiftContextElOriginalClick    = _swiftContextEl.onclick;
    var _currentlyTrackingTouch         = false;
    var _touchStartPoint                = {x:0, y:0};
    var _scrollStartPoint               = {x:0, y:0};
    var _clickedAlready                 = false;


    // SwiftClick is only initialised if both touch and orientationchange are supported.
    if ('onorientationchange' in window && 'ontouchstart' in window)
    {
        init();
    }

    function init ()
    {
        // check if the swift el already has a click handler and if so hijack it so it get's fired after SwiftClick's, instead of beforehand.
        if (typeof _swiftContextElOriginalClick === 'function')
        {
            _swiftContextEl.addEventListener('click', hijackedSwiftElClickHandler, false);
            _swiftContextEl.onclick = null;
        }

        _swiftContextEl.addEventListener('touchstart', touchStartHandler, false);
        _swiftContextEl.addEventListener('click', clickHandler, true);
    }

    function hijackedSwiftElClickHandler (event)
    {
        _swiftContextElOriginalClick(event);
    }

    function touchStartHandler (event)
    {
        var targetEl = event.target;
        var nodeName = targetEl.nodeName.toLowerCase();
        var touch = event.changedTouches[0];

        // don't synthesize an event if the node is not an acceptable type (the type isn't in the dictionary).
        if (typeof _self.options.elements[nodeName] === 'undefined')
        {
            return true;
        }

        // don't synthesize an event if we are already tracking an element.
        if (_currentlyTrackingTouch)
        {
            return true;
        }

        // check parents for 'swiftclick-ignore' class name.
        if (_self.options.useCssParser && checkIfElementShouldBeIgnored(targetEl))
        {
            _clickedAlready = false;
            return true;
        }

        event.stopPropagation();

        _currentlyTrackingTouch = true;

        // store touchstart positions so we can check for changes later (within touchend handler).
        _touchStartPoint.x = touch.pageX;
        _touchStartPoint.y = touch.pageY;
        _scrollStartPoint = getScrollPoint();

        // only add the 'touchend' listener now that we know the element should be tracked.
        targetEl.removeEventListener('touchend', touchEndHandler, false);
        targetEl.addEventListener('touchend', touchEndHandler, false);

        targetEl.removeEventListener('touchcancel', touchCancelHandler, false);
        targetEl.addEventListener('touchcancel', touchCancelHandler, false);
    }

    function touchEndHandler (event)
    {
        var targetEl = event.target;
        var touchend = event.changedTouches[0];

        targetEl.removeEventListener('touchend', touchEndHandler, false);
        
        _currentlyTrackingTouch = false;

        // don't synthesize a click event if the touchpoint position has drifted significantly, as the user is not trying to click.
        if (hasTouchDriftedTooFar(touchend))
        {
            return true;
        }

        // prevent default actions and create a synthetic click event before returning false.
        event.stopPropagation();
        event.preventDefault();

        _clickedAlready = false;

        targetEl.focus();
        synthesizeClickEvent(targetEl, touchend);

        // return false in order to surpress the regular click event.
        return false;
    }

    function touchCancelHandler(event) {
        event.target.removeEventListener('touchcancel', touchCancelHandler, false);

        _currentlyTrackingTouch = false;
    }

    function clickHandler (event)
    {
        var targetEl = event.target;
        var nodeName = targetEl.nodeName.toLowerCase();

{'fraction_non_alphanumeric': 0.08303167420814479, 'fraction_numerical': 0.002149321266968326, 'mean_word_length': 2.4240898528272656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6391811', 'n_tokens_mistral': 2405, 'n_tokens_neox': 2255, 'n_words': 690}