-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheventManager.js
311 lines (275 loc) · 7.59 KB
/
eventManager.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// a wrapper for the pub/sub pattern described here: http://api.jquery.com/jQuery.Callbacks/
'use strict';
var $ = require('jquery');
/**
* @class EventManager
* @param {Writer} writer
*/
function EventManager(writer) {
var w = writer;
var doDebug = false;
var events = {};
/**
* Register an event with the Writer
* @memberof Writer
* @method event
* @instance
* @param {String} id The unique event name
*/
w.event = function(id) {
var callbacks, method, event = id && events[id];
if (!event) {
callbacks = $.Callbacks();
event = {
publish: function() {
if (doDebug) {
console.debug('CWRC-Writer "'+this.event+'":', arguments);
}
callbacks.fire.apply(this, arguments);
},
subscribe: callbacks.add,
unsubscribe: callbacks.remove,
event: id
};
}
if (id) {
events[id] = event;
}
return event;
};
/**
* CWRCWriter events
*/
/**
* The writer has been initialized
* @event Writer#writerInitialized
* @param {Object} writer The CWRCWriter
*/
w.event('writerInitialized');
/**
* The editor has been initialized
* @event Writer#tinymceInitialized
* @param {Object} writer The CWRCWriter
*/
w.event('tinymceInitialized');
/**
* The StructureTree has been initialized
* @event Writer#structureTreeInitialized
* @param {Object} structureTree The StructureTree
*/
w.event('structureTreeInitialized');
/**
* The EntitiesList has been initialized
* @event Writer#entitiesListInitialized
* @param {Object} entitiesList The EntitiesList
*/
w.event('entitiesListInitialized');
/**
* The current node was changed
* @event Writer#nodeChanged
* @param {Element} node The current node
*/
w.event('nodeChanged');
/**
* Content was changed in the editor.
* Should only be fired if tags change, not simply text.
* @event Writer#contentChanged
*/
w.event('contentChanged');
/**
* A document is being fetched from a source
* @event Writer#loadingDocument
*/
w.event('loadingDocument');
/**
* A document is being processed into the editor format
* @event Writer#processingDocument
* @param {Number} percentComplete
*/
w.event('processingDocument');
/**
* A document was loaded into the editor
* @event Writer#documentLoaded
* @params {Boolean} success Was the document successfully loaded?
* @param {Element} body The editor body element
*/
w.event('documentLoaded');
/**
* A document was saved
* @event Writer#documentSaved
*/
w.event('documentSaved');
/**
* A document is being saved to server
* @event Writer#documentSaved
*/
w.event('savingDocument');
/**
* A schema is being fetched from a source
* @event Writer#loadingSchema
*/
w.event('loadingSchema');
/**
* A schema was loaded into the editor
* @event Writer#schemaLoaded
*/
w.event('schemaLoaded');
/**
* The current schema was changed
* @event Writer#schemaChanged
* @param {String} id The id of the new schema
*/
w.event('schemaChanged');
/**
* A schema was added to the list of available schemas
* @event Writer#schemaAdded
* @param {String} id The id of the new schema
*/
w.event('schemaAdded');
/**
* A document was sent to the validation service
* @event Writer#validationInitiated
*/
w.event('validationInitiated');
/**
* A document was validated
* @event Writer#documentValidated
* @param {Boolean} isValid True if the doc is valid
* @param {Document} results Validation results
* @param {String} docString The string sent to the validator
*/
w.event('documentValidated');
/**
* A segment of the document was copied
* @event Writer#contentCopied
*/
w.event('contentCopied');
/**
* Content was pasted into the document
* @event Writer#contentPasted
*/
w.event('contentPasted');
/**
* The user triggered a keydown event in the editor
* @event Writer#writerKeydown
* @param {Object} event Event object
*/
w.event('writerKeydown');
/**
* The user triggered a keyup event in the editor
* @event Writer#writerKeyup
* @param {Object} event Event object
*/
w.event('writerKeyup');
/**
* An entity was added to the document
* @event Writer#entityAdded
* @param {String} id The entity ID
*/
w.event('entityAdded');
/**
* An entity was edited in the document
* @event Writer#entityEdited
* @param {String} id The entity ID
*/
w.event('entityEdited');
/**
* An entity was removed from the document
* @event Writer#entityRemoved
* @param {String} id The entity ID
*/
w.event('entityRemoved');
/**
* An entity was focused on in the document
* @event Writer#entityFocused
* @param {String} id The entity ID
*/
w.event('entityFocused');
/**
* An entity was unfocused on in the document
* @event Writer#entityUnfocused
* @param {String} id The entity ID
*/
w.event('entityUnfocused');
/**
* An entity was copied to the internal clipboard
* @event Writer#entityCopied
* @param {String} id The entity ID
*/
w.event('entityCopied');
/**
* An entity was pasted to the document
* @event Writer#entityPasted
* @param {String} id The entity ID
*/
w.event('entityPasted');
/**
* A structure tag was added
* @event Writer#tagAdded
* @param {Element} tag The tag
*/
w.event('tagAdded');
/**
* A structure tag was edited
* @event Writer#tagEdited
* @param {String} id The tag ID
*/
w.event('tagEdited');
/**
* A structure tag was removed
* @event Writer#tagRemoved
* @param {Element} tag The tag
*/
w.event('tagRemoved');
/**
* A structure tag's contents were removed
* @event Writer#tagContentsRemoved
* @param {String} id The tag ID
*/
w.event('tagContentsRemoved');
/**
* A structure tag was selected
* @event Writer#tagSelected
* @param {String} id The tag ID
* @param {Boolean} contentsSelected True if only tag contents were selected
*/
w.event('tagSelected');
/**
* The selection in the editor changed
* @event Writer@selectionChanged
*/
w.event('selectionChanged');
/**
* Numerous changes to the document are being made in succession
* @event Writer@massUpdateStarted
*/
w.event('massUpdateStarted');
/**
* The numerous changes to the document are complete
* @event Writer@massUpdateCompleted
*/
w.event('massUpdateCompleted');
/**
* @lends EventManager.prototype
*/
var e = {};
/**
* Get the list of events
* @returns {Object}
*/
e.getEvents = function() {
return events;
};
e.destroy = function() {
// TODO empty callbacks
};
/**
* Whether to output events to the console.
* @param {Boolean} doIt
*/
e.debug = function(doIt) {
doDebug = doIt;
}
return e;
};
module.exports = EventManager;