UNPKG

siesta-lite

Version:

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

158 lines (108 loc) 4.68 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 */ Role(&#39;Siesta.Recorder.Role.CanRecordMouseDownUp&#39;, { has : { mouseState : &#39;up&#39;, eventNameMap : { lazy : &#39;this.buildEventNameMap&#39; }, needToCaptureInitialMouseState : true }, override : { initialize : function () { this.SUPERARG(arguments) this.onDocMouseDown = this.safeBind(this.onDocMouseDown) this.onDocMouseUp = this.safeBind(this.onDocMouseUp) this.onInitialMouseMove = this.safeBind(this.onInitialMouseMove) }, onStart : function () { this.SUPERARG(arguments); var eventNameMap = this.getEventNameMap() var win = this.window; var doc = win.document; doc.addEventListener(eventNameMap.mousedown, this.onDocMouseDown, true); doc.addEventListener(eventNameMap.mouseup, this.onDocMouseUp, true); doc.body.addEventListener(&#39;mousemove&#39;, this.onInitialMouseMove, true) this.needToCaptureInitialMouseState = true }, onStop : function () { this.SUPERARG(arguments); var eventNameMap = this.getEventNameMap() var win = this.window; var doc = win.document; doc.removeEventListener(eventNameMap.mousedown, this.onDocMouseDown, true); doc.removeEventListener(eventNameMap.mouseup, this.onDocMouseUp, true); if (this.needToCaptureInitialMouseState) this.onInitialStateCaptured() } }, methods : { onInitialMouseMove : function (e) { if (e.buttons != null &amp;&amp; (e.buttons &amp; 1)) this.mouseState = &#39;down&#39; this.onInitialStateCaptured() }, onInitialStateCaptured : function () { this.window.document.body.removeEventListener(&#39;mousemove&#39;, this.onInitialMouseMove, true) this.needToCaptureInitialMouseState = false }, onDocMouseDown : function (e) { // Skip test playback events and mouse moves in frames if ((this.ignoreSynthetic &amp;&amp; e.synthetic) || e.target.ownerDocument !== this.window.document) return; if (this.needToCaptureInitialMouseState) this.onInitialStateCaptured() this.processDocMouseDown(e) }, processDocMouseDown : function (e) { this.mouseState = &#39;down&#39; }, onDocMouseUp : function (e) { // Skip test playback events and mouse moves in frames if ((this.ignoreSynthetic &amp;&amp; e.synthetic) || e.target.ownerDocument !== this.window.document) return; if (this.needToCaptureInitialMouseState) this.onInitialStateCaptured() this.processDocMouseUp(e) }, processDocMouseUp : function (e) { this.mouseState = &#39;up&#39; }, isPointerDownEvent : function (event) { return /(ms)?(pointer|mouse)down/i.test(event.type) }, isPointerUpEvent : function (event) { return /(ms)?(pointer|mouse)up/i.test(event.type) }, buildEventNameMap : function () { var events = {} if (window.PointerEvent) { events.mousedown = &#39;pointerdown&#39; events.mouseup = &#39;pointerup&#39; } else if (window.MSPointerEvent) { events.mousedown = &#39;MSPointerDown&#39; events.mouseup = &#39;MSPointerUp&#39; } else { events.mousedown = &#39;mousedown&#39; events.mouseup = &#39;mouseup&#39; } return events } } // eof `override` });</pre> </body> </html>