forked from rmariuzzo/cloud9-emmet-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud9-emmet-ext.js
154 lines (125 loc) · 3.92 KB
/
cloud9-emmet-ext.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*!
* Emmet for the Cloud9 IDE.
*
* @copyright 2013, Rubens Mariuzzo, Mariuzzo.com
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
*/
// RequireJS configuration for non AMD dependencies.
requirejs.config({
shim: {
'./vendors/underscore.js': {
exports: '_'
},
'./vendors/emmet-full.js': {
deps : ['_'],
exports: 'emmet'
},
'./cloud9-editor-proxy.js': {
deps: ['_', 'emmet'],
exports: 'editorProxy'
}
}
});
// Cloud9 Emmet extension.
define(function(require, exports, module) {
// Cloud9's dependencies.
var ext = require('core/ext');
var menus = require('ext/menus/menus');
var editors = require("ext/editors/editors");
var commands = require('ext/commands/commands');
// Extension's dependencies.
require('./vendors/underscore.js');
require('./vendors/emmet-full.js');
var editorProxy = require('./cloud9-editor-proxy.js');
// Cloud9 extension definition.
module.exports = ext.register('ext/cloud9-emmet-ext/cloud9-emmet-ext', {
// C9 Extension Properties
name: 'Emmet Extension',
dev: 'Rubens Mariuzzo',
alone: true,
offline: false,
type: ext.GENERAL,
nodes: [],
// C9 Extension Methods
/**
* Initialize the extension.
*/
init: function(amlNode) {},
/**
* Hook the extension into the Cloud9 IDE.
*/
hook: function() {
// Prepare the menu.
this.nodes.push(menus.addItemByPath('Tools/Emmet/', new apf.menu(), 900));
// Emmet > Expand Abbreviation
var mnuItemExpand = new apf.item({
command: 'expand',
onclick: function(editor) {
runEmmetAction('expand_abbreviation', editor);
}
});
this.nodes.push(menus.addItemByPath('Tools/Emmet/Expand Abbreviation', mnuItemExpand, 910));
commands.addCommand({
name: 'expand',
hint: 'expands CSS-like abbreviations into HTML/XML/CSS code, depending on current document’s syntax.',
msg: 'Expanding abbreviation.',
bindKey: {
mac: 'Command-Ctrl-Enter',
win: 'Shift-Ctrl-E'
},
isAvailable: function(editor) {
return true;
},
exec: function(editor) {
runEmmetAction('expand_abbreviation', editor);
}
});
ext.initExtension(this);
},
/**
* Enable the extension.
*/
enable: function() {
this.nodes.each(function(item) {
item.enable();
});
this.disabled = false;
},
/**
* Disable the extension.
*/
disable: function() {
this.nodes.each(function(item) {
item.disable();
});
this.disabled = true;
},
/**
* Destroy the extension depdendencies.
*/
destroy: function() {
// Restore the menu.
menus.remove('Tools/Emmet');
this.nodes.each(function(item) {
item.destroy(true, true);
});
this.nodes = [];
}
});
// Private functions //
//-------------------//
function runEmmetAction(name, editor) {
if (this.disabled === true)
return;
// Set current editor.
if (!editor)
editor = editors.currentEditor;
if (editor.amlEditor)
editor = editor.amlEditor.$editor;
editorProxy.setEditor(editor);
// Delegate emmet action.
try {
emmet.require('actions').run(name, editorProxy);
} catch (err) {}
}
});