hedera-web/js/vn/scope.js

90 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-10-20 12:06:16 +00:00
var VnObject = require ('./object');
var scopeUid = 0;
module.exports = new Class
({
Extends: VnObject
2017-10-22 00:25:57 +00:00
,initialize: function (builder, objects, thisArg, parentScope, lot)
2017-10-20 12:06:16 +00:00
{
this.builder = builder;
this.objects = objects;
2017-10-22 00:25:57 +00:00
this.thisArg = thisArg;
2017-10-20 12:06:16 +00:00
this.parentScope = parentScope;
this.uid = ++scopeUid;
2017-10-20 17:09:06 +00:00
this.lot = lot;
2017-10-20 12:06:16 +00:00
2017-10-22 00:25:57 +00:00
if (!thisArg && parentScope)
this.thisArg = parentScope.thisArg;
2017-10-20 12:06:16 +00:00
this.parent ();
}
2017-10-20 17:09:06 +00:00
,init: function (extraObjects)
2017-10-20 12:06:16 +00:00
{
2017-10-20 17:09:06 +00:00
var contextMap = this.builder._contextMap;
var objectMap = this.parentScope ? Object.create (this.parentScope.$) : {};
this.$ = objectMap;
for (var id in extraObjects)
objectMap[id] = extraObjects[id];
for (var id in contextMap)
objectMap[id] = this.objects[contextMap[id]];
2017-10-20 12:06:16 +00:00
}
2017-10-20 17:09:06 +00:00
,getMain: function ()
2017-10-20 12:06:16 +00:00
{
2017-10-20 17:09:06 +00:00
return this.builder.getMain (this);
2017-10-20 12:06:16 +00:00
}
/**
* Fetchs a set of elements by it's tag name.
*
* @param {String} tagName The object tag name
* @return {Array[Object]} The list of objects or an empty array
2017-10-20 12:06:16 +00:00
*/
,getByTagName: function (tagName)
{
return this.builder.getByTagName (this, tagName);
}
/**
* Links all scope objects and connects it's events.
*/
,link: function ()
{
this.builder.link (this);
}
,getMethod: function (value, binded)
{
2017-10-22 00:25:57 +00:00
if (this.thisArg)
2017-10-20 12:06:16 +00:00
{
2017-10-22 00:25:57 +00:00
var method = this.thisArg[value];
2017-10-20 12:06:16 +00:00
if (method && binded)
2017-10-22 00:25:57 +00:00
method = method.bind (this.thisArg);
2017-10-20 12:06:16 +00:00
}
else
var method = window[value];
if (method === undefined)
this.builder._showError ('Function \'%s\' not found', value);
return method;
}
,getHtmlId: function (nodeId)
{
return 'vn-'+ this.uid +'-'+ nodeId;
}
,_destroy: function ()
{
2017-10-22 00:25:57 +00:00
this.builder.freeScope (this);
2017-10-20 12:06:16 +00:00
this.parent ();
}
});