EXPORTED_SYMBOLS = ["core", "resources"];
function Application() {
var $ = this;
$.xbCore = {
init: function (api) {
$.init(api);
}
,
finalize: function () {
$.finalize();
}
,
buildWidget: function (wiid, toolbarItem) {
$.wiid = wiid;
toolbarItem.application = $;
toolbarItem.__buildWidget = true;
toolbarItem.setAttribute("xb-native-widget-name",$.widget_name);
toolbarItem.__instns = (new Date()).valueOf();
var mailman = $.mailman;
mailman.send({
subject: "widget-instance-created",
body: wiid});
}
,
destroyWidget: function (wiid, toolbarItem) {
toolbarItem.__finalizeMailman && toolbarItem.__finalizeMailman(true);
toolbarItem.removeAttribute("xb-native-widget-name");
delete toolbarItem.application;
}
};
$.init = function (api) {
$.api = api;
$.logger = api.logger;
$.notifications = $.loadModule("notifications");
$.pages = new ($.loadModule("pages"))();
$.counters = new ($.loadModule("counters"))();
$.repeater = new ($.loadModule("Repeater"))(["new-messages", "new-friends", "user-id"]);
$.updater = new ($.loadModule("LazyUpdater"))();
$.updater.init("update-interval",{
subject: "please-update",
body: "all"});
$.updater.start();
$.requests = new ($.loadModule("requests"))();
$.requests.init();
$.settingsManager = new (this.loadModule("SettingsManager"))();
$.settingsManager.init(api);
$.vkAPI = new (this.loadModule("api/vk.api"))();
$.vkAuth = new (this.loadModule("api/vk.auth"))();
var mailman = $.mailman;
mailman.addSubscriber({
subject: "please-logout",
subscriber: {
receive: function () {
$.updater.stop();
$.vkAuth.logout();
$.repeater.clear();
$.counters.reset();
}
}});
mailman.addSubscriber({
subject: "please-open-settings",
subscriber: {
receive: function () {
$.api.Controls.openSettingsDialog(null,$.wiid);
}
}});
}
;
$.finalize = function () {
$.notifications.finalize();
$._mailman && $._mailman.removeAllSubscribers();
$.vkAuth.destroy();
$.vkAPI.destroy();
$.updater.destroy();
}
;
}

Application.prototype = {
widget_name: "ru.yandex.bar.vkontakte",
constructor: Application,
_commonModules: ["Ajax", "Cache", "Mailman"],
_loadedModules: {
},
loadModule: function (moduleName, knownLocation) {
var cachedModule = this._loadedModules[moduleName];
if ("undefined" != typeof cachedModule)
{
return cachedModule;
}

var application = this;
var scope = {
};
var bCommon = ! knownLocation && this._commonModules.indexOf(moduleName) >= 0;
const LOCATIONS = [application.api.Package.resolvePath("modules/" + moduleName + ".jsm"), application.api.Package.resolvePath("modules/common/" + moduleName + "/module.js")];
var locations = knownLocation ? [knownLocation] : bCommon ? [LOCATIONS[1]] : LOCATIONS;
var moduleLoaded = false;
for (let i = 0, len = locations.length;i < len;i++) {
let path = locations[i];
let moduleFound = true;
try {
Components.utils.import(path,scope);
}
catch (e) {
moduleFound = false;
}

if (moduleFound)
{
moduleLoaded = true;
break;
}

}

if (! moduleLoaded)
{
let message = "[Loader] No module found with name \"" + moduleName + "\".";
this.logger.error(message);
throw Error(message);
}

var module = scope.module;
if ("function" != typeof module)
{
let message = "[Loader] Module \"" + moduleName + "\" does not export \"module\" function.";
this.logger.error(message);
throw Error(message);
}

var appliedModule = module.call(scope,application);
this._loadedModules[moduleName] = appliedModule;
return appliedModule;
}
,
toString: function () {
return "[Application " + this.widget_name + "]";
}
,
_templater: null,
get templater() {
return this._templater ? this._templater : (this._templater = new (this.loadModule("SimpleStringTemplates"))("/vkontakte.properties"));
}
,
_mailman: null,
get mailman() {
return this._mailman ? this._mailman : (this._mailman = this.loadModule("Mailman"));
}
,
_Cache: null,
get Cache() {
return this._Cache ? this._Cache : (this._Cache = this.loadModule("Cache"));
}
,
_Ajax: null,
get Ajax() {
return this._Ajax ? this._Ajax : (this._Ajax = this.loadModule("Ajax"));
}
,
_getPluralForm: null,
get getPluralForm() {
if (null === this._getPluralForm)
{
let path = this.api.Package.resolvePath("plural.js");
this._getPluralForm = this.loadModule("plural",path);
}

return this._getPluralForm;
}
};
var application = new Application();
var core = application.xbCore;
var resources = {
browser: {
styles: ["/content/bindings.css", "/xb-skin/default/style.css"]}};
