<commit_before>###
  QuoJS 2.0
  (c) 2011, 2012 <NAME> (@soyjavi)
  http://quojs.tapquo.com
###

(($$) ->

    TOUCH = {}
    TOUCH_TIMEOUT = undefined
    HOLD_DELAY = 650
    GESTURES = ["doubleTap",
                "hold",
                "swipe", "swiping", "swipeLeft", "swipeRight", "swipeUp", "swipeDown",
                "drag" ]

    GESTURES.forEach (event) ->
        $$.fn[event] = (callback) -> @on event, callback
        return

    $$(document).ready -> _listenTouches()

    _listenTouches = ->
        environment = $$(document.body)
        environment.bind "touchstart", _onTouchStart
        environment.bind "touchmove", _onTouchMove
        environment.bind "touchend", _onTouchEnd
        environment.bind "touchcancel", _cleanGesture

    _onTouchStart = (event) ->
        now = Date.now()
        delta = now - (TOUCH.last or now)
        touch_event = _captureTouch(event)
        TOUCH_TIMEOUT and clearTimeout(TOUCH_TIMEOUT)
        TOUCH =
            el: $$(_parentIfText(touch_event.target))
            x1: touch_event.pageX
            y1: touch_event.pageY
            isDoubleTap: (if (delta > 0 and delta <= 250) then true else false)
            last: now
            fingers: _countFingers(event)

        setTimeout _hold, HOLD_DELAY

    _onTouchMove = (event) ->
        touch_event = _captureTouch(event)
        TOUCH.x2 = touch_event.pageX
        TOUCH.y2 = touch_event.pageY
        TOUCH.el.trigger "swiping", TOUCH    if _isSwipe(event)

    _onTouchEnd = (event) ->
        if TOUCH.isDoubleTap
            _trigger "doubleTap", true
        else if TOUCH.x2 > 0 or TOUCH.y2 > 0
            if _isSwipe(event)
                if TOUCH.fingers is 1
                    _trigger "swipe", false
                    swipe_direction = _swipeDirection(TOUCH.x1, TOUCH.x2, TOUCH.y1, TOUCH.y2)
                    _trigger swipe_direction, false
                else
                    _trigger "drag", false
            _cleanGesture()
        else
            _trigger "tap" if TOUCH.el
            TOUCH_TIMEOUT = setTimeout(_cleanGesture, 250)

    _trigger = (type, clean) ->
        TOUCH.el.trigger type, TOUCH
        clean and _cleanGesture()

    _cleanGesture = (event) ->
        TOUCH = {}
        clearTimeout TOUCH_TIMEOUT

    _isSwipe = (event) ->
        TOUCH.el and (Math.abs(TOUCH.x1 - TOUCH.x2) > 30 or Math.abs(TOUCH.y1 - TOUCH.y2) > 30)

    _captureTouch = (event) ->
        (if $$.isMobile() then event.touches[0] else event)

    _parentIfText = (node) ->
        (if "tagName" of node then node else node.parentNode)

    _swipeDirection = (x1, x2, y1, y2) ->
        xDelta = Math.abs(x1 - x2)
        yDelta = Math.abs(y1 - y2)
        if xDelta >= yDelta
            (if x1 - x2 > 0 then "swipeLeft" else "swipeRight")
        else
            (if y1 - y2 > 0 then "swipeUp" else "swipeDown")

    _hold = ->
        if TOUCH.last and (Date.now() - TOUCH.last >= HOLD_DELAY)
            _trigger "hold"
            _cleanGesture()
            return

    _countFingers = (event) ->
        (if event.touches then event.touches.length else 1)

    return

) Quo<commit_msg>New gestures in coffee: rotate and pinch<commit_after>###
  QuoJS 2.0
  (c) 2011, 2012 <NAME> (@soyjavi)
  http://quojs.tapquo.com
###

(($$) ->

    GESTURE = {}
    FIRST_TOUCH = []
    CURRENT_TOUCH = []
    TOUCH_TIMEOUT = undefined
    HOLD_DELAY = 650
    GESTURES = ["doubleTap",
                "hold",
                "swipe", "swiping", "swipeLeft", "swipeRight", "swipeUp", "swipeDown",
                "rotate", "rotating", "rotateLeft", "rotateRight",
                "pinch", "pinching", "pinchIn", "pinchOut",
                "drag"]

    GESTURES.forEach (event) ->
        $$.fn[event] = (callback) -> @on event, callback
        return

    $$(document).ready -> _listenTouches()

    _listenTouches = ->
        environment = $$(document.body)
        environment.bind "touchstart", _onTouchStart
        environment.bind "touchmove", _onTouchMove
        environment.bind "touchend", _onTouchEnd
        environment.bind "touchcancel", _cleanGesture

    _onTouchStart = (event) ->
        now = Date.now()
        delta = now - (GESTURE.last or now)
        TOUCH_TIMEOUT and clearTimeout(TOUCH_TIMEOUT)
        touches = _getTouches(event)
        fingers = touches.length
        FIRST_TOUCH = _fingersPosition(touches, fingers)
        GESTURE.el = $$(_parentIfText(touches[0].target))
        GESTURE.fingers = fingers
        GESTURE.last = now
        if fingers is 1
            GESTURE.isDoubleTap = (delta > 0 and delta <= 250)
            setTimeout _hold, HOLD_DELAY
        else if fingers is 2
            GESTURE.initial_angle = parseInt(_angle(FIRST_TOUCH), 10)
            GESTURE.initial_distance = parseInt(_distance(FIRST_TOUCH), 10)
            GESTURE.angle_difference = 0
            GESTURE.distance_difference = 0

    _onTouchMove = (event) ->
        if GESTURE.el
            touches = _getTouches(event)
            fingers = touches.length
            if fingers == GESTURE.fingers
                CURRENT_TOUCH = _fingersPosition(touches, fingers)
                _trigger "swiping" if _isSwipe(event)
                if fingers == 2
                    _captureRotation()
                    _capturePinch()
            else
                _cleanGesture()
        true

    _isSwipe = (event) ->
        ret = false
        if CURRENT_TOUCH[0]
            move_horizontal = Math.abs(FIRST_TOUCH[0].x - CURRENT_TOUCH[0].x) > 30
            move_vertical = Math.abs(FIRST_TOUCH[0].y - CURRENT_TOUCH[0].y) > 30
            ret = GESTURE.el and (move_horizontal or move_vertical)
        ret

    _onTouchEnd = (event) ->
        if GESTURE.isDoubleTap
            _trigger "doubleTap"
            _cleanGesture()
        else if GESTURE.fingers is 1
            if _isSwipe()
                _trigger "swipe"
                swipe_direction = _swipeDirection(FIRST_TOUCH[0].x, CURRENT_TOUCH[0].x, FIRST_TOUCH[0].y, CURRENT_TOUCH[0].y)
                _trigger swipe_direction
                _cleanGesture()
            else
                _trigger "tap"
                TOUCH_TIMEOUT = setTimeout(_cleanGesture, 250)
        else if GESTURE.fingers is 2
            if GESTURE.angle_difference isnt 0
                _trigger "rotate", angle: GESTURE.angle_difference
                rotation_direction = if GESTURE.angle_difference > 0 then "rotateRight" else "rotateLeft"
                _trigger rotation_direction, angle: GESTURE.angle_difference
            if GESTURE.distance_difference isnt 0
                _trigger "pinch", angle: GESTURE.distance_difference
                pinch_direction = if GESTURE.distance_difference > 0 then "pinchOut" else "pinchIn"
                _trigger pinch_direction, distance: GESTURE.distance_difference
            _cleanGesture()

    _fingersPosition = (touches, fingers) ->
        result = []
        i = 0
        while i < fingers
            result.push
                x: touches[i].pageX
                y: touches[i].pageY
            i++
        result

    _captureRotation = () ->
        angle = parseInt(_angle(CURRENT_TOUCH), 10)
        diff = parseInt(GESTURE.initial_angle - angle, 10)
        if Math.abs(diff) > 10 or GESTURE.angle_difference isnt 0
            i = 0
            symbol = if GESTURE.angle_difference < 0 then "-" else "+"
            eval "diff " + symbol + "= 180;" while Math.abs(diff - GESTURE.angle_difference) > 90 and i++ < 10
            GESTURE.angle_difference = parseInt(diff, 10)
            _trigger "rotating", angle: GESTURE.angle_difference

    _capturePinch = () ->
        distance = parseInt(_distance(CURRENT_TOUCH), 10)
        diff = GESTURE.initial_distance - distance
        if Math.abs(diff) > 5
            GESTURE.distance_difference = diff
            _trigger "pinching", distance: diff

    _trigger = (type, params) ->
        if GESTURE.el
            params = params or {}
            GESTURE.el.trigger type, params

    _cleanGesture = (event) ->
        FIRST_TOUCH = []
        CURRENT_TOUCH = []
        GESTURE = {}
        clearTimeout TOUCH_TIMEOUT

    _angle = (touches_data) ->
        A = touches_data[0]
        B = touches_data[1]
        angle = Math.atan((B.y-A.y)*-1/(B.x-A.x))*(180/Math.PI)
        if angle < 0 then (angle + 180) else angle

    _distance = (touches_data) ->
        A = touches_data[0]
        B = touches_data[1]
        Math.sqrt((B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y))*-1

    _getTouches = (event) ->
        if $$.isMobile() then event.touches else [event]

    _parentIfText = (node) ->
        if "tagName" of node then node else node.parentNode

    _swipeDirection = (x1, x2, y1, y2) ->
        xDelta = Math.abs(x1 - x2)
        yDelta = Math.abs(y1 - y2)
        if xDelta >= yDelta
            if x1-x2>0 then "swipeLeft" else "swipeRight"
        else
            if y1-y2>0 then "swipeUp" else "swipeDown"

    _hold = ->
        if GESTURE.last and (Date.now() - GESTURE.last >= HOLD_DELAY)
            _trigger "hold"
            _cleanGesture()

    return

) Quo
{'fraction_non_alphanumeric': 0.10791288168983255, 'fraction_numerical': 0.0169639925577323, 'mean_word_length': 1.8726815466834328, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 62, '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': '6414232', 'n_tokens_mistral': 3155, 'n_tokens_neox': 2928, 'n_words': 651}