-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbi.debug.js
193 lines (172 loc) · 8.64 KB
/
bbi.debug.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*! BBI Debug (c) Blackbaud, Inc. */
(function(_win, bbi) {
"use strict";
var alias = "debug";
bbi.on("init", function() {
bbi.extension({
alias: alias,
defaults: {
bbiStylesHref: '//api.blackbaud.com/bbi/v/' + bbi.settings("version") + '/css/bbi.min.css',
debug: false,
guestbookURL: '//api.blackbaud.com/services/bbi-guestbook/',
isAdminView: false,
isPageEditor: false,
isPartEditor: false,
bbiLogContainerDisclaimer: '* This message pane is visible only to administrators.',
bbiLogContainerId: 'bbi-message',
bbiLogPrependSelector: 'body',
bbiLogContainerTitle: 'Customization Alerts:',
loadBBIStyles: true,
pageEditorUrlRegex: 'edit=|/cms/',
adminViewSelector: '.bb_menu'
},
directive: function(ext, bbi, $) {
var settings = ext.settings();
var methods = {
info: function() {
var settingsString = "";
var bbiSettings = bbi.settings();
for (var s in bbiSettings) {
settingsString += "[" + s + "] " + bbiSettings[s] + "\n";
}
console.log("[ " + bbiSettings.alias + " Scope, exposed via: BBI(slug) ]\n", bbi());
console.log("\nExplicit Settings:\n" + settingsString + "\n");
},
isAdminView: function() {
if (settings.isAdminView === true) {
return true;
}
settings.isAdminView = !! $(settings.adminViewSelector).length;
return settings.isAdminView;
},
isDebugMode: function() {
return settings.debug;
},
isPageEditor: function() {
if (settings.isPageEditor === true) {
return true;
}
settings.isPageEditor = !! _win.location.href.match(settings.pageEditorUrlRegex);
return settings.isPageEditor;
},
isPartEditor: function() {
if (typeof BLACKBAUD !== "object") {
return false;
}
if (settings.isPartEditor === true) {
return true;
}
settings.isPartEditor = (typeof BLACKBAUD.api.customPartEditor === "object");
return settings.isPartEditor;
},
log: function(message, addToDOM) {
console.log("[BBI.debug.log]", message);
if (typeof addToDOM !== "boolean") {
addToDOM = true;
}
if (addToDOM === false || settings.isAdminView === false) {
return;
}
var container = $('#' + settings.bbiLogContainerId + ' .bbi-message-list');
var html = '<li>' + message + '</li>';
if (container.length) {
$(container).append(html);
} else {
$(settings.bbiLogPrependSelector).prepend('<div id="' + settings.bbiLogContainerId + '"><h4 class="bbi-message-title">' + settings.bbiLogContainerTitle + '</h4><ul class="bbi-message-list">' + html + '</ul><p class="bbi-message-helplet">' + settings.bbiLogContainerDisclaimer + '</p></div>');
}
},
preparePage: function() {
var body = _win.document.getElementsByTagName('body')[0];
var className = methods.isPageEditor() ? 'isEditor' : 'isViewer';
if (methods.isAdminView() === true) {
className += " isAdmin";
}
if (methods.isDebugMode() === true) {
className += " isDebug";
}
body.className += (body.className == '' ? '' : ' ') + className;
if (settings.loadBBIStyles) {
if (_win.document.createStyleSheet) {
_win.document.createStyleSheet(settings.bbiStylesHref);
} else {
$('head').append('<link rel="stylesheet" href="' + settings.bbiStylesHref + '" />');
}
if (methods.isDebugMode() === true) {
methods.log("BBI stylesheet loaded.", false);
}
}
},
safeConsole: function() {
_win.log = function() {
// Make it safe to use console.log always
log.history = log.history || [];
log.history.push(arguments);
if (_win.console) {
arguments.callee = arguments.callee.caller;
var a = [].slice.call(arguments);
if (typeof console.log === "object") {
log.apply.call(console.log, console, a);
} else {
console.log.apply(console, a);
}
}
};
(function(d) {
// Add properties to console object, if they exist.
// Otherwise, assign empty function.
var f;
var fns = ['assert', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'timeStamp', 'profile', 'profileEnd', 'time', 'timeEnd', 'trace', 'warn'];
var a = function() {};
while (f = fns.pop()) {
d[f] = d[f] || a;
}
})((function() {
// Return _win.console if it exists.
// Otherwise, return an empty object.
try {
console.log();
return _win.console;
} catch (b) {
return _win.console = {};
}
})());
},
signGuestBook: function (name) {
if (typeof name !== "string") {
name = "namespace";
}
name = encodeURIComponent(name);
//'&v=' + new Date().getTime() + '
//$('body').append('<img class="bbi-pixel" src="' + settings.guestbookURL + '?requestType=' + name + '">');
}
};
methods.info.version = bbi.settings("version");
var __construct = (function() {
methods.signGuestBook();
methods.safeConsole();
methods.isPageEditor();
bbi.jQuery()(function() {
methods.isAdminView();
methods.preparePage();
});
}());
return {
info: methods.info,
isAdminView: methods.isAdminView,
isDebugMode: methods.isDebugMode,
isPageEditor: methods.isPageEditor,
isPartEditor: methods.isPartEditor,
log: methods.log,
signGuestBook: methods.signGuestBook
};
}
});
var instance = bbi.instantiate(alias, bbi.options());
bbi.map("info", instance.info);
bbi.map("isAdminView", instance.isAdminView);
bbi.map("isDebugMode", instance.isDebugMode);
bbi.map("isPageEditor", instance.isPageEditor);
bbi.map("isPartEditor", instance.isPartEditor);
bbi.map("log", instance.log);
});
}.call({}, window, bbiGetInstance()));