PluginProbe ʕ •ᴥ•ʔ
SiteOrigin CSS / 1.6.3
SiteOrigin CSS v1.6.3
1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.10 1.5.11 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0
so-css / lib / codemirror / addon / fold / foldcode.js
so-css / lib / codemirror / addon / fold Last commit date
brace-fold.js 9 years ago brace-fold.min.js 6 years ago comment-fold.js 9 years ago comment-fold.min.js 6 years ago foldcode.js 9 years ago foldcode.min.js 6 years ago foldgutter.css 11 years ago foldgutter.js 9 years ago foldgutter.min.js 6 years ago indent-fold.js 9 years ago indent-fold.min.js 6 years ago markdown-fold.js 11 years ago markdown-fold.min.js 6 years ago xml-fold.js 9 years ago xml-fold.min.js 6 years ago
foldcode.js
151 lines
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 function doFold(cm, pos, options, force) {
15 if (options && options.call) {
16 var finder = options;
17 options = null;
18 } else {
19 var finder = getOption(cm, options, "rangeFinder");
20 }
21 if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
22 var minSize = getOption(cm, options, "minFoldSize");
23
24 function getRange(allowFolded) {
25 var range = finder(cm, pos);
26 if (!range || range.to.line - range.from.line < minSize) return null;
27 var marks = cm.findMarksAt(range.from);
28 for (var i = 0; i < marks.length; ++i) {
29 if (marks[i].__isFold && force !== "fold") {
30 if (!allowFolded) return null;
31 range.cleared = true;
32 marks[i].clear();
33 }
34 }
35 return range;
36 }
37
38 var range = getRange(true);
39 if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
40 pos = CodeMirror.Pos(pos.line - 1, 0);
41 range = getRange(false);
42 }
43 if (!range || range.cleared || force === "unfold") return;
44
45 var myWidget = makeWidget(cm, options);
46 CodeMirror.on(myWidget, "mousedown", function(e) {
47 myRange.clear();
48 CodeMirror.e_preventDefault(e);
49 });
50 var myRange = cm.markText(range.from, range.to, {
51 replacedWith: myWidget,
52 clearOnEnter: getOption(cm, options, "clearOnEnter"),
53 __isFold: true
54 });
55 myRange.on("clear", function(from, to) {
56 CodeMirror.signal(cm, "unfold", cm, from, to);
57 });
58 CodeMirror.signal(cm, "fold", cm, range.from, range.to);
59 }
60
61 function makeWidget(cm, options) {
62 var widget = getOption(cm, options, "widget");
63 if (typeof widget == "string") {
64 var text = document.createTextNode(widget);
65 widget = document.createElement("span");
66 widget.appendChild(text);
67 widget.className = "CodeMirror-foldmarker";
68 }
69 return widget;
70 }
71
72 // Clumsy backwards-compatible interface
73 CodeMirror.newFoldFunction = function(rangeFinder, widget) {
74 return function(cm, pos) { doFold(cm, pos, {rangeFinder: rangeFinder, widget: widget}); };
75 };
76
77 // New-style interface
78 CodeMirror.defineExtension("foldCode", function(pos, options, force) {
79 doFold(this, pos, options, force);
80 });
81
82 CodeMirror.defineExtension("isFolded", function(pos) {
83 var marks = this.findMarksAt(pos);
84 for (var i = 0; i < marks.length; ++i)
85 if (marks[i].__isFold) return true;
86 });
87
88 CodeMirror.commands.toggleFold = function(cm) {
89 cm.foldCode(cm.getCursor());
90 };
91 CodeMirror.commands.fold = function(cm) {
92 cm.foldCode(cm.getCursor(), null, "fold");
93 };
94 CodeMirror.commands.unfold = function(cm) {
95 cm.foldCode(cm.getCursor(), null, "unfold");
96 };
97 CodeMirror.commands.foldAll = function(cm) {
98 cm.operation(function() {
99 for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
100 cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
101 });
102 };
103 CodeMirror.commands.unfoldAll = function(cm) {
104 cm.operation(function() {
105 for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
106 cm.foldCode(CodeMirror.Pos(i, 0), null, "unfold");
107 });
108 };
109
110 CodeMirror.registerHelper("fold", "combine", function() {
111 var funcs = Array.prototype.slice.call(arguments, 0);
112 return function(cm, start) {
113 for (var i = 0; i < funcs.length; ++i) {
114 var found = funcs[i](cm, start);
115 if (found) return found;
116 }
117 };
118 });
119
120 CodeMirror.registerHelper("fold", "auto", function(cm, start) {
121 var helpers = cm.getHelpers(start, "fold");
122 for (var i = 0; i < helpers.length; i++) {
123 var cur = helpers[i](cm, start);
124 if (cur) return cur;
125 }
126 });
127
128 var defaultOptions = {
129 rangeFinder: CodeMirror.fold.auto,
130 widget: "\u2194",
131 minFoldSize: 0,
132 scanUp: false,
133 clearOnEnter: true
134 };
135
136 CodeMirror.defineOption("foldOptions", null);
137
138 function getOption(cm, options, name) {
139 if (options && options[name] !== undefined)
140 return options[name];
141 var editorOptions = cm.options.foldOptions;
142 if (editorOptions && editorOptions[name] !== undefined)
143 return editorOptions[name];
144 return defaultOptions[name];
145 }
146
147 CodeMirror.defineExtension("foldOption", function(options, name) {
148 return getOption(this, options, name);
149 });
150 });
151