Browse files

experimental/menu_scroll: menu scroll view enhancements:

 * views were always scrollable- now when the the content fills
   the view scrolling is disabled.
 * 'autohidesVerticalScroller' will now autohide both scrollers
   at a time. in combination with 'autohidesVerticalScrollers',
   you can have the option of having both scrollers visible at
   all times, disappearing scrollers, or none at all.
  • Loading branch information...
1 parent 934f2a7 commit d6be00bae9f0d715fc9b9dfc381c2d59a9fb0915 Tim Evans committed Jun 15, 2011
Showing with 31 additions and 9 deletions.
  1. +31 −9 frameworks/experimental/frameworks/menu/views/menu/scroll.js
View
40 frameworks/experimental/frameworks/menu/views/menu/scroll.js
@@ -107,15 +107,24 @@ SC.MenuScrollView = SC.ScrollView.extend(
/**
If YES, the vertical scroller will autohide if the contentView is
- smaller than the visible area. You must set hasVerticalScroller to YES
- for this property to have any effect.
+ smaller than the visible area. You must set `autohidesVerticalScroller`
+ or `hasVerticalScroller` to YES for this property to have any effect.
@type Boolean
@default YES
*/
autohidesVerticalScrollers: YES,
/**
+ If YES, the vertical scroller will autohide (and show) both scrollers if the
+ contentView is smaller than the visible area.
+
+ @type Boolean
+ @default YES
+ */
+ autohidesVerticalScroller: YES,
+
+ /**
Use this property to set the 'bottom' offset of your vertical scroller,
to make room for a thumb view or other accessory view. Default is 0.
@@ -184,36 +193,48 @@ SC.MenuScrollView = SC.ScrollView.extend(
vOffset = this.get('verticalScrollOffset'),
maxOffset = this.get('maximumVerticalScrollOffset'),
scrollerThickness, vScrollerIsVisible,
- cFrame = this.getPath('contentView.frame'),
+ cView = this.get('contentView'),
+ cFrame = cView.get('frame'),
view = this.get('containerView'),
frame = view.get('frame');
+ this.set('canScrollVertical',
+ (cView.get('calculatedHeight') || cFrame.height || 0) * this._scale > this.get('frame').height);
+
// Fast path when the scrollers shouldn't be automatically hidden.
if (hasScroller && !this.get('autohidesVerticalScrollers')) {
vScroller = this.get('verticalScrollerView');
- layout.top = vScroller.get('scrollerThickness');
- vScroller.set('layout', { height: layout.top, top: 0, right: 0, left: 0 });
+ vScrollerIsVisible = vScroller && isVisible;
+ vScroller.set('isVisible', vScrollerIsVisible);
+ if (vScrollerIsVisible) {
+ layout.top = vScroller.get('scrollerThickness');
+ vScroller.set('layout', { height: layout.top, top: 0, right: 0, left: 0 });
+ }
vScroller = this.get('verticalScrollerView2');
- layout.bottom = vScroller.get('scrollerThickness');
- vScroller.set('layout', { height: layout.bottom, bottom: 0, right: 0, left: 0 });
+ vScrollerIsVisible = vScroller && isVisible;
+ vScroller.set('isVisible', vScrollerIsVisible);
+ if (vScrollerIsVisible) {
+ layout.bottom = vScroller.get('scrollerThickness');
+ vScroller.set('layout', { height: layout.bottom, bottom: 0, right: 0, left: 0 });
+ }
// Automatically hide scrollers.
} else {
// Top scrollbar calculations.
vScroller = hasScroller ? this.get('verticalScrollerView') : null;
vScrollerIsVisible = vScroller && isVisible;
- vScroller.set('isVisible', vScrollerIsVisible);
if (vScrollerIsVisible) {
scrollerThickness = vScroller.get('scrollerThickness');
layout.top = (vOffset === 0) ? 0 : scrollerThickness; // Scrolled; show the scrollbar.
vScroller.set('layout', { height: layout.top, top: 0, right: 0, left: 0 });
}
+ vScroller.set('isVisible', vScrollerIsVisible && layout.top !== 0);
// Bottom scrollbar calculations
vScroller = hasScroller ? this.get('verticalScrollerView2') : null;
- vScroller.set('isVisible', (vScrollerIsVisible = vScroller && isVisible));
+ vScrollerIsVisible = vScroller && isVisible;
if (vScroller && isVisible) {
scrollerThickness = vScroller.get('scrollerThickness');
@@ -228,6 +249,7 @@ SC.MenuScrollView = SC.ScrollView.extend(
scrollerThickness : 0;
vScroller.set('layout', { height: layout.bottom, bottom: 0, right: 0, left: 0 });
}
+ vScroller.set('isVisible', vScrollerIsVisible && layout.bottom !== 0);
}
view.adjust(layout);

0 comments on commit d6be00b

Please sign in to comment.