UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

132 lines (103 loc) 4.6 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The source code</title> <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="../resources/prettify/prettify.js"></script> <style type="text/css"> .highlight { display: block; background-color: #ddd; } </style> <script type="text/javascript"> function highlight() { document.getElementById(location.hash.replace(/#/, "")).className = "highlight"; } </script> </head> <body onload="prettyPrint(); highlight();"> <pre class="prettyprint lang-js">/* Siesta 5.6.1 Copyright(c) 2009-2022 Bryntum AB https://bryntum.com/contact https://bryntum.com/products/siesta/license */ <span id='Siesta-Recorder-Role-CanRecordWheel'>/** </span> @class Siesta.Recorder.Role.CanRecordWheel A mixin, providing the feature of recording the &quot;wheel&quot; event. */ Role(&#39;Siesta.Recorder.Role.CanRecordWheel&#39;, { has : { <span id='Siesta-Recorder-Role-CanRecordWheel-cfg-recordWheel'> /** </span> * @cfg {Boolean} recordWheel Set this option to `true` to enable recording of `wheel` events. * Several consequent `wheel` events on the same element will be merged into one `wheel` action. */ recordWheel : true, <span id='Siesta-Recorder-Role-CanRecordWheel-cfg-wheelEventBuffer'> /** </span> * @cfg {Number} wheelEventBuffer If similar wheel events are fired on same target during this time (ms), * (and in same direction / axis) merge the events */ wheelEventBuffer : 200, skipIfNoModifierKeysPressed : false }, override : { initialize : function () { var me = this; me.SUPERARG(arguments); me.onWheelEvent = me.onWheelEvent.bind(me); }, onStart : function () { this.SUPERARG(arguments); var win = this.window; var doc = win.document; // Observe wheel events if (this.recordWheel) { doc.addEventListener(&#39;wheel&#39;, this.onWheelEvent, true); } }, onStop : function () { this.SUPERARG(arguments); var win = this.window; var doc = win.document; if (this.recordWheel) { doc.removeEventListener(&#39;wheel&#39;, this.onWheelEvent, true); } }, // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign sign : Math.sign || function(x) { // If x is NaN, the result is NaN. // If x is -0, the result is -0. // If x is +0, the result is +0. // If x is negative and not -0, the result is -1. // If x is positive and not +0, the result is +1. return ((x &gt; 0) - (x &lt; 0)) || +x; }, isSameWheelAxisAndDirection : function(event1, event2) { return this.sign(event1.deltaX) === this.sign(event2.deltaX) &amp;&amp; this.sign(event1.deltaY) === this.sign(event2.deltaY) &amp;&amp; this.sign(event1.deltaZ) === this.sign(event2.deltaZ); }, onWheelEvent : function (wheelEvent) { var me = this; var lastAction = this.getLastAction(); if (me.skipIfNoModifierKeysPressed &amp;&amp; !wheelEvent.ctrlKey &amp;&amp; !wheelEvent.altKey &amp;&amp; !wheelEvent.metaKey &amp;&amp; !wheelEvent.shiftKey) { return; } // Merge subsequent wheel events (they occur at very high rates on a touch pad) which go in the same axis/direction if (lastAction &amp;&amp; lastAction.action === &#39;wheel&#39; &amp;&amp; wheelEvent.target === lastAction.sourceEvent.target) { var lastEvent = lastAction.sourceEvent; if (me.isSameWheelAxisAndDirection(wheelEvent, lastEvent.rawEvent) &amp;&amp; Date.now() - lastAction.timestamp &lt; me.wheelEventBuffer) { lastAction.options.deltaX += wheelEvent.deltaX; lastAction.options.deltaY += wheelEvent.deltaY; lastAction.options.deltaZ += wheelEvent.deltaZ; lastAction.timestamp = Date.now(); this.fireEvent(&#39;actionupdate&#39;, lastAction); return; } } me.onDomEvent(wheelEvent); } } }); </pre> </body> </html>