nice-elements 1.10.15 → 1.10.16

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 (38) hide show
  1. package/.vscode/settings.json +0 -1
  2. package/CHANGELOG.md +8 -0
  3. package/README.md +1 -1
  4. package/bower.json +1 -1
  5. package/dist/nice.js +320 -299
  6. package/dist/nice.min.js +1 -1
  7. package/dist/style.css.map +1 -1
  8. package/eslint.config.mjs +6 -2
  9. package/package.json +4 -4
  10. package/src/components/nice-calendar/nice-calendar.js +16 -16
  11. package/src/components/nice-choice/nice-choice.js +6 -6
  12. package/src/components/nice-click-outside/nice-click-outside.js +7 -7
  13. package/src/components/nice-comment/nice-comment.js +2 -2
  14. package/src/components/nice-date/nice-date.js +5 -3
  15. package/src/components/nice-date-input/nice-date-input.js +3 -3
  16. package/src/components/nice-date-range/nice-date-range.js +2 -2
  17. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.js +21 -21
  18. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +8 -7
  19. package/src/components/nice-dropdown/nice-dropdown.js +29 -22
  20. package/src/components/nice-dropdown/nice-dropdown.scss +1 -1
  21. package/src/components/nice-dropdown-date/nice-dropdown-date.js +9 -5
  22. package/src/components/nice-dropdown-date/nice-dropdown-date.scss +5 -1
  23. package/src/components/nice-dropdown-old/nice-dropdown-old.js +26 -27
  24. package/src/components/nice-dtp/nice-dtp.js +85 -85
  25. package/src/components/nice-help/nice-help.js +7 -4
  26. package/src/components/nice-input/nice-input.js +8 -8
  27. package/src/components/nice-notification/nice-notification.js +42 -42
  28. package/src/components/nice-number/nice-number.js +3 -3
  29. package/src/components/nice-percent/nice-percent.js +1 -1
  30. package/src/components/nice-popup/nice-popup.js +2 -2
  31. package/src/components/nice-search/nice-search.js +12 -9
  32. package/src/components/nice-search2/nice-search2.js +15 -13
  33. package/src/components/nice-time-picker/nice-time-picker.js +1 -1
  34. package/src/components/nice-toast/nice-toast.js +2 -2
  35. package/src/components/nice-upload/nice-upload.js +4 -4
  36. package/src/filters/nice-date.js +1 -1
  37. package/src/filters/nice-highlight.js +2 -2
  38. package/src/services/nice-service.js +2 -2
package/eslint.config.mjs CHANGED
@@ -14,7 +14,10 @@ export default [
14
14
  ...globals.browser,
15
15
  angular: true,
16
16
  moment: true,
17
- Popper: true
17
+ Popper: true,
18
+ gettextCatalog: true,
19
+ Decimal: true,
20
+ _: true
18
21
  }
19
22
  }
20
23
  },
@@ -22,7 +25,8 @@ export default [
22
25
  {
23
26
  rules: {
24
27
  "no-unused-vars": "warn",
25
- "no-vars": "warn"
28
+ "no-var": "warn",
29
+ "no-console": "warn"
26
30
  }
27
31
  }
28
32
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nice-elements",
3
- "version": "1.10.15",
3
+ "version": "1.10.16",
4
4
  "description": "Nice elements used in olaii angular 1.x webapps.",
5
5
  "main": "dist/nice.js",
6
6
  "license": "MIT",
@@ -27,9 +27,9 @@
27
27
  "ng-dialog": "0.5.6"
28
28
  },
29
29
  "devDependencies": {
30
- "@eslint/js": "8.57.0",
31
- "eslint": "8.57.0",
32
- "globals": "15.2.0",
30
+ "@eslint/js": "^9.2.0",
31
+ "eslint": "^9.2.0",
32
+ "globals": "^15.2.0",
33
33
  "express": "4.17.1",
34
34
  "grunt": "1.6.1",
35
35
  "grunt-angular-templates": "1.2.0",
@@ -93,7 +93,7 @@ angular.module('niceElements')
93
93
  }
94
94
 
95
95
  scope.month = angular.copy(moment(scope.startDate));
96
- var start = angular.copy(moment(scope.startDate));
96
+ const start = angular.copy(moment(scope.startDate));
97
97
  _removeTimeWithDate(start.date(0));
98
98
  _buildMonth(scope, start, scope.month);
99
99
  }
@@ -104,7 +104,7 @@ angular.module('niceElements')
104
104
  // ------------------ Day was selected ------------------
105
105
  scope.select = function (day) {
106
106
  if (!day.isDisabled) {
107
- var selectedDate = angular.copy(day.date);
107
+ const selectedDate = angular.copy(day.date);
108
108
 
109
109
  if (scope.selectStart) {
110
110
  if (!scope.time) {
@@ -217,7 +217,7 @@ angular.module('niceElements')
217
217
 
218
218
  // ------------------ Go to next month ------------------
219
219
  scope.next = function () {
220
- var next = angular.copy(scope.month);
220
+ const next = angular.copy(scope.month);
221
221
  _removeTimeWithDate(next.month(next.month() + 1).date(0));
222
222
  scope.month.month(scope.month.month() + 1);
223
223
  _buildMonth(scope, next, scope.month);
@@ -226,7 +226,7 @@ angular.module('niceElements')
226
226
 
227
227
  // ------------------ Go to previous month ------------------
228
228
  scope.previous = function () {
229
- var previous = angular.copy(scope.month);
229
+ const previous = angular.copy(scope.month);
230
230
  _removeTimeWithDate(previous.month(previous.month() - 1).date(0));
231
231
  scope.month.month(scope.month.month() - 1);
232
232
  _buildMonth(scope, previous, scope.month);
@@ -235,8 +235,8 @@ angular.module('niceElements')
235
235
 
236
236
  // ------------------ Check if dates are equal without time ------------------
237
237
  scope.isSameDay = function (date1, date2) {
238
- var d1 = _removeTime(angular.copy(date1));
239
- var d2 = _removeTime(angular.copy(date2));
238
+ const d1 = _removeTime(angular.copy(date1));
239
+ const d2 = _removeTime(angular.copy(date2));
240
240
  return d1.isSame(d2);
241
241
  };
242
242
 
@@ -256,25 +256,25 @@ angular.module('niceElements')
256
256
 
257
257
  // ------------------ Lighten color by 20% ------------------
258
258
  scope.lighten = function (col) {
259
- var amt = 20;
260
- var usePound = false;
259
+ const amt = 20;
260
+ let usePound = false;
261
261
 
262
262
  if (col[0] == "#") {
263
263
  col = col.slice(1);
264
264
  usePound = true;
265
265
  }
266
266
 
267
- var num = parseInt(col, 16);
268
- var r = (num >> 16) + amt;
267
+ const num = parseInt(col, 16);
268
+ let r = (num >> 16) + amt;
269
269
 
270
270
  if (r > 255) r = 255;
271
271
  else if (r < 0) r = 0;
272
272
 
273
- var b = ((num >> 8) & 0x00FF) + amt;
273
+ let b = ((num >> 8) & 0x00FF) + amt;
274
274
  if (b > 255) b = 255;
275
275
  else if (b < 0) b = 0;
276
276
 
277
- var g = (num & 0x0000FF) + amt;
277
+ let g = (num & 0x0000FF) + amt;
278
278
  if (g > 255) g = 255;
279
279
  else if (g < 0) g = 0;
280
280
 
@@ -296,7 +296,7 @@ angular.module('niceElements')
296
296
  // ------------------ Build month ------------------
297
297
  function _buildMonth(scope, start, month) {
298
298
  scope.weeks = [];
299
- var done = false, date = start.clone().startOf('week').isoWeekday(1), monthIndex = date.month(), count = 0;
299
+ let done = false, date = start.clone().startOf('week').isoWeekday(1), monthIndex = date.month(), count = 0;
300
300
  date.add(1, "w");
301
301
  while (!done) {
302
302
  scope.weeks.push({ days: _buildWeek(date.clone(), month) });
@@ -309,9 +309,9 @@ angular.module('niceElements')
309
309
 
310
310
  // ------------------ Build week ------------------
311
311
  function _buildWeek(date, month) {
312
- var days = [];
313
- for (var i = 0; i < 7; i++) {
314
- var day = {
312
+ const days = [];
313
+ for (let i = 0; i < 7; i++) {
314
+ const day = {
315
315
  name: date.format("dd"),
316
316
  number: date.date(),
317
317
  isCurrentMonth: date.month() === month.month(),
@@ -62,7 +62,7 @@ angular.module('niceElements')
62
62
  scope.internalList = scope.list;
63
63
  } else {
64
64
  scope.internalList = _.map(scope.list, function (val) {
65
- var obj = {};
65
+ const obj = {};
66
66
  obj[scope.objKey] = val;
67
67
  obj[scope.objValue] = val;
68
68
  return obj;
@@ -75,14 +75,14 @@ angular.module('niceElements')
75
75
  } else {
76
76
  if (scope.multiple) {
77
77
  scope.internalSelected = _.map(scope.model, function (val) {
78
- var obj = {};
78
+ const obj = {};
79
79
  obj[scope.objKey] = val;
80
80
  obj[scope.objValue] = val;
81
81
  return obj;
82
82
  });
83
83
  } else {
84
84
  if (scope.model) {
85
- var obj = {};
85
+ const obj = {};
86
86
  obj[scope.objKey] = scope.model;
87
87
  obj[scope.objValue] = scope.model;
88
88
  scope.internalSelected = obj;
@@ -93,9 +93,9 @@ angular.module('niceElements')
93
93
  }
94
94
  },
95
95
  controller: function ($rootScope, $scope) {
96
- var getFilter = function (item) {
96
+ const getFilter = function (item) {
97
97
  // Create filter for finding object by objValue with _.where()
98
- var filter = {};
98
+ const filter = {};
99
99
  if (item.hasOwnProperty($scope.objKey))
100
100
  filter[$scope.objKey] = item[$scope.objKey];
101
101
  else
@@ -152,7 +152,7 @@ angular.module('niceElements')
152
152
  $scope.internalList = $scope.list;
153
153
  } else {
154
154
  $scope.internalList = _.map($scope.list, function (val) {
155
- var obj = {};
155
+ const obj = {};
156
156
  obj[$scope.objKey] = val;
157
157
  obj[$scope.objValue] = val;
158
158
  return obj;
@@ -7,25 +7,25 @@
7
7
  * # clickOutside
8
8
  */
9
9
  angular.module('niceElements')
10
- .directive('clickOutside', function($document, $parse, $timeout){
10
+ .directive('clickOutside', function ($document, $parse, $timeout) {
11
11
  return {
12
12
  restrict: 'A',
13
13
  link: function ($scope, elem, attr) {
14
14
  $scope.isOpen = false;
15
15
 
16
16
  // watch for is open
17
- attr.$observe('isOpen', function(value){
17
+ attr.$observe('isOpen', function (value) {
18
18
  $scope.isOpen = value == 'true';
19
19
  });
20
20
 
21
21
  $timeout(function () {
22
22
  // postpone linking to next digest to allow for unique id generation
23
- var classList = (attr.outsideIfNot !== undefined) ? attr.outsideIfNot.split(/[ ,]+/) : [];
24
- var fn;
23
+ const classList = (attr.outsideIfNot !== undefined) ? attr.outsideIfNot.split(/[ ,]+/) : [];
24
+ let fn;
25
25
 
26
26
  function eventHandler(e) {
27
27
  if ($scope.isOpen) {
28
- var i, element, r, id, classNames, l;
28
+ let i, element, r, id, classNames, l;
29
29
 
30
30
  // if there is no click target, no point going on
31
31
  if (!e || !e.target) {
@@ -69,7 +69,7 @@ angular.module('niceElements')
69
69
  // if we have got this far, then we are good to go with processing the command passed in via the click-outside attribute
70
70
  $timeout(function () {
71
71
  fn = $parse(attr['clickOutside']);
72
- fn($scope, {event: e});
72
+ fn($scope, { event: e });
73
73
  });
74
74
  }
75
75
  }
@@ -103,4 +103,4 @@ angular.module('niceElements')
103
103
  });
104
104
  }
105
105
  };
106
- });
106
+ });
@@ -35,7 +35,7 @@ angular.module('niceElements')
35
35
  if (!attrs.help) { attrs.help = ''; }
36
36
  if (!attrs.rows) { attrs.rows = 1; }
37
37
 
38
- var textareas = element.find('textarea');
38
+ const textareas = element.find('textarea');
39
39
 
40
40
  scope.edit = function () {
41
41
  scope.editing = true;
@@ -48,7 +48,7 @@ angular.module('niceElements')
48
48
  autosize();
49
49
 
50
50
  function autosize() {
51
- var el = textareas[0];
51
+ const el = textareas[0];
52
52
  $timeout(function () {
53
53
  el.style.cssText = 'height:auto; padding:0';
54
54
 
@@ -30,10 +30,12 @@ angular.module('niceElements')
30
30
  isDisabled: '=',
31
31
  isInline: '=',
32
32
  onChange: '&?',
33
- required: '='
33
+ required: '=',
34
+ placement: '@', // Describes the preferred placement of the popper
34
35
  },
35
36
  controller: function ($scope, $element, $timeout, gettextCatalog) {
36
37
  $scope.isOpen = false;
38
+ if (!$scope.placement) { $scope.placement = "bottom-start"; }
37
39
  if ($scope.date == undefined) $scope.date = true;
38
40
  if ($scope.time == undefined) $scope.time = false;
39
41
  $scope.hours = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23];
@@ -96,7 +98,7 @@ angular.module('niceElements')
96
98
  const tooltip = $element[0].getElementsByClassName('nice-date-dropdown-wrapper')[0];
97
99
  $scope.popper = Popper.createPopper(button, tooltip, {
98
100
  strategy: 'fixed',
99
- placement: 'bottom-start',
101
+ placement: $scope.placement,
100
102
  modifiers: [
101
103
  {
102
104
  name: 'offset',
@@ -282,7 +284,7 @@ angular.module('niceElements')
282
284
 
283
285
 
284
286
  // ------------------ Watch for model change ------------------
285
- $scope.$watchGroup(["model", 'minDate', 'maxDate', 'nextDate'], function (value) {
287
+ $scope.$watchGroup(["model", 'minDate', 'maxDate', 'nextDate'], function () {
286
288
  $scope.bootstrap();
287
289
  });
288
290
 
@@ -56,7 +56,7 @@ angular.module('niceElements')
56
56
 
57
57
  // -------------------- On date change --------------------
58
58
  $scope.handleChange = function () {
59
- var newModel = moment($scope.modelDate + " " + $scope.modelTime, $scope.formatDate + " " + $scope.formatTime).seconds(0).milliseconds(0);
59
+ const newModel = moment($scope.modelDate + " " + $scope.modelTime, $scope.formatDate + " " + $scope.formatTime).seconds(0).milliseconds(0);
60
60
  if (newModel.isValid()) {
61
61
  $scope.model = newModel;
62
62
  $scope.niceDateInputForm.$setValidity('validDate', true);
@@ -77,7 +77,7 @@ angular.module('niceElements')
77
77
 
78
78
  // -------------------- Date --------------------
79
79
  $scope.dateBlur = function () {
80
- var newDate = moment($scope.modelDate, $scope.formatDate);
80
+ const newDate = moment($scope.modelDate, $scope.formatDate);
81
81
  if (newDate.isValid()) {
82
82
  $scope.niceDateInputForm.$setValidity('validDate', true);
83
83
  $scope.handleChange();
@@ -88,7 +88,7 @@ angular.module('niceElements')
88
88
 
89
89
  // -------------------- Time --------------------
90
90
  $scope.timeBlur = function () {
91
- var newTime = moment($scope.modelTime, $scope.formatTime);
91
+ const newTime = moment($scope.modelTime, $scope.formatTime);
92
92
  if (newTime.isValid()) {
93
93
  $scope.niceDateInputForm.$setValidity('validDate', true);
94
94
  $scope.handleChange();
@@ -38,7 +38,7 @@ angular.module('niceElements')
38
38
  attrs.noMargin = angular.isDefined(attrs.noMargin);
39
39
 
40
40
  if (!angular.isDefined(scope.model)) {
41
- var model = null;
41
+ let model = null;
42
42
  if (!angular.isDefined(scope.startOfTheYear)) {
43
43
  model = {
44
44
  startDate: moment().format(),
@@ -71,7 +71,7 @@ angular.module('niceElements')
71
71
  $scope.opts.ranges[gettextCatalog.getString("Last 30 days", null, "Nice")] = [moment().subtract(30, 'days'), moment()];
72
72
  $scope.opts.ranges[gettextCatalog.getString("This month", null, "Nice")] = [moment().startOf('month'), moment().endOf('month')];
73
73
 
74
- if (angular.isDefined($scope.format)) $scope.opts.format = format;
74
+ if (angular.isDefined($scope.format)) $scope.opts.format = $scope.format;
75
75
  }
76
76
 
77
77
  };
@@ -42,7 +42,7 @@ angular.module('niceElements')
42
42
  pre: function ($scope) {
43
43
  console.warn("[NICE ELEMENTS] nice-datetimerange-picker component is deprecated!");
44
44
  // Default parameters
45
- var params = {
45
+ const params = {
46
46
  title: '',
47
47
  noMargin: false,
48
48
  fieldWidth: 'col-sm-8',
@@ -64,26 +64,26 @@ angular.module('niceElements')
64
64
 
65
65
  if ($scope.formatOutput === undefined) $scope.formatOutput = false;
66
66
 
67
- var setLabelValue = function () {
68
- var _from = moment($scope.internalStart).format(params.format);
69
- var _to = moment($scope.internalEnd).format(params.format);
67
+ const setLabelValue = function () {
68
+ const _from = moment($scope.internalStart).format(params.format);
69
+ const _to = moment($scope.internalEnd).format(params.format);
70
70
  $scope.value = _from + ' - ' + _to;
71
71
  };
72
72
 
73
- var initCurrentDates = function () {
73
+ const initCurrentDates = function () {
74
74
  if (typeof ($scope.modelStart) === 'undefined' || $scope.modelStart === null) {
75
- var _start = moment().subtract(1, 'days');
75
+ let _start = moment().subtract(1, 'days');
76
76
  if ($scope.formatOutput) _start = _start.format(params.modelFormat);
77
77
  $scope.modelStart = _start;
78
78
 
79
79
  } else {
80
80
  if (!params.date && params.time) {
81
81
  // if only time
82
- var _time = moment();
83
- var i_hour = params.modelFormat.indexOf('HH:mm');
84
- var i_min = params.modelFormat.indexOf('mm');
85
- var hours = $scope.model.substring(i_hour, i_hour + 2);
86
- var minutes = $scope.model.substring(i_min, i_min + 2);
82
+ const _time = moment();
83
+ const i_hour = params.modelFormat.indexOf('HH:mm');
84
+ const i_min = params.modelFormat.indexOf('mm');
85
+ const hours = $scope.model.substring(i_hour, i_hour + 2);
86
+ const minutes = $scope.model.substring(i_min, i_min + 2);
87
87
 
88
88
  if (i_hour > -1 && i_min > -1) {
89
89
  _time.hours(hours);
@@ -101,18 +101,18 @@ angular.module('niceElements')
101
101
 
102
102
  // initialize dateEnd
103
103
  if (typeof ($scope.modelEnd) === 'undefined' || $scope.modelEnd === null) {
104
- var _end = moment();
104
+ let _end = moment();
105
105
  if ($scope.formatOutput) _end = _end.format(params.modelFormat);
106
106
  $scope.modelEnd = _end;
107
107
 
108
108
  } else {
109
109
  if (!params.date && params.time) {
110
110
  // if only time
111
- var _time = moment();
112
- var i_hour = params.modelFormat.indexOf('HH:mm');
113
- var i_min = params.modelFormat.indexOf('mm');
114
- var hours = $scope.model.substring(i_hour, i_hour + 2);
115
- var minutes = $scope.model.substring(i_min, i_min + 2);
111
+ const _time = moment();
112
+ const i_hour = params.modelFormat.indexOf('HH:mm');
113
+ const i_min = params.modelFormat.indexOf('mm');
114
+ const hours = $scope.model.substring(i_hour, i_hour + 2);
115
+ const minutes = $scope.model.substring(i_min, i_min + 2);
116
116
 
117
117
  if (i_hour > -1 && i_min > -1) {
118
118
  _time.hours(hours);
@@ -173,11 +173,11 @@ angular.module('niceElements')
173
173
 
174
174
  $scope.okClick = function () {
175
175
  setLabelValue();
176
- var _start = moment($scope.internalStart, params.modelFormat);
176
+ let _start = moment($scope.internalStart, params.modelFormat);
177
177
  if ($scope.formatOutput) _start = _start.format(params.modelFormat);
178
178
  $scope.modelStart = _start;
179
179
 
180
- var _end = moment($scope.internalEnd, params.modelFormat);
180
+ let _end = moment($scope.internalEnd, params.modelFormat);
181
181
  if ($scope.formatOutput) _end = _end.format(params.modelFormat);
182
182
  $scope.modelEnd = _end;
183
183
 
@@ -192,9 +192,9 @@ angular.module('niceElements')
192
192
  $scope.showDtpRange = false;
193
193
  //$scope.internalStart = angular.copy($scope.modelStart);
194
194
  //$scope.internalEnd = angular.copy($scope.modelEnd);
195
- var _start = moment($scope.modelStart);
195
+ let _start = moment($scope.modelStart);
196
196
  if ($scope.formatOutput) _start = _start.format(params.modelFormat);
197
- var _end = moment($scope.modelEnd);
197
+ let _end = moment($scope.modelEnd);
198
198
  if ($scope.formatOutput) _end = _end.format(params.modelFormat);
199
199
 
200
200
  $scope.internalStart = _start;
@@ -26,7 +26,8 @@ angular.module('niceElements')
26
26
  help: '@',
27
27
  isInline: '=',
28
28
  onChange: '&?',
29
- required: '='
29
+ required: '=',
30
+ placement: '@', // Describes the preferred placement of the popper
30
31
  },
31
32
  templateUrl: 'src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html',
32
33
  controller: function ($element, $timeout, $scope) {
@@ -39,7 +40,7 @@ angular.module('niceElements')
39
40
 
40
41
  // Set defaults
41
42
  if ($scope.time == undefined) $scope.time = false;
42
-
43
+ if (!$scope.placement) { $scope.placement = "bottom-start"; }
43
44
 
44
45
  // Set format string
45
46
  if (!$scope.formatString) {
@@ -65,11 +66,11 @@ angular.module('niceElements')
65
66
  // Setup popper
66
67
  // https://popper.js.org/docs/v2/constructors/
67
68
  $scope.setupPopper = function () {
68
- var button = $element[0].getElementsByClassName('nice-daterange-picker-button')[0];
69
- var tooltip = $element[0].getElementsByClassName('nice-daterange-picker-wrapper')[0];
69
+ const button = $element[0].getElementsByClassName('nice-daterange-picker-button')[0];
70
+ const tooltip = $element[0].getElementsByClassName('nice-daterange-picker-wrapper')[0];
70
71
  $scope.popper = Popper.createPopper(button, tooltip, {
71
72
  strategy: 'fixed',
72
- placement: 'bottom-start',
73
+ placement: $scope.placement,
73
74
  modifiers: [
74
75
  {
75
76
  name: 'offset',
@@ -149,14 +150,14 @@ angular.module('niceElements')
149
150
  if ($scope.model.innerStartDate && $scope.model.innerEndDate) {
150
151
  // Check if start date is after end date
151
152
  if ($scope.model.innerStartDate.isAfter($scope.model.innerEndDate)) {
152
- var temp = angular.copy($scope.model.innerStartDate);
153
+ const temp = angular.copy($scope.model.innerStartDate);
153
154
  $scope.model.innerStartDate = angular.copy($scope.model.innerEndDate);
154
155
  $scope.model.innerEndDate = temp;
155
156
  }
156
157
 
157
158
  // Check if end date is before start date
158
159
  if ($scope.model.innerEndDate.isBefore($scope.model.innerStartDate)) {
159
- var temp = angular.copy($scope.model.innerStartDate);
160
+ const temp = angular.copy($scope.model.innerStartDate);
160
161
  $scope.model.innerStartDate = angular.copy($scope.model.innerEndDate);
161
162
  $scope.model.innerEndDate = temp;
162
163
  }
@@ -7,7 +7,7 @@
7
7
  * # nice-dropdown
8
8
  */
9
9
  angular.module('niceElements')
10
- .directive('niceDropdown', function ($window) {
10
+ .directive('niceDropdown', function () {
11
11
  return {
12
12
  templateUrl: 'src/components/nice-dropdown/nice-dropdown.html',
13
13
  restrict: 'E',
@@ -49,7 +49,8 @@ angular.module('niceElements')
49
49
  filterFunction: '=?',
50
50
  isInline: '=',
51
51
  clearOnSelect: '@',
52
- enableLoadMore: '@' // Enable load more
52
+ enableLoadMore: '@', // Enable load more
53
+ placement: '@', // Describes the preferred placement of the popper
53
54
  },
54
55
  controller: function ($scope, $http, $element, $timeout, gettextCatalog, NiceService) {
55
56
  $scope.id = Math.random().toString(36).substring(7);
@@ -63,6 +64,7 @@ angular.module('niceElements')
63
64
  if (!$scope.selectText) { $scope.selectText = gettextCatalog.getString("None", null, "Nice"); }
64
65
  if (!$scope.selectedText) { $scope.selectedText = gettextCatalog.getString("selected", null, "Nice"); }
65
66
  if (!$scope.addButtonFunction) { $scope.addButtonFunction = null; }
67
+ if (!$scope.placement) { $scope.placement = "bottom-start"; }
66
68
  $scope.nullable = $scope.nullable === 'true' || $scope.nullable === true;
67
69
  $scope.noMargin = $scope.noMargin === 'true' || $scope.noMargin === true;
68
70
  $scope.multiple = $scope.multiple === 'true' || $scope.multiple === true;
@@ -83,10 +85,11 @@ angular.module('niceElements')
83
85
  // Setup popper
84
86
  // https://popper.js.org/docs/v2/constructors/
85
87
  $scope.setupPopper = function () {
86
- var button = $element[0].getElementsByClassName('btn-dropdown')[0];
87
- var tooltip = $element[0].getElementsByClassName('nice-dropdown-menu-wrapper')[0];
88
+ const button = $element[0].getElementsByClassName('btn-dropdown')[0];
89
+ const tooltip = $element[0].getElementsByClassName('nice-dropdown-menu-wrapper')[0];
88
90
  $scope.popper = Popper.createPopper(button, tooltip, {
89
91
  strategy: 'fixed',
92
+ placement: $scope.placement,
90
93
  scroll: true,
91
94
  resize: true,
92
95
  modifiers: [
@@ -102,12 +105,16 @@ angular.module('niceElements')
102
105
  phase: "beforeWrite",
103
106
  requires: ["computeStyles"],
104
107
  fn: function (e) {
105
- var state = e.state;
106
- state.styles.popper.width = state.rects.reference.width + "px";
108
+ const state = e.state;
109
+ let width = state.rects.reference.width;
110
+ if (width < 200) width = 200;
111
+ state.styles.popper.width = width + "px";
107
112
  },
108
113
  effect: function (e) {
109
- var state = e.state;
110
- state.elements.popper.style.width = state.elements.reference.offsetWidth + "px";
114
+ const state = e.state;
115
+ let width = state.elements.reference.width;
116
+ if (width < 200) width = 200;
117
+ state.elements.popper.style.width = width + "px";
111
118
  }
112
119
  }
113
120
  ],
@@ -152,12 +159,12 @@ angular.module('niceElements')
152
159
 
153
160
 
154
161
  // ----------------------------------- Handle scroll to bottom -----------------------------------
155
- var lastScrollPosition = Infinity;
162
+ let lastScrollPosition = Infinity;
156
163
  $scope.handleScrollToBottom = function () {
157
164
  lastScrollPosition = Infinity;
158
- var element = angular.element($element[0].getElementsByClassName("nice-dropdown-items")[0]);
165
+ const element = angular.element($element[0].getElementsByClassName("nice-dropdown-items")[0]);
159
166
  element.bind("scroll mousewheel", function (e) {
160
- var scrollPosition = element[0].scrollHeight - element[0].scrollTop;
167
+ const scrollPosition = element[0].scrollHeight - element[0].scrollTop;
161
168
  if (scrollPosition === element[0].clientHeight && lastScrollPosition != scrollPosition) {
162
169
  $scope.loadMore();
163
170
  }
@@ -176,7 +183,7 @@ angular.module('niceElements')
176
183
  headers: NiceService.getHeader()
177
184
  }).then(function (response) {
178
185
  response = response.data;
179
- var metadata = {
186
+ const metadata = {
180
187
  count: response.count,
181
188
  previous: response.previous,
182
189
  next: response.next,
@@ -227,13 +234,13 @@ angular.module('niceElements')
227
234
 
228
235
  // ----------------------------------- Scroll to hover -----------------------------------
229
236
  $scope.scrollToHover = function (notSmooth) {
230
- var dropdownMenu = $element[0].getElementsByClassName("nice-dropdown-menu")[0];
237
+ const dropdownMenu = $element[0].getElementsByClassName("nice-dropdown-menu")[0];
231
238
  if (!dropdownMenu) return;
232
- var dorpdownList = dropdownMenu.getElementsByClassName("nice-dropdown-items")[0];
233
- var hoverItem = dorpdownList.getElementsByClassName("hover")[0];
239
+ const dropdownList = dropdownMenu.getElementsByClassName("nice-dropdown-items")[0];
240
+ const hoverItem = dropdownList.getElementsByClassName("hover")[0];
234
241
  if (!hoverItem) return
235
- var topPos = hoverItem.offsetTop;
236
- dorpdownList.scroll({
242
+ const topPos = hoverItem.offsetTop;
243
+ dropdownList.scroll({
237
244
  top: topPos - 120,
238
245
  left: 0,
239
246
  behavior: notSmooth ? 'auto' : 'smooth'
@@ -249,7 +256,7 @@ angular.module('niceElements')
249
256
  $scope.handleNewInternalList(response);
250
257
  $scope.loading = false;
251
258
  $scope.handleDefault();
252
- }, function (error) {
259
+ }, function () {
253
260
  $scope.internalList = null;
254
261
  $scope.loading = false;
255
262
  });
@@ -325,7 +332,7 @@ angular.module('niceElements')
325
332
 
326
333
  // ----------------------------------- Handle set model -----------------------------------
327
334
  $scope.handleSetModel = function () {
328
- var obj = angular.copy($scope.selected);
335
+ let obj = angular.copy($scope.selected);
329
336
 
330
337
  if ($scope.selected != null) {
331
338
  // Remove selected flag
@@ -492,10 +499,10 @@ angular.module('niceElements')
492
499
  if ($scope.searchFunction) {
493
500
  $scope.handleSearch();
494
501
  }
495
-
496
-
502
+
503
+
497
504
  // ----------------------------------- Handle add button function -----------------------------------
498
- $scope.handleAddButton = function($event) {
505
+ $scope.handleAddButton = function ($event) {
499
506
  let element = $event.target;
500
507
  while (true) {
501
508
  if (element.nodeName == 'BUTTON') {
@@ -259,4 +259,4 @@
259
259
  @extend .nice-focus;
260
260
  }
261
261
  }
262
- }
262
+ }