var VnObject = require ('./object'); var scopeUid = 0; module.exports = new Class ({ Extends: VnObject ,initialize: function (builder, objects, signalData, parentScope, extraObjects) { this.builder = builder; this.objects = objects; this.signalData = signalData; this.parentScope = parentScope; this.uid = ++scopeUid; this.extraObjects = extraObjects; if (!signalData && parentScope) this.signalData = parentScope.signalData; this.parent (); } ,getMain: function () { return this.builder.getMain (this); } /** * Fetchs an element by it's identifier. * * @param {String} id The node identifier * @return {Object} The object or %null if it doesn't exists */ ,$: function (id) { var object; var index = this.builder.getById (id); if (index !== undefined) object = this.objects[index]; else { object = this.extraObjects[id]; if (object === undefined && this.parentScope) object = this.parentScope.getById (id); } return object ? object : null; } /** * Fetchs an element by it's identifier. * * @param {String} id The node identifier * @return {Object} The object or %null if it doesn't exists */ ,getById: function (id) { return this.$(id); } /** * 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 */ ,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) { if (this.signalData) { var method = this.signalData[value]; if (method && binded) method = method.bind (this.signalData); } 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 () { var objects = this.objects; for (var i = objects.length; i--;) if (objects[i] instanceof VnObject) { objects[i].unref (); objects[i].disconnectByInstance (this.builder.signalData); } this.parent (); } });