Git Product home page Git Product logo

findhandlersjs's Issues

2022 doesn't work with jquery 3.4

Alas, I had hopes. But it is several years old.

If you are curious, attached is a sample file.

Daniel Hellerstein ([email protected])

// example file

<title>test findEventHandlers </title> <script type="text/javascript" src="/wsurvey/publicLib/jquery-3.4.1.min.js"></script> <script type="text/javascript" > window.onload=init1; var findEventHandlers = function (eventType, jqSelector) { var results = []; var $ = jQuery;// to avoid conflict between others frameworks like Mootools var arrayIntersection = function (array1, array2) { return $(array1).filter(function (index, element) { return $.inArray(element, $(array2)) !== -1; }); }; var haveCommonElements = function (array1, array2) { return arrayIntersection(array1, array2).length !== 0; }; var addEventHandlerInfo = function (element, event, $elementsCovered) { var extendedEvent = event; if ($elementsCovered !== void 0 && $elementsCovered !== null) { $.extend(extendedEvent, { targets: $elementsCovered.toArray() }); } var eventInfo; var eventsInfo = $.grep(results, function (evInfo, index) { return element === evInfo.element; }); if (eventsInfo.length === 0) { eventInfo = { element: element, events: [extendedEvent] }; results.push(eventInfo); } else { eventInfo = eventsInfo[0]; eventInfo.events.push(extendedEvent); } }; var $elementsToWatch = $(jqSelector); if (jqSelector === "*")//* does not include document and we might be interested in handlers registered there $elementsToWatch = $elementsToWatch.add(document); var $allElements = $("*").add(document); $.each($allElements, function (elementIndex, element) { var allElementEvents = $._data(element, "events"); if (allElementEvents !== void 0 && allElementEvents[eventType] !== void 0) { var eventContainer = allElementEvents[eventType]; $.each(eventContainer, function(eventIndex, event){ var isDelegateEvent = event.selector !== void 0 && event.selector !== null; var $elementsCovered; if (isDelegateEvent) { $elementsCovered = $(event.selector, element); //only look at children of the element, since those are the only ones the handler covers } else { $elementsCovered = $(element); //just itself } if (haveCommonElements($elementsCovered, $elementsToWatch)) { addEventHandlerInfo(element, event, $elementsCovered); } }); } }); return results; }; function init1(a) { $('.foo1').on('click',sayFoo) ; $('.goo1').on('click',sayGoo) ; } function sayFoo(evt) { let e1=$(evt.target); let aa=e1.val(); alert('sayfoo= '+aa); return 1; } function sayGoo(evt) { let e1=$(evt.target); let aa=e1.val(); alert('sayGoo= '+aa); return 1; } // ------------ call it here. Just to be sure everything is laoded // return arary of 0 length :( function findem(x) { alert(' about to call findEventHandlers '); let dd= findEventHandlers("click", document) ; alert('# of found events= ' + dd.length); } </script>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.