-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbi.application-script.js
121 lines (85 loc) · 3.56 KB
/
bbi.application-script.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
/*! BBI Application Script Handler (c) Blackbaud, Inc. */
(function(_win, bbi) {
"use strict";
/**
* The _Script object looks for special tags on the page that have the attribute 'data-bbi-src'.
* It then loads each of these scripts dynamically on the page, and lets BBI know when they've been loaded.
**/
var alias = "applications-script-handler";
bbi.on("init", function () {
bbi.extension({
alias: alias,
defaults: {
dataAttr_script: 'data-bbi-src'
},
directive: function (ext, bbi, $) {
var _settings = ext.settings();
var _scripts = [];
var _done = false;
var _onDone = [];
var methods = {
done: function () {
_done = true;
for (var i = 0, len = _onDone.length; i < len; i++) {
_onDone[i].call({}, {scripts: methods.getScripts});
}
},
find: function() {
var scripts = $('[' + _settings.dataAttr_script + '], [bbi-src]');
var length = scripts.length;
if (bbi.isDebugMode() === true) {
bbi.log(length + " application tags found.", false);
}
var i;
if (length > 0) {
for (i = 0; i < length; i++) {
methods.process(scripts[i]);
}
}
},
getScripts: function() {
return _scripts;
},
isUnique: function(src) {
for (var i = 0, len = _scripts.length; i < len; i++) {
if (_scripts[i].src === src) {
return false;
}
}
// Check if there's another script with the same source attribute.
// We don't want to load duplicates of the same file.
return true;
},
process: function(elem) {
var script = {
src: elem.getAttribute(_settings.dataAttr_script) || elem.getAttribute('bbi-src')
};
if (script.src && methods.isUnique(script.src)) {
_scripts.push(script);
bbi.helper.loadScript(script.src);
}
}
};
var __construct = (function() {
$(_win.document).on('bbi-ready', function() {
$(function () {
methods.find();
methods.done();
});
});
}());
return {
done: function (callback) {
if (_done) {
callback.call({}, {scripts: methods.getScripts});
} else {
_onDone.push(callback);
}
},
scripts: methods.getScripts
};
}
});
var instance = bbi.instantiate(alias);
});
}.call({}, window, bbiGetInstance()));