5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineOption("rulers", false, function(cm, val) {
15
if (cm.state.rulerDiv) {
16
cm.state.rulerDiv.parentElement.removeChild(cm.state.rulerDiv)
17
cm.state.rulerDiv = null
18
cm.off("refresh", drawRulers)
20
if (val && val.length) {
21
cm.state.rulerDiv = cm.display.lineSpace.parentElement.insertBefore(document.createElement("div"), cm.display.lineSpace)
22
cm.state.rulerDiv.className = "CodeMirror-rulers"
24
cm.on("refresh", drawRulers)
28
function drawRulers(cm) {
29
cm.state.rulerDiv.textContent = ""
30
var val = cm.getOption("rulers");
31
var cw = cm.defaultCharWidth();
32
var left = cm.charCoords(CodeMirror.Pos(cm.firstLine(), 0), "div").left;
33
cm.state.rulerDiv.style.minHeight = (cm.display.scroller.offsetHeight + 30) + "px";
34
for (var i = 0; i < val.length; i++) {
35
var elt = document.createElement("div");
36
elt.className = "CodeMirror-ruler";
37
var col, conf = val[i];
38
if (typeof conf == "number") {
42
if (conf.className) elt.className += " " + conf.className;
43
if (conf.color) elt.style.borderColor = conf.color;
44
if (conf.lineStyle) elt.style.borderLeftStyle = conf.lineStyle;
45
if (conf.width) elt.style.borderLeftWidth = conf.width;
47
elt.style.left = (left + col * cw) + "px";
48
cm.state.rulerDiv.appendChild(elt)