UNPKG

siesta-lite

Version:

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

154 lines (115 loc) 4.7 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 */ // Internal class visualizing the cursor position, only used in good browsers (!== IE) Class(&#39;Siesta.Project.Browser.UI.MouseVisualizer&#39;, { has : { cursorEl : null, currentContainer : { required : true }, clickEvents : function () { return { click : null, touchend : null, contextmenu : null } }, mouseDownEvents : function () { return { touchstart : null, mousedown : null } }, mouseUpEvents : function () { return { touchend : null, mouseup : null } } }, methods : { initialize : function (config) { this.onEventSimulated = this.onEventSimulated.bind(this); }, getCursorEl : function () { if (this.cursorEl) return this.cursorEl var currentContainer = this.currentContainer if (!currentContainer) throw &quot;Need container for cursor&quot; var el = document.createElement(&#39;div&#39;); el.className = &#39;ghost-cursor fa fa-mouse-pointer&#39;; return this.cursorEl = currentContainer.appendChild(el) }, destroy : function () { var cursorEl = this.cursorEl if (cursorEl) { cursorEl.parentElement.removeChild(cursorEl); this.cursorEl = null } this.currentContainer = null }, onEventSimulated : function (event, point) { if (typeof event.clientX === &#39;number&#39;) { this.updatePointer(event.type, point) } }, updatePointer : function (eventType, point) { var x = point[ 0 ], y = point[ 1 ] this.updateGhostCursor(x, y); if (eventType in this.clickEvents) { this.showClickIndicator(eventType, x, y); } else if (eventType in this.mouseDownEvents) { this.getCursorEl().classList.add(&#39;ghost-cursor-press&#39;); } if (eventType in this.mouseUpEvents || eventType in this.clickEvents) { this.getCursorEl().classList.remove(&#39;ghost-cursor-press&#39;); } }, // This method shows a fading growing circle at the xy position showClickIndicator : function (type, x, y) { var clickEl = document.createElement(&#39;div&#39;); clickEl.className = &#39;ghost-cursor-click-indicator &#39;; clickEl.style.setProperty(&#39;left&#39;, x + &#39;px&#39;); clickEl.style.setProperty(&#39;top&#39;, y + &#39;px&#39;); clickEl.addEventListener(&quot;animationend&quot;, this.afterAnimation); clickEl.addEventListener(&quot;webkitAnimationEnd&quot;, this.afterAnimation); this.currentContainer.appendChild(clickEl); }, afterAnimation : function() { // &quot;this&quot; here is a DOM element instance this.parentElement &amp;&amp; this.parentElement.removeChild(this); }, // Updates the ghost cursor position and appearance updateGhostCursor : function (x, y) { var cursorEl = this.getCursorEl() var translateStyle = bowser.opera ? &#39;translate(&#39; + x + &#39;px,&#39; + y + &#39;px)&#39; : &#39;translate3d(&#39; + x + &#39;px, &#39; + y + &#39;px, 0)&#39; cursorEl.style.setProperty(&#39;-webkit-transform&#39;, translateStyle) cursorEl.style.setProperty(&#39;transform&#39;, translateStyle) } } }); </pre> </body> </html>