-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbi.applications.js
156 lines (109 loc) · 5.04 KB
/
bbi.applications.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*! BBI Application Handler (c) Blackbaud, Inc. */
(function(_win, bbi) {
"use strict";
var alias = "applications-handler";
bbi.on("init", function() {
bbi.extension({
alias: alias,
defaults: {},
directive: function(ext, bbi, $) {
var settings = ext.settings();
var _apps = {};
var _appsLoaded = false;
var _appsReady = false;
var _events = bbi("events").getInstance();
var methods = {
activate: function () {
if (bbi.isDebugMode() === true) {
bbi.log("Activating " + bbi.helper.objectLength(_apps) + " apps.", false);
}
var app;
for (var a in _apps) {
app = _apps[a];
app.compile();
}
if (bbi.isDebugMode() === true) {
bbi.log("Apps loaded. [Event: bbi-apps-loaded]", false);
}
_events.trigger('bbi-apps-loaded');
},
check: function () {
if (bbi.isDebugMode() === true) {
bbi.log("Checking applications' status...", false);
}
bbi("applications-script-handler").getInstance(0).done(function (handler) {
if (_appsLoaded === true && _appsReady === true) {
return;
}
var allLoaded = true;
var allReady = true;
var numApps = 0;
var numScripts = handler.scripts().length;
for (var x in _apps) {
numApps++;
if (_apps[x].status.ready === false) {
allReady = false;
break;
}
if (_apps[x].status.loaded === false) {
allLoaded = false;
break;
}
}
// The number of unique scripts must be the same number of apps.
// (Each app has its own file, but can be initialized more than once.)
if (bbi.isDebugMode() === true) {
bbi.log("Number of apps loaded vs. number of script tags on page:\n" + numApps + "/" + numScripts);
}
if (numApps === numScripts || numScripts === 0) {
// App has been built.
if (_appsReady === false && allReady === true) {
_appsReady = true;
if (bbi.isDebugMode() === true) {
bbi.log("Apps ready. [Event: bbi-apps-ready]", false);
}
_events.trigger('bbi-apps-ready');
}
// Required assets have been loaded.
if (_appsLoaded === false && allLoaded === true) {
_appsLoaded = true;
methods.activate();
}
}
});
},
getApps: function () {
var app;
var temp = {};
for (var a in _apps) {
app = _apps[a];
temp[a] = {
actions: app.actions,
alias: app.alias,
scope: app.scope,
settings: app.settings
};
}
return temp;
},
register: function (options) {
return bbi.instantiate("app", options);
},
save: function (alias, instance) {
_apps[alias] = instance;
}
};
return {
activate: methods.activate,
check: methods.check,
getApps: methods.getApps,
register: methods.register,
save: methods.save
};
}
});
var instance = bbi.instantiate(alias);
bbi.map("register", instance.register);
bbi.map("apps", instance.getApps);
});
}.call({}, window, bbiGetInstance()));