UNPKG

siesta-lite

Version:

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

177 lines (133 loc) 7.18 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 */ Class(&#39;Siesta.Project.Browser.UI.ElementHighlighter&#39;, { does : [ Siesta.Util.Role.CanCalculatePageScroll ], has : { window : { required : true }, containerEl : null, el : null, // showSelectorText : true, active : false }, methods : { initialize : function () { // for now we don&#39;t take into accoun the offset of the `containerEl` // so it is always assumed to be a &lt;body&gt; of the `this.window` this.containerEl = this.window.document.body }, start : function() { if (this.active) return var me = this; var containerEl = this.containerEl; var boxSizingStyle = &#39;box-sizing: border-box;-moz-box-sizing: border-box;-ms-box-sizing: border-box;-webkit-box-sizing: border-box;&#39;; var innerEl = document.createElement(&#39;div&#39;); var el = me.el = document.createElement(&#39;div&#39;); el.className = &#39;target-inspector-box&#39;; el.style.cssText = &#39;position: absolute; left:0; top:0; pointer-events: none; z-index: 100000001; border: 2px solid red;transition-property: transform,border-color; transition-duration: 0.3s;&#39;; innerEl.style.cssText = &#39;border:1px solid;border-color:inherit;width : 13px; height : 13px;position : absolute;margin-top : -8px;margin-left : -8px;border-radius:19px;transition-property : transform;transition-duration : 0.3s;&#39; + boxSizingStyle; innerEl.className = &#39;target-inspector-coordinate&#39;; innerEl.innerHTML = &#39;&lt;div style=&quot;border-left: 1px solid;border-color:inherit;position: absolute;top: -3px;left: 5px;height: 6px;&#39; + boxSizingStyle + &#39;&quot;&gt;&lt;/div&gt;&#39; + &#39;&lt;div style=&quot;border-left: 1px solid;border-color:inherit;position: absolute;bottom: -3px;left: 5px;height: 6px;&#39; + boxSizingStyle + &#39;&quot;&gt;&lt;/div&gt;&#39; + &#39;&lt;div style=&quot;border-top: 1px solid;border-color:inherit;position: absolute;top: 5px;left: -3px;width: 6px;&#39; + boxSizingStyle + &#39;&quot;&gt;&lt;/div&gt;&#39; + &#39;&lt;div style=&quot;border-top: 1px solid;border-color:inherit;position: absolute;top: 5px;right: -3px;width: 6px;&#39; + boxSizingStyle + &#39;&quot;&gt;&lt;/div&gt;&#39;; el.appendChild(innerEl); // ].concat(this.showSelectorText ? { // tag : &#39;a&#39;, // cls : &#39;target-inspector-label&#39;, // target : &#39;_blank&#39; // } : []) // } containerEl.appendChild(el); this.active = true; }, getIndicatorEl : function () { return this.el; }, stop : function (suppressEvent) { if (!this.active) return; this.active = false; this.el.parentElement.removeChild(this.el); this.el = null }, // `offset` is expected to be already &quot;normalized&quot; to an array with 2 numbers highlightTarget : function (node, offset/*, content*/) { if (!this.active) this.start(); var boxStyle = this.el.style; if (node) { var rect = node.getBoundingClientRect(); var left = this.viewportXtoPageX(rect.left - 2 /*+ offsets[ 0 ]*/, this.window) var top = this.viewportYtoPageY(rect.top - 2 /*+ offsets[ 1 ]*/, this.window) var width = (rect.width || this.getCssWidth(node)) + 2 var height = (rect.height || this.getCssHeight(node)) + 2 // Regular getWidth/getHeight doesn&#39;t work if another iframe is on the page boxStyle.setProperty(&#39;transform&#39;, &#39;translate(&#39; + left + &#39;px,&#39; + top + &#39;px)&#39;) boxStyle.width = width + &#39;px&#39;; boxStyle.height = height + &#39;px&#39;; boxStyle[ &#39;border-color&#39; ] = &#39;red&#39;; // if (this.showSelectorText &amp;&amp; content) { // this.updateHighlightContent(content); // } var crosshair = this.el.firstChild; if (offset) { crosshair.style.setProperty(&#39;display&#39;, &#39;block&#39;); crosshair.style.setProperty(&#39;transform&#39;, &#39;translate(&#39; + offset[ 0 ] + &#39;px,&#39; + offset[ 1 ] + &#39;px)&#39;) } else { crosshair.style.setProperty(&#39;display&#39;, &#39;none&#39;); } } else { // boxStyle.display = &#39;none&#39; boxStyle[ &#39;border-color&#39; ] = &#39;#ddd&#39;; } }, getCssWidth : function (node) { var cssValue = node.style.width return Number(cssValue.substring(0, cssValue.length - 2)) }, getCssHeight : function (node) { var cssValue = node.style.height return Number(cssValue.substring(0, cssValue.length - 2)) } // , // getOffsets : function (node) { // var targetDoc = this.window.document; // var offsets = [ 0, 0 ] // // if (node.ownerDocument !== targetDoc) { // var innerFrame = (node.ownerDocument.parentWindow || node.ownerDocument.defaultView).frameElement; // var rect = innerFrame.getBoundingClientRect(); // var offsets = [ rect.left, rec.top ]; // // offsets[ 0 ] -= node.ownerDocument.body.scrollLeft; // offsets[ 1 ] -= node.ownerDocument.body.scrollTop; // } // // return offsets; // } } });</pre> </body> </html>