Skip to content

Commit 0b6c9a5

Browse files
authored
Global custom style classes (Issue JanStevens#101)
Allow custom style classes related to severities to be defined globally.
1 parent 3533910 commit 0b6c9a5

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/growlFactory.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ angular.module("angular-growl").provider("growl", function () {
1717
_disableIcons = false,
1818
_reverseOrder = false,
1919
_disableCountDown = false,
20-
_translateMessages = true;
20+
_translateMessages = true,
21+
_styleClasses = {success: 'alert-success', info: 'alert-info', warning: 'alert-warning',
22+
error: 'alert-error', danger: 'alert-danger'};
2123

2224
/**
2325
* set a global timeout (time to live) after which messages will be automatically closed
@@ -120,6 +122,30 @@ angular.module("angular-growl").provider("growl", function () {
120122
_position = position;
121123
return this;
122124
};
125+
126+
/**
127+
* sets the style classes to use related to a severity.
128+
* 'danger' and 'error' are related to error severity, but have distinct styles
129+
*
130+
*
131+
* @param {object} styleClasses default:
132+
* {success: 'alert-success', info: 'alert-info', warning: 'alert-warning',
133+
* error: 'alert-error', danger: 'alert-danger'}
134+
*/
135+
this.globalStyleClasses = function (styleClasses) {
136+
if (styleClasses) {
137+
// only change the styles defined by the user
138+
// if not added to customized object then don't change default one
139+
_styleClasses.success = styleClasses.success || _styleClasses.success;
140+
_styleClasses.info = styleClasses.info || _styleClasses.info;
141+
_styleClasses.warning = styleClasses.warning || _styleClasses.warning;
142+
_styleClasses.error = styleClasses.error || _styleClasses.error;
143+
_styleClasses.danger = styleClasses.danger || _styleClasses.danger;
144+
}
145+
return this;
146+
};
147+
148+
123149
/**
124150
* sets the key in $http response the serverMessagesInterecptor is looking for server-sent messages, value of key
125151
* needs to be an array of objects

0 commit comments

Comments
 (0)