RecorderManager.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-ux-event-RecorderManager'>/**
  19. </span> * Recorder manager.
  20. * Used as a bookmarklet:
  21. *
  22. * javascript:void(window.open(&quot;../ux/event/RecorderManager.html&quot;,&quot;recmgr&quot;))
  23. */
  24. Ext.define('Ext.ux.event.RecorderManager', {
  25. extend: 'Ext.panel.Panel',
  26. alias: 'widget.eventrecordermanager',
  27. uses: [
  28. 'Ext.ux.event.Recorder',
  29. 'Ext.ux.event.Player'
  30. ],
  31. layout: 'fit',
  32. buttonAlign: 'left',
  33. eventsToIgnore: {
  34. mousemove: 1,
  35. mouseover: 1,
  36. mouseout: 1
  37. },
  38. bodyBorder: false,
  39. playSpeed: 1,
  40. initComponent: function () {
  41. var me = this;
  42. me.recorder = new Ext.ux.event.Recorder({
  43. attachTo: me.attachTo,
  44. listeners: {
  45. add: me.updateEvents,
  46. coalesce: me.updateEvents,
  47. buffer: 200,
  48. scope: me
  49. }
  50. });
  51. me.recorder.eventsToRecord = Ext.apply({}, me.recorder.eventsToRecord);
  52. function speed (text, value) {
  53. return {
  54. text: text,
  55. speed: value,
  56. group: 'speed',
  57. checked: value == me.playSpeed,
  58. handler: me.onPlaySpeed,
  59. scope: me
  60. };
  61. }
  62. me.tbar = [
  63. {
  64. text: 'Record',
  65. xtype: 'splitbutton',
  66. whenIdle: true,
  67. handler: me.onRecord,
  68. scope: me,
  69. menu: me.makeRecordButtonMenu()
  70. },
  71. {
  72. text: 'Play',
  73. xtype: 'splitbutton',
  74. whenIdle: true,
  75. handler: me.onPlay,
  76. scope: me,
  77. menu: [
  78. speed('Recorded Speed (1x)', 1),
  79. speed('Double Speed (2x)', 2),
  80. speed('Quad Speed (4x)', 4),
  81. '-',
  82. speed('Full Speed', 1000)
  83. ]
  84. },
  85. {
  86. text: 'Clear',
  87. whenIdle: true,
  88. handler: me.onClear,
  89. scope: me
  90. },
  91. '-&gt;',
  92. {
  93. text: 'Stop',
  94. whenActive: true,
  95. disabled: true,
  96. handler: me.onStop,
  97. scope: me
  98. }
  99. ];
  100. var events = me.attachTo.testEvents;
  101. me.items = [
  102. {
  103. xtype: 'textarea',
  104. itemId: 'eventView',
  105. fieldStyle: 'font-family: monospace',
  106. selectOnFocus: true,
  107. emptyText: 'Events go here!',
  108. value: events ? me.stringifyEvents(events) : '',
  109. scrollToBottom: function () {
  110. var inputEl = this.inputEl.dom;
  111. inputEl.scrollTop = inputEl.scrollHeight;
  112. }
  113. }
  114. ];
  115. me.fbar = [
  116. {
  117. xtype: 'tbtext',
  118. text: 'Attached To: ' + me.attachTo.location.href
  119. }
  120. ];
  121. me.callParent();
  122. },
  123. makeRecordButtonMenu: function () {
  124. var ret = [],
  125. subs = {},
  126. eventsToRec = this.recorder.eventsToRecord,
  127. ignoredEvents = this.eventsToIgnore;
  128. Ext.Object.each(eventsToRec, function (name, value) {
  129. var sub = subs[value.kind];
  130. if (!sub) {
  131. subs[value.kind] = sub = [];
  132. ret.push({
  133. text: value.kind,
  134. menu: sub
  135. });
  136. }
  137. sub.push({
  138. text: name,
  139. checked: true,
  140. handler: function (menuItem) {
  141. if (menuItem.checked) {
  142. eventsToRec[name] = value;
  143. } else {
  144. delete eventsToRec[name];
  145. }
  146. }
  147. });
  148. if (ignoredEvents[name]) {
  149. sub[sub.length - 1].checked = false;
  150. Ext.Function.defer(function () {
  151. delete eventsToRec[name];
  152. }, 1);
  153. }
  154. });
  155. function less (lhs, rhs) {
  156. return (lhs.text &lt; rhs.text) ? -1
  157. : ((rhs.text &lt; lhs.text) ? 1 : 0);
  158. }
  159. ret.sort(less);
  160. Ext.Array.each(ret, function (sub) {
  161. sub.menu.sort(less);
  162. });
  163. return ret;
  164. },
  165. getEventView: function () {
  166. return this.down('#eventView');
  167. },
  168. onClear: function () {
  169. var view = this.getEventView();
  170. view.setValue('');
  171. },
  172. onPlay: function () {
  173. var me = this,
  174. view = me.getEventView(),
  175. events = view.getValue();
  176. if (events) {
  177. events = Ext.decode(events);
  178. if (events.length) {
  179. me.player = Ext.create('Ext.ux.event.Player', {
  180. attachTo: window.opener,
  181. eventQueue: events,
  182. listeners: {
  183. stop: me.onPlayStop,
  184. scope: me
  185. }
  186. });
  187. me.player.start();
  188. me.syncBtnUI();
  189. }
  190. }
  191. },
  192. onPlayStop: function () {
  193. this.player = null;
  194. this.syncBtnUI();
  195. },
  196. onPlaySpeed: function (menuitem) {
  197. this.playSpeed = menuitem.speed;
  198. },
  199. onRecord: function () {
  200. this.recorder.start();
  201. this.syncBtnUI();
  202. },
  203. onStop: function () {
  204. var me = this;
  205. if (me.player) {
  206. me.player.stop();
  207. me.player = null;
  208. } else {
  209. me.recorder.stop();
  210. }
  211. me.syncBtnUI();
  212. me.updateEvents();
  213. },
  214. syncBtnUI: function () {
  215. var me = this,
  216. idle = !me.player &amp;&amp; !me.recorder.active;
  217. Ext.each(me.query('[whenIdle]'), function (btn) {
  218. btn.setDisabled(!idle);
  219. });
  220. Ext.each(me.query('[whenActive]'), function (btn) {
  221. btn.setDisabled(idle);
  222. });
  223. var view = me.getEventView();
  224. view.setReadOnly(!idle);
  225. },
  226. stringifyEvents: function (events) {
  227. var line,
  228. lines = [];
  229. Ext.each(events, function (ev) {
  230. line = [];
  231. Ext.Object.each(ev, function (name, value) {
  232. if (line.length) {
  233. line.push(', ');
  234. } else {
  235. line.push(' { ');
  236. }
  237. line.push(name, ': ');
  238. line.push(Ext.encode(value));
  239. });
  240. line.push(' }');
  241. lines.push(line.join(''));
  242. });
  243. return '[\n' + lines.join(',\n') + '\n]';
  244. },
  245. updateEvents: function () {
  246. var me = this,
  247. text = me.stringifyEvents(me.recorder.getRecordedEvents()),
  248. view = me.getEventView();
  249. view.setValue(text);
  250. view.scrollToBottom();
  251. }
  252. });
  253. </pre>
  254. </body>
  255. </html>