-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
51 lines (44 loc) · 1.62 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
define(function (require, exports, module) {
'use strict';
var css = ".h-phantom{position:relative;}\
.h-phantom:before{content:attr(data-color);color:inherit;background-color:inherit;pointer-events:none;position:absolute;top:0;left:0;border-radius:2px;white-space:pre;}";
var document = window.document;
var style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
document.head.appendChild(style);
var Colorhighlighter = require('colorhighlighter'),
EditorManager = brackets.getModule('editor/EditorManager');
function validLang(mode) {
return mode == 'css' ||
mode == 'sass' ||
mode == 'scss' ||
mode == 'less' ||
mode == 'html' ||
mode == 'php' ||
mode == 'stylus';
}
function processEditor(editor) {
var cm = editor._codeMirror;
if (cm) {
if (editor.document && validLang(editor.document.language._id)) {
Colorhighlighter.addHighlighter(cm);
}
else {
Colorhighlighter.destroyHighlighter(cm);
}
}
}
EditorManager.on('activeEditorChange', function (event, editor) {
if (editor && editor._codeMirror) {
processEditor(editor);
var doc = editor.document;
if (!doc._hasColorHighlighterListeners) {
doc._hasColorHighlighterListeners = true;
doc.on('languageChanged', function () {
processEditor(editor);
});
}
}
});
});