DataTables / VisualEvent

Visually show Javascript events on a page
http://sprymedia.co.uk
1.04k stars 162 forks source link

jQuery document delegated events aren't picked up #33

Closed DataTables closed 10 years ago

DataTables commented 10 years ago

Looks like:

$(document).on('click', '#Button_Email', function(event) { });

Isn't picked up by Visual Event. Assuming its because its attached as a delegate to the document.

KoalaBear84 commented 10 years ago

I see that you can access this with the following code, at least for the delegated events for 'document' which I always use:

$(document).data('events');

Still need to find a good way to get all 'data' for 'events' for all tags.. It also looks like you cannot do this the same for every jQuery version: http://bugs.jquery.com/ticket/10589

KoalaBear84 commented 10 years ago

Hmm. Was just checking this again and now I get undefined for $(document).data('events'); ...

KoalaBear84 commented 10 years ago

Just found out that you need to use this for jQuery 1.8+

$._data(document, 'events');

KoalaBear84 commented 10 years ago

I think this will list all events added with jQuery. The 'old' / normal ones, and the delegated ones with the .on().

$(document).each(function(index1, element) {
  var events = $._data(element, 'events');

  if (events !== undefined) {
    $.each(events, function(index2, eventtypes) {
      $.each(eventtypes, function(index3, event) {
        //console.log(event);
        console.log('delegated ' + event.type + ' on ' + event.selector);
      });
    });
  }
});
$('*').each(function(index1, element) {
  var events = $._data(element, 'events');

  if (events !== undefined) {
    $.each(events, function(index2, eventtypes) {
      $.each(eventtypes, function(index3, event) {
        //console.log(element);
        //console.log(event);
        console.log(event.type + ' on ' + element.nodeName + ', element #' + $(element).index('*') + ' in DOM');
      });
    });
  }
});

Now only 'merge' this with the current code. I dont know if there already is a loop over all elements in the code where we can add this so it will not get much slower than now.

I also see that none of the events listed with these loops are currently returned by Visual Event 1 and 2. That's why it has gotten useless for me. :P

Maybe the author can integrate? Else I will look another time if I can add it.

KoalaBear84 commented 10 years ago

Maybe you can do something like this:

var events = $._data(element, 'events') || $.fn('events');

This way the new jQuery 1.8+ method will be used first, and as fallback the old method.

KoalaBear84 commented 10 years ago

I finally succeeded in integrating this into Visual Event. It's not yet pretty because I had to change the jQueryGeneric method a bit, to make it work with the old and new method without completely duplicating 90% of the method.

Can't continue now, but will 'redo' it better and then see how to contribute on Github (first time).

DataTables commented 10 years ago

Sounds great - thanks for looking into this!

KoalaBear84 commented 10 years ago

I guess I've succeeded in editing the parser to make it work with jQuery 1.8+: https://github.com/DataTables/VisualEvent/pull/34

Please review and 'merge' or how that works here on GitHub.

Also please look the other 2 welcome changes. And after that, please compile and place the new version on website.

KoalaBear84 commented 10 years ago

Can you update the main hosted code with my additions?

Including the 2 other changes?

Thanks in advance, and happy new year!

DataTables commented 10 years ago

Yes - sorry for the long delay! I will try to look at this next week. Been tied up with my DataTables work of late.

KoalaBear84 commented 10 years ago

Hi Allan,

Have a new predection? :)

Kind regards, Bas

On Thu, Jan 2, 2014 at 10:10 PM, Allan Jardine notifications@github.comwrote:

Yes - sorry for the long delay! I will try to look at this next week. Been tied up with my DataTables work of late.

— Reply to this email directly or view it on GitHubhttps://github.com/DataTables/VisualEvent/issues/33#issuecomment-31484924 .

DataTables commented 10 years ago

Yup - whenever I get time - sorry. Completely overwhelmed here...

KoalaBear84 commented 10 years ago

Haha. Sounds familiair! Good luck!

On Tue, Jan 14, 2014 at 12:34 PM, Allan Jardine notifications@github.comwrote:

Yup - whenever I get time - sorry. Completely overwhelmed here...

— Reply to this email directly or view it on GitHubhttps://github.com/DataTables/VisualEvent/issues/33#issuecomment-32257575 .

DataTables commented 10 years ago

Brilliant fix - thanks for this. I've just pull it in, and your other changes and it appears to work very well. I've made a number of other changes such as adding jQuery 1.10 support and I'll be deploying the updates shortly.

Sorry for the delay in getting this in :-)

KoalaBear84 commented 10 years ago

Haha. You're welcome.

Thanks for the 'merging' and hope to see it soon on 'production'.

Our lives these days can get very busy easily.. :)

Is there some sort of newsletter of update mail? Or how will I know it's live?

On Wed, Jan 15, 2014 at 11:55 AM, Allan Jardine notifications@github.comwrote:

Brilliant fix - thanks for this. I've just pull it in, and your other changes and it appears to work very well. I've made a number of other changes such as adding jQuery 1.10 support and I'll be deploying the updates shortly.

Sorry for the delay in getting this in :-)

— Reply to this email directly or view it on GitHubhttps://github.com/DataTables/VisualEvent/issues/33#issuecomment-32351555 .

DataTables commented 10 years ago

It should be live now - although it is possibly you might need to clear your browser's cache if it has bookmarked the loader.

There isn't an update feed for Visual Event at the moment. its not really a popular enough library to warrant that (yet?...)

KoalaBear84 commented 10 years ago

Ok, thanks.

It should be more popular! Very handy sometimes! :)

I understand that you do not have it, no problem.

On Wed, Jan 15, 2014 at 12:08 PM, Allan Jardine notifications@github.comwrote:

It should be live now - although it is possibly you might need to clear your browser's cache if it has bookmarked the loader.

There isn't an update feed for Visual Event at the moment. its not really a popular enough library to warrant that (yet?...)

— Reply to this email directly or view it on GitHubhttps://github.com/DataTables/VisualEvent/issues/33#issuecomment-32352323 .