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

Bug when growing #4

Open
eldamir opened this issue Dec 8, 2017 · 0 comments
Open

Bug when growing #4

eldamir opened this issue Dec 8, 2017 · 0 comments

Comments

@eldamir
Copy link

eldamir commented Dec 8, 2017

When the frame grows enough that an li is taken out of the dropdown, the width variable is not updated, causing wrong behaviour. I found the issue by inserting console logs

            // Window is growing
            else {
                // We used to just look at the first one, but this doesn't work when the window is maximized
                //var dropdownFirstItem = dropdown.children('ul.dropdown-menu').children().first();
                dropdown.children('ul.dropdown-menu').children().each(function() {
                    console.log(width, width+parseInt($(this).attr('data-original-width')), parent_width)
                    if (width+parseInt($(this).attr('data-original-width')); < parent_width) {
                        // Restore the topmost dropdown item to the main menu
                        console.log("Inserting")
                        dropdown.before(this);
                    }
                    else {
                        // If the topmost item can't be restored, don't look any further
                        return false;
                    }
                });

The solution is here:

            // Window is growing
            else {
                // We used to just look at the first one, but this doesn't work when the window is maximized
                //var dropdownFirstItem = dropdown.children('ul.dropdown-menu').children().first();
                dropdown.children('ul.dropdown-menu').children().each(function() {
                    var newWidth = width+parseInt($(this).attr('data-original-width'));  // <---- this
                    if (newWidth < parent_width) {  // <---- this
                        // Restore the topmost dropdown item to the main menu
                        width = newWidth;  // <---- this
                        dropdown.before(this);
                    }
                    else {
                        // If the topmost item can't be restored, don't look any further
                        return false;
                    }
                });
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

1 participant