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.Player', {
16 extend: 'Ext.ux.event.Driver',
20 tagPathRegEx: /(\w+)(?:\[(\d+)\])?/,
22 constructor: function (config) {
25 me.callParent(arguments);
27 me.eventObject = new Ext.EventObjectImpl();
28 me.timerFn = Ext.Function.bind(me.onTick, me);
31 getElementFromXPath: function (xpath) {
32 var parts = xpath.split('/'),
33 regex = this.tagPathRegEx,
34 i, n, m, count, tag, child,
35 el = (parts[0] == '~') ? document.body
36 : Ext.fly(parts[0].substring(1)).dom; // remove '#'
38 for (i = 1, n = parts.length; el && i < n; ++i) {
39 m = regex.exec(parts[i]);
40 count = m[2] ? parseInt(m[2], 10) : 1;
41 tag = m[1].toUpperCase();
43 for (child = el.firstChild; child; child = child.nextSibling) {
44 if (child.tagName == tag) {
58 onEnd: function () {},
60 onStart: function () {
68 clearTimeout(me.timer);
78 eventIndex = me.nextEvent,
80 timeIndex = me.getTimestamp() * me.speed;
85 event = events[eventIndex];
87 if (event.ts > timeIndex) {
88 me.schedule(eventIndex);
94 if (++eventIndex == events.length) {
101 playEvent: function (event) {
103 eventObject = me.eventObject,
104 modKeys = event.modKeys || '',
105 target = me.getElementFromXPath(event.target);
108 Ext.log('play: ' + Ext.encode(event));
109 eventObject.type = event.type;
110 eventObject.xy = event.xy || null;
111 eventObject.button = event.button;
113 if ('wheel' in event) {
117 eventObject.altKey = modKeys.indexOf('A') > 0;
118 eventObject.ctrlKey = modKeys.indexOf('C') > 0;
119 eventObject.metaKey = modKeys.indexOf('M') > 0;
120 eventObject.shiftKey = modKeys.indexOf('S') > 0;
122 eventObject.injectEvent(target);
124 Ext.log('Cannot find: ', event.target);
128 schedule: function (eventIndex) {
130 me.nextEvent = eventIndex;
131 me.timer = setTimeout(me.timerFn, 10);