Rename ScrollBarV -> VScrollBar, ScrollBarH -> HScrollBar

This commit is contained in:
DanyaPostfactum 2013-12-10 17:41:02 +10:00
commit 8ecc94a181
2 changed files with 43 additions and 21 deletions

View file

@ -58,6 +58,7 @@ var ScrollBar = function(parent) {
parent.appendChild(this.element); parent.appendChild(this.element);
this.setVisible(false); this.setVisible(false);
this.skipEvent = false;
event.addListener(this.element, "scroll", this.onScroll.bind(this)); event.addListener(this.element, "scroll", this.onScroll.bind(this));
event.addListener(this.element, "mousedown", event.preventDefault); event.addListener(this.element, "mousedown", event.preventDefault);
@ -74,18 +75,19 @@ var ScrollBar = function(parent) {
/** /**
* Represents a vertical scroll bar. * Represents a vertical scroll bar.
* @class ScrollBarV * @class VScrollBar
**/ **/
/** /**
* Creates a new `ScrollBarV`. `parent` is the owner of the scroll bar. * Creates a new `VScrollBar`. `parent` is the owner of the scroll bar.
* @param {DOMElement} parent A DOM element * @param {DOMElement} parent A DOM element
* @param {Object} renderer An editor renderer * @param {Object} renderer An editor renderer
* *
* @constructor * @constructor
**/ **/
var ScrollBarV = function(parent, renderer) { var VScrollBar = function(parent, renderer) {
ScrollBar.call(this, parent); ScrollBar.call(this, parent);
this.scrollTop = 0;
// in OSX lion the scrollbars appear to have no width. In this case resize the // in OSX lion the scrollbars appear to have no width. In this case resize the
// element to show the scrollbar but still pretend that the scrollbar has a width // element to show the scrollbar but still pretend that the scrollbar has a width
@ -96,10 +98,9 @@ var ScrollBarV = function(parent, renderer) {
this.width = dom.scrollbarWidth(parent.ownerDocument); this.width = dom.scrollbarWidth(parent.ownerDocument);
this.inner.style.width = this.inner.style.width =
this.element.style.width = (this.width || 15) + 5 + "px"; this.element.style.width = (this.width || 15) + 5 + "px";
this.element.style.overflowY = "scroll";
}; };
oop.inherits(ScrollBarV, ScrollBar); oop.inherits(VScrollBar, ScrollBar);
(function() { (function() {
@ -137,11 +138,20 @@ oop.inherits(ScrollBarV, ScrollBar);
/** /**
* Sets the inner height of the scroll bar, in pixels. * Sets the inner height of the scroll bar, in pixels.
* @param {Number} height The new inner height * @param {Number} height The new inner height
* @deprecated Use setScrollHeight instead
**/ **/
this.setInnerHeight = function(height) { this.setInnerHeight = function(height) {
this.inner.style.height = height + "px"; this.inner.style.height = height + "px";
}; };
/**
* Sets the scroll height of the scroll bar, in pixels.
* @param {Number} height The new scroll height
**/
this.setScrollHeight = function(height) {
this.inner.style.height = height + "px";
};
/** /**
* Sets the scroll top of the scroll bar. * Sets the scroll top of the scroll bar.
* @param {Number} scrollTop The new scroll top * @param {Number} scrollTop The new scroll top
@ -155,22 +165,23 @@ oop.inherits(ScrollBarV, ScrollBar);
} }
}; };
}).call(ScrollBarV.prototype); }).call(VScrollBar.prototype);
/** /**
* Represents a horisontal scroll bar. * Represents a horisontal scroll bar.
* @class ScrollBarV * @class HScrollBar
**/ **/
/** /**
* Creates a new `ScrollBarH`. `parent` is the owner of the scroll bar. * Creates a new `HScrollBar`. `parent` is the owner of the scroll bar.
* @param {DOMElement} parent A DOM element * @param {DOMElement} parent A DOM element
* @param {Object} renderer An editor renderer * @param {Object} renderer An editor renderer
* *
* @constructor * @constructor
**/ **/
var ScrollBarH = function(parent, renderer) { var HScrollBar = function(parent, renderer) {
ScrollBar.call(this, parent); ScrollBar.call(this, parent);
this.scrollLeft = 0;
// in OSX lion the scrollbars appear to have no width. In this case resize the // in OSX lion the scrollbars appear to have no width. In this case resize the
// element to show the scrollbar but still pretend that the scrollbar has a width // element to show the scrollbar but still pretend that the scrollbar has a width
@ -180,10 +191,9 @@ var ScrollBarH = function(parent, renderer) {
this.height = renderer.$scrollbarWidth; this.height = renderer.$scrollbarWidth;
this.inner.style.height = this.inner.style.height =
this.element.style.height = (this.height || 15) + 5 + "px"; this.element.style.height = (this.height || 15) + 5 + "px";
this.element.style.overflowX = "scroll";
}; };
oop.inherits(ScrollBarH, ScrollBar); oop.inherits(HScrollBar, ScrollBar);
(function() { (function() {
@ -221,11 +231,20 @@ oop.inherits(ScrollBarH, ScrollBar);
/** /**
* Sets the inner width of the scroll bar, in pixels. * Sets the inner width of the scroll bar, in pixels.
* @param {Number} width The new inner width * @param {Number} width The new inner width
* @deprecated Use setScrollWidth instead
**/ **/
this.setInnerWidth = function(width) { this.setInnerWidth = function(width) {
this.inner.style.width = width + "px"; this.inner.style.width = width + "px";
}; };
/**
* Sets the scroll width of the scroll bar, in pixels.
* @param {Number} width The new scroll width
**/
this.setScrollWidth = function(width) {
this.inner.style.width = width + "px";
};
/** /**
* Sets the scroll left of the scroll bar. * Sets the scroll left of the scroll bar.
* @param {Number} scrollTop The new scroll left * @param {Number} scrollTop The new scroll left
@ -239,10 +258,13 @@ oop.inherits(ScrollBarH, ScrollBar);
} }
}; };
}).call(ScrollBarH.prototype); }).call(HScrollBar.prototype);
exports.ScrollBar = ScrollBarV; // backward compatibility exports.ScrollBar = VScrollBar; // backward compatibility
exports.ScrollBarV = ScrollBarV; exports.ScrollBarV = VScrollBar; // backward compatibility
exports.ScrollBarH = ScrollBarH; exports.ScrollBarH = HScrollBar; // backward compatibility
exports.VScrollBar = VScrollBar;
exports.HScrollBar = HScrollBar;
}); });

View file

@ -39,8 +39,8 @@ var GutterLayer = require("./layer/gutter").Gutter;
var MarkerLayer = require("./layer/marker").Marker; var MarkerLayer = require("./layer/marker").Marker;
var TextLayer = require("./layer/text").Text; var TextLayer = require("./layer/text").Text;
var CursorLayer = require("./layer/cursor").Cursor; var CursorLayer = require("./layer/cursor").Cursor;
var ScrollBarH = require("./scrollbar").ScrollBarH; var HScrollBar = require("./scrollbar").HScrollBar;
var ScrollBarV = require("./scrollbar").ScrollBarV; var VScrollBar = require("./scrollbar").VScrollBar;
var RenderLoop = require("./renderloop").RenderLoop; var RenderLoop = require("./renderloop").RenderLoop;
var EventEmitter = require("./lib/event_emitter").EventEmitter; var EventEmitter = require("./lib/event_emitter").EventEmitter;
var editorCss = require("./requirejs/text!./css/editor.css"); var editorCss = require("./requirejs/text!./css/editor.css");
@ -105,8 +105,8 @@ var VirtualRenderer = function(container, theme) {
this.$vScroll = false; this.$vScroll = false;
this.scrollBar = this.scrollBar =
this.scrollBarV = new ScrollBarV(this.container, this); this.scrollBarV = new VScrollBar(this.container, this);
this.scrollBarH = new ScrollBarH(this.container, this); this.scrollBarH = new HScrollBar(this.container, this);
this.scrollBarV.addEventListener("scroll", function(e) { this.scrollBarV.addEventListener("scroll", function(e) {
if (!_self.$scrollAnimation) if (!_self.$scrollAnimation)
_self.session.setScrollTop(e.data - _self.scrollMargin.top); _self.session.setScrollTop(e.data - _self.scrollMargin.top);
@ -727,11 +727,11 @@ var VirtualRenderer = function(container, theme) {
}; };
this.$updateScrollBarV = function() { this.$updateScrollBarV = function() {
this.scrollBarV.setInnerHeight(this.layerConfig.maxHeight + this.scrollMargin.v); this.scrollBarV.setScrollHeight(this.layerConfig.maxHeight + this.scrollMargin.v);
this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top); this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top);
}; };
this.$updateScrollBarH = function() { this.$updateScrollBarH = function() {
this.scrollBarH.setInnerWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h); this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h);
this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left); this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left);
}; };