Skip to content

Commit c283dd8

Browse files
authored
Merge pull request #103 from Math3v/priorities
Notification priorities
2 parents fc92bd7 + e0f78cc commit c283dd8

File tree

6 files changed

+111
-4
lines changed

6 files changed

+111
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ The options list:
132132
| onClose | Any function | undefined | Callback to execute when a notification element is closed. Callback receives the element as its argument. |
133133
| closeOnClick | true, false | true | If true, messages are closed on click |
134134
| maxCount | Any integer | 0 | Show only [maxCount] last messages. Old messages will be killed. 0 - do not kill |
135+
| priority | Any integer | 10 | The highier the priority is, the higher the notification will be |
135136
136137
Also you can pass the "scope" option. This is an angular scope option Notification scope will be inherited from. This option can be passed only in the methods. The default value is $rootScope
137138

demo/angular-ui-notification.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/notification_priority.html

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!DOCTYPE html>
2+
<html ng-app="notificationTest">
3+
<head>
4+
<title>Notification demo (custom configuration)</title>
5+
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
6+
<link rel="stylesheet" href="angular-csp.css">
7+
<link rel="stylesheet" href="angular-ui-notification.min.css">
8+
</head>
9+
<body>
10+
<div class="container">
11+
<h1>Notification demo (custom configuration)</h1>
12+
</div>
13+
14+
<div ng-controller="notificationController">
15+
<div class="container">
16+
<h3>Types of notifications</h3>
17+
<div class="btn-group-vertical">
18+
<button class="btn btn-danger" ng-click="highPriority()">Notification with high priority</button>
19+
<button class="btn btn-primary" ng-click="mediumPriority()">Notification with medium priority</button>
20+
<button class="btn btn-success" ng-click="lowPriority()">Notification with low priority</button>
21+
</div>
22+
</div>
23+
</div>
24+
25+
<script src="angular.min.js"></script>
26+
<script src="angular-ui-notification.min.js"></script>
27+
<script type="text/javascript">
28+
// Configuration
29+
angular.module('notificationTest', ['ui-notification'])
30+
.config(function(NotificationProvider) {
31+
NotificationProvider.setOptions({
32+
delay: 10000,
33+
startTop: 20,
34+
startRight: 10,
35+
verticalSpacing: 20,
36+
horizontalSpacing: 20,
37+
positionX: 'center',
38+
positionY: 'bottom'
39+
});
40+
});
41+
42+
angular.module('notificationTest')
43+
.controller('notificationController', function($scope, Notification) {
44+
$scope.mediumPriority = function() {
45+
Notification({
46+
message: "Notification with medium priority",
47+
delay: 3000
48+
});
49+
};
50+
51+
$scope.highPriority = function() {
52+
Notification.error({
53+
message: "Notification with high priority",
54+
delay: 4000,
55+
priority: 15
56+
});
57+
};
58+
59+
$scope.lowPriority = function() {
60+
Notification.success({
61+
message: "Notification with low priority",
62+
delay: 2000,
63+
priority: 5
64+
});
65+
};
66+
});
67+
68+
</script>
69+
</body>
70+
</html>

dist/angular-ui-notification.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ angular.module('ui-notification').provider('Notification', function() {
2222
onClose: undefined,
2323
closeOnClick: true,
2424
maxCount: 0, // 0 - Infinite
25-
container: 'body'
25+
container: 'body',
26+
priority: 10
2627
};
2728

2829
this.setOptions = function(options) {
@@ -59,6 +60,7 @@ angular.module('ui-notification').provider('Notification', function() {
5960
args.onClose = args.onClose ? args.onClose : options.onClose;
6061
args.closeOnClick = (args.closeOnClick !== null && args.closeOnClick !== undefined) ? args.closeOnClick : options.closeOnClick;
6162
args.container = args.container ? args.container : options.container;
63+
args.priority = args.priority ? args.priority : options.priority;
6264

6365
var template=$templateCache.get(args.template);
6466

@@ -84,12 +86,27 @@ angular.module('ui-notification').provider('Notification', function() {
8486
scope.delay = args.delay;
8587
scope.onClose = args.onClose;
8688

89+
var priorityCompareTop = function(a, b) {
90+
return a._priority - b._priority;
91+
};
92+
93+
var priorityCompareBtm = function(a, b) {
94+
return b._priority - a._priority;
95+
};
96+
8797
var reposite = function() {
8898
var j = 0;
8999
var k = 0;
90100
var lastTop = startTop;
91101
var lastRight = startRight;
92102
var lastPosition = [];
103+
104+
if( args.positionY === 'top' ) {
105+
messageElements.sort( priorityCompareTop );
106+
} else if( args.positionY === 'bottom' ) {
107+
messageElements.sort( priorityCompareBtm );
108+
}
109+
93110
for(var i = messageElements.length - 1; i >= 0; i --) {
94111
var element = messageElements[i];
95112
if (args.replaceMessage && i < messageElements.length - 1) {
@@ -129,6 +146,7 @@ angular.module('ui-notification').provider('Notification', function() {
129146
var templateElement = $compile(template)(scope);
130147
templateElement._positionY = args.positionY;
131148
templateElement._positionX = args.positionX;
149+
templateElement._priority = args.priority;
132150
templateElement.addClass(args.type);
133151

134152
var closeEvent = function(e) {

0 commit comments

Comments
 (0)