LaravelTest
152 строки · 5.3 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14function Bar(cls, orientation, scroll) {15this.orientation = orientation;16this.scroll = scroll;17this.screen = this.total = this.size = 1;18this.pos = 0;19
20this.node = document.createElement("div");21this.node.className = cls + "-" + orientation;22this.inner = this.node.appendChild(document.createElement("div"));23
24var self = this;25CodeMirror.on(this.inner, "mousedown", function(e) {26if (e.which != 1) return;27CodeMirror.e_preventDefault(e);28var axis = self.orientation == "horizontal" ? "pageX" : "pageY";29var start = e[axis], startpos = self.pos;30function done() {31CodeMirror.off(document, "mousemove", move);32CodeMirror.off(document, "mouseup", done);33}34function move(e) {35if (e.which != 1) return done();36self.moveTo(startpos + (e[axis] - start) * (self.total / self.size));37}38CodeMirror.on(document, "mousemove", move);39CodeMirror.on(document, "mouseup", done);40});41
42CodeMirror.on(this.node, "click", function(e) {43CodeMirror.e_preventDefault(e);44var innerBox = self.inner.getBoundingClientRect(), where;45if (self.orientation == "horizontal")46where = e.clientX < innerBox.left ? -1 : e.clientX > innerBox.right ? 1 : 0;47else48where = e.clientY < innerBox.top ? -1 : e.clientY > innerBox.bottom ? 1 : 0;49self.moveTo(self.pos + where * self.screen);50});51
52function onWheel(e) {53var moved = CodeMirror.wheelEventPixels(e)[self.orientation == "horizontal" ? "x" : "y"];54var oldPos = self.pos;55self.moveTo(self.pos + moved);56if (self.pos != oldPos) CodeMirror.e_preventDefault(e);57}58CodeMirror.on(this.node, "mousewheel", onWheel);59CodeMirror.on(this.node, "DOMMouseScroll", onWheel);60}61
62Bar.prototype.setPos = function(pos, force) {63if (pos < 0) pos = 0;64if (pos > this.total - this.screen) pos = this.total - this.screen;65if (!force && pos == this.pos) return false;66this.pos = pos;67this.inner.style[this.orientation == "horizontal" ? "left" : "top"] =68(pos * (this.size / this.total)) + "px";69return true70};71
72Bar.prototype.moveTo = function(pos) {73if (this.setPos(pos)) this.scroll(pos, this.orientation);74}75
76var minButtonSize = 10;77
78Bar.prototype.update = function(scrollSize, clientSize, barSize) {79var sizeChanged = this.screen != clientSize || this.total != scrollSize || this.size != barSize80if (sizeChanged) {81this.screen = clientSize;82this.total = scrollSize;83this.size = barSize;84}85
86var buttonSize = this.screen * (this.size / this.total);87if (buttonSize < minButtonSize) {88this.size -= minButtonSize - buttonSize;89buttonSize = minButtonSize;90}91this.inner.style[this.orientation == "horizontal" ? "width" : "height"] =92buttonSize + "px";93this.setPos(this.pos, sizeChanged);94};95
96function SimpleScrollbars(cls, place, scroll) {97this.addClass = cls;98this.horiz = new Bar(cls, "horizontal", scroll);99place(this.horiz.node);100this.vert = new Bar(cls, "vertical", scroll);101place(this.vert.node);102this.width = null;103}104
105SimpleScrollbars.prototype.update = function(measure) {106if (this.width == null) {107var style = window.getComputedStyle ? window.getComputedStyle(this.horiz.node) : this.horiz.node.currentStyle;108if (style) this.width = parseInt(style.height);109}110var width = this.width || 0;111
112var needsH = measure.scrollWidth > measure.clientWidth + 1;113var needsV = measure.scrollHeight > measure.clientHeight + 1;114this.vert.node.style.display = needsV ? "block" : "none";115this.horiz.node.style.display = needsH ? "block" : "none";116
117if (needsV) {118this.vert.update(measure.scrollHeight, measure.clientHeight,119measure.viewHeight - (needsH ? width : 0));120this.vert.node.style.bottom = needsH ? width + "px" : "0";121}122if (needsH) {123this.horiz.update(measure.scrollWidth, measure.clientWidth,124measure.viewWidth - (needsV ? width : 0) - measure.barLeft);125this.horiz.node.style.right = needsV ? width + "px" : "0";126this.horiz.node.style.left = measure.barLeft + "px";127}128
129return {right: needsV ? width : 0, bottom: needsH ? width : 0};130};131
132SimpleScrollbars.prototype.setScrollTop = function(pos) {133this.vert.setPos(pos);134};135
136SimpleScrollbars.prototype.setScrollLeft = function(pos) {137this.horiz.setPos(pos);138};139
140SimpleScrollbars.prototype.clear = function() {141var parent = this.horiz.node.parentNode;142parent.removeChild(this.horiz.node);143parent.removeChild(this.vert.node);144};145
146CodeMirror.scrollbarModel.simple = function(place, scroll) {147return new SimpleScrollbars("CodeMirror-simplescroll", place, scroll);148};149CodeMirror.scrollbarModel.overlay = function(place, scroll) {150return new SimpleScrollbars("CodeMirror-overlayscroll", place, scroll);151};152});153