-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbi.olx.js
231 lines (231 loc) · 10.6 KB
/
bbi.olx.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*! BBI Online Express (c) Blackbaud, Inc. */
(function(_win, bbi) {
"use strict";
var alias = "online-express";
bbi.on("init", function() {
bbi.extension({
alias: alias,
defaults: {},
directive: function(ext, bbi, $) {
var settings = ext.settings();
var _bbiReady = false;
var _olxReady = false;
var _bb$, _$btn, _$root, _updateForm;
var _$doc = $(_win.document);
var _on = {
init: [],
error: [],
validate: [],
fail: [],
submit: [],
success: [],
beforeUpdate: [],
afterUpdate: []
};
var _methods = {
attach: function(fn, args, context) {
$(function() {
$.proxy(fn, context)(args);
});
_methods.on("afterUpdate", function() {
$.proxy(fn, context)(args);
});
},
block: function() {
_$root.block({
message: "Processing",
css: {
padding: "10px",
border: "none",
fontSize: "16px",
backgroundColor: "#000",
borderRadius: "10px",
"-webkit-border-radius": "10px",
"-moz-border-radius": "10px",
opacity: 0.5,
color: "#fff"
},
overlayCSS: {
backgroundColor: "#fff",
opacity: 0.5
}
});
},
check: function() {
if (_bbiReady && _olxReady) {
_$doc.trigger("olx-ready");
}
},
on: function(when, fn) {
if (typeof _on[when] === "undefined") {
throw new Error('The Online Express event "' + when + '" does not exist.');
}
_on[when].push(fn);
},
overrides: function() {
var _html = "";
// Add our own validations object.
_win.BBOXSectionScripts.BBI_NAMESPACE = _win.BBOXSectionScripts.BBI_NAMESPACE || {};
_win.BBOXSectionScripts.BBI_NAMESPACE.presubmit = function() {
var form = {
block: _methods.block,
unblock: _methods.unblock
};
var status = true;
var validations = _on["validate"];
if (bbi.isDebugMode()) {
bbi.log("Online Express Form has been submitted. Validations in progress...", false);
}
for (var i = 0, len = validations.length; i < len; i++) {
if (validations[i].call(form, form) === false) {
status = false;
break;
}
}
if (bbi.isDebugMode()) {
bbi.log("Online Express validated? " + status, false);
}
return status;
};
// Hijack the HTML as it is returned from post-processing.
if (typeof _win.bbox === "object" && typeof _win.bbox.squirtMarkup === "function") {
_win.bboxOverrides = _win.bboxOverrides || {};
_win.bboxOverrides.handleSubmitCallbackOverride = function(html) {
_html = html;
var numErrors = $(html).find('.BBFormErrorItem').length;
var form = {
block: _methods.block,
update: _methods.triggerFormSubmitted
};
// Register the onUpdate functions.
_updateForm = function() {
_methods.update(html);
};
// There are errors on the page.
if (numErrors > 0 && _on.fail.length) {
_methods.trigger("fail", [form, html], form);
} else {
_methods.triggerFormSubmitted();
}
// Update the form's HTML.
_win.bbox.squirtMarkup(html, true);
};
} else {
_methods.on("submit", function() {
_methods.triggerFormSubmitted();
});
}
// Hijack the submit button
_$btn.on("click", function() {
var form = {};
_methods.trigger("submit");
if ($('#divClientError').is(":visible")) {
_methods.trigger("error", [form, _html], form);
}
});
},
trigger: function(when, args, context) {
if (typeof context !== "object") {
context = {};
}
if (Object.prototype.toString.call(args) !== "[object Array]") {
args = [];
}
if (typeof _on[when] !== "undefined") {
var list = _on[when];
var length = list.length;
var i;
for (i = 0; i < length; i++) {
if (typeof list[i] === "function") {
list[i].apply(context, args);
}
}
}
},
triggerFormSubmitted: function() {
_$doc.trigger("olx-form-submitted");
},
unblock: function() {
_$root.unblock();
},
update: function(html) {
var form = {
block: _methods.block,
update: _methods.triggerFormSubmitted
};
// Give OLX time to breathe.
_win.setTimeout(function() {
_methods.trigger("beforeUpdate", [form, html], form);
_$root.find('.bbi-olx-message').addClass('bbi-off');
_$root.find('.bbi-olx-form').removeClass('bbi-off');
if (typeof _bb$.fn.unblock === "function") {
_$root.unblock();
}
_methods.trigger("afterUpdate", [form, html], form);
}, 50);
}
};
var __construct = (function() {
// BBI ready.
_$doc.on("bbi-ready", function() {
_bbiReady = true;
_methods.check();
});
// OLX ready.
_$doc.on("olx-ready", function() {
_methods.overrides();
});
_$doc.off("olx-form-submitted").on("olx-form-submitted", function() {
if (typeof _updateForm === "function") {
_updateForm();
}
// Successful submission of the form.
bbi.helper.doOnFind('.BBFormConfirmation', function() {
var form = {
block: _methods.block,
update: _methods.triggerFormSubmitted
};
_methods.trigger("success", [form], form);
});
});
// OLX loaded.
_win.bboxShowFormComplete = function() {
// Get OLX's jQuery.
var j = bbi("jQuery").getInstance(0);
j.setLocation("olx", _win["bb$"]);
_bb$ = j.jQuery("olx");
// Set the root container.
_$root = _bb$('#bbox-root');
if (_$root.length === 0) {
_$root = _bb$('div[id^="bbox-root-"]');
}
// Hijack the submit button.
_$btn = _$root.find('.BBFormSubmitbutton');
_olxReady = true;
_methods.check();
};
}());
return {
attach: _methods.attach,
block: _methods.block,
on: function(when, fn) {
if (_olxReady) {
_methods.on(when, fn);
} else {
_$doc.on("olx-ready", function() {
_methods.on(when, fn);
});
}
},
unblock: _methods.unblock,
update: _methods.triggerFormSubmitted
};
}
});
var instance = bbi.instantiate(alias);
bbi.map("olx", instance);
if (bbi("bbnc").getInstance(0).usesMicrosoftAjax() === false) {
bbi.map("attach", instance.attach, true);
}
});
}.call({}, window, bbiGetInstance()));