-
Notifications
You must be signed in to change notification settings - Fork 15
/
ui-recorder-ext-selector.js
303 lines (265 loc) · 6.97 KB
/
ui-recorder-ext-selector.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
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/*jslint nomen: true*/
/*global $,define,require,module */
var recorder = require('./recorder');
var eventsToRecord = require('./events-to-record');
var codeGenerator = require('./object-generator-ext-selector');
recorder.init({
generateObject: codeGenerator.generateObject,
eventsToRecord: eventsToRecord
});
window.recorderES = recorder;
module.exports = recorder;
},{"./events-to-record":2,"./object-generator-ext-selector":4,"./recorder":5}],2:[function(require,module,exports){
/*jslint nomen: true*/
/*global $,define,require,module */
module.exports = [
'click',
// 'focus',
// 'blur',
'dblclick',
'change',
'keyup',
// 'keydown',
// 'keypress',
'mousedown',
// 'mousemove',
// 'mouseout',
// 'mouseover',
// 'mouseup',
'resize',
// 'scroll',
'select',
'submit',
'load',
'unload'
];
//var events = [
// abort,
// afterprint,
// beforeprint,
// beforeunload,
// blur,
// canplay,
// canplaythrough,
// change,
// click,
// contextmenu,
// copy,
// cuechange,
// cut,
// dblclick,
// DOMContentLoaded,
// drag,
// dragend,
// dragenter,
// dragleave,
// dragover,
// dragstart,
// drop,
// durationchange,
// emptied,
// ended,
// error,
// focus,
// focusin,
// focusout,
// formchange,
// forminput,
// hashchange,
// input,
// invalid,
// keydown,
// keypress,
// keyup,
// load,
// loadeddata,
// loadedmetadata,
// loadstart,
// message,
// mousedown,
// mouseenter,
// mouseleave,
// mousemove,
// mouseout,
// mouseover,
// mouseup,
// mousewheel,
// offline,
// online,
// pagehide,
// pageshow,
// paste,
// pause,
// play,
// playing,
// popstate,
// progress,
// ratechange,
// readystatechange,
// redo,
// reset,
// resize,
// scroll,
// seeked,
// seeking,
// select,
// show,
// stalled,
// storage,
// submit,
// suspend,
// timeupdate,
// undo,
// unload,
// volumechange,
// waiting
//];
},{}],3:[function(require,module,exports){
/*jslint nomen: true*/
/*global $,define,require,module,Ext */
function getComponent(el) {
var cmp,
target = el;
while (target) {
cmp = Ext.getCmp(target.id);
if (cmp) {
return cmp;
}
target = target.parentNode;
}
return null;
}
function getQuery(el) {
var cmp = getComponent(el),
query;
if (!cmp) {
return 'No component query available.';
}
// Depend on the ExtJS app, either itemId or cls may be the right one to use.
// Use cmp.cls with cmp.getXType() to create 'someXtype[cls=someClass]'
query = {
itemId: cmp.getItemId(),
cls: cmp.cls,
xtype: cmp.getXType(),
el: {
name: el.nodeName,
className: el.className
}
};
return query;
}
module.exports = {
getQuery: getQuery
};
},{}],4:[function(require,module,exports){
/*jslint nomen: true*/
/*global $,define,require,module */
var extComponentQueryFactory = require('./ext-component-query-factory');
function generateObject(evt) {
var query = extComponentQueryFactory.getQuery(evt.target);
query.event = evt.type;
return query;
}
module.exports = {
generateObject: generateObject
};
},{"./ext-component-query-factory":3}],5:[function(require,module,exports){
/*jslint nomen: true*/
/*global $,define,require,module */
var recordedCode = '',
generateCode,
generateObject,
eventsToRecord,
windowToListen;
function init(config) {
generateCode = config.generateCode;
generateObject = config.generateObject;
eventsToRecord = config.eventsToRecord;
}
function setWindowToListen(windowElement) {
windowToListen = windowElement;
}
// Each frame is a window
function getAllFrames(windowElement, allFrames) {
allFrames.push(windowElement.frames);
for (var i = 0; i < windowElement.frames.length; i++) {
getAllFrames(windowElement.frames[i], allFrames);
}
return allFrames;
}
function getElementsToListen(windowElement) {
return getAllFrames(windowElement, []);
}
function bind(el, eventType, handler) {
if (el.addEventListener) { // DOM Level 2 browsers
el.addEventListener(eventType, handler, false);
} else if (el.attachEvent) { // IE <= 8
el.attachEvent('on' + eventType, handler);
} else { // ancient browsers
el['on' + eventType] = handler;
}
}
function unbind(el, eventType, handler) {
if (el.removeEventListener) {
el.removeEventListener(eventType, handler, false);
} else if (el.detachEvent) {
el.detachEvent("on" + eventType, handler);
} else {
el["on" + eventType] = null;
}
}
function manageSingleElementEvents(element, action, events, handler) {
var eventIndex = 0,
eventCount = events.length;
for (; eventIndex < eventCount; eventIndex++) {
action(element, events[eventIndex], handler);
}
}
function manageEvents(elements, action, events, handler) {
var elementIndex = 0,
elementCount = elements.length;
for (; elementIndex < elementCount; elementIndex++) {
// Have to attach events with some delay between iframes. Otherwise, iframe events are not captured
setTimeout(manageSingleElementEvents, 50, elements[elementIndex], action, events, handler);
}
}
function recordEvent(e) {
var code;
if (generateObject) {
console.recorderLog(JSON.stringify(generateObject(e), true, 2));
}
if (generateCode) {
code = generateCode(e);
recordedCode = recordedCode + code + '\n';
console.recorderLog(code);
}
}
function record() {
var elementsToListen = getElementsToListen(windowToListen || window);
console.recorderLog = console.log; // hijack the console.log so that only recorded code will be shown
console.log = function () {};
manageEvents(elementsToListen, bind, eventsToRecord, recordEvent);
}
function stop() {
var elementsToListen = getElementsToListen(windowToListen || window);
if (console.recorderLog) {
console.log = console.recorderLog;
}
manageEvents(elementsToListen, unbind, eventsToRecord, recordEvent);
}
function getRecordedCode() {
return recordedCode;
}
function clearRecordedCode() {
return recordedCode = '';
}
module.exports = {
init: init,
setWindowToListen: setWindowToListen,
record: record,
stop: stop,
getRecordedCode: getRecordedCode,
clearRecordedCode: clearRecordedCode
};
},{}]},{},[1])