3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
15 Ext.define('Ext.ux.event.Recorder', {
16 extend: 'Ext.ux.event.Driver',
18 eventsToRecord: function () {
19 var //key = { modKeys: true, key: true },
20 mouse = { button: true, modKeys: true, xy: true };
31 //mousewheel: Ext.apply({ wheel: true }, mouse),
37 ignoreIdRegEx: /ext-gen(?:\d+)/,
39 constructor: function (config) {
41 events = config && config.eventsToRecord;
44 me.eventsToRecord = Ext.apply(Ext.apply({}, me.eventsToRecord), // duplicate
46 delete config.eventsToRecord; // don't smash
49 me.callParent(arguments);
59 coalesce: function (rec) {
62 length = events.length,
63 tail = length && events[length-1];
65 if (tail && tail.type == 'mousemove' && rec.type == 'mousemove') {
66 if (rec.ts - tail.ts < 200) {
67 events[length-1] = rec;
75 getElementXPath: function (el) {
84 for (t = el; t; t = t.parentNode) {
85 if (t == document.body) {
90 if (t.id && !me.ignoreIdRegEx.test(t.id)) {
91 xpath.unshift('#' + t.id);
96 for (count = 1, sibling = t; !!(sibling = sibling.previousSibling); ) {
97 if (sibling.tagName == t.tagName) {
102 tag = t.tagName.toLowerCase();
106 xpath.unshift(tag + '[' + count + ']');
110 return good ? xpath.join('/') : null;
113 onEvent: function (e) {
115 info = me.eventsToRecord[e.type],
119 ts: me.getTimestamp(),
120 target: me.getElementXPath(e.target)
132 rec.button = e.button;
136 rec.wheel = e.getWheelDelta();
140 me.modKeys[0] = e.altKey ? 'A' : '';
141 me.modKeys[1] = e.ctrlKey ? 'C' : '';
142 me.modKeys[2] = e.metaKey ? 'M' : '';
143 me.modKeys[3] = e.shiftKey ? 'S' : '';
145 modKeys = me.modKeys.join('');
147 rec.modKeys = modKeys;
152 rec.charCode = e.getCharCode();
153 rec.keyCode = e.getKey();
156 if (!me.coalesce(rec)) {
159 Ext.log('record: ' + Ext.encode(rec));
162 onStart: function () {
167 ddm = Ext.dd.DragDropManager,
168 evproto = Ext.EventObjectImpl.prototype;
170 Ext.Object.each(me.eventsToRecord, function (name, value) {
172 on[name] = me.onEvent;
176 me.ddmStopEvent = ddm.stopEvent;
177 ddm.stopEvent = Ext.Function.createSequence(ddm.stopEvent, function (e) {
180 me.evStopEvent = evproto.stopEvent;
181 evproto.stopEvent = Ext.Function.createSequence(evproto.stopEvent, function () {
185 Ext.getBody().on(on);
188 onStop: function () {
190 body = Ext.getBody();
192 Ext.Object.each(me.eventsToRecord, function (name, value) {
194 body.un(name, me.onEvent, me);
198 Ext.dd.DragDropManager.stopEvent = me.ddmStopEvent;
199 Ext.EventObjectImpl.prototype.stopEvent = me.evStopEvent;