siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
154 lines (108 loc) • 4.51 kB
HTML
<!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('Siesta.Recorder.Target', {
has : {
targets : Joose.I.Array,
activeTarget : null
},
methods : {
initialize : function () {
if (!this.targets) this.targets = []
var firstTarget = this.targets[ 0 ]
if (firstTarget && !this.activeTarget) this.activeTarget = firstTarget.type
},
clear : function () {
this.targets = []
},
getTargets : function () {
var target = this.getTarget()
return target && target.targets || null
},
// returns "query-able" target
getTargetAsQueryString : function () {
var target = this.getTarget()
if (target.type == 'xy') return target.target
return (target.type == 'cq' ? '>>' : '') + target.target
},
// `getActiveTarget`
getTarget : function () {
return this.getTargetByType(this.activeTarget)
},
clearOffset : function () {
this.setOffset(null)
},
setOffset : function (value) {
var target = this.getTarget()
if (target)
if (value)
target.offset = value
else
delete target.offset
},
getOffset : function () {
var target = this.getTarget()
if (target) return target.offset
},
getTargetByType : function (type) {
var targetByType
Joose.A.each(this.targets, function (target) {
if (target.type == type) {
targetByType = target
return false
}
})
return targetByType
},
setUserTarget : function (value, offset) {
var userTarget = this.getTargetByType('user')
if (!userTarget) {
var target = { type : 'user', target : value }
if (offset) target.offset = offset
this.targets.unshift(target)
} else {
userTarget.target = value
if (offset)
userTarget.offset = offset
else
delete userTarget.offset
}
this.activeTarget = 'user'
},
// some old crap with unclear semantic - need to get rid of it
// returns `true` if targeting the coordinates on the screen or <body> (which is the same thing)
isTooGeneric : function () {
var targets = this.targets
if (!targets || targets.length === 0) return true
if (targets.length === 1 && targets[ 0 ].type == 'xy') return true
if (targets.length === 2) {
var xy = this.getTargetByType('xy')
var css = this.getTargetByType('css')
if (xy && css && css.target == 'body') return true
}
return false
}
}
});</pre>
</body>
</html>