nice-elements 1.14.1 → 1.15.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/CLAUDE.md +89 -0
  3. package/README.md +3 -1
  4. package/bower.json +1 -1
  5. package/dist/nice.js +590 -83
  6. package/dist/nice.min.js +1 -1
  7. package/dist/style.css +180 -1
  8. package/dist/style.css.map +1 -1
  9. package/dist/style.min.css +1 -1
  10. package/package.json +2 -2
  11. package/src/components/nice-badges-list/nice-badges-list.html +13 -0
  12. package/src/components/nice-badges-list/nice-badges-list.js +135 -0
  13. package/src/components/nice-badges-list/nice-badges-list.scss +75 -0
  14. package/src/components/nice-checkbox/nice-checkbox.html +1 -1
  15. package/src/components/nice-date/nice-date.js +3 -1
  16. package/src/components/nice-date-range/nice-date-range.js +7 -7
  17. package/src/components/nice-datetime-picker/nice-datetime-picker.html +3 -3
  18. package/src/components/nice-datetime-picker/nice-datetime-picker.js +7 -2
  19. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +2 -2
  20. package/src/components/nice-dialog/nice-dialog.html +16 -0
  21. package/src/components/nice-dialog/nice-dialog.js +47 -0
  22. package/src/components/nice-dialog/nice-dialog.scss +126 -0
  23. package/src/components/nice-dropdown/nice-dropdown.js +4 -1
  24. package/src/components/nice-dropdown-date/nice-dropdown-date.js +3 -1
  25. package/src/components/nice-input/nice-input.js +12 -8
  26. package/src/components/nice-no-data/nice-no-data.js +3 -1
  27. package/src/components/nice-number/nice-number.html +23 -9
  28. package/src/components/nice-number/nice-number.js +81 -12
  29. package/src/components/nice-percent/nice-percent.js +5 -3
  30. package/src/components/nice-popup/nice-popup.js +2 -2
  31. package/src/components/nice-search/nice-search.html +2 -4
  32. package/src/components/nice-search/nice-search.js +32 -6
  33. package/src/components/nice-svgs/nice-svgs.html +165 -20
  34. package/src/components/nice-table/nice-table.js +9 -4
  35. package/src/components/nice-view/_nice-view.scss +10 -1
  36. package/src/components/nice-view/nice-view.html +1 -0
  37. package/src/components/nice-wrapper/nice-wrapper.js +3 -1
  38. package/src/components/nice-yesno/nice-yesno.js +4 -2
  39. package/src/services/nice-service.js +16 -1
  40. package/src/styles/_nice.scss +2 -0
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @ngdoc directive
5
+ * @name niceElements.directive:niceDialog
6
+ * @description
7
+ * # niceDialog
8
+ * Layout for dialog content (header, scrollable body, footer). Meant to be used inside an ngDialog template,
9
+ * opened with `className: 'nice-ngdialog'` and `showClose: false` (close from the footer instead).
10
+ * The whole dialog is a <form>, so `nice-submit` is called on submit (e.g. pressing enter or a type="submit" button).
11
+ * Header / footer borders appear based on the body scroll position.
12
+ *
13
+ * Usage:
14
+ * <nice-dialog nice-title="Edit" nice-subtitle="Event" nice-icon="icon-edit" nice-submit="save()">
15
+ * ...body...
16
+ * <nice-dialog-footer>
17
+ * <button type="button" class="btn btn-default" ng-click="closeThisDialog()">Cancel</button>
18
+ * <button type="submit" class="btn btn-primary">Save</button>
19
+ * </nice-dialog-footer>
20
+ * </nice-dialog>
21
+ *
22
+ * Pass <nice-dialog-header> to replace the default header (icon + subtitle + title).
23
+ */
24
+ angular.module('niceElements')
25
+ .directive('niceDialog', function () {
26
+ return {
27
+ templateUrl: 'src/components/nice-dialog/nice-dialog.html',
28
+ restrict: 'E',
29
+ replace: true,
30
+ transclude: {
31
+ 'header': '?niceDialogHeader',
32
+ 'footer': '?niceDialogFooter'
33
+ },
34
+ scope: {
35
+ niceTitle: '@',
36
+ niceIcon: '@',
37
+ niceSubtitle: '@',
38
+ niceSubmit: '&?',
39
+ niceHideSubtitle: '=?'
40
+ },
41
+ link: function (scope) {
42
+ scope.handleSubmit = function () {
43
+ if (scope.niceSubmit) scope.niceSubmit();
44
+ };
45
+ }
46
+ };
47
+ });
@@ -0,0 +1,126 @@
1
+ // ngDialog wrapper, open with className: 'nice-ngdialog', showClose: false
2
+ .nice-ngdialog {
3
+ .ngdialog-content {
4
+ background: unset;
5
+ display: flex;
6
+ justify-content: center;
7
+ align-items: center;
8
+
9
+ .nice-dialog {
10
+ max-height: calc(100dvh - 4rem);
11
+ max-width: 95%;
12
+ width: 800px;
13
+ margin: 2rem;
14
+
15
+ background: var(--nice-card-bg);
16
+ border: 1px solid var(--nice-border-color);
17
+ position: relative;
18
+ border-radius: var(--nice-border-radius);
19
+ }
20
+ }
21
+ }
22
+
23
+
24
+ .nice-dialog {
25
+ display: flex;
26
+ flex-direction: column;
27
+ max-height: calc(100vh - 6rem);
28
+ --nice-dialog-padding: 2rem;
29
+
30
+ // Header / footer borders are driven by the body scroll position (same as nice-view)
31
+ timeline-scope: --nice-dialog-scroll;
32
+
33
+ // ---------------- Dialog Header ----------------
34
+ .nice-dialog-header {
35
+ font-size: 1.3em;
36
+ line-height: 1.3;
37
+ padding: var(--nice-dialog-padding);
38
+ padding-bottom: calc(var(--nice-dialog-padding) / 2);
39
+ flex-shrink: 0;
40
+ border-bottom: 1px solid transparent;
41
+ animation: nice-dialog-header-border linear both;
42
+ animation-timeline: --nice-dialog-scroll;
43
+ animation-range: 0 1rem;
44
+
45
+ display: flex;
46
+ align-items: center;
47
+ gap: 1rem;
48
+
49
+ .nice-icon {
50
+ height: 30px;
51
+ width: 30px;
52
+ }
53
+
54
+ .nice-dialog-sub-title {
55
+ font-size: 0.7em;
56
+ color: var(--nice-font-color);
57
+ opacity: 0.8;
58
+ }
59
+
60
+ .nice-dialog-title {
61
+ font-size: 1.2em;
62
+ color: var(--nice-primary-color);
63
+ text-transform: uppercase;
64
+ }
65
+ }
66
+
67
+ // ---------------- Dialog Body ----------------
68
+ .nice-dialog-body {
69
+ padding: calc(var(--nice-dialog-padding) / 2) var(--nice-dialog-padding);
70
+ flex-grow: 1;
71
+ overflow: auto;
72
+ scroll-timeline: --nice-dialog-scroll block;
73
+ }
74
+
75
+ // ---------------- Dialog Footer ----------------
76
+ .nice-dialog-footer {
77
+ position: relative;
78
+ display: block;
79
+ padding: var(--nice-dialog-padding);
80
+ padding-top: calc(var(--nice-dialog-padding) / 2);
81
+ flex-shrink: 0;
82
+ border-top: 1px solid transparent;
83
+ animation: nice-dialog-footer-border linear both;
84
+ animation-timeline: --nice-dialog-scroll;
85
+ animation-range: calc(100% - 1rem) 100%;
86
+
87
+ // Hide the footer when nothing was passed in
88
+ &:empty {
89
+ display: none;
90
+ }
91
+
92
+ .btn-navigation {
93
+ margin: 0;
94
+ }
95
+
96
+ .view-actions {
97
+ gap: 0.5rem;
98
+
99
+ @media (max-width: $screen-xs-max) {
100
+ .split {
101
+ display: none;
102
+ }
103
+ .btn {
104
+ flex-grow: 1;
105
+ }
106
+ }
107
+ }
108
+
109
+ nice-dialog-footer {
110
+ display: flex;
111
+ justify-content: flex-end;
112
+ flex-wrap: wrap;
113
+ gap: 0.5rem;
114
+ }
115
+ }
116
+ }
117
+
118
+ @keyframes nice-dialog-header-border {
119
+ from { border-bottom-color: transparent; }
120
+ to { border-bottom-color: var(--nice-border-color); }
121
+ }
122
+
123
+ @keyframes nice-dialog-footer-border {
124
+ from { border-top-color: var(--nice-border-color); }
125
+ to { border-top-color: transparent; }
126
+ }
@@ -56,7 +56,10 @@ angular.module('niceElements')
56
56
  enableLoadMore: '@', // Enable load more
57
57
  placement: '@', // Describes the preferred placement of the popper
58
58
  },
59
- controller: function ($scope, $http, $element, $timeout, gettextCatalog, NiceService) {
59
+ controller: function ($scope, $attrs, $http, $element, $timeout, gettextCatalog, NiceService) {
60
+ NiceService.bindFlag($scope, $attrs, 'selectedIsKey');
61
+ NiceService.bindFlag($scope, $attrs, 'enableLoadMore');
62
+
60
63
  $scope.id = Math.random().toString(36).substring(7);
61
64
  if (!$scope.dropdownDistance) { $scope.dropdownDistance = 5; }
62
65
  if (!$scope.objValue) { $scope.objValue = 'value'; }
@@ -29,7 +29,9 @@ angular.module('niceElements')
29
29
  onChange: '&?',
30
30
  required: '='
31
31
  },
32
- controller: function ($scope, $timeout) {
32
+ controller: function ($scope, $attrs, $timeout, NiceService) {
33
+ NiceService.bindFlag($scope, $attrs, 'mature');
34
+
33
35
  $scope.days = [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];
34
36
  $scope.months = [
35
37
  { value: 0, name: gettextCatalog.getString('Jan', null, 'Nice') },
@@ -45,16 +45,14 @@ angular.module('niceElements')
45
45
  autocomplete: "@?",
46
46
  disableTrim: "@?"
47
47
  },
48
- controller: function ($scope, $attrs, $rootScope, $element, ngDialog, NiceService) {
48
+ controller: function ($scope, $attrs, $rootScope, $element, $timeout, ngDialog, NiceService) {
49
49
  if (!$attrs.type) { $attrs.type = 'text'; }
50
50
  if (!$attrs.title) { $attrs.title = ''; }
51
51
  if (!$attrs.regex) { $attrs.regex = null; }
52
52
  if (!$attrs.placeholder) { $attrs.placeholder = ''; }
53
- if (!$attrs.minlength) { $attrs.minlength = 1; }
54
- if (!$attrs.maxlength) { $attrs.maxlength = 100; }
55
53
  if (!$attrs.fieldWidth) { $attrs.fieldWidth = 'col-sm-8'; }
56
54
  if (!$attrs.labelWidth) { $attrs.labelWidth = 'col-sm-4'; }
57
- if (!$attrs.textAreaLines) { $attrs.textAreaLines = 3; }
55
+ if (!$scope.textAreaLines) { $scope.textAreaLines = 3; }
58
56
  if (!$attrs.symbol) { $attrs.symbol = ''; }
59
57
  if (!$attrs.help) { $attrs.help = ''; }
60
58
  if (!$attrs.name) { $attrs.name = ''; }
@@ -74,9 +72,12 @@ angular.module('niceElements')
74
72
  $scope.elementType = "textarea";
75
73
  }
76
74
 
75
+ // Focus after the input (rendered inside ng-if) is in the DOM
77
76
  if ($scope.isFocused) {
78
- const input = $element[0].getElementsByTagName($scope.elementType)[0];
79
- if (input) input.focus();
77
+ $timeout(function () {
78
+ const input = $element[0].getElementsByTagName($scope.elementType)[0];
79
+ if (input) input.focus();
80
+ });
80
81
  }
81
82
 
82
83
  if ($scope.numbersOnly) {
@@ -111,8 +112,11 @@ angular.module('niceElements')
111
112
  $scope.regexexp = new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$");
112
113
  }
113
114
 
114
- if (angular.isDefined($scope.valid)) {
115
- $scope.valid = $scope.forma;
115
+ // Link form object with valid object (the form only exists after the template is linked)
116
+ if ($attrs.valid) {
117
+ $scope.$watch('forma', function (form) {
118
+ if (form) $scope.valid = form;
119
+ });
116
120
  }
117
121
 
118
122
  if ($scope.model && !$scope.decimalConstructor && angular.isDefined($scope.minDecimalsCutZeros) && $scope.type == 'number') {
@@ -18,7 +18,9 @@ angular.module('niceElements')
18
18
  message: '@?',
19
19
  fulldiv: '@?'
20
20
  },
21
- controller: function ($scope, gettextCatalog) {
21
+ controller: function ($scope, $attrs, gettextCatalog, NiceService) {
22
+ NiceService.bindFlag($scope, $attrs, 'fulldiv');
23
+
22
24
  if ($scope.icon == "" || !$scope.icon) $scope.innerIcon = "icon-alert-circle";
23
25
  else $scope.innerIcon = $scope.icon;
24
26
  if ($scope.message == "" || !$scope.message) $scope.innerMessage = gettextCatalog.getString("No data");
@@ -26,15 +26,29 @@
26
26
  </button>
27
27
  </span>
28
28
 
29
- <!-- Value -->
30
- <input
31
- type="number"
32
- step="{{ step }}"
33
- ng-change="inputChanged()"
34
- class="form-control"
35
- max="{{ max }}"
36
- min="{{ min }}"
37
- ng-disabled="isDisabled"
29
+ <!-- Value. Two inputs, because Angular picks the input type before {{ }} is evaluated -->
30
+ <input
31
+ ng-if="!decimalMode"
32
+ type="number"
33
+ inputmode="numeric"
34
+ step="{{ step }}"
35
+ ng-change="inputChanged()"
36
+ class="form-control"
37
+ max="{{ max }}"
38
+ min="{{ min }}"
39
+ ng-disabled="isDisabled"
40
+ ng-model="internal.value"
41
+ />
42
+
43
+ <!-- Value in decimal mode: text input, so "1,5" can be typed -->
44
+ <input
45
+ ng-if="decimalMode"
46
+ type="text"
47
+ inputmode="decimal"
48
+ ng-change="inputChanged()"
49
+ ng-blur="inputBlurred()"
50
+ class="form-control"
51
+ ng-disabled="isDisabled"
38
52
  ng-model="internal.value"
39
53
  />
40
54
 
@@ -29,6 +29,7 @@ angular.module('niceElements')
29
29
  noMargin: '@',
30
30
  step: '@',
31
31
  decimals: '@',
32
+ lang: '@',
32
33
  allowNegative: '@',
33
34
  floatingError: '@',
34
35
  help: '@',
@@ -36,14 +37,20 @@ angular.module('niceElements')
36
37
  onChange: '&?'
37
38
  },
38
39
 
39
- controller: function ($scope, $timeout, NiceService) {
40
+ controller: function ($scope, $attrs, $timeout, NiceService, gettextCatalog) {
41
+ NiceService.bindFlag($scope, $attrs, 'allowNegative');
42
+ NiceService.bindFlag($scope, $attrs, 'hideError');
43
+ NiceService.bindFlag($scope, $attrs, 'floatingError');
44
+
40
45
  $scope.canAdd = true;
41
46
  $scope.canSubtract = true;
42
47
  $scope.preventZero = $scope.preventZero == "true";
43
48
 
44
49
  // Link form object with valid object
45
- if ($scope.valid) {
46
- $scope.valid = $scope.forma;
50
+ if ($attrs.valid) {
51
+ $scope.$watch('niceNumberForm', function (form) {
52
+ if (form) $scope.valid = form;
53
+ });
47
54
  }
48
55
 
49
56
  // Fix min
@@ -61,12 +68,22 @@ angular.module('niceElements')
61
68
  if ($scope.min != 0 && $scope.min != -Infinity) $scope.defaultValue = $scope.min;
62
69
  else $scope.defaultValue = 0;
63
70
  } else {
64
- $scope.defaultValue = parseInt($scope.defaultValue);
71
+ $scope.defaultValue = parseFloat($scope.defaultValue);
65
72
  }
66
73
 
67
- // Fix decimals
68
- if (!$scope.decimals) $scope.decimals = 0;
69
- else $scope.decimals = parseInt($scope.decimals);
74
+ // Decimal mode: when `decimals` is set, the input is a text field so "1.5" and "1,5" can be typed,
75
+ // and values are rounded to `decimals` places. Kept in a local variable, because Angular
76
+ // writes the "@" attribute back to $scope.decimals as a string.
77
+ const decimalPlaces = parseInt($attrs.decimals);
78
+ $scope.decimalMode = !Number.isNaN(decimalPlaces);
79
+
80
+ // Decimal separator of the locale, e.g. "." for "en" and "," for "sl".
81
+ // Uses the `lang` attribute, or the app language from angular-gettext ("sl_SI" -> "sl-SI").
82
+ const lang = ($attrs.lang || gettextCatalog.getCurrentLanguage()).replace("_", "-");
83
+ const decimalSeparator = new Intl.NumberFormat(lang)
84
+ .formatToParts(1.5)
85
+ .find(function (part) { return part.type === "decimal"; })
86
+ .value;
70
87
 
71
88
  // Fix step
72
89
  if (!$scope.step) $scope.step = 1;
@@ -122,6 +139,15 @@ angular.module('niceElements')
122
139
  $scope.niceNumberForm.$setValidity("zero", null);
123
140
  }
124
141
  }
142
+
143
+ // Text input has no built-in min/max validation, so decimal mode checks it here
144
+ if ($scope.decimalMode && $scope.niceNumberForm) {
145
+ const value = parseFloat($scope.model);
146
+ const tooSmall = !Number.isNaN(value) && value < $scope.min;
147
+ const tooBig = !Number.isNaN(value) && $scope.max && value > $scope.max;
148
+ $scope.niceNumberForm.$setValidity("min", tooSmall ? false : null);
149
+ $scope.niceNumberForm.$setValidity("max", tooBig ? false : null);
150
+ }
125
151
  };
126
152
 
127
153
 
@@ -131,11 +157,35 @@ angular.module('niceElements')
131
157
  });
132
158
 
133
159
 
134
- // Input model. <input type="number"> needs a number, so Decimal model is converted.
160
+ // Returns a plain number, rounded to `decimals` places in decimal mode
161
+ const round = function (value) {
162
+ if (value == null) return null;
163
+ if (!$scope.decimalMode) return Number(value);
164
+ return new Decimal(value).toDecimalPlaces(decimalPlaces).toNumber();
165
+ };
166
+
167
+ // Decimal mode: typed text -> number ("1,5" -> 1.5).
168
+ // Returns null for empty text and NaN for text that is not a number.
169
+ const parseText = function (text) {
170
+ const cleaned = (text || "").trim().replace(",", ".");
171
+ if (cleaned === "") return null;
172
+ if (!/^-?(\d+\.?\d*|\.\d+)$/.test(cleaned)) return NaN;
173
+ return parseFloat(cleaned);
174
+ };
175
+
176
+ // Model -> input value. Number input needs a number, decimal mode needs text
177
+ // with the locale separator. Decimal.toFixed() avoids exponent notation (1e-7).
135
178
  const toInternal = function (value) {
179
+ if ($scope.decimalMode) return value == null ? "" : new Decimal(value).toFixed().replace(".", decimalSeparator);
136
180
  return NiceService.isDecimal(value) ? value.toNumber() : value;
137
181
  };
138
182
 
183
+ // Does the input already show the model value? (In decimal mode "1,50" shows 1.5)
184
+ const isInputInSync = function () {
185
+ if (!$scope.decimalMode) return toInternal($scope.model) === $scope.internal.value;
186
+ return round($scope.model) === round(parseText($scope.internal.value));
187
+ };
188
+
139
189
  const setModel = function (value) {
140
190
  if ($scope.decimalConstructor && value != null && !NiceService.isDecimal(value)) {
141
191
  value = new $scope.decimalConstructor(value);
@@ -150,11 +200,28 @@ angular.module('niceElements')
150
200
 
151
201
  // On input change
152
202
  $scope.inputChanged = function () {
153
- setModel($scope.internal.value);
203
+ if ($scope.decimalMode) {
204
+ // Invalid text keeps the last valid model and marks the field invalid
205
+ const value = parseText($scope.internal.value);
206
+ const isNumber = !Number.isNaN(value);
207
+ $scope.niceNumberForm.$setValidity("number", isNumber ? null : false);
208
+ if (isNumber) setModel(round(value));
209
+ } else {
210
+ setModel($scope.internal.value);
211
+ }
154
212
  $scope.check();
155
213
  };
156
214
 
157
215
 
216
+ // Decimal mode: on blur show the cleaned up value ("1,239" -> "1.24" with decimals="2")
217
+ $scope.inputBlurred = function () {
218
+ if (!$scope.decimalMode) return;
219
+ if (!Number.isNaN(parseText($scope.internal.value))) {
220
+ $scope.internal.value = toInternal($scope.model);
221
+ }
222
+ };
223
+
224
+
158
225
  // Watch for model change. Decimal is watched by value, because parent can replace it with new equal object.
159
226
  $scope.$watch(function () {
160
227
  return NiceService.isDecimal($scope.model) ? $scope.model.toString() : $scope.model;
@@ -164,8 +231,10 @@ angular.module('niceElements')
164
231
  } else if ($scope.model != null) {
165
232
  $scope.decimalConstructor = null; // Parent switched to plain value
166
233
  }
167
- if (toInternal($scope.model) !== $scope.internal.value) {
234
+ if (!isInputInSync()) {
168
235
  $scope.internal.value = toInternal($scope.model);
236
+ // Input shows a valid value again (e.g. after plus/minus)
237
+ if ($scope.decimalMode && $scope.niceNumberForm) $scope.niceNumberForm.$setValidity("number", null);
169
238
  }
170
239
  $scope.check();
171
240
  if ($scope.onChange && oldModel != newModel) {
@@ -178,7 +247,7 @@ angular.module('niceElements')
178
247
 
179
248
  // Add to the value
180
249
  $scope.add = function () {
181
- const result = new Decimal($scope.model != undefined ? $scope.model : $scope.defaultValue).plus($scope.innerStep).toNumber(); //.toFixed($scope.decimals);
250
+ const result = round(new Decimal($scope.model != undefined ? $scope.model : $scope.defaultValue).plus($scope.innerStep));
182
251
  if ($scope.max) {
183
252
  if (result <= parseFloat($scope.max)) {
184
253
  setModel(result);
@@ -194,7 +263,7 @@ angular.module('niceElements')
194
263
 
195
264
  // Subtract to the value
196
265
  $scope.subtract = function () {
197
- const result = new Decimal($scope.model != undefined ? $scope.model : $scope.defaultValue).minus($scope.innerStep).toNumber();
266
+ const result = round(new Decimal($scope.model != undefined ? $scope.model : $scope.defaultValue).minus($scope.innerStep));
198
267
  if (result >= Number($scope.min)) {
199
268
  setModel(result);
200
269
  $scope.niceNumberForm.$setDirty();
@@ -38,10 +38,12 @@ angular.module('niceElements')
38
38
  attrs.noMargin = attrs.noMargin === 'true' || attrs.noMargin === true;
39
39
  },
40
40
 
41
- controller: function ($rootScope, $scope) {
41
+ controller: function ($rootScope, $scope, $attrs) {
42
42
  // Link form object with valid object
43
- if (angular.isDefined($scope.valid)) {
44
- $scope.valid = $scope.form;
43
+ if ($attrs.valid) {
44
+ $scope.$watch('form', function (form) {
45
+ if (form) $scope.valid = form;
46
+ });
45
47
  }
46
48
 
47
49
  const roundN = function (number, decimals) {
@@ -112,13 +112,13 @@ angular.module('niceElements')
112
112
 
113
113
  $scope.close = function () {
114
114
  $scope.isOpen = false;
115
- if ($scope.onChange) $scope.onChange($scope.isOpen);
115
+ if ($scope.onChange) $scope.onChange({ isOpen: $scope.isOpen });
116
116
  };
117
117
 
118
118
  $scope.open = function () {
119
119
  if ($scope.popper) $scope.popper.update();
120
120
  $scope.isOpen = true;
121
- if ($scope.onChange) $scope.onChange($scope.isOpen);
121
+ if ($scope.onChange) $scope.onChange({ isOpen: $scope.isOpen });
122
122
  $timeout(function () {
123
123
  if ($scope.popper) $scope.popper.update();
124
124
  });
@@ -33,13 +33,11 @@
33
33
 
34
34
  <div class="nice-dropdown" ng-if="results.length">
35
35
  <div ng-repeat="result in results" class="nice-search-row" ng-class="{'active': selectedIndex == $index}" ng-click="selectRow(result)">
36
- <span class="text-bold">{{ result[keyForInputLabel] }}</span>
37
- <!--<div ng-transclude></div>-->
36
+ <span class="text-bold" ng-if="!hasRowTemplate">{{ result[keyForInputLabel] }}</span>
37
+ <div ng-if="hasRowTemplate" nice-search-row-transclude></div>
38
38
  </div>
39
39
  </div>
40
40
  </div>
41
41
  </div>
42
42
 
43
- <!--Here is injected dropdown html if passed and results present and open.-->
44
- <!--<div ng-transclude></div>-->
45
43
  </ng-form>
@@ -38,7 +38,7 @@ angular.module('niceElements')
38
38
  isInline: '=',
39
39
  onChange: '&?'
40
40
  },
41
- link: function (scope, element, attrs) {
41
+ link: function (scope, element, attrs, ctrl, transcludeFn) {
42
42
  if (!attrs.title) { attrs.title = ''; }
43
43
  if (!attrs.placeholder) { attrs.placeholder = ''; }
44
44
  if (!attrs.fieldWidth) { attrs.fieldWidth = 'col-sm-8'; }
@@ -53,11 +53,20 @@ angular.module('niceElements')
53
53
  attrs.disableRow = attrs.disableRow === 'true' || attrs.disableRow === true;
54
54
  attrs.noMargin = attrs.noMargin === 'true' || attrs.noMargin === true;
55
55
 
56
- // This is used for connecting directive's scope to transcluded html.
57
- // transcludeFn(scope, function(clone, scope) {
58
- // var el = element.find('.nice-search');
59
- // el.append(clone);
60
- // });
56
+ // Custom row content: markup placed inside <nice-search> is rendered for every
57
+ // result row (with `result` in scope) instead of the default label.
58
+ scope.rowTransclude = transcludeFn;
59
+ scope.hasRowTemplate = false;
60
+
61
+ // Make one throwaway copy of the content just to check if there is any
62
+ transcludeFn(function (clone, cloneScope) {
63
+ for (let i = 0; i < clone.length; i++) {
64
+ const isElement = clone[i].nodeType === 1;
65
+ const isText = clone[i].nodeType === 3 && clone[i].textContent.trim() !== '';
66
+ if (isElement || isText) scope.hasRowTemplate = true;
67
+ }
68
+ cloneScope.$destroy();
69
+ });
61
70
 
62
71
  // Set default text
63
72
  scope.$watch("setText", function () {
@@ -241,4 +250,21 @@ angular.module('niceElements')
241
250
  };
242
251
  }
243
252
  };
253
+ })
254
+
255
+ // Renders nice-search's transcluded content for one result row, with `result` in scope
256
+ .directive('niceSearchRowTransclude', function () {
257
+ return {
258
+ restrict: 'A',
259
+ link: function (scope, element) {
260
+ // Copy the content into this row; the copy gets its own scope (rowScope)
261
+ scope.rowTransclude(function (clone, rowScope) {
262
+ // Give the copy access to this row's result, and keep it up to date
263
+ scope.$watch('result', function (result) {
264
+ rowScope.result = result;
265
+ });
266
+ element.append(clone);
267
+ });
268
+ }
269
+ };
244
270
  });