corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 ace.define("ace/ext/static_highlight",["require","exports","module","ace/edit_session","ace/layer/text","ace/config","ace/lib/dom"], function(require, exports, module) {
2 "use strict";
3  
4 var EditSession = require("../edit_session").EditSession;
5 var TextLayer = require("../layer/text").Text;
6 var baseStyles = ".ace_static_highlight {\
7 font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'Droid Sans Mono', monospace;\
8 font-size: 12px;\
9 white-space: pre-wrap\
10 }\
11 .ace_static_highlight .ace_gutter {\
12 width: 2em;\
13 text-align: right;\
14 padding: 0 3px 0 0;\
15 margin-right: 3px;\
16 }\
17 .ace_static_highlight.ace_show_gutter .ace_line {\
18 padding-left: 2.6em;\
19 }\
20 .ace_static_highlight .ace_line { position: relative; }\
21 .ace_static_highlight .ace_gutter-cell {\
22 -moz-user-select: -moz-none;\
23 -khtml-user-select: none;\
24 -webkit-user-select: none;\
25 user-select: none;\
26 top: 0;\
27 bottom: 0;\
28 left: 0;\
29 position: absolute;\
30 }\
31 .ace_static_highlight .ace_gutter-cell:before {\
32 content: counter(ace_line, decimal);\
33 counter-increment: ace_line;\
34 }\
35 .ace_static_highlight {\
36 counter-reset: ace_line;\
37 }\
38 ";
39 var config = require("../config");
40 var dom = require("../lib/dom");
41  
42 var SimpleTextLayer = function() {
43 this.config = {};
44 };
45 SimpleTextLayer.prototype = TextLayer.prototype;
46  
47 var highlight = function(el, opts, callback) {
48 var m = el.className.match(/lang-(\w+)/);
49 var mode = opts.mode || m && ("ace/mode/" + m[1]);
50 if (!mode)
51 return false;
52 var theme = opts.theme || "ace/theme/textmate";
53  
54 var data = "";
55 var nodes = [];
56  
57 if (el.firstElementChild) {
58 var textLen = 0;
59 for (var i = 0; i < el.childNodes.length; i++) {
60 var ch = el.childNodes[i];
61 if (ch.nodeType == 3) {
62 textLen += ch.data.length;
63 data += ch.data;
64 } else {
65 nodes.push(textLen, ch);
66 }
67 }
68 } else {
69 data = dom.getInnerText(el);
70 if (opts.trim)
71 data = data.trim();
72 }
73  
74 highlight.render(data, mode, theme, opts.firstLineNumber, !opts.showGutter, function (highlighted) {
75 dom.importCssString(highlighted.css, "ace_highlight");
76 el.innerHTML = highlighted.html;
77 var container = el.firstChild.firstChild;
78 for (var i = 0; i < nodes.length; i += 2) {
79 var pos = highlighted.session.doc.indexToPosition(nodes[i]);
80 var node = nodes[i + 1];
81 var lineEl = container.children[pos.row];
82 lineEl && lineEl.appendChild(node);
83 }
84 callback && callback();
85 });
86 };
87 highlight.render = function(input, mode, theme, lineStart, disableGutter, callback) {
88 var waiting = 1;
89 var modeCache = EditSession.prototype.$modes;
90 if (typeof theme == "string") {
91 waiting++;
92 config.loadModule(['theme', theme], function(m) {
93 theme = m;
94 --waiting || done();
95 });
96 }
97 var modeOptions;
98 if (mode && typeof mode === "object" && !mode.getTokenizer) {
99 modeOptions = mode;
100 mode = modeOptions.path;
101 }
102 if (typeof mode == "string") {
103 waiting++;
104 config.loadModule(['mode', mode], function(m) {
105 if (!modeCache[mode] || modeOptions)
106 modeCache[mode] = new m.Mode(modeOptions);
107 mode = modeCache[mode];
108 --waiting || done();
109 });
110 }
111 function done() {
112 var result = highlight.renderSync(input, mode, theme, lineStart, disableGutter);
113 return callback ? callback(result) : result;
114 }
115 return --waiting || done();
116 };
117 highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) {
118 lineStart = parseInt(lineStart || 1, 10);
119  
120 var session = new EditSession("");
121 session.setUseWorker(false);
122 session.setMode(mode);
123  
124 var textLayer = new SimpleTextLayer();
125 textLayer.setSession(session);
126  
127 session.setValue(input);
128  
129 var stringBuilder = [];
130 var length = session.getLength();
131  
132 for(var ix = 0; ix < length; ix++) {
133 stringBuilder.push("<div class='ace_line'>");
134 if (!disableGutter)
135 stringBuilder.push("<span class='ace_gutter ace_gutter-cell' unselectable='on'>" + /*(ix + lineStart) + */ "</span>");
136 textLayer.$renderLine(stringBuilder, ix, true, false);
137 stringBuilder.push("\n</div>");
138 }
139 var html = "<div class='" + theme.cssClass + "'>" +
140 "<div class='ace_static_highlight" + (disableGutter ? "" : " ace_show_gutter") +
141 "' style='counter-reset:ace_line " + (lineStart - 1) + "'>" +
142 stringBuilder.join("") +
143 "</div>" +
144 "</div>";
145  
146 textLayer.destroy();
147  
148 return {
149 css: baseStyles + theme.cssText,
150 html: html,
151 session: session
152 };
153 };
154  
155 module.exports = highlight;
156 module.exports.highlight =highlight;
157 });
158 (function() {
159 ace.require(["ace/ext/static_highlight"], function() {});
160 })();
161