siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
117 lines (83 loc) • 3.54 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
*/
Class('Siesta.Content.Preset', {
has : {
preload : Joose.I.Array,
resources : Joose.I.Array
},
methods : {
initialize : function () {
var me = this
Joose.A.each(this.preload, function (preloadDesc) {
me.addResource(preloadDesc)
})
},
isCSS : function (url) {
return /\.css(\?.*)?$/i.test(url)
},
getResourceFromDescriptor : function (desc) {
var constructor, config
var CSS
if (typeof desc == 'string') {
constructor = this.isCSS(desc) ? Siesta.Content.Resource.CSS : Siesta.Content.Resource.JavaScript
config = { url : desc }
} else if (desc.text) {
constructor = Siesta.Content.Resource.JavaScript
config = { content : desc.text }
} else {
if (!desc.url && !desc.content) throw "Incorrect preload descriptor:" + desc
constructor = desc.type && desc.type == 'css' || this.isCSS(desc.url) ? Siesta.Content.Resource.CSS : Siesta.Content.Resource.JavaScript
config = {}
if (desc.url) config.url = desc.url
if (desc.content) config.content = desc.content
if (desc.instrument) config.instrument = desc.instrument
if (desc.isEcmaModule) config.isEcmaModule = desc.isEcmaModule
}
return new constructor(config)
},
addResource : function (desc) {
var resource = (desc instanceof Siesta.Content.Resource) && desc || this.getResourceFromDescriptor(desc)
this.resources.push(resource)
return resource
},
eachResource : function (func, scope) {
return Joose.A.each(this.resources, func, scope || this)
},
// deprecated - seems preset doesn't need to know about scope providers
prepareScope : function (scopeProvider, contentManager) {
this.eachResource(function (resource) {
if (contentManager.hasContentOf(resource))
scopeProvider.addPreload({
type : (resource instanceof Siesta.Content.Resource.CSS) ? 'css' : 'js',
content : contentManager.getContentOf(resource)
})
else
scopeProvider.addPreload(resource.asDescriptor())
})
}
}
})
</pre>
</body>
</html>