(cls, orientation, scroll)
| 12 | "use strict"; |
| 13 | |
| 14 | function Bar(cls, orientation, scroll) { |
| 15 | this.orientation = orientation; |
| 16 | this.scroll = scroll; |
| 17 | this.screen = this.total = this.size = 1; |
| 18 | this.pos = 0; |
| 19 | |
| 20 | this.node = document.createElement("div"); |
| 21 | this.node.className = cls + "-" + orientation; |
| 22 | this.inner = this.node.appendChild(document.createElement("div")); |
| 23 | |
| 24 | var self = this; |
| 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; |
| 30 | function done() { |
| 31 | CodeMirror.off(document, "mousemove", move); |
| 32 | CodeMirror.off(document, "mouseup", done); |
| 33 | } |
| 34 | function move(e) { |
| 35 | if (e.which != 1) return done(); |
| 36 | self.moveTo(startpos + (e[axis] - start) * (self.total / self.size)); |
| 37 | } |
| 38 | CodeMirror.on(document, "mousemove", move); |
| 39 | CodeMirror.on(document, "mouseup", done); |
| 40 | }); |
| 41 | |
| 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; |
| 47 | else |
| 48 | where = e.clientY < innerBox.top ? -1 : e.clientY > innerBox.bottom ? 1 : 0; |
| 49 | self.moveTo(self.pos + where * self.screen); |
| 50 | }); |
| 51 | |
| 52 | function onWheel(e) { |
| 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); |
| 57 | } |
| 58 | CodeMirror.on(this.node, "mousewheel", onWheel); |
| 59 | CodeMirror.on(this.node, "DOMMouseScroll", onWheel); |
| 60 | } |
| 61 | |
| 62 | Bar.prototype.moveTo = function(pos, update) { |
| 63 | if (pos < 0) pos = 0; |
nothing calls this directly
no outgoing calls
no test coverage detected