Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with e.offsetTop #289

Closed
artknight opened this issue Apr 27, 2015 · 3 comments
Closed

issue with e.offsetTop #289

artknight opened this issue Apr 27, 2015 · 3 comments

Comments

@artknight
Copy link

Here is the code that generates the error:

position: function(e, t) {
            for (var s = {top: 0,left: 0}; e !== t; )
                s.top += e.offsetTop, s.left += e.offsetLeft, e = e.parentNode;
            return s
}

error: Uncaught TypeError: Cannot read property 'offsetTop' of null

Suggestion: add a check to make sure "e" is not null.

Thanks,

@Robdel12
Copy link
Owner

Robdel12 commented May 2, 2015

Can you provide an example that caused this error?

@artknight
Copy link
Author

OK, here is a code snippet that I modified off of the original example that was provided on your example page. You could probably say that "its my custom code" so no guaranties ... which is correct.. but the issue is in the main lib. My work-around for this was to add a check whether e is null or not but I had to do it within the dropkick.js and as soon as you released a new update it got overwritten. So, I am just humbly asking to add the check to the main lib so that i do not have to do any manual work later on. And it will not harm anything in drokick.js any ways.

=== code snippet ===

searchDropdown: function(options){
        var options = _.extend({},options),
            keys = { UP:38, DOWN:40 };

        //must add .search-select class for proper styling
        this.addClass('search-select');

        return this.dropkick({
            mobile: true,
            initialize: function(){
                var $input,
                    dk = this;

                    dk.temp = {
                        found: dk.options,
                        lastSelectedIndex: dk.selectedIndex || 0
                    };

                $('.dk-selected',dk.data.elem).after('<div class="dk-search"><input type="text" class="dk-search-input" placeholder="Search"></div>');
                $input = $('.dk-search-input',dk.data.elem);
                $input.on("click",function(event){
                    event.stopPropagation();
                }).on('keypress keyup', function(event){
                    event.stopPropagation();
                    var keyCode = UTILS.getCharKey(event);

                    if (keyCode===keys.UP){
                        dk.temp.lastSelectedIndex--;
                        (dk.temp.lastSelectedIndex < 0) && (dk.temp.lastSelectedIndex = 0);
                        dk.selectOne(dk.temp.found[dk.temp.lastSelectedIndex]);
                    }
                    else if (keyCode===keys.DOWN){
                        dk.temp.lastSelectedIndex++;
                        (dk.temp.lastSelectedIndex > dk.temp.found.length-1) && (dk.temp.lastSelectedIndex = dk.temp.found.length-1);
                        dk.selectOne(dk.temp.found[dk.temp.lastSelectedIndex]);
                    }
                    else {
                        dk.temp.found = dk.search(this.value, dk.data.settings.search);
                        dk.temp.lastSelectedIndex = 0;

                        $('.dk-option', dk.data.elem).remove();
                        if (dk.temp.found.length){
                            $(dk.temp.found).appendTo(dk.data.elem.lastChild);
                            dk.selectOne(dk.temp.found[0]);
                        }
                        else
                            $('<li></li>').addClass('dk-option dk-option-disabled').text('Not Found').appendTo(dk.data.elem.lastChild);
                    }
                });
                ('selectedValue' in options) && dk.select(options.selectedValue);
            },
            search: options.search || 'strict',
            open: function(){
                $('.dk-search-input',this.data.elem).focus();
                ('open' in options) && options.open.call(this);
            },
            close: function(){
                $('.dk-search-input',this.data.elem).val("").blur();
                $('.dk-option',this.data.elem).remove();
                $(this.options).appendTo(this.data.elem.lastChild);
                ('close' in options) && options.close.call(this);
            },
            change: ('change' in options) ? options.change : new Function
        });
    }

@Robdel12
Copy link
Owner

Robdel12 commented May 4, 2015

I pushed a change. You should be able to pull master and see it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants