|
|
@@ -0,0 +1,117 @@
|
|
|
+
|
|
|
+var Scroller = FC.Scroller = Class.extend(Emitter, {
|
|
|
+
|
|
|
+ el: null, // the guaranteed outer element
|
|
|
+ scrollEl: null, // the element with the scrollbars
|
|
|
+ overflowX: null,
|
|
|
+ overflowY: null,
|
|
|
+ height: null,
|
|
|
+
|
|
|
+
|
|
|
+ constructor: function(options) {
|
|
|
+ options = options || {};
|
|
|
+ this.overflowX = options.overflowX || options.overflow || 'auto';
|
|
|
+ this.overflowY = options.overflowY || options.overflow || 'auto';
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ render: function() {
|
|
|
+ this.el = this.renderEl();
|
|
|
+ this.applyOverflow();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ renderEl: function() {
|
|
|
+ return (this.scrollEl = $('<div class="fc-scroller"></div>'));
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // sets to natural height, unlocks overflow
|
|
|
+ clear: function() {
|
|
|
+ this.setHeight('auto');
|
|
|
+ this.applyOverflow();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ destroy: function() {
|
|
|
+ this.el.remove();
|
|
|
+ this.el = null;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // Overflow
|
|
|
+ // -----------------------------------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+
|
|
|
+ applyOverflow: function() {
|
|
|
+ this.scrollEl.css({
|
|
|
+ 'overflow-x': this.overflowX,
|
|
|
+ 'overflow-y': this.overflowY
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // Causes any 'auto' overflow values to resolves to 'scroll' or 'hidden'.
|
|
|
+ // Useful for preserving scrollbar widths regardless of future resizes.
|
|
|
+ lockOverflow: function(scrollbarWidths) { // can pass in scrollbarWidths for optimization
|
|
|
+ var overflowX = this.overflowX;
|
|
|
+ var overflowY = this.overflowY;
|
|
|
+
|
|
|
+ scrollbarWidths = scrollbarWidths || this.getScrollbarWidths();
|
|
|
+
|
|
|
+ if (overflowX === 'auto') {
|
|
|
+ overflowX = (
|
|
|
+ scrollbarWidths.top || scrollbarWidths.bottom || // horizontal scrollbars?
|
|
|
+ // OR scrolling pane with massless scrollbars?
|
|
|
+ this.scrollEl[0].scrollWidth - 1 > this.scrollEl[0].clientWidth
|
|
|
+ // subtract 1 because of IE off-by-one issue
|
|
|
+ ) ? 'scroll' : 'hidden';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (overflowY === 'auto') {
|
|
|
+ overflowY = (
|
|
|
+ scrollbarWidths.left || scrollbarWidths.right || // vertical scrollbars?
|
|
|
+ // OR scrolling pane with massless scrollbars?
|
|
|
+ this.scrollEl[0].scrollHeight - 1 > this.scrollEl[0].clientHeight
|
|
|
+ // subtract 1 because of IE off-by-one issue
|
|
|
+ ) ? 'scroll' : 'hidden';
|
|
|
+ }
|
|
|
+
|
|
|
+ this.scrollEl.css({ 'overflow-x': overflowX, 'overflow-y': overflowY });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ // Getters / Setters
|
|
|
+ // -----------------------------------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+
|
|
|
+ setHeight: function(height) {
|
|
|
+ this.scrollEl.height(height);
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getScrollTop: function() {
|
|
|
+ return this.scrollEl.scrollTop();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ setScrollTop: function(top) {
|
|
|
+ this.scrollEl.scrollTop(top);
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getClientWidth: function() {
|
|
|
+ return this.scrollEl[0].clientWidth;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getClientHeight: function() {
|
|
|
+ return this.scrollEl[0].clientHeight;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getScrollbarWidths: function() {
|
|
|
+ return getScrollbarWidths(this.scrollEl);
|
|
|
+ }
|
|
|
+
|
|
|
+});
|