LaravelTest
51 строка · 1.9 Кб
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
14CodeMirror.defineOption("rulers", false, function(cm, val) {15if (cm.state.rulerDiv) {16cm.state.rulerDiv.parentElement.removeChild(cm.state.rulerDiv)17cm.state.rulerDiv = null18cm.off("refresh", drawRulers)19}20if (val && val.length) {21cm.state.rulerDiv = cm.display.lineSpace.parentElement.insertBefore(document.createElement("div"), cm.display.lineSpace)22cm.state.rulerDiv.className = "CodeMirror-rulers"23drawRulers(cm)24cm.on("refresh", drawRulers)25}26});27
28function drawRulers(cm) {29cm.state.rulerDiv.textContent = ""30var val = cm.getOption("rulers");31var cw = cm.defaultCharWidth();32var left = cm.charCoords(CodeMirror.Pos(cm.firstLine(), 0), "div").left;33cm.state.rulerDiv.style.minHeight = (cm.display.scroller.offsetHeight + 30) + "px";34for (var i = 0; i < val.length; i++) {35var elt = document.createElement("div");36elt.className = "CodeMirror-ruler";37var col, conf = val[i];38if (typeof conf == "number") {39col = conf;40} else {41col = conf.column;42if (conf.className) elt.className += " " + conf.className;43if (conf.color) elt.style.borderColor = conf.color;44if (conf.lineStyle) elt.style.borderLeftStyle = conf.lineStyle;45if (conf.width) elt.style.borderLeftWidth = conf.width;46}47elt.style.left = (left + col * cw) + "px";48cm.state.rulerDiv.appendChild(elt)49}50}51});52