Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / codemirror / addon / scroll / scrollpastend.js
1 (function(mod) {
2 if (typeof exports == "object" && typeof module == "object") // CommonJS
3 mod(require("../../lib/codemirror"));
4 else if (typeof define == "function" && define.amd) // AMD
5 define(["../../lib/codemirror"], mod);
6 else // Plain browser env
7 mod(CodeMirror);
8 })(function(CodeMirror) {
9 "use strict";
10
11 CodeMirror.defineOption("scrollPastEnd", false, function(cm, val, old) {
12 if (old && old != CodeMirror.Init) {
13 cm.off("change", onChange);
14 cm.off("refresh", updateBottomMargin);
15 cm.display.lineSpace.parentNode.style.paddingBottom = "";
16 cm.state.scrollPastEndPadding = null;
17 }
18 if (val) {
19 cm.on("change", onChange);
20 cm.on("refresh", updateBottomMargin);
21 updateBottomMargin(cm);
22 }
23 });
24
25 function onChange(cm, change) {
26 if (CodeMirror.changeEnd(change).line == cm.lastLine())
27 updateBottomMargin(cm);
28 }
29
30 function updateBottomMargin(cm) {
31 var padding = "";
32 if (cm.lineCount() > 1) {
33 var totalH = cm.display.scroller.clientHeight - 30,
34 lastLineH = cm.getLineHandle(cm.lastLine()).height;
35 padding = (totalH - lastLineH) + "px";
36 }
37 if (cm.state.scrollPastEndPadding != padding) {
38 cm.state.scrollPastEndPadding = padding;
39 cm.display.lineSpace.parentNode.style.paddingBottom = padding;
40 cm.setSize();
41 }
42 }
43 });