-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform-cues.js
78 lines (70 loc) · 3.19 KB
/
form-cues.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
'use strict';
(function () {
// Establish the root object, `window` in the browser, or `exports` on the server.
var root = this;
// Create a safe reference to the FormCues object for use below.
var cues = function (obj) {
if (obj instanceof cues) return obj;
if (!(this instanceof cues)) return new cues(obj);
};
// Export the FormCues object for **Node.js**, with
// backwards-compatibility for the old `require()` API. If we're in
// the browser, add `cues` as a global object.
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = cues;
}
exports.cues = cues;
} else {
root.cues = cues;
}
/**
* Adds a Bootstrap alert to a page, assumes a div element with an id of [alert]
* @param alertElement {Object|String}
* @param message
* @param options
*/
cues.addAlert = function (alertElement, message, options) {
options = options || {};
var level = options.level || 'info';
var isDismissable = options.isDismissable || options.dismissable || false;
var doMultiple = options.doMultiple || options.multiple || false;
alertElement = ((alertElement instanceof Object) ? alertElement : $('#' + alertElement));
var dismissHtml = (isDismissable ? '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' : '');
var alertHtml = '<div class="alert alert-' + level + '">' + dismissHtml + message + '</div>';
var alert = (doMultiple ? alertElement.append(alertHtml) : alertElement.html(alertHtml));
alert.alert();
};
/**
* Disables/enables buttons and animates their icons
* @param submitButton {Object|String}
* @param submitIcon {Object|String}
* @param submitText {Object|String}
* @param options
*/
cues.setSubmitState = function (submitButton, submitIcon, submitText, options) {
options = options || {};
var isEnabled = options.isEnabled || options.enabled || false;
var doSpin = options.doSpin || options.spin || false;
var defaultIcon = options.defaultIcon || options.icon || 'check';
var spinnerIcon = options.spinnerIcon || 'spinner';
var animation = options.animation || 'spin';
var buttonText = options.buttonText || options.text || null;
submitButton = ((submitButton instanceof Object) ? submitButton : $('#' + submitButton));
submitIcon = ((submitIcon instanceof Object) ? submitIcon : $('#' + submitIcon));
submitText = ((submitText instanceof Object) ? submitText : $('#' + submitText));
if (!!buttonText) {
submitText.html(buttonText);
}
submitButton.prop('disabled', !isEnabled);
if (!!doSpin) {
submitIcon.removeClass('fa-' + defaultIcon);
submitIcon.addClass('fa-' + spinnerIcon);
submitIcon.addClass('fa-' + animation);
} else {
submitIcon.removeClass('fa-' + spinnerIcon);
submitIcon.removeClass('fa-' + animation);
submitIcon.addClass('fa-' + defaultIcon);
}
};
}.call(this));