LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 267 forks source link

ss.isVisible bug if elem==null #160

Closed RCohenE5Group closed 8 years ago

RCohenE5Group commented 8 years ago

Hello I use Simple Ajax Uploader Version 2.5.3 , and have the following error :

Uncaught TypeError: Cannot read property 'nodeType' of null SimpleAjaxUploader.js:389

In debug mode I find that elem.parentNode==null. I'm not sure but I think this is because the div containing "upload" button is hidden by jquery tabs(). In that context, it seems that parentNode can be null, which is not tested in the recursivity of isVisible() :

`ss.isVisible = function( elem ) { "use strict";

if ( elem.nodeType !== 1 || elem == document.body ) {
    elem = null;
    return true;
}

if ( elem.offsetWidth > 0 ||
     elem.offsetHeight > 0 ||
     ss.getStyle( elem, 'display' ).toLowerCase() != 'none' )
{
    return ss.isVisible( **elem.parentNode** );
}

elem = null;
return false;

}; `

Thanks for your help.

LPology commented 8 years ago

This is a strange one. Even if a parent element is invisible it shouldn't be null, right? The only thing I can think of is to check for elem.parentNode prior to referencing:

ss.isVisible = function( elem ) {
    "use strict";

    if ( !elem ) {
        return false;
    }

    if ( elem.nodeType !== 1 || elem == document.body ) {
        elem = null;
        return true;
    }

    if ( elem.parentNode &&
        ( elem.offsetWidth > 0 ||
         elem.offsetHeight > 0 ||
         ss.getStyle( elem, 'display' ).toLowerCase() != 'none' ) )
    {
        return ss.isVisible( elem.parentNode );
    }

    elem = null;
    return false;
};

I'm about to push an update with this change now (it will be version 2.5.4).

I'm going to close this issue, but if this doesn't fix the problem please re-open the issue and we'll figure out another approach.

RCohenE5Group commented 8 years ago

version 2.5.5 fixed the problem. Thanks.