Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50665 views
1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: http://codemirror.net/LICENSE
3
4
(function(mod) {
5
if (typeof exports == "object" && typeof module == "object") // CommonJS
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd) // AMD
8
define(["../../lib/codemirror"], mod);
9
else // Plain browser env
10
mod(CodeMirror);
11
})(function(CodeMirror) {
12
"use strict";
13
14
CodeMirror.defineOption("rulers", false, function(cm, val, old) {
15
if (old && old != CodeMirror.Init) {
16
clearRulers(cm);
17
cm.off("refresh", refreshRulers);
18
}
19
if (val && val.length) {
20
setRulers(cm);
21
cm.on("refresh", refreshRulers);
22
}
23
});
24
25
function clearRulers(cm) {
26
for (var i = cm.display.lineSpace.childNodes.length - 1; i >= 0; i--) {
27
var node = cm.display.lineSpace.childNodes[i];
28
if (/(^|\s)CodeMirror-ruler($|\s)/.test(node.className))
29
node.parentNode.removeChild(node);
30
}
31
}
32
33
function setRulers(cm) {
34
var val = cm.getOption("rulers");
35
var cw = cm.defaultCharWidth();
36
var left = cm.charCoords(CodeMirror.Pos(cm.firstLine(), 0), "div").left;
37
var minH = cm.display.scroller.offsetHeight + 30;
38
for (var i = 0; i < val.length; i++) {
39
var elt = document.createElement("div");
40
elt.className = "CodeMirror-ruler";
41
var col, cls = null, conf = val[i];
42
if (typeof conf == "number") {
43
col = conf;
44
} else {
45
col = conf.column;
46
if (conf.className) elt.className += " " + conf.className;
47
if (conf.color) elt.style.borderColor = conf.color;
48
if (conf.lineStyle) elt.style.borderLeftStyle = conf.lineStyle;
49
if (conf.width) elt.style.borderLeftWidth = conf.width;
50
cls = val[i].className;
51
}
52
elt.style.left = (left + col * cw) + "px";
53
elt.style.top = "-50px";
54
elt.style.bottom = "-20px";
55
elt.style.minHeight = minH + "px";
56
cm.display.lineSpace.insertBefore(elt, cm.display.cursorDiv);
57
}
58
}
59
60
function refreshRulers(cm) {
61
clearRulers(cm);
62
setRulers(cm);
63
}
64
});
65
66