siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
134 lines (101 loc) • 3.97 kB
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-TargetExtractor'>/**
</span>
@class Siesta.Recorder.TargetExtractor
The type of target, possible options:
- 'css' css selector
- 'xy' XY coordinates
*/
Class('Siesta.Recorder.TargetExtractor', {
does : [
Siesta.Util.Role.Dom,
Siesta.Recorder.Role.CanSwallowException
],
has : {
ariadneDomFinder : null,
shouldIgnoreDomElementId : null,
ignoreCssClasses : null,
uniqueDomNodeProperty : 'id',
// optional, used as a bubble target for `exception` event
recorder : null
},
methods : {
initialize : function () {
this.ariadneDomFinder = new Ariadne.DomQueryFinder({
uniqueDomNodeProperty : this.uniqueDomNodeProperty,
shouldIgnoreDomElementId : this.shouldIgnoreDomElementId,
ignoreCssClasses : this.ignoreCssClasses
})
if (this.swallowExceptions) this.findDomQueryFor = this.safeBind(this.findDomQueryFor)
},
getBubbleTarget : function () {
return this.recorder
},
findOffset : function (pageX, pageY, relativeTo) {
var offset = this.offset(relativeTo)
offset.left = offset.left
offset.top = offset.top
var relativeOffset = [ pageX - offset.left, pageY - offset.top ]
return relativeOffset;
},
findDomQueryFor : function (target, root) {
return this.ariadneDomFinder.findQuery(target, root)
},
getTargets : function (event, saveOffset, targetOverride, onlyXY) {
var result = []
var cssQuery
var target = targetOverride || event.target;
var hasCoordinates = event.x != null && event.y != null
if (onlyXY && !hasCoordinates) return result
if (!onlyXY && (target != target.ownerDocument.body || !hasCoordinates)) {
cssQuery = this.findDomQueryFor(target)
if (cssQuery) {
var data = {
type : 'css',
target : cssQuery
};
if (hasCoordinates && (saveOffset || !this.isElementReachableAtCenter(target, false))) {
data.offset = this.findOffset(event.x, event.y, target);
}
result.push(data);
}
}
hasCoordinates && result.push({
type : 'xy',
target : [ event.x, event.y ]
})
return result
}
// something old, not used, and wrong (as Sizzle is not re-scope), remove after some time
//- resolveTarget : function (target) {
//- if (target.type == 'css') {
//- return Siesta.Sizzle(target.target)[ 0 ]
//- }
//- },
}
});
</pre>
</body>
</html>