DataTables / VisualEvent

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

elements[elements.length-1] sometimes undefined #46

Closed Benno007 closed 10 years ago

Benno007 commented 10 years ago

I'm not entirely sure how this occurs, but in the setup at my work's website using jQuery 2, a fatal JS error is thrown, meaning the overlays don't show at all. This is the offending code:

if ( elements[ elements.length-1 ].listeners.length === 0 ) {
        elements.splice( elements.length-1, 1 );
}

To fix it, we just need to change it to the following:

if ( typeof elements[ elements.length-1 ] != 'undefined' && elements[ elements.length-1 ].listeners.length === 0 ) {
            elements.splice( elements.length-1, 1 );
}

I absolutely love visual event!

DataTables commented 10 years ago

Thanks :-)

Are you able to link me to the page so I can tae a look at what is going on and ensure that I fix it correctly?

Benno007 commented 10 years ago

Hey Allan,

Sorry at the moment I can't as it's only available in a development environment. I think it will be released in 2 weeks... I'll check it out again once it's released and share it with you then.

Sent from my iPhone

On 6 Mar 2014, at 6:24 pm, "Allan Jardine" notifications@github.com wrote:

Thanks :-)

Are you able to link me to the page so I can tae a look at what is going on and ensure that I fix it correctly?

— Reply to this email directly or view it on GitHub.

DataTables commented 10 years ago

That would be great thanks. I'm just wondering why an undefined option would be added to the array. Or if the fix perhaps should be checking that the array has length ( elements.length !== 0 )?

Benno007 commented 10 years ago

Hey Allan,

The project is now live, you can see it here: http://goo.gl/eFjoAX

I'm not sure, either way could possibly work, as elements would still be defined.

DataTables commented 10 years ago

Nice one - thanks for the link! Fixed now :-). I'm not 100% convinced about the event count (800+ events on that page?) but it is at least running now...

Benno007 commented 10 years ago

Thanks Allan :)!

It may well be true lol... The form has like 5 steps with so many form elements and help tool tips and interactions. Each form field has at least 2-3 bindings too. Looks like when they started they didn't seem to like optimizing their code.

Sent from my iPhone

On 21 Mar 2014, at 12:33 am, "Allan Jardine" notifications@github.com wrote:

Nice one - thanks for the link! Fixed now :-). I'm not 100% convinced about the event count (800+ events on that page?) but it is at least running now...

— Reply to this email directly or view it on GitHub.