nice-elements 1.13.8 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/bower.json +1 -1
- package/dist/nice.js +217 -158
- package/dist/nice.min.js +1 -1
- package/dist/style.css +351 -996
- package/dist/style.css.map +1 -59
- package/dist/style.min.css +2 -2
- package/package.json +6 -6
- package/src/components/nice-comment/nice-comment.js +11 -11
- package/src/components/nice-comment/nice-comment.scss +0 -2
- package/src/components/nice-date/nice-date.js +8 -1
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +9 -2
- package/src/components/nice-dropdown/nice-dropdown.js +16 -15
- package/src/components/nice-help/nice-help.html +3 -4
- package/src/components/nice-help/nice-help.js +10 -37
- package/src/components/nice-help/nice-help.scss +59 -27
- package/src/components/nice-input/nice-input.html +3 -0
- package/src/components/nice-input/nice-input.js +4 -4
- package/src/components/nice-notification/nice-notification.html +9 -4
- package/src/components/nice-notification/nice-notification.js +66 -46
- package/src/components/nice-notification/nice-notification.scss +97 -19
- package/src/components/nice-popup/nice-popup.js +10 -5
- package/src/components/nice-search2/nice-search2.js +15 -5
- package/src/components/nice-virtual-scroll/nice-virtual-scroll.js +15 -3
- package/src/directives/nice-click-outside.js +24 -18
- package/src/directives/nice-tooltip/nice-tooltip.js +14 -4
- package/src/services/nice-service.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nice-elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Nice elements used in olaii angular 1.x webapps.",
|
|
5
5
|
"main": "dist/nice.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@olaii/ng-infinite-scroll": "1.3.1",
|
|
13
|
-
"angular-infinite-scroll": "3.1.1",
|
|
14
13
|
"@popperjs/core": "2.11.6",
|
|
15
14
|
"angular": "1.5.8",
|
|
16
15
|
"angular-animate": "1.5.8",
|
|
17
16
|
"angular-gettext": "2.4.2",
|
|
17
|
+
"angular-infinite-scroll": "3.1.1",
|
|
18
18
|
"angular-route": "1.5.8",
|
|
19
19
|
"angular-sanitize": "1.5.8",
|
|
20
20
|
"angular-touch": "1.5.8",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"ng-dialog": "0.5.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@eslint/js": "
|
|
31
|
-
"eslint": "
|
|
32
|
-
"globals": "^15.2.0",
|
|
30
|
+
"@eslint/js": "9.2.0",
|
|
31
|
+
"eslint": "9.2.0",
|
|
33
32
|
"express": "4.17.1",
|
|
33
|
+
"globals": "15.2.0",
|
|
34
34
|
"grunt": "1.6.1",
|
|
35
35
|
"grunt-angular-templates": "1.2.0",
|
|
36
36
|
"grunt-contrib-clean": "2.0.0",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"grunt-contrib-uglify": "5.0.1",
|
|
41
41
|
"grunt-sass": "3.1.0",
|
|
42
42
|
"load-grunt-tasks": "5.1.0",
|
|
43
|
-
"
|
|
43
|
+
"sass": "1.107.1"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -45,21 +45,21 @@ angular.module('niceElements')
|
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
// Resize to fit the content. Runs outside Angular: it only touches the
|
|
49
|
+
// textarea's style, so it never triggers a digest.
|
|
51
50
|
function autosize() {
|
|
52
51
|
const el = textareas[0];
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
el.style.height = 'auto';
|
|
53
|
+
el.style.height = (el.scrollHeight + 2) + 'px';
|
|
54
|
+
}
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
// 'input' fires after the value changes (typing, paste, cut), so no timeout is needed
|
|
57
|
+
textareas[0].addEventListener('input', autosize);
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
59
|
+
// Also fit when the model is set from outside; wait for ngModel to render it
|
|
60
|
+
scope.$watch('model', function () {
|
|
61
|
+
$timeout(autosize, 0, false);
|
|
62
|
+
});
|
|
63
63
|
},
|
|
64
64
|
controller: function ($scope) {
|
|
65
65
|
$scope.editing = false;
|
|
@@ -27,13 +27,11 @@
|
|
|
27
27
|
|
|
28
28
|
border-radius: $nice-border-radius;
|
|
29
29
|
border-color: transparent;
|
|
30
|
-
color: $nice-base-color;
|
|
31
30
|
-webkit-user-select: none;
|
|
32
31
|
padding: 6px 0px;
|
|
33
32
|
|
|
34
33
|
&.editing {
|
|
35
34
|
padding: 6px;
|
|
36
|
-
color: $nice-font-color;
|
|
37
35
|
-webkit-user-select: initial;
|
|
38
36
|
}
|
|
39
37
|
}
|
|
@@ -114,10 +114,17 @@ angular.module('niceElements')
|
|
|
114
114
|
});
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
-
$timeout(function () {
|
|
117
|
+
const setupTimer = $timeout(function () {
|
|
118
118
|
if (!$scope.inline) $scope.setupPopper();
|
|
119
119
|
}, 100);
|
|
120
120
|
|
|
121
|
+
// Popper adds scroll/resize listeners to window; remove them with the component
|
|
122
|
+
$scope.$on('$destroy', function () {
|
|
123
|
+
$timeout.cancel(setupTimer);
|
|
124
|
+
if ($scope.popper) $scope.popper.destroy();
|
|
125
|
+
$scope.popper = null;
|
|
126
|
+
});
|
|
127
|
+
|
|
121
128
|
|
|
122
129
|
// ------------------ Time changes ------------------
|
|
123
130
|
$scope.timeChange = function () {
|
|
@@ -83,10 +83,17 @@ angular.module('niceElements')
|
|
|
83
83
|
});
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
-
$timeout(function () {
|
|
86
|
+
const setupTimer = $timeout(function () {
|
|
87
87
|
$scope.setupPopper();
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
+
// Popper adds scroll/resize listeners to window; remove them with the component
|
|
91
|
+
$scope.$on('$destroy', function () {
|
|
92
|
+
$timeout.cancel(setupTimer);
|
|
93
|
+
if ($scope.popper) $scope.popper.destroy();
|
|
94
|
+
$scope.popper = null;
|
|
95
|
+
});
|
|
96
|
+
|
|
90
97
|
|
|
91
98
|
$scope.format = function () {
|
|
92
99
|
$scope.modelFormat = $scope.startDate.format($scope.formatString) + " - " + $scope.endDate.format($scope.formatString);
|
|
@@ -96,7 +103,7 @@ angular.module('niceElements')
|
|
|
96
103
|
$scope.open = function () {
|
|
97
104
|
if (!$scope.isDisabled) {
|
|
98
105
|
$scope.isOpen = true;
|
|
99
|
-
$scope.popper.update();
|
|
106
|
+
if ($scope.popper) $scope.popper.update();
|
|
100
107
|
}
|
|
101
108
|
};
|
|
102
109
|
|
|
@@ -91,8 +91,6 @@ angular.module('niceElements')
|
|
|
91
91
|
$scope.popper = Popper.createPopper(button, tooltip, {
|
|
92
92
|
strategy: 'fixed',
|
|
93
93
|
placement: $scope.placement,
|
|
94
|
-
scroll: true,
|
|
95
|
-
resize: true,
|
|
96
94
|
modifiers: [
|
|
97
95
|
{
|
|
98
96
|
name: 'offset',
|
|
@@ -122,10 +120,17 @@ angular.module('niceElements')
|
|
|
122
120
|
});
|
|
123
121
|
};
|
|
124
122
|
|
|
125
|
-
$timeout(function () {
|
|
123
|
+
const setupTimer = $timeout(function () {
|
|
126
124
|
$scope.setupPopper();
|
|
127
125
|
});
|
|
128
126
|
|
|
127
|
+
// Popper adds scroll/resize listeners to window; remove them with the component
|
|
128
|
+
$scope.$on('$destroy', function () {
|
|
129
|
+
$timeout.cancel(setupTimer);
|
|
130
|
+
if ($scope.popper) $scope.popper.destroy();
|
|
131
|
+
$scope.popper = null;
|
|
132
|
+
});
|
|
133
|
+
|
|
129
134
|
|
|
130
135
|
// ----------------------------------- Open -----------------------------------
|
|
131
136
|
$scope.toggle = function () {
|
|
@@ -142,13 +147,13 @@ angular.module('niceElements')
|
|
|
142
147
|
};
|
|
143
148
|
|
|
144
149
|
$scope.open = function () {
|
|
145
|
-
$scope.popper.update();
|
|
150
|
+
if ($scope.popper) $scope.popper.update();
|
|
146
151
|
if ($scope.filterFunction) $scope.internalList = $scope.filterFunction($scope.originalList, $scope.model);
|
|
147
152
|
$timeout(function () {
|
|
148
153
|
$scope.isOpen = true;
|
|
149
154
|
if ($scope.onOpen) $scope.onOpen();
|
|
150
155
|
$timeout(function () {
|
|
151
|
-
$scope.popper.update();
|
|
156
|
+
if ($scope.popper) $scope.popper.update();
|
|
152
157
|
});
|
|
153
158
|
});
|
|
154
159
|
$timeout(function () {
|
|
@@ -504,16 +509,12 @@ angular.module('niceElements')
|
|
|
504
509
|
|
|
505
510
|
// ----------------------------------- Handle add button function -----------------------------------
|
|
506
511
|
$scope.handleAddButton = function ($event) {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
element = element.parentElement;
|
|
514
|
-
}
|
|
515
|
-
$scope.addButtonFunction();
|
|
516
|
-
}
|
|
512
|
+
// Blur the clicked button. closest() stops at the root instead of
|
|
513
|
+
// walking past it (the old loop crashed if no <button> was found).
|
|
514
|
+
const button = $event && $event.target && $event.target.closest ? $event.target.closest('button') : null;
|
|
515
|
+
if (button) button.blur();
|
|
516
|
+
if ($scope.addButtonFunction) $scope.addButtonFunction();
|
|
517
|
+
};
|
|
517
518
|
}
|
|
518
519
|
};
|
|
519
520
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
<div class="nice-help" ng-
|
|
1
|
+
<div class="nice-help" ng-class="'nice-help-' + placement" style="anchor-name: --nice-help-{{ id }}">
|
|
2
2
|
<nice-icon icon="icon-help-circle" class="nice-help-button"></nice-icon>
|
|
3
|
-
<div class="nice-help-popup">
|
|
3
|
+
<div class="nice-help-popup" role="tooltip" style="position-anchor: --nice-help-{{ id }}">
|
|
4
4
|
<span ng-bind-html="text">{{ text }}</span>
|
|
5
|
-
<div data-popper-arrow class="nice-help-arrow"></div>
|
|
6
5
|
</div>
|
|
7
|
-
</div>
|
|
6
|
+
</div>
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* @name niceElements.directive:niceHelp
|
|
6
6
|
* @description
|
|
7
7
|
* # niceHelp
|
|
8
|
+
* Help icon with a hover popup. Positioning is pure CSS (anchor positioning,
|
|
9
|
+
* with an absolute-position fallback), so there are no JS listeners to clean up.
|
|
8
10
|
*/
|
|
9
11
|
angular.module('niceElements')
|
|
10
12
|
.directive('niceHelp', function () {
|
|
@@ -14,45 +16,16 @@ angular.module('niceElements')
|
|
|
14
16
|
replace: true,
|
|
15
17
|
scope: {
|
|
16
18
|
text: '@',
|
|
17
|
-
placement: '@', //
|
|
19
|
+
placement: '@', // top (default) | bottom | left | right
|
|
18
20
|
},
|
|
19
|
-
controller: function ($scope
|
|
20
|
-
|
|
21
|
+
controller: function ($scope) {
|
|
22
|
+
const placements = ['top', 'bottom', 'left', 'right'];
|
|
23
|
+
// Popper-style values like "top-start" map to their base side
|
|
24
|
+
const side = ($scope.placement || 'top').split('-')[0];
|
|
25
|
+
$scope.placement = placements.indexOf(side) >= 0 ? side : 'top';
|
|
21
26
|
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
$scope.setupPopper = function () {
|
|
25
|
-
const button = $element[0].getElementsByClassName('nice-help-button')[0];
|
|
26
|
-
const tooltip = $element[0].getElementsByClassName('nice-help-popup')[0];
|
|
27
|
-
$scope.popper = Popper.createPopper(button, tooltip, {
|
|
28
|
-
strategy: 'fixed',
|
|
29
|
-
placement: $scope.placement,
|
|
30
|
-
scroll: true,
|
|
31
|
-
resize: true,
|
|
32
|
-
modifiers: [
|
|
33
|
-
{
|
|
34
|
-
name: 'offset',
|
|
35
|
-
options: {
|
|
36
|
-
offset: [0, 5],
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'arrow',
|
|
41
|
-
options: {
|
|
42
|
-
padding: 2,
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
],
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// $timeout(function () {
|
|
50
|
-
// $scope.setupPopper();
|
|
51
|
-
// });
|
|
52
|
-
|
|
53
|
-
$scope.onHover = function () {
|
|
54
|
-
$scope.setupPopper();
|
|
55
|
-
}
|
|
27
|
+
// Unique anchor name so each popup attaches to its own icon
|
|
28
|
+
$scope.id = Math.random().toString(36).substring(2, 9);
|
|
56
29
|
}
|
|
57
30
|
};
|
|
58
31
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
.nice-help {
|
|
2
|
-
$nice-help-
|
|
2
|
+
$nice-help-offset: 6px;
|
|
3
3
|
position: relative;
|
|
4
4
|
display: inline-block;
|
|
5
5
|
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
display: block;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
&:hover
|
|
18
|
+
&:hover,
|
|
19
|
+
&:focus-within {
|
|
19
20
|
.nice-help-popup {
|
|
20
21
|
display: block;
|
|
21
22
|
}
|
|
@@ -24,8 +25,8 @@
|
|
|
24
25
|
.nice-help-popup {
|
|
25
26
|
display: none;
|
|
26
27
|
z-index: 9999;
|
|
27
|
-
background:
|
|
28
|
-
color:
|
|
28
|
+
background: var(--nice-help-popup-bg);
|
|
29
|
+
color: var(--nice-help-popup-color);
|
|
29
30
|
max-width: 200px;
|
|
30
31
|
width: max-content;
|
|
31
32
|
border-radius: $nice-border-radius;
|
|
@@ -34,46 +35,77 @@
|
|
|
34
35
|
padding: 7px 10px;
|
|
35
36
|
font-weight: normal;
|
|
36
37
|
text-align: center;
|
|
38
|
+
white-space: normal;
|
|
37
39
|
|
|
38
40
|
a {
|
|
39
41
|
color: $nice-base-color;
|
|
40
42
|
text-transform: none;
|
|
41
43
|
}
|
|
44
|
+
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
// ---------- Native anchor positioning ----------
|
|
47
|
+
// Fixed + anchored: escapes overflow:hidden parents (tables, modals)
|
|
48
|
+
// and flips automatically when there is no room, like Popper did.
|
|
49
|
+
@supports (position-area: top) {
|
|
50
|
+
.nice-help-popup {
|
|
51
|
+
position: fixed;
|
|
52
|
+
margin: 0;
|
|
53
|
+
position-try-fallbacks: flip-block, flip-inline;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&.nice-help-top .nice-help-popup {
|
|
57
|
+
position-area: top;
|
|
58
|
+
margin-bottom: $nice-help-offset;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&.nice-help-bottom .nice-help-popup {
|
|
62
|
+
position-area: bottom;
|
|
63
|
+
margin-top: $nice-help-offset;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&.nice-help-left .nice-help-popup {
|
|
67
|
+
position-area: left;
|
|
68
|
+
margin-right: $nice-help-offset;
|
|
49
69
|
}
|
|
50
70
|
|
|
51
|
-
.nice-help-
|
|
52
|
-
|
|
71
|
+
&.nice-help-right .nice-help-popup {
|
|
72
|
+
position-area: right;
|
|
73
|
+
margin-left: $nice-help-offset;
|
|
53
74
|
}
|
|
75
|
+
}
|
|
54
76
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
// ---------- Fallback for browsers without anchor positioning ----------
|
|
78
|
+
@supports not (position-area: top) {
|
|
79
|
+
.nice-help-popup {
|
|
80
|
+
position: absolute;
|
|
59
81
|
}
|
|
60
82
|
|
|
61
|
-
|
|
62
|
-
bottom:
|
|
63
|
-
|
|
83
|
+
&.nice-help-top .nice-help-popup {
|
|
84
|
+
bottom: 100%;
|
|
85
|
+
left: 50%;
|
|
86
|
+
transform: translateX(-50%);
|
|
87
|
+
margin-bottom: $nice-help-offset;
|
|
64
88
|
}
|
|
65
89
|
|
|
66
|
-
|
|
67
|
-
top:
|
|
68
|
-
|
|
90
|
+
&.nice-help-bottom .nice-help-popup {
|
|
91
|
+
top: 100%;
|
|
92
|
+
left: 50%;
|
|
93
|
+
transform: translateX(-50%);
|
|
94
|
+
margin-top: $nice-help-offset;
|
|
69
95
|
}
|
|
70
96
|
|
|
71
|
-
|
|
72
|
-
right:
|
|
97
|
+
&.nice-help-left .nice-help-popup {
|
|
98
|
+
right: 100%;
|
|
99
|
+
top: 50%;
|
|
100
|
+
transform: translateY(-50%);
|
|
101
|
+
margin-right: $nice-help-offset;
|
|
73
102
|
}
|
|
74
103
|
|
|
75
|
-
|
|
76
|
-
left:
|
|
104
|
+
&.nice-help-right .nice-help-popup {
|
|
105
|
+
left: 100%;
|
|
106
|
+
top: 50%;
|
|
107
|
+
transform: translateY(-50%);
|
|
108
|
+
margin-left: $nice-help-offset;
|
|
77
109
|
}
|
|
78
110
|
}
|
|
79
|
-
}
|
|
111
|
+
}
|
|
@@ -63,6 +63,9 @@
|
|
|
63
63
|
/>
|
|
64
64
|
|
|
65
65
|
<div class="input-group-addon" ng-if="symbol">{{ symbol }}</div>
|
|
66
|
+
<button type="button" class="input-group-btn" ng-if="type=='password'" ng-click="togglePasswordType()">
|
|
67
|
+
<nice-icon icon="icon-eye"></nice-icon>
|
|
68
|
+
</button>
|
|
66
69
|
<button type="button" class="input-group-btn" ng-if="!multilanguageDisabled && multilanguageField" ng-click="openMultilanguage()">
|
|
67
70
|
<nice-icon icon="icon-translate"></nice-icon>
|
|
68
71
|
<div class="nice-input-addon-bubble" ng-if="numberOfLanguages > 0">{{ numberOfLanguages }}</div>
|
|
@@ -109,8 +109,6 @@ angular.module('niceElements')
|
|
|
109
109
|
} else if ($scope.type == "email") {
|
|
110
110
|
$scope.inputMode = "email";
|
|
111
111
|
$scope.regexexp = new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$");
|
|
112
|
-
} else {
|
|
113
|
-
$scope.internalType = "text";
|
|
114
112
|
}
|
|
115
113
|
|
|
116
114
|
if (angular.isDefined($scope.valid)) {
|
|
@@ -143,8 +141,6 @@ angular.module('niceElements')
|
|
|
143
141
|
} else if ($scope.type == "number" && value_old && value_old[value_old.length - 1] == ".") {
|
|
144
142
|
// IGNORE
|
|
145
143
|
} else {
|
|
146
|
-
// Parent switched to plain value (null keeps Decimal, e.g. cleared input)
|
|
147
|
-
if ($scope.model != null) $scope.decimalConstructor = null;
|
|
148
144
|
$scope.internalModel = angular.copy($scope.model);
|
|
149
145
|
}
|
|
150
146
|
|
|
@@ -233,6 +229,10 @@ angular.module('niceElements')
|
|
|
233
229
|
};
|
|
234
230
|
};
|
|
235
231
|
|
|
232
|
+
$scope.togglePasswordType = function () {
|
|
233
|
+
$scope.internalType = $scope.internalType == 'password' ? 'text' : 'password';
|
|
234
|
+
};
|
|
235
|
+
|
|
236
236
|
$scope.keypress = function (event) {
|
|
237
237
|
if ($scope.numbersOnly) {
|
|
238
238
|
if ((event.charCode >= 48 && event.charCode <= 58) || event.charCode == 0) { // Allow only numbers
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
<div class="notification">
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
<div class="notification" ng-class="{ 'has-icon': icon }">
|
|
2
|
+
<div class="notification-inner">
|
|
3
|
+
<nice-icon ng-if="icon" class="notification-icon" icon="{{ icon }}"></nice-icon>
|
|
4
|
+
<div class="notification-content">
|
|
5
|
+
<div class="notification-title" ng-show="title" ng-bind-html="title"></div>
|
|
6
|
+
<div class="notification-message" ng-bind-html="message"></div>
|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
</div>
|
|
@@ -10,12 +10,35 @@ angular.module('niceElements')
|
|
|
10
10
|
.factory('NiceNotification', function ($timeout, $http, $compile, $templateCache, $rootScope, $sce) {
|
|
11
11
|
|
|
12
12
|
let startTop = 10;
|
|
13
|
-
let startRight = 10;
|
|
14
13
|
let verticalSpacing = 10;
|
|
15
|
-
let horizontalSpacing = 10;
|
|
16
14
|
let delay = 5000;
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
// Default icon per type (primary has none). Override with notify.config({ icons: { ... } })
|
|
17
|
+
const icons = {
|
|
18
|
+
success: 'icon-check-circle',
|
|
19
|
+
error: 'icon-alert-triangle',
|
|
20
|
+
warning: 'icon-alert-circle',
|
|
21
|
+
info: 'icon-info',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// All notifications live in one fixed container; CSS (flexbox) does the stacking
|
|
25
|
+
let container = null;
|
|
26
|
+
|
|
27
|
+
const applyConfig = function () {
|
|
28
|
+
if (!container) return;
|
|
29
|
+
container.style.setProperty('--nice-notification-top', startTop + 'px');
|
|
30
|
+
container.style.setProperty('--nice-notification-spacing', verticalSpacing + 'px');
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getContainer = function () {
|
|
34
|
+
if (!container || !document.body.contains(container)) {
|
|
35
|
+
container = document.createElement('div');
|
|
36
|
+
container.className = 'nice-notifications';
|
|
37
|
+
applyConfig();
|
|
38
|
+
document.body.appendChild(container);
|
|
39
|
+
}
|
|
40
|
+
return container;
|
|
41
|
+
};
|
|
19
42
|
|
|
20
43
|
const notify = function (args, t) {
|
|
21
44
|
|
|
@@ -33,6 +56,8 @@ angular.module('niceElements')
|
|
|
33
56
|
scope.message = $sce.trustAsHtml(args.message);
|
|
34
57
|
scope.title = $sce.trustAsHtml(args.title);
|
|
35
58
|
scope.t = args.type.substr(0, 1);
|
|
59
|
+
// icon: undefined → type default, false/null/'' → no icon, string → that icon id
|
|
60
|
+
scope.icon = angular.isUndefined(args.icon) ? icons[args.type] : args.icon;
|
|
36
61
|
scope.delay = args.delay;
|
|
37
62
|
|
|
38
63
|
if (typeof args.scope === 'object') {
|
|
@@ -41,54 +66,42 @@ angular.module('niceElements')
|
|
|
41
66
|
}
|
|
42
67
|
}
|
|
43
68
|
|
|
44
|
-
const reposite = function () {
|
|
45
|
-
let j = 0;
|
|
46
|
-
let k = 0;
|
|
47
|
-
let lastTop = startTop;
|
|
48
|
-
let top = 0;
|
|
49
|
-
// const lastRight = startRight;
|
|
50
|
-
for (let i = messageElements.length - 1; i >= 0; i--) {
|
|
51
|
-
const element = messageElements[i];
|
|
52
|
-
const elHeight = parseInt(element[0].offsetHeight);
|
|
53
|
-
const elWidth = parseInt(element[0].offsetWidth);
|
|
54
|
-
if ((top + elHeight) > window.innerHeight) {
|
|
55
|
-
lastTop = startTop;
|
|
56
|
-
k++;
|
|
57
|
-
j = 0;
|
|
58
|
-
}
|
|
59
|
-
top = lastTop + (j === 0 ? 0 : verticalSpacing);
|
|
60
|
-
const right = startRight + (k * (horizontalSpacing + elWidth));
|
|
61
|
-
|
|
62
|
-
element.css('top', top + 'px');
|
|
63
|
-
element.css('right', right + 'px');
|
|
64
|
-
|
|
65
|
-
lastTop = top + elHeight;
|
|
66
|
-
j++;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
69
|
const templateElement = $compile(template)(scope);
|
|
71
70
|
templateElement.addClass(args.type);
|
|
72
|
-
templateElement.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd click', function (e) {
|
|
73
|
-
e = e.originalEvent || e;
|
|
74
|
-
if (e.type === 'click' || (e.propertyName === 'opacity' && e.elapsedTime >= 0.4)) {
|
|
75
|
-
templateElement.remove();
|
|
76
|
-
messageElements.splice(messageElements.indexOf(templateElement), 1);
|
|
77
|
-
reposite();
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
71
|
|
|
81
|
-
|
|
72
|
+
let closed = false;
|
|
73
|
+
let closeTimer = null;
|
|
74
|
+
|
|
75
|
+
// Single exit path: safe to call any number of times (click + timer)
|
|
76
|
+
const close = function () {
|
|
77
|
+
if (closed) return;
|
|
78
|
+
closed = true;
|
|
79
|
+
if (closeTimer) $timeout.cancel(closeTimer);
|
|
80
|
+
|
|
81
|
+
// Mark as closed; the leave animation is defined entirely in CSS (.killed).
|
|
82
|
+
// Remove the element once whatever CSS animations it has are done
|
|
83
|
+
// (resolves right away if there are none, e.g. a custom template).
|
|
84
|
+
const el = templateElement[0];
|
|
82
85
|
templateElement.addClass('killed');
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
const running = el.getAnimations ? el.getAnimations() : [];
|
|
87
|
+
// An interrupted enter animation rejects its promise; treat that as done
|
|
88
|
+
// so it doesn't cut the leave transitions short.
|
|
89
|
+
Promise.all(running.map(function (a) { return a.finished.catch(angular.noop); }))
|
|
90
|
+
.then(function () {
|
|
91
|
+
templateElement.remove();
|
|
92
|
+
scope.$destroy();
|
|
93
|
+
});
|
|
94
|
+
};
|
|
87
95
|
|
|
88
|
-
|
|
89
|
-
messageElements.push(templateElement);
|
|
96
|
+
templateElement.on('click', close);
|
|
90
97
|
|
|
91
|
-
|
|
98
|
+
// Newest on top; the CSS enter animation runs on insertion
|
|
99
|
+
const list = getContainer();
|
|
100
|
+
list.insertBefore(templateElement[0], list.firstChild);
|
|
101
|
+
|
|
102
|
+
if (args.delay > 0) {
|
|
103
|
+
closeTimer = $timeout(close, args.delay);
|
|
104
|
+
}
|
|
92
105
|
|
|
93
106
|
}).error(function (data) {
|
|
94
107
|
throw new Error('Template (' + args.template + ') could not be loaded. ' + data);
|
|
@@ -98,6 +111,13 @@ angular.module('niceElements')
|
|
|
98
111
|
notify.config = function (args) {
|
|
99
112
|
startTop = args.top ? args.top : startTop;
|
|
100
113
|
verticalSpacing = args.verticalSpacing ? args.verticalSpacing : verticalSpacing;
|
|
114
|
+
applyConfig();
|
|
115
|
+
if (args.icons) {
|
|
116
|
+
// Use 'primary' as the key for the default type
|
|
117
|
+
angular.forEach(args.icons, function (icon, type) {
|
|
118
|
+
icons[type === 'primary' ? '' : type] = icon;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
101
121
|
};
|
|
102
122
|
|
|
103
123
|
notify.primary = function (args) {
|
|
@@ -122,4 +142,4 @@ angular.module('niceElements')
|
|
|
122
142
|
|
|
123
143
|
|
|
124
144
|
return notify;
|
|
125
|
-
});
|
|
145
|
+
});
|