Skip to content

Commit

Permalink
! The select box component could get confused when reopening a previo…
Browse files Browse the repository at this point in the history
…usly closed dropdown when the conditions for the scrollbar to show up changed. (sbox.js)

! Fixed undefined event variable. (sbox.js)

* Ensure that dropdowns aren't so narrow you won't actually be able to browse them... (sbox.js)
  • Loading branch information
Nao committed Aug 9, 2014
1 parent 172b9a4 commit 298d4fc
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions core/javascript/sbox.js
Expand Up @@ -181,11 +181,15 @@
{
if ($sb.hasClass('open'))
{
scrollbar = '';
$display.blur();
$sb.removeClass('open');
$dd.removeClass('has_bar');
$dd
.animate(is_opera ? { opacity: 'toggle' } : { opacity: 'toggle', height: 'toggle' }, instantClose == 1 ? 0 : 100)
.attr('aria-hidden', true);
$dd.find('.scrollbar').remove();
$dd.find('.overview').contents().unwrap().unwrap();
}
$(document).off('.sb');
},
Expand Down Expand Up @@ -218,7 +222,7 @@

displayClick = function (e) {
$sb.hasClass('open') ? closeAndUnbind(1) : openSB(0, 1);
e.stopPropagation();
e && e.stopPropagation();
},

// Show, reposition, and reset dropdown markup.
Expand Down Expand Up @@ -255,7 +259,7 @@

// Show scrollbars if the dropdown is taller than 250 pixels (or the viewport height).
// Touch-enabled phones have poor usability and shouldn't bother -- let them stretch all the way.
ddMaxHeight = Math.min(Math.max(500, ddHeight / 5), ddHeight, Math.max(bottomSpace, topSpace - 50) - 50),
ddMaxHeight = Math.max(Math.min(ddHeight, 50), Math.min(Math.max(500, ddHeight / 5), ddHeight, Math.max(bottomSpace, topSpace - 50) - 50)),

// If we have enough space below the button, or if we don't have enough room above either, show a dropdown.
// Otherwise, show a drop-up, but only if there's enough size, or the space above is more comfortable.
Expand All @@ -265,7 +269,7 @@
if (ddMaxHeight < ddHeight)
{
$dd.height(ddMaxHeight - ddHeight + $dd.height());
scrollbar ? scrollbar.init() : scrollbar = new ScrollBar($dd);
scrollbar = new ScrollBar($dd);
centerOnSelected();
}

Expand Down Expand Up @@ -484,7 +488,6 @@
// Destroy existing data
$sb.remove();
$orig.removeClass('sb').off('.sb');
scrollbar = '';
$(window).off('.sb');

loadSB();
Expand Down Expand Up @@ -537,23 +540,6 @@
});
};

that.init = function ()
{
viewportAxis = $dd.height();
$dd.find('.viewport').height(viewportAxis);
$scrollbar = $dd.find('.scrollbar').height(viewportAxis);
$content = $dd.find('.overview');
contentAxis = $content.height();
$thumb = $scrollbar.find('div');

scrollbarRatio = contentAxis / viewportAxis;
thumbAxis = Math.min(viewportAxis, viewportAxis / scrollbarRatio);

// Set size.
iMouse = $thumb.offset().top;
$thumb.height(thumbAxis);
};

// Scroll to...
that.st = function (iTop, iHeight)
{
Expand All @@ -568,11 +554,24 @@
if ($dd.find('.viewport').length)
return;

// Gentlemen, start your engines.
$dd.addClass('has_bar').width(Math.min($dd.width(), $(window).width() - 25));
$dd.contents().wrapAll('<div class="viewport"><div class="overview">');
$dd.append('<div class="scrollbar"><div>');

that.init();
viewportAxis = $dd.height();
$dd.find('.viewport').height(viewportAxis);
$scrollbar = $dd.find('.scrollbar').height(viewportAxis);
$content = $dd.find('.overview');
contentAxis = $content.height();
$thumb = $scrollbar.find('div');

scrollbarRatio = contentAxis / viewportAxis;
thumbAxis = Math.min(viewportAxis, viewportAxis / scrollbarRatio);

// Set size.
iMouse = $thumb.offset().top;
$thumb.height(thumbAxis);

// Set events
$scrollbar.mousedown(drag);
Expand Down

0 comments on commit 298d4fc

Please sign in to comment.