<commit_before>Rye.define('DOMEvents', function(){

    var util = Rye.require('Util')
      , events = Rye.require('Events')
      , query = Rye.require('Query')
      , listeners = {}
      , environmentMap = {}
      , eventIgnoreProperties = /^([A-Z]|layer[XY]$)/

    function callHandler (element, DOMEvent, handler) {
        var eventProxy = { DOMEvent: DOMEvent }
          , matched
        
        if (handler.selector != '*') {
            matched = DOMEvent.target
            while (matched && !query.matches(matched, handler.selector)) {
                matched = matched !== element && matched !== document && matched.parentNode
            }
            if (!matched) {
                return
            }
        }

        for (var key in DOMEvent) {
            if (!eventIgnoreProperties.test(key) && DOMEvent[key] !== undefined) {
                eventProxy[key] = DOMEvent[key]
            }
        }

        if (matched) {
            eventProxy.currentTarget = matched
        }
        handler.callback.apply(element, [eventProxy].concat(DOMEvent.data))
    }

    function addEvent (element, event) {
        var id = util.getUid(element)
          , evt = events.parseEvent(event)
          , eventType = (listeners[id] || (listeners[id] = {}))[evt.name]

        if (!eventType) {
            var handlers = []
            eventType = {
                handlers: handlers
              , proxy: function (nativeEvent) {
                    handlers.forEach(function (handler) {
                        callHandler(element, nativeEvent, handler)
                    })
                }
            }
            element.addEventListener(evt.name, eventType.proxy, false)
            return listeners[id][evt.name] = eventType
        }
    }

    function removeEvent (element, event) {
        var id = util.getUid(element)
          , evt = events.parseEvent(event)
          , eventType = listeners[id] && listeners[id][evt.name]

        if (!eventType) {
            return
        }
        element.removeEventListener(evt.name, eventType.proxy, false)
        delete listeners[id][evt.name]
    }

    function createEvent (type, properties) {
        if (typeof type != 'string') {
            data = type
            type = data.type
        }
        var isMouse = ['click', 'mousedown', 'mouseup', 'mousemove'].indexOf(type) != -1
          , event = document.createEvent(isMouse ? 'MouseEvent' : 'Event')
        if (properties) {
            util.extend(event, properties)
        }
        event.initEvent(type, true, true)
        return event
    }

    function addHandler (element, event, selector, callback) {<commit_msg>fixing create proxy event and calling them only on delegate<commit_after>Rye.define('DOMEvents', function(){

    var util = Rye.require('Util')
      , events = Rye.require('Events')
      , query = Rye.require('Query')
      , listeners = {}
      , environmentMap = {}
      , eventIgnoreProperties = /^([A-Z]|layer[XY]$)/

    function callHandler (element, DOMEvent, handler) {
        var event = DOMEvent
          , matched
        
        if (handler.selector != '*') {
            matched = DOMEvent.target
            while (matched && !query.matches(matched, handler.selector)) {
                matched = matched !== element && matched !== document && matched.parentNode
            }
            if (!matched) {
                return
            }
            event = createEventProxy(event)
            event.currentTarget = matched
        }
        handler.callback.apply(element, [event].concat(DOMEvent.data))
    }

    function addEvent (element, event) {
        var id = util.getUid(element)
          , evt = events.parseEvent(event)
          , eventType = (listeners[id] || (listeners[id] = {}))[evt.name]

        if (!eventType) {
            var handlers = []
            eventType = {
                handlers: handlers
              , proxy: function (nativeEvent) {
                    handlers.forEach(function (handler) {
                        callHandler(element, nativeEvent, handler)
                    })
                }
            }
            element.addEventListener(evt.name, eventType.proxy, false)
            return listeners[id][evt.name] = eventType
        }
    }

    function removeEvent (element, event) {
        var id = util.getUid(element)
          , evt = events.parseEvent(event)
          , eventType = listeners[id] && listeners[id][evt.name]

        if (!eventType) {
            return
        }
        element.removeEventListener(evt.name, eventType.proxy, false)
        delete listeners[id][evt.name]
    }

    function createEvent (type, properties) {
        if (typeof type != 'string') {
            data = type
            type = data.type
        }
        var isMouse = ['click', 'mousedown', 'mouseup', 'mousemove'].indexOf(type) != -1
          , event = document.createEvent(isMouse ? 'MouseEvent' : 'Event')
        if (properties) {
            util.extend(event, properties)
        }
        event.initEvent(type, true, true)
        return event
    }

    function createEventProxy (DOMEvent) {
        var proxy = { DOMEvent: DOMEvent }
          , returnTrue = function(){ return true }
          , returnFalse = function(){ return false }
          , methods = {
                preventDefault: 'isDefaultPrevented'
              , stopImmediatePropagation: 'isImmediatePropagationStopped'
              , stopPropagation: 'isPropagationStopped'
            }

        for (var key in DOMEvent) {
            if (!eventIgnoreProperties.test(key) && DOMEvent[key] !== undefined) {
                proxy[key] = DOMEvent[key]
            }
        }

        for (var name in methods) {
            proxy[name] = function(){
                this[methods[name]] = returnTrue
                return DOMEvent[name].apply(DOMEvent, arguments)
            }
            proxy[methods[name]] = returnFalse
        }
        return proxy
    }

    function addHandler (element, event, selector, callback) {
{'fraction_non_alphanumeric': 0.11768584143728367, 'fraction_numerical': 0.00032965221691115873, 'mean_word_length': 1.7494336202990486, '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': '1256382', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1588, 'n_words': 344}