diff options
Diffstat (limited to 'public/vendor/codemirror/addon/scroll')
4 files changed, 374 insertions, 0 deletions
| diff --git a/public/vendor/codemirror/addon/scroll/annotatescrollbar.js b/public/vendor/codemirror/addon/scroll/annotatescrollbar.js new file mode 100755 index 00000000..e62a45ac --- /dev/null +++ b/public/vendor/codemirror/addon/scroll/annotatescrollbar.js @@ -0,0 +1,115 @@ +// CodeMirror, copyright (c) by Marijn Haverbeke and others +// Distributed under an MIT license: http://codemirror.net/LICENSE + +(function(mod) { +  if (typeof exports == "object" && typeof module == "object") // CommonJS +    mod(require("../../lib/codemirror")); +  else if (typeof define == "function" && define.amd) // AMD +    define(["../../lib/codemirror"], mod); +  else // Plain browser env +    mod(CodeMirror); +})(function(CodeMirror) { +  "use strict"; + +  CodeMirror.defineExtension("annotateScrollbar", function(options) { +    if (typeof options == "string") options = {className: options}; +    return new Annotation(this, options); +  }); + +  CodeMirror.defineOption("scrollButtonHeight", 0); + +  function Annotation(cm, options) { +    this.cm = cm; +    this.options = options; +    this.buttonHeight = options.scrollButtonHeight || cm.getOption("scrollButtonHeight"); +    this.annotations = []; +    this.doRedraw = this.doUpdate = null; +    this.div = cm.getWrapperElement().appendChild(document.createElement("div")); +    this.div.style.cssText = "position: absolute; right: 0; top: 0; z-index: 7; pointer-events: none"; +    this.computeScale(); + +    function scheduleRedraw(delay) { +      clearTimeout(self.doRedraw); +      self.doRedraw = setTimeout(function() { self.redraw(); }, delay); +    } + +    var self = this; +    cm.on("refresh", this.resizeHandler = function() { +      clearTimeout(self.doUpdate); +      self.doUpdate = setTimeout(function() { +        if (self.computeScale()) scheduleRedraw(20); +      }, 100); +    }); +    cm.on("markerAdded", this.resizeHandler); +    cm.on("markerCleared", this.resizeHandler); +    if (options.listenForChanges !== false) +      cm.on("change", this.changeHandler = function() { +        scheduleRedraw(250); +      }); +  } + +  Annotation.prototype.computeScale = function() { +    var cm = this.cm; +    var hScale = (cm.getWrapperElement().clientHeight - cm.display.barHeight - this.buttonHeight * 2) / +      cm.heightAtLine(cm.lastLine() + 1, "local"); +    if (hScale != this.hScale) { +      this.hScale = hScale; +      return true; +    } +  }; + +  Annotation.prototype.update = function(annotations) { +    this.annotations = annotations; +    this.redraw(); +  }; + +  Annotation.prototype.redraw = function(compute) { +    if (compute !== false) this.computeScale(); +    var cm = this.cm, hScale = this.hScale; + +    var frag = document.createDocumentFragment(), anns = this.annotations; + +    var wrapping = cm.getOption("lineWrapping"); +    var singleLineH = wrapping && cm.defaultTextHeight() * 1.5; +    var curLine = null, curLineObj = null; +    function getY(pos, top) { +      if (curLine != pos.line) { +        curLine = pos.line; +        curLineObj = cm.getLineHandle(curLine); +      } +      if (wrapping && curLineObj.height > singleLineH) +        return cm.charCoords(pos, "local")[top ? "top" : "bottom"]; +      var topY = cm.heightAtLine(curLineObj, "local"); +      return topY + (top ? 0 : curLineObj.height); +    } + +    if (cm.display.barWidth) for (var i = 0, nextTop; i < anns.length; i++) { +      var ann = anns[i]; +      var top = nextTop || getY(ann.from, true) * hScale; +      var bottom = getY(ann.to, false) * hScale; +      while (i < anns.length - 1) { +        nextTop = getY(anns[i + 1].from, true) * hScale; +        if (nextTop > bottom + .9) break; +        ann = anns[++i]; +        bottom = getY(ann.to, false) * hScale; +      } +      if (bottom == top) continue; +      var height = Math.max(bottom - top, 3); + +      var elt = frag.appendChild(document.createElement("div")); +      elt.style.cssText = "position: absolute; right: 0px; width: " + Math.max(cm.display.barWidth - 1, 2) + "px; top: " +        + (top + this.buttonHeight) + "px; height: " + height + "px"; +      elt.className = this.options.className; +    } +    this.div.textContent = ""; +    this.div.appendChild(frag); +  }; + +  Annotation.prototype.clear = function() { +    this.cm.off("refresh", this.resizeHandler); +    this.cm.off("markerAdded", this.resizeHandler); +    this.cm.off("markerCleared", this.resizeHandler); +    if (this.changeHandler) this.cm.off("change", this.changeHandler); +    this.div.parentNode.removeChild(this.div); +  }; +}); diff --git a/public/vendor/codemirror/addon/scroll/scrollpastend.js b/public/vendor/codemirror/addon/scroll/scrollpastend.js new file mode 100755 index 00000000..008ae4c7 --- /dev/null +++ b/public/vendor/codemirror/addon/scroll/scrollpastend.js @@ -0,0 +1,46 @@ +// CodeMirror, copyright (c) by Marijn Haverbeke and others +// Distributed under an MIT license: http://codemirror.net/LICENSE + +(function(mod) { +  if (typeof exports == "object" && typeof module == "object") // CommonJS +    mod(require("../../lib/codemirror")); +  else if (typeof define == "function" && define.amd) // AMD +    define(["../../lib/codemirror"], mod); +  else // Plain browser env +    mod(CodeMirror); +})(function(CodeMirror) { +  "use strict"; + +  CodeMirror.defineOption("scrollPastEnd", false, function(cm, val, old) { +    if (old && old != CodeMirror.Init) { +      cm.off("change", onChange); +      cm.off("refresh", updateBottomMargin); +      cm.display.lineSpace.parentNode.style.paddingBottom = ""; +      cm.state.scrollPastEndPadding = null; +    } +    if (val) { +      cm.on("change", onChange); +      cm.on("refresh", updateBottomMargin); +      updateBottomMargin(cm); +    } +  }); + +  function onChange(cm, change) { +    if (CodeMirror.changeEnd(change).line == cm.lastLine()) +      updateBottomMargin(cm); +  } + +  function updateBottomMargin(cm) { +    var padding = ""; +    if (cm.lineCount() > 1) { +      var totalH = cm.display.scroller.clientHeight - 30, +          lastLineH = cm.getLineHandle(cm.lastLine()).height; +      padding = (totalH - lastLineH) + "px"; +    } +    if (cm.state.scrollPastEndPadding != padding) { +      cm.state.scrollPastEndPadding = padding; +      cm.display.lineSpace.parentNode.style.paddingBottom = padding; +      cm.setSize(); +    } +  } +}); diff --git a/public/vendor/codemirror/addon/scroll/simplescrollbars.css b/public/vendor/codemirror/addon/scroll/simplescrollbars.css new file mode 100755 index 00000000..5eea7aa1 --- /dev/null +++ b/public/vendor/codemirror/addon/scroll/simplescrollbars.css @@ -0,0 +1,66 @@ +.CodeMirror-simplescroll-horizontal div, .CodeMirror-simplescroll-vertical div { +  position: absolute; +  background: #ccc; +  -moz-box-sizing: border-box; +  box-sizing: border-box; +  border: 1px solid #bbb; +  border-radius: 2px; +} + +.CodeMirror-simplescroll-horizontal, .CodeMirror-simplescroll-vertical { +  position: absolute; +  z-index: 6; +  background: #eee; +} + +.CodeMirror-simplescroll-horizontal { +  bottom: 0; left: 0; +  height: 8px; +} +.CodeMirror-simplescroll-horizontal div { +  bottom: 0; +  height: 100%; +} + +.CodeMirror-simplescroll-vertical { +  right: 0; top: 0; +  width: 8px; +} +.CodeMirror-simplescroll-vertical div { +  right: 0; +  width: 100%; +} + + +.CodeMirror-overlayscroll .CodeMirror-scrollbar-filler, .CodeMirror-overlayscroll .CodeMirror-gutter-filler { +  display: none; +} + +.CodeMirror-overlayscroll-horizontal div, .CodeMirror-overlayscroll-vertical div { +  position: absolute; +  background: #bcd; +  border-radius: 3px; +} + +.CodeMirror-overlayscroll-horizontal, .CodeMirror-overlayscroll-vertical { +  position: absolute; +  z-index: 6; +} + +.CodeMirror-overlayscroll-horizontal { +  bottom: 0; left: 0; +  height: 6px; +} +.CodeMirror-overlayscroll-horizontal div { +  bottom: 0; +  height: 100%; +} + +.CodeMirror-overlayscroll-vertical { +  right: 0; top: 0; +  width: 6px; +} +.CodeMirror-overlayscroll-vertical div { +  right: 0; +  width: 100%; +} diff --git a/public/vendor/codemirror/addon/scroll/simplescrollbars.js b/public/vendor/codemirror/addon/scroll/simplescrollbars.js new file mode 100755 index 00000000..f78353a1 --- /dev/null +++ b/public/vendor/codemirror/addon/scroll/simplescrollbars.js @@ -0,0 +1,147 @@ +// CodeMirror, copyright (c) by Marijn Haverbeke and others +// Distributed under an MIT license: http://codemirror.net/LICENSE + +(function(mod) { +  if (typeof exports == "object" && typeof module == "object") // CommonJS +    mod(require("../../lib/codemirror")); +  else if (typeof define == "function" && define.amd) // AMD +    define(["../../lib/codemirror"], mod); +  else // Plain browser env +    mod(CodeMirror); +})(function(CodeMirror) { +  "use strict"; + +  function Bar(cls, orientation, scroll) { +    this.orientation = orientation; +    this.scroll = scroll; +    this.screen = this.total = this.size = 1; +    this.pos = 0; + +    this.node = document.createElement("div"); +    this.node.className = cls + "-" + orientation; +    this.inner = this.node.appendChild(document.createElement("div")); + +    var self = this; +    CodeMirror.on(this.inner, "mousedown", function(e) { +      if (e.which != 1) return; +      CodeMirror.e_preventDefault(e); +      var axis = self.orientation == "horizontal" ? "pageX" : "pageY"; +      var start = e[axis], startpos = self.pos; +      function done() { +        CodeMirror.off(document, "mousemove", move); +        CodeMirror.off(document, "mouseup", done); +      } +      function move(e) { +        if (e.which != 1) return done(); +        self.moveTo(startpos + (e[axis] - start) * (self.total / self.size)); +      } +      CodeMirror.on(document, "mousemove", move); +      CodeMirror.on(document, "mouseup", done); +    }); + +    CodeMirror.on(this.node, "click", function(e) { +      CodeMirror.e_preventDefault(e); +      var innerBox = self.inner.getBoundingClientRect(), where; +      if (self.orientation == "horizontal") +        where = e.clientX < innerBox.left ? -1 : e.clientX > innerBox.right ? 1 : 0; +      else +        where = e.clientY < innerBox.top ? -1 : e.clientY > innerBox.bottom ? 1 : 0; +      self.moveTo(self.pos + where * self.screen); +    }); + +    function onWheel(e) { +      var moved = CodeMirror.wheelEventPixels(e)[self.orientation == "horizontal" ? "x" : "y"]; +      var oldPos = self.pos; +      self.moveTo(self.pos + moved); +      if (self.pos != oldPos) CodeMirror.e_preventDefault(e); +    } +    CodeMirror.on(this.node, "mousewheel", onWheel); +    CodeMirror.on(this.node, "DOMMouseScroll", onWheel); +  } + +  Bar.prototype.moveTo = function(pos, update) { +    if (pos < 0) pos = 0; +    if (pos > this.total - this.screen) pos = this.total - this.screen; +    if (pos == this.pos) return; +    this.pos = pos; +    this.inner.style[this.orientation == "horizontal" ? "left" : "top"] = +      (pos * (this.size / this.total)) + "px"; +    if (update !== false) this.scroll(pos, this.orientation); +  }; + +  var minButtonSize = 10; + +  Bar.prototype.update = function(scrollSize, clientSize, barSize) { +    this.screen = clientSize; +    this.total = scrollSize; +    this.size = barSize; + +    var buttonSize = this.screen * (this.size / this.total); +    if (buttonSize < minButtonSize) { +      this.size -= minButtonSize - buttonSize; +      buttonSize = minButtonSize; +    } +    this.inner.style[this.orientation == "horizontal" ? "width" : "height"] = +      buttonSize + "px"; +    this.inner.style[this.orientation == "horizontal" ? "left" : "top"] = +      this.pos * (this.size / this.total) + "px"; +  }; + +  function SimpleScrollbars(cls, place, scroll) { +    this.addClass = cls; +    this.horiz = new Bar(cls, "horizontal", scroll); +    place(this.horiz.node); +    this.vert = new Bar(cls, "vertical", scroll); +    place(this.vert.node); +    this.width = null; +  } + +  SimpleScrollbars.prototype.update = function(measure) { +    if (this.width == null) { +      var style = window.getComputedStyle ? window.getComputedStyle(this.horiz.node) : this.horiz.node.currentStyle; +      if (style) this.width = parseInt(style.height); +    } +    var width = this.width || 0; + +    var needsH = measure.scrollWidth > measure.clientWidth + 1; +    var needsV = measure.scrollHeight > measure.clientHeight + 1; +    this.vert.node.style.display = needsV ? "block" : "none"; +    this.horiz.node.style.display = needsH ? "block" : "none"; + +    if (needsV) { +      this.vert.update(measure.scrollHeight, measure.clientHeight, +                       measure.viewHeight - (needsH ? width : 0)); +      this.vert.node.style.display = "block"; +      this.vert.node.style.bottom = needsH ? width + "px" : "0"; +    } +    if (needsH) { +      this.horiz.update(measure.scrollWidth, measure.clientWidth, +                        measure.viewWidth - (needsV ? width : 0) - measure.barLeft); +      this.horiz.node.style.right = needsV ? width + "px" : "0"; +      this.horiz.node.style.left = measure.barLeft + "px"; +    } + +    return {right: needsV ? width : 0, bottom: needsH ? width : 0}; +  }; + +  SimpleScrollbars.prototype.setScrollTop = function(pos) { +    this.vert.moveTo(pos, false); +  }; + +  SimpleScrollbars.prototype.setScrollLeft = function(pos) { +    this.horiz.moveTo(pos, false); +  }; + +  SimpleScrollbars.prototype.clear = function() { +    var parent = this.horiz.node.parentNode; +    parent.removeChild(this.horiz.node); +    parent.removeChild(this.vert.node); +  }; + +  CodeMirror.scrollbarModel.simple = function(place, scroll) { +    return new SimpleScrollbars("CodeMirror-simplescroll", place, scroll); +  }; +  CodeMirror.scrollbarModel.overlay = function(place, scroll) { +    return new SimpleScrollbars("CodeMirror-overlayscroll", place, scroll); +  }; +}); | 
