5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
function Bar(cls, orientation, scroll) {
15
this.orientation = orientation;
17
this.screen = this.total = this.size = 1;
20
this.node = document.createElement("div");
21
this.node.className = cls + "-" + orientation;
22
this.inner = this.node.appendChild(document.createElement("div"));
25
CodeMirror.on(this.inner, "mousedown", function(e) {
26
if (e.which != 1) return;
27
CodeMirror.e_preventDefault(e);
28
var axis = self.orientation == "horizontal" ? "pageX" : "pageY";
29
var start = e[axis], startpos = self.pos;
31
CodeMirror.off(document, "mousemove", move);
32
CodeMirror.off(document, "mouseup", done);
35
if (e.which != 1) return done();
36
self.moveTo(startpos + (e[axis] - start) * (self.total / self.size));
38
CodeMirror.on(document, "mousemove", move);
39
CodeMirror.on(document, "mouseup", done);
42
CodeMirror.on(this.node, "click", function(e) {
43
CodeMirror.e_preventDefault(e);
44
var innerBox = self.inner.getBoundingClientRect(), where;
45
if (self.orientation == "horizontal")
46
where = e.clientX < innerBox.left ? -1 : e.clientX > innerBox.right ? 1 : 0;
48
where = e.clientY < innerBox.top ? -1 : e.clientY > innerBox.bottom ? 1 : 0;
49
self.moveTo(self.pos + where * self.screen);
53
var moved = CodeMirror.wheelEventPixels(e)[self.orientation == "horizontal" ? "x" : "y"];
54
var oldPos = self.pos;
55
self.moveTo(self.pos + moved);
56
if (self.pos != oldPos) CodeMirror.e_preventDefault(e);
58
CodeMirror.on(this.node, "mousewheel", onWheel);
59
CodeMirror.on(this.node, "DOMMouseScroll", onWheel);
62
Bar.prototype.setPos = function(pos, force) {
64
if (pos > this.total - this.screen) pos = this.total - this.screen;
65
if (!force && pos == this.pos) return false;
67
this.inner.style[this.orientation == "horizontal" ? "left" : "top"] =
68
(pos * (this.size / this.total)) + "px";
72
Bar.prototype.moveTo = function(pos) {
73
if (this.setPos(pos)) this.scroll(pos, this.orientation);
76
var minButtonSize = 10;
78
Bar.prototype.update = function(scrollSize, clientSize, barSize) {
79
var sizeChanged = this.screen != clientSize || this.total != scrollSize || this.size != barSize
81
this.screen = clientSize;
82
this.total = scrollSize;
86
var buttonSize = this.screen * (this.size / this.total);
87
if (buttonSize < minButtonSize) {
88
this.size -= minButtonSize - buttonSize;
89
buttonSize = minButtonSize;
91
this.inner.style[this.orientation == "horizontal" ? "width" : "height"] =
93
this.setPos(this.pos, sizeChanged);
96
function SimpleScrollbars(cls, place, scroll) {
98
this.horiz = new Bar(cls, "horizontal", scroll);
99
place(this.horiz.node);
100
this.vert = new Bar(cls, "vertical", scroll);
101
place(this.vert.node);
105
SimpleScrollbars.prototype.update = function(measure) {
106
if (this.width == null) {
107
var style = window.getComputedStyle ? window.getComputedStyle(this.horiz.node) : this.horiz.node.currentStyle;
108
if (style) this.width = parseInt(style.height);
110
var width = this.width || 0;
112
var needsH = measure.scrollWidth > measure.clientWidth + 1;
113
var needsV = measure.scrollHeight > measure.clientHeight + 1;
114
this.vert.node.style.display = needsV ? "block" : "none";
115
this.horiz.node.style.display = needsH ? "block" : "none";
118
this.vert.update(measure.scrollHeight, measure.clientHeight,
119
measure.viewHeight - (needsH ? width : 0));
120
this.vert.node.style.bottom = needsH ? width + "px" : "0";
123
this.horiz.update(measure.scrollWidth, measure.clientWidth,
124
measure.viewWidth - (needsV ? width : 0) - measure.barLeft);
125
this.horiz.node.style.right = needsV ? width + "px" : "0";
126
this.horiz.node.style.left = measure.barLeft + "px";
129
return {right: needsV ? width : 0, bottom: needsH ? width : 0};
132
SimpleScrollbars.prototype.setScrollTop = function(pos) {
133
this.vert.setPos(pos);
136
SimpleScrollbars.prototype.setScrollLeft = function(pos) {
137
this.horiz.setPos(pos);
140
SimpleScrollbars.prototype.clear = function() {
141
var parent = this.horiz.node.parentNode;
142
parent.removeChild(this.horiz.node);
143
parent.removeChild(this.vert.node);
146
CodeMirror.scrollbarModel.simple = function(place, scroll) {
147
return new SimpleScrollbars("CodeMirror-simplescroll", place, scroll);
149
CodeMirror.scrollbarModel.overlay = function(place, scroll) {
150
return new SimpleScrollbars("CodeMirror-overlayscroll", place, scroll);