nice-elements 1.4.2 → 1.4.5

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/dist/nice.js CHANGED
@@ -75,7 +75,7 @@ angular.module('niceElements')
75
75
  * # niceCalendar
76
76
  */
77
77
  angular.module('niceElements')
78
- .directive("niceCalendar", function($timeout, gettextCatalog) {
78
+ .directive("niceCalendar", function ($timeout, gettextCatalog) {
79
79
  return {
80
80
  restrict: "E",
81
81
  templateUrl: "src/components/nice-calendar/nice-calendar.html",
@@ -86,7 +86,7 @@ angular.module('niceElements')
86
86
  minDate: '=',
87
87
  maxDate: '=',
88
88
  hideHover: '=',
89
- time: '@',
89
+ time: '=',
90
90
  noMargin: '@',
91
91
  color: '@',
92
92
  endDate: '=',
@@ -96,7 +96,7 @@ angular.module('niceElements')
96
96
  isInline: '=',
97
97
  onChange: '&?'
98
98
  },
99
- link: function(scope, element) {
99
+ link: function (scope, element) {
100
100
  // ------------------ Init default values ------------------
101
101
  scope.selectStart = true;
102
102
  scope.popupText = gettextCatalog.getString("Select start date", null, "Nice");
@@ -111,37 +111,52 @@ angular.module('niceElements')
111
111
 
112
112
 
113
113
  // ------------------ Check if attributes are set ------------------
114
- if(!scope.startDate) scope.startDate = moment().minutes(0).second(0).millisecond(0);
115
- if(!scope.endDate) scope.endDate = moment().minutes(0).second(0).millisecond(0);
114
+ if (!scope.startDate) scope.startDate = moment().minutes(0).second(0).millisecond(0);
115
+ if (!scope.endDate) scope.endDate = moment().minutes(0).second(0).millisecond(0);
116
116
 
117
117
 
118
118
  // ------------------ Look for model changes ------------------
119
- scope.$watch("startDate", function(value, valueOld){
119
+ scope.$watch("startDate", function (value, valueOld) {
120
120
  bootstrap();
121
121
  });
122
122
 
123
- scope.$watch("endDate", function(value, valueOld){
123
+ scope.$watch("endDate", function (value, valueOld) {
124
124
  bootstrap();
125
125
  });
126
126
 
127
- scope.$watch("minDate", function(value, valueOld){
127
+ scope.$watch("minDate", function (value, valueOld) {
128
128
  bootstrap();
129
129
  });
130
130
 
131
- scope.$watch("maxDate", function(value, valueOld){
131
+ scope.$watch("maxDate", function (value, valueOld) {
132
132
  bootstrap();
133
133
  });
134
134
 
135
135
 
136
136
  // ------------------ Bootstrap calendar ------------------
137
137
  function bootstrap() {
138
- //scope.startDate = moment(scope.startDate.second(0).millisecond(0));
139
- //scope.endDate = moment(scope.endDate.second(0).millisecond(0));
140
-
141
- scope.startDateHour = moment(scope.startDate).hours();
142
- scope.startDateMinute = moment(scope.startDate).minutes();
143
- scope.endDateHour = moment(scope.endDate).hours();
144
- scope.endDateMinute = moment(scope.endDate).minutes();
138
+ // scope.startDate = moment(scope.startDate.second(0).millisecond(0));
139
+ // scope.endDate = moment(scope.endDate.second(0).millisecond(0));
140
+
141
+ if (!scope.time) {
142
+ scope.startDateHour = 0;
143
+ scope.startDateMinute = 0;
144
+ scope.startDate.hours(0);
145
+ scope.startDate.minutes(0);
146
+ scope.startDate.seconds(0);
147
+ scope.startDate.millisecond(0);
148
+ scope.endDateHour = 0;
149
+ scope.endDateMinut = 0;
150
+ scope.endDate.hours(23);
151
+ scope.endDate.minutes(59);
152
+ scope.endDate.seconds(59);
153
+ scope.endDate.millisecond(999);
154
+ } else {
155
+ scope.startDateHour = moment(scope.startDate).hours();
156
+ scope.startDateMinute = moment(scope.startDate).minutes();
157
+ scope.endDateHour = moment(scope.endDate).hours();
158
+ scope.endDateMinute = moment(scope.endDate).minutes();
159
+ }
145
160
 
146
161
  scope.month = angular.copy(moment(scope.startDate));
147
162
  var start = angular.copy(moment(scope.startDate));
@@ -153,13 +168,20 @@ angular.module('niceElements')
153
168
 
154
169
 
155
170
  // ------------------ Day was selected ------------------
156
- scope.select = function(day) {
157
- if(!day.isDisabled){
171
+ scope.select = function (day) {
172
+ if (!day.isDisabled) {
158
173
  var selectedDate = angular.copy(day.date);
159
174
 
160
- if(scope.selectStart){
161
- selectedDate.hours(scope.startDateHour);
162
- selectedDate.minutes(scope.startDateMinute);
175
+ if (scope.selectStart) {
176
+ if (!scope.time) {
177
+ selectedDate.hours(0);
178
+ selectedDate.minutes(0);
179
+ selectedDate.seconds(0);
180
+ selectedDate.millisecond(0);
181
+ } else {
182
+ selectedDate.hours(scope.startDateHour);
183
+ selectedDate.minutes(scope.startDateMinute);
184
+ }
163
185
 
164
186
  // Set start date
165
187
  scope.startDate = selectedDate;
@@ -169,12 +191,19 @@ angular.module('niceElements')
169
191
  scope.displayStartChange();
170
192
 
171
193
  // If start date is after end date
172
- if(scope.startDate.isAfter(scope.endDate)){
194
+ if (scope.startDate.isAfter(scope.endDate)) {
173
195
  scope.endDate = angular.copy(scope.startDate);
174
196
  }
175
197
  } else {
176
- selectedDate.hours(scope.endDateHour);
177
- selectedDate.minutes(scope.endDateMinute);
198
+ if (!scope.time) {
199
+ selectedDate.hours(23);
200
+ selectedDate.minutes(59);
201
+ selectedDate.seconds(59);
202
+ selectedDate.millisecond(999);
203
+ } else {
204
+ selectedDate.hours(scope.endDateHour);
205
+ selectedDate.minutes(scope.endDateMinute);
206
+ }
178
207
 
179
208
  // Set end date
180
209
  scope.endDate = selectedDate;
@@ -184,85 +213,94 @@ angular.module('niceElements')
184
213
  scope.displayEndChange();
185
214
 
186
215
  // If end date is before start date
187
- if(scope.endDate.isBefore(scope.startDate)){
216
+ if (scope.endDate.isBefore(scope.startDate)) {
188
217
  scope.startDate = angular.copy(scope.endDate);
189
218
  }
190
219
  }
191
220
 
192
- if (scope.onChange) scope.onChange({ model: {startDate: scope.startDate, endDate: scope.endDate}, element: element });
221
+ if (scope.onChange) scope.onChange({ model: { startDate: scope.startDate, endDate: scope.endDate }, element: element });
193
222
  }
194
223
  };
195
224
 
196
225
 
197
226
  // ------------------ Display date changes ------------------
198
- scope.displayStartChange = function(){
227
+ scope.displayStartChange = function () {
199
228
  scope.startTimeClass = "change";
200
- $timeout(function(){
229
+ $timeout(function () {
201
230
  scope.startTimeClass = "";
202
231
  }, 1000);
203
232
  };
204
233
 
205
- scope.displayEndChange = function(){
234
+ scope.displayEndChange = function () {
206
235
  scope.endTimeClass = "change";
207
- $timeout(function(){
236
+ $timeout(function () {
208
237
  scope.endTimeClass = "";
209
238
  }, 1000);
210
239
  };
211
240
 
212
241
 
213
242
  // ------------------ Time changes ------------------
214
- scope.startHourChange = function(value){
243
+ scope.startHourChange = function (value) {
215
244
  scope.startDateHour = value;
216
245
  scope.startDate = moment(scope.startDate).hours(scope.startDateHour);
217
246
  scope.formCalendar.$setDirty();
218
247
  scope.displayStartChange();
248
+ scope.handleUpdate();
219
249
  };
220
250
 
221
251
 
222
- scope.startMinuteChange = function(value) {
252
+ scope.startMinuteChange = function (value) {
223
253
  scope.startDateMinute = value;
224
254
  scope.startDate = moment(scope.startDate).minutes(scope.startDateMinute);
225
255
  scope.formCalendar.$setDirty();
226
256
  scope.displayStartChange();
257
+ scope.handleUpdate();
227
258
  };
228
259
 
229
260
 
230
- scope.endHourChange = function(value){
261
+ scope.endHourChange = function (value) {
231
262
  scope.endDateHour = value;
232
263
  scope.endDate = moment(scope.endDate).hours(scope.endDateHour);
233
264
  scope.formCalendar.$setDirty();
234
265
  scope.displayEndChange();
266
+ scope.handleUpdate();
235
267
  };
236
268
 
237
269
 
238
- scope.endMinuteChange = function(value) {
270
+ scope.endMinuteChange = function (value) {
239
271
  scope.endDateMinute = value;
240
272
  scope.endDate = moment(scope.endDate).minutes(scope.endDateMinute);
241
273
  scope.formCalendar.$setDirty();
242
274
  scope.displayEndChange();
275
+ scope.handleUpdate();
276
+ };
277
+
278
+
279
+ scope.handleUpdate = function () {
280
+ if (scope.onChange) scope.onChange({ model: { startDate: scope.startDate, endDate: scope.endDate }, element: element });
243
281
  };
244
282
 
245
283
 
246
284
  // ------------------ Go to next month ------------------
247
- scope.next = function() {
285
+ scope.next = function () {
248
286
  var next = angular.copy(scope.month);
249
- _removeTimeWithDate(next.month(next.month()+1).date(0));
250
- scope.month.month(scope.month.month()+1);
287
+ _removeTimeWithDate(next.month(next.month() + 1).date(0));
288
+ scope.month.month(scope.month.month() + 1);
251
289
  _buildMonth(scope, next, scope.month);
252
290
  };
253
291
 
254
292
 
255
293
  // ------------------ Go to previous month ------------------
256
- scope.previous = function() {
294
+ scope.previous = function () {
257
295
  var previous = angular.copy(scope.month);
258
- _removeTimeWithDate(previous.month(previous.month()-1).date(0));
259
- scope.month.month(scope.month.month()-1);
296
+ _removeTimeWithDate(previous.month(previous.month() - 1).date(0));
297
+ scope.month.month(scope.month.month() - 1);
260
298
  _buildMonth(scope, previous, scope.month);
261
299
  };
262
300
 
263
301
 
264
302
  // ------------------ Check if dates are equal without time ------------------
265
- scope.isSameDay = function(date1, date2){
303
+ scope.isSameDay = function (date1, date2) {
266
304
  var d1 = _removeTime(angular.copy(date1));
267
305
  var d2 = _removeTime(angular.copy(date2));
268
306
  return d1.isSame(d2);
@@ -270,20 +308,20 @@ angular.module('niceElements')
270
308
 
271
309
 
272
310
  // ------------------ Check if date is between start and end date ------------------
273
- scope.isBetweenRange = function(date){
311
+ scope.isBetweenRange = function (date) {
274
312
  return (date.isBefore(moment(scope.endDate)) && date.isAfter(moment(scope.startDate)));
275
313
  };
276
314
 
277
315
 
278
316
  // ------------------ Format date ------------------
279
- scope.formatDate = function(date){
280
- if(scope.time) return moment(date).format('D.M.YYYY • H:mm');
317
+ scope.formatDate = function (date) {
318
+ if (scope.time) return moment(date).format('D.M.YYYY • H:mm');
281
319
  else return moment(date).format('D.M.YYYY');
282
320
  };
283
321
 
284
322
 
285
323
  // ------------------ Lighten color by 20% ------------------
286
- scope.lighten = function(col){
324
+ scope.lighten = function (col) {
287
325
  var amt = 20;
288
326
  var usePound = false;
289
327
 
@@ -292,21 +330,21 @@ angular.module('niceElements')
292
330
  usePound = true;
293
331
  }
294
332
 
295
- var num = parseInt(col,16);
333
+ var num = parseInt(col, 16);
296
334
  var r = (num >> 16) + amt;
297
335
 
298
336
  if (r > 255) r = 255;
299
- else if (r < 0) r = 0;
337
+ else if (r < 0) r = 0;
300
338
 
301
339
  var b = ((num >> 8) & 0x00FF) + amt;
302
340
  if (b > 255) b = 255;
303
- else if (b < 0) b = 0;
341
+ else if (b < 0) b = 0;
304
342
 
305
343
  var g = (num & 0x0000FF) + amt;
306
344
  if (g > 255) g = 255;
307
345
  else if (g < 0) g = 0;
308
346
 
309
- return (usePound?"#":"") + (g | (b << 8) | (r << 16)).toString(16);
347
+ return (usePound ? "#" : "") + (g | (b << 8) | (r << 16)).toString(16);
310
348
  };
311
349
 
312
350
 
@@ -348,9 +386,9 @@ angular.module('niceElements')
348
386
  date: date
349
387
  };
350
388
 
351
- if(scope.minDate) day.isDisabled = date.isBefore(moment(scope.minDate));
352
- if(scope.maxDate) day.isDisabled = date.isAfter(moment(scope.maxDate));
353
- if(scope.minDate && scope.maxDate) day.isDisabled = !date.isBetween(moment(scope.minDate), moment(scope.maxDate));
389
+ if (scope.minDate) day.isDisabled = date.isBefore(moment(scope.minDate));
390
+ if (scope.maxDate) day.isDisabled = date.isAfter(moment(scope.maxDate));
391
+ if (scope.minDate && scope.maxDate) day.isDisabled = !date.isBetween(moment(scope.minDate), moment(scope.maxDate));
354
392
 
355
393
  days.push(day);
356
394
  date = date.clone();
@@ -361,7 +399,7 @@ angular.module('niceElements')
361
399
  }
362
400
  }
363
401
  };
364
- });
402
+ });
365
403
 
366
404
  'use strict';
367
405
 
@@ -883,7 +921,7 @@ angular.module('niceElements')
883
921
  isInline: '=',
884
922
  onChange: '&?'
885
923
  },
886
- controller: function($scope, gettextCatalog) {
924
+ controller: function($scope, $element, gettextCatalog) {
887
925
  $scope.isOpen = false;
888
926
  $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];
889
927
  $scope.minutes = [0, 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, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59];
@@ -943,6 +981,27 @@ angular.module('niceElements')
943
981
  if ($scope.maxDate) $scope.maxDate = moment($scope.maxDate);
944
982
  if ($scope.minDate) $scope.minDate = moment($scope.minDate);
945
983
 
984
+
985
+ // Setup popper
986
+ // https://popper.js.org/docs/v2/constructors/
987
+ $scope.setupPopper = function() {
988
+ var button = $element[0].getElementsByClassName('nice-date-button')[0];
989
+ var tooltip = $element[0].getElementsByClassName('nice-date-dropdown-wrapper')[0];
990
+ $scope.popper = Popper.createPopper(button, tooltip, {
991
+ strategy: 'fixed',
992
+ placement: 'bottom-start',
993
+ modifiers: [
994
+ {
995
+ name: 'offset',
996
+ options: {
997
+ offset: [0, 5],
998
+ },
999
+ }
1000
+ ],
1001
+ });
1002
+ };
1003
+ if (!$scope.inline) $scope.setupPopper();
1004
+
946
1005
 
947
1006
  // ------------------ Time changes ------------------
948
1007
  $scope.timeChange = function() {
@@ -1149,6 +1208,7 @@ angular.module('niceElements')
1149
1208
  $scope.toggleOpen = function() {
1150
1209
  if (!$scope.isDisabled) {
1151
1210
  $scope.isOpen = !$scope.isOpen;
1211
+ $scope.popper.update();
1152
1212
  }
1153
1213
  };
1154
1214
  }
@@ -1271,7 +1331,7 @@ angular.module('niceElements')
1271
1331
  onChange: '&?'
1272
1332
  },
1273
1333
  templateUrl: 'src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html',
1274
- controller: function ($rootScope, $scope) {
1334
+ controller: function ($element, $scope) {
1275
1335
  $scope.isOpen = false;
1276
1336
 
1277
1337
 
@@ -1301,6 +1361,27 @@ angular.module('niceElements')
1301
1361
  }
1302
1362
 
1303
1363
 
1364
+ // Setup popper
1365
+ // https://popper.js.org/docs/v2/constructors/
1366
+ $scope.setupPopper = function() {
1367
+ var button = $element[0].getElementsByClassName('nice-daterange-picker-button')[0];
1368
+ var tooltip = $element[0].getElementsByClassName('nice-daterange-picker-wrapper')[0];
1369
+ $scope.popper = Popper.createPopper(button, tooltip, {
1370
+ strategy: 'fixed',
1371
+ placement: 'bottom-start',
1372
+ modifiers: [
1373
+ {
1374
+ name: 'offset',
1375
+ options: {
1376
+ offset: [0, 5],
1377
+ },
1378
+ }
1379
+ ],
1380
+ });
1381
+ };
1382
+ $scope.setupPopper();
1383
+
1384
+
1304
1385
  $scope.format = function(){
1305
1386
  $scope.modelFormat = $scope.startDate.format($scope.formatString) + " - " + $scope.endDate.format($scope.formatString);
1306
1387
  };
@@ -1309,6 +1390,7 @@ angular.module('niceElements')
1309
1390
  $scope.open = function() {
1310
1391
  if (!$scope.isDisabled) {
1311
1392
  $scope.isOpen = true;
1393
+ $scope.popper.update();
1312
1394
  }
1313
1395
  };
1314
1396
 
@@ -2128,8 +2210,7 @@ angular.module('niceElements')
2128
2210
  selectedText: '@',
2129
2211
  searchFunction: '=?',
2130
2212
  isInline: '=',
2131
- clearOnSelect: '@',
2132
- positionFixed: '=' // Dropdown menu will be fixed to page
2213
+ clearOnSelect: '@'
2133
2214
  },
2134
2215
  controller: function ($scope, $element, $timeout, gettextCatalog) {
2135
2216
  if (!$scope.objValue) { $scope.objValue = 'value'; }
@@ -2150,11 +2231,47 @@ angular.module('niceElements')
2150
2231
  $scope.isOpen = false;
2151
2232
  $scope.selected = null;
2152
2233
  $scope.selectedIndex = 0;
2234
+ $scope.popper = null;
2153
2235
 
2154
2236
  $scope.internal = {
2155
2237
  search: ""
2156
2238
  };
2157
2239
 
2240
+ // Setup popper
2241
+ // https://popper.js.org/docs/v2/constructors/
2242
+ $scope.setupPopper = function() {
2243
+ var button = $element[0].getElementsByClassName('btn-dropdown')[0];
2244
+ var tooltip = $element[0].getElementsByClassName('nice-dropdown-menu-wrapper')[0];
2245
+ $scope.popper = Popper.createPopper(button, tooltip, {
2246
+ strategy: 'fixed',
2247
+ scroll: true,
2248
+ resize: true,
2249
+ modifiers: [
2250
+ {
2251
+ name: 'offset',
2252
+ options: {
2253
+ offset: [0, 5],
2254
+ },
2255
+ },
2256
+ {
2257
+ name: "sameWidth",
2258
+ enabled: true,
2259
+ phase: "beforeWrite",
2260
+ requires: ["computeStyles"],
2261
+ fn: ({ state }) => {
2262
+ state.styles.popper.width = `${state.rects.reference.width}px`;
2263
+ },
2264
+ effect: ({ state }) => {
2265
+ state.elements.popper.style.width = `${
2266
+ state.elements.reference.offsetWidth
2267
+ }px`;
2268
+ }
2269
+ }
2270
+ ],
2271
+ });
2272
+ };
2273
+ $scope.setupPopper();
2274
+
2158
2275
  // -----------------------------------Open -----------------------------------
2159
2276
  $scope.toggle = function () {
2160
2277
  if ($scope.isOpen) {
@@ -2169,10 +2286,10 @@ angular.module('niceElements')
2169
2286
  };
2170
2287
 
2171
2288
  $scope.open = function () {
2172
- $scope.focusInput();
2173
2289
  $scope.isOpen = true;
2174
- if($scope.positionFixed) $scope.updateStyle();
2175
- $timeout(function() {
2290
+ $timeout(function () {
2291
+ $scope.popper.update();
2292
+ $scope.focusInput();
2176
2293
  $scope.scrollToHover(true);
2177
2294
  }, 100);
2178
2295
  };
@@ -2190,18 +2307,18 @@ angular.module('niceElements')
2190
2307
 
2191
2308
 
2192
2309
  // ----------------------------------- Scroll to hover -----------------------------------
2193
- $scope.scrollToHover = function(notSmooth) {
2194
- var dropdownMenu = $element[0].getElementsByClassName("dropdown-menu")[0];
2195
- var dorpdownList = dropdownMenu.getElementsByTagName("ul")[0];
2310
+ $scope.scrollToHover = function (notSmooth) {
2311
+ var dropdownMenu = $element[0].getElementsByClassName("nice-dropdown-menu")[0];
2312
+ if (!dropdownMenu) return;
2313
+ var dorpdownList = dropdownMenu.getElementsByClassName("nice-dropdown-items")[0];
2196
2314
  var hoverItem = dorpdownList.getElementsByClassName("hover")[0];
2197
- if (hoverItem) {
2198
- var topPos = hoverItem.offsetTop;
2199
- dorpdownList.scroll({
2200
- top: topPos - 120,
2201
- left: 0,
2202
- behavior: notSmooth ? 'auto' : 'smooth'
2203
- });
2204
- }
2315
+ if (!hoverItem) return
2316
+ var topPos = hoverItem.offsetTop;
2317
+ dorpdownList.scroll({
2318
+ top: topPos - 120,
2319
+ left: 0,
2320
+ behavior: notSmooth ? 'auto' : 'smooth'
2321
+ });
2205
2322
  };
2206
2323
 
2207
2324
 
@@ -2236,11 +2353,11 @@ angular.module('niceElements')
2236
2353
 
2237
2354
 
2238
2355
  // ----------------------------------- Handle multiple select -----------------------------------
2239
- $scope.handleMultipleSelect = function(item, index) {
2356
+ $scope.handleMultipleSelect = function (item, index) {
2240
2357
  if (!$scope.selected) $scope.selected = [];
2241
2358
 
2242
- if(item._selected) {
2243
- $scope.selected = $scope.selected.filter(function(s) {
2359
+ if (item._selected) {
2360
+ $scope.selected = $scope.selected.filter(function (s) {
2244
2361
  return s[$scope.objKey] != item[$scope.objKey];
2245
2362
  });
2246
2363
  } else {
@@ -2252,7 +2369,7 @@ angular.module('niceElements')
2252
2369
 
2253
2370
 
2254
2371
  // ----------------------------------- Handle single slect -----------------------------------
2255
- $scope.handleSingleSelect = function(item, index) {
2372
+ $scope.handleSingleSelect = function (item, index) {
2256
2373
  $scope.selected = item;
2257
2374
  $scope.close();
2258
2375
  $scope.handleSetModel();
@@ -2260,13 +2377,13 @@ angular.module('niceElements')
2260
2377
 
2261
2378
 
2262
2379
  // ----------------------------------- Handle set model -----------------------------------
2263
- $scope.handleSetModel = function() {
2380
+ $scope.handleSetModel = function () {
2264
2381
  var obj = angular.copy($scope.selected);
2265
2382
 
2266
2383
  if ($scope.selected != null) {
2267
2384
  // Remove selected flag
2268
2385
  if ($scope.multiple) {
2269
- angular.forEach(obj, function(o) {
2386
+ angular.forEach(obj, function (o) {
2270
2387
  o._selected = undefined;
2271
2388
  });
2272
2389
  } else {
@@ -2276,7 +2393,7 @@ angular.module('niceElements')
2276
2393
  // Selected is object
2277
2394
  if ($scope.selectedIsKey) {
2278
2395
  if ($scope.multiple) {
2279
- angular.forEach(obj, function(o) {
2396
+ angular.forEach(obj, function (o) {
2280
2397
  o = o[$scope.objKey];
2281
2398
  });
2282
2399
  } else {
@@ -2284,7 +2401,7 @@ angular.module('niceElements')
2284
2401
  }
2285
2402
  }
2286
2403
  }
2287
-
2404
+
2288
2405
  if ($scope.clearOnSelect) {
2289
2406
  // Clear on select
2290
2407
  $scope.model = null;
@@ -2301,7 +2418,7 @@ angular.module('niceElements')
2301
2418
 
2302
2419
 
2303
2420
  // ----------------------------------- Handle default -----------------------------------
2304
- $scope.handleDefault = function() {
2421
+ $scope.handleDefault = function () {
2305
2422
  if ($scope.model) $scope.handleModelChange();
2306
2423
  if (!$scope.nullable && !$scope.model && !$scope.clearOnSelect && $scope.internalList && $scope.internalList.length > 0) {
2307
2424
  $scope.handleSelected($scope.internalList[0], 0);
@@ -2320,16 +2437,16 @@ angular.module('niceElements')
2320
2437
  $scope.handleModelChange();
2321
2438
  });
2322
2439
 
2323
- $scope.handleModelChange = function() {
2440
+ $scope.handleModelChange = function () {
2324
2441
  $scope.selected = angular.copy($scope.model);
2325
- angular.forEach($scope.internalList, function(i, index) {
2442
+ angular.forEach($scope.internalList, function (i, index) {
2326
2443
  i._selected = false;
2327
2444
 
2328
2445
  if ($scope.selectedIsKey) {
2329
2446
  // Not object
2330
2447
  if ($scope.multiple) {
2331
2448
  // Multiple
2332
- angular.forEach($scope.selected, function(s) {
2449
+ angular.forEach($scope.selected, function (s) {
2333
2450
  if (i[$scope.objKey] == s) {
2334
2451
  i._selected = true;
2335
2452
  // $scope.selected.push(i);
@@ -2344,12 +2461,12 @@ angular.module('niceElements')
2344
2461
  $scope.selectedIndex = index;
2345
2462
  $scope.scrollToHover();
2346
2463
  }
2347
- }
2464
+ }
2348
2465
  } else {
2349
2466
  // Is object
2350
2467
  if ($scope.multiple) {
2351
2468
  // Multiple
2352
- angular.forEach($scope.selected, function(s) {
2469
+ angular.forEach($scope.selected, function (s) {
2353
2470
  if (i[$scope.objKey] == s[$scope.objKey]) {
2354
2471
  i._selected = true;
2355
2472
  // $scope.selected.push(i);
@@ -2368,41 +2485,16 @@ angular.module('niceElements')
2368
2485
  }
2369
2486
  });
2370
2487
  }
2371
-
2372
- // ----------------------------------- Handle fixed position -----------------------------------
2373
- if ($scope.positionFixed) {
2374
- $scope.dropdownButton = $element[0].getElementsByClassName('btn-dropdown')[0]
2375
- $scope.dropdownMenu = $element[0].getElementsByClassName('dropdown-menu')[0]
2376
- $scope.updateStyle = function () {
2377
- if (this.isOpen) {
2378
- var buttonPos = $scope.dropdownButton.getBoundingClientRect();
2379
- $scope.dropdownMenu.style.top = (buttonPos.top + buttonPos.height) + "px";
2380
- $scope.dropdownMenu.style.left = buttonPos.left + "px";
2381
- $scope.dropdownMenu.style.width = buttonPos.width + "px";
2382
- }
2383
- }
2384
-
2385
- $scope.updateStyle();
2386
-
2387
- angular.element($window).on("resize", function () {
2388
- $scope.updateStyle();
2389
- })
2390
-
2391
- angular.element($window).on("scroll", function () {
2392
- $scope.updateStyle();
2393
- })
2394
- }
2395
-
2396
2488
 
2397
2489
  // ----------------------------------- Watch for keydown and keypress -----------------------------------
2398
2490
  $element.bind("keydown keypress", function (event) {
2399
2491
  // Arrow Up
2400
2492
  if (event.keyCode == 38) {
2401
2493
  event.preventDefault();
2402
- $timeout(function() {
2403
- if ( $scope.selectedIndex > 0) {
2494
+ $timeout(function () {
2495
+ if ($scope.selectedIndex > 0) {
2404
2496
  $scope.selectedIndex -= 1;
2405
- $timeout(function() {
2497
+ $timeout(function () {
2406
2498
  $scope.scrollToHover();
2407
2499
  });
2408
2500
  }
@@ -2412,10 +2504,10 @@ angular.module('niceElements')
2412
2504
  // Arrow Down
2413
2505
  if (event.keyCode == 40) {
2414
2506
  event.preventDefault();
2415
- $timeout(function() {
2507
+ $timeout(function () {
2416
2508
  if ($scope.internalList && $scope.selectedIndex < $scope.internalList.length - 1) {
2417
2509
  $scope.selectedIndex += 1;
2418
- $timeout(function() {
2510
+ $timeout(function () {
2419
2511
  $scope.scrollToHover();
2420
2512
  });
2421
2513
  }
@@ -2425,14 +2517,14 @@ angular.module('niceElements')
2425
2517
  // Enter
2426
2518
  if (event.keyCode == 13) {
2427
2519
  event.preventDefault();
2428
- $timeout(function() {
2520
+ $timeout(function () {
2429
2521
  $scope.handleSelected($scope.internalList[$scope.selectedIndex], $scope.selectedIndex);
2430
2522
  });
2431
2523
  }
2432
2524
 
2433
2525
  // Escape
2434
2526
  if (event.keyCode == 27) {
2435
- $timeout(function() {
2527
+ $timeout(function () {
2436
2528
  $scope.close();
2437
2529
  });
2438
2530
  }
@@ -4285,6 +4377,40 @@ angular.module('niceElements')
4285
4377
 
4286
4378
  if (!$scope.debounceTime) $scope.debounceTime = 500;
4287
4379
  if (!$scope.model) $scope.model = "";
4380
+
4381
+ // Setup popper
4382
+ // https://popper.js.org/docs/v2/constructors/
4383
+ $scope.setupPopper = function() {
4384
+ var button = $element[0].getElementsByClassName('nice-search-button')[0];
4385
+ var tooltip = $element[0].getElementsByClassName('nice-search-dropdown-wrapper')[0];
4386
+ $scope.popper = Popper.createPopper(button, tooltip, {
4387
+ strategy: 'fixed',
4388
+ placement: 'bottom-start',
4389
+ modifiers: [
4390
+ {
4391
+ name: 'offset',
4392
+ options: {
4393
+ offset: [0, 5],
4394
+ },
4395
+ },
4396
+ {
4397
+ name: "sameWidth",
4398
+ enabled: true,
4399
+ phase: "beforeWrite",
4400
+ requires: ["computeStyles"],
4401
+ fn: ({ state }) => {
4402
+ state.styles.popper.width = `${state.rects.reference.width}px`;
4403
+ },
4404
+ effect: ({ state }) => {
4405
+ state.elements.popper.style.width = `${
4406
+ state.elements.reference.offsetWidth
4407
+ }px`;
4408
+ }
4409
+ }
4410
+ ],
4411
+ });
4412
+ };
4413
+ $scope.setupPopper();
4288
4414
 
4289
4415
  // ------------------- On focus -------------------
4290
4416
  $scope.onFocus = function() {
@@ -4311,6 +4437,10 @@ angular.module('niceElements')
4311
4437
 
4312
4438
  var input = $element[0].getElementsByTagName('input')[0];
4313
4439
  if (input) input.blur();
4440
+
4441
+ $timeout(function() {
4442
+ $scope.popper.update();
4443
+ })
4314
4444
  };
4315
4445
 
4316
4446
 
@@ -4884,6 +5014,7 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
4884
5014
  "<div class=\"nice-field col-xs-12\" ng-class=\"[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]\">\n" +
4885
5015
  "<div class=\"disabled-shield\" ng-if=\"isDisabled\"></div>\n" +
4886
5016
  "<div class=\"nice-calendar-wrapper\">\n" +
5017
+ "<div class=\"nice-calendar-weeks\">\n" +
4887
5018
  "<div class=\"header\">\n" +
4888
5019
  "<i class=\"fa fa-angle-left\" ng-click=\"previous()\" title=\"{{ 'Previous month' | translate:'Nice' }}\"></i>\n" +
4889
5020
  "<span title=\"{{ month.format('M.YYYY' )}}\">{{ month.format(\"MMMM, YYYY\" )}}</span>\n" +
@@ -4900,25 +5031,25 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
4900
5031
  "</div>\n" +
4901
5032
  "<div class=\"week\" ng-repeat=\"week in weeks\">\n" +
4902
5033
  "<span class=\"day\" title=\"{{ day.date.format('D.M.YYYY') }}\" ng-class=\"{\n" +
4903
- " today: day.isToday,\n" +
4904
- " 'different-month': !day.isCurrentMonth,\n" +
4905
- " 'start-selected': isSameDay(day.date, startDate),\n" +
4906
- " 'end-selected': isSameDay(day.date, endDate),\n" +
4907
- " 'selected': isBetweenRange(day.date),\n" +
4908
- " 'selecting-start': selectStart,\n" +
4909
- " 'selecting-end': !selectStart,\n" +
4910
- " 'weekend': day.isWeekday,\n" +
4911
- " 'disabled': day.isDisabled\n" +
4912
- " }\" ng-style=\"\n" +
4913
- " (color && isBetweenRange(day.date)) && {'background-color': lighten(color) } ||\n" +
4914
- " (color && isSameDay(day.date, startDate)) && {'background-color': color } ||\n" +
4915
- " (color && isSameDay(day.date, endDate)) && {'background-color': color }\n" +
4916
- " \" ng-click=\"select(day)\" ng-repeat=\"day in week.days\">\n" +
5034
+ " today: day.isToday,\n" +
5035
+ " 'different-month': !day.isCurrentMonth,\n" +
5036
+ " 'start-selected': isSameDay(day.date, startDate),\n" +
5037
+ " 'end-selected': isSameDay(day.date, endDate),\n" +
5038
+ " 'selected': isBetweenRange(day.date),\n" +
5039
+ " 'selecting-start': selectStart,\n" +
5040
+ " 'selecting-end': !selectStart,\n" +
5041
+ " 'weekend': day.isWeekday,\n" +
5042
+ " 'disabled': day.isDisabled\n" +
5043
+ " }\" ng-style=\"\n" +
5044
+ " (color && isBetweenRange(day.date)) && {'background-color': lighten(color) } ||\n" +
5045
+ " (color && isSameDay(day.date, startDate)) && {'background-color': color } ||\n" +
5046
+ " (color && isSameDay(day.date, endDate)) && {'background-color': color }\n" +
5047
+ " \" ng-click=\"select(day)\" ng-repeat=\"day in week.days\">\n" +
4917
5048
  "{{ day.number }}\n" +
4918
5049
  "<p class=\"popup\" ng-if=\"!hideHover\">{{ popupText }}</p>\n" +
4919
5050
  "</span>\n" +
4920
5051
  "</div>\n" +
4921
- "<div class=\"clearfix\"></div>\n" +
5052
+ "</div>\n" +
4922
5053
  "<div class=\"nice-calendar-time\" ng-if=\"time\">\n" +
4923
5054
  "<div class=\"time-picker\">\n" +
4924
5055
  "<select title=\"{{ 'Select start time' | translate:'Nice' }}\" class=\"time-picker-hour\" ng-model=\"startDateHour\" ng-change=\"startHourChange(startDateHour)\" ng-options=\"hour for hour in hours\">\n" +
@@ -4949,7 +5080,6 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
4949
5080
  "<label translate translate-context=\"Nice\">End</label>\n" +
4950
5081
  "<div ng-class=\"endTimeClass\">{{ formatDate(endDate) }}</div>\n" +
4951
5082
  "</div>\n" +
4952
- "<div class=\"clearfix\"></div>\n" +
4953
5083
  "</div>\n" +
4954
5084
  "</div>\n" +
4955
5085
  "</div>\n" +
@@ -5033,12 +5163,13 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
5033
5163
  "</div>\n" +
5034
5164
  "<div class=\"nice-field col-xs-12\" ng-class=\"[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]\">\n" +
5035
5165
  "<div class=\"disabled-shield\" ng-if=\"isDisabled\"></div>\n" +
5036
- "<div class=\"input-group\" ng-class=\"{ 'open': isOpen }\" ng-if=\"!inline\" ng-click=\"toggleOpen()\">\n" +
5166
+ "<div class=\"nice-date-button input-group\" ng-class=\"{ 'open': isOpen }\" ng-show=\"!inline\" ng-click=\"toggleOpen()\">\n" +
5037
5167
  "<input type=\"text\" class=\"form-control\" value=\"{{ model | niceDate:time }}\" readonly=\"readonly\">\n" +
5038
5168
  "<span class=\"input-group-addon clickable\">\n" +
5039
5169
  "<i class=\"fa fa-calendar\"></i>\n" +
5040
5170
  "</span>\n" +
5041
5171
  "</div>\n" +
5172
+ "<div class=\"nice-date-dropdown-wrapper\">\n" +
5042
5173
  "<div ng-class=\"{ 'nice-date-dropdown': !inline }\" ng-if=\"inline || isOpen\">\n" +
5043
5174
  "<div class=\"nice-date-date\" ng-class=\"{ 'with-time': time }\">\n" +
5044
5175
  "<div class=\"nice-date-header\">\n" +
@@ -5057,13 +5188,13 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
5057
5188
  "</div>\n" +
5058
5189
  "<div class=\"nice-date-week\" ng-repeat=\"week in weeks\">\n" +
5059
5190
  "<span class=\"nice-date-day\" title=\"{{ day.value }}\" ng-class=\"{\n" +
5060
- " 'today': day.isToday,\n" +
5061
- " 'different-month': !day.isCurrentMonth,\n" +
5062
- " 'selected': isSameDay(model, day.date),\n" +
5063
- " 'weekend': day.isWeekday,\n" +
5064
- " 'disabled': day.isDisabled,\n" +
5065
- " 'between': isBetween(day.date, model, nextDate)\n" +
5066
- " }\" ng-click=\"select(day)\" ng-repeat=\"day in week.days\">{{ day.number }}</span>\n" +
5191
+ " 'today': day.isToday,\n" +
5192
+ " 'different-month': !day.isCurrentMonth,\n" +
5193
+ " 'selected': isSameDay(model, day.date),\n" +
5194
+ " 'weekend': day.isWeekday,\n" +
5195
+ " 'disabled': day.isDisabled,\n" +
5196
+ " 'between': isBetween(day.date, model, nextDate)\n" +
5197
+ " }\" ng-click=\"select(day)\" ng-repeat=\"day in week.days\">{{ day.number }}</span>\n" +
5067
5198
  "</div>\n" +
5068
5199
  "</div>\n" +
5069
5200
  "<div class=\"nice-date-time\" ng-if=\"time\">\n" +
@@ -5081,6 +5212,7 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
5081
5212
  "</div>\n" +
5082
5213
  "</div>\n" +
5083
5214
  "</div>\n" +
5215
+ "</div>\n" +
5084
5216
  "</div>"
5085
5217
  );
5086
5218
 
@@ -5119,11 +5251,12 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
5119
5251
  "<nice-help class=\"nice-title-help\" ng-if=\"help\" text=\"{{ help }}\"></nice-help>\n" +
5120
5252
  "</div>\n" +
5121
5253
  "<div class=\"nice-field col-xs-12\" ng-class=\"[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]\">\n" +
5122
- "<div class=\"input-group\" ng-class=\"{ 'open': isOpen }\" ng-click=\"open()\">\n" +
5254
+ "<div class=\"nice-daterange-picker-button input-group\" ng-class=\"{ 'open': isOpen }\" ng-click=\"open()\">\n" +
5123
5255
  "<input type=\"text\" class=\"form-control\" value=\"{{ modelFormat }}\" readonly=\"readonly\">\n" +
5124
5256
  "<span class=\"input-group-addon clickable\"><i class=\"fa fa-calendar\"></i></span>\n" +
5125
5257
  "</div>\n" +
5126
- "<div class=\"dtp-wrapper\" ng-show=\"isOpen\">\n" +
5258
+ "<div class=\"nice-daterange-picker-wrapper\">\n" +
5259
+ "<div class=\"dtp-wrapper\" ng-if=\"isOpen\">\n" +
5127
5260
  "<div class=\"dtp-buttons-left\">\n" +
5128
5261
  "<div class=\"dtp-buttons-top\">\n" +
5129
5262
  "<a class=\"btn btn-primary btn-block\" ng-click=\"selectToday()\" translate translate-context=\"Nice\">Last 24 hours</a>\n" +
@@ -5145,6 +5278,7 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
5145
5278
  "</div>\n" +
5146
5279
  "</div>\n" +
5147
5280
  "</div>\n" +
5281
+ "</div>\n" +
5148
5282
  "</div>"
5149
5283
  );
5150
5284
 
@@ -5287,23 +5421,25 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
5287
5421
  "<span class=\"caret\" ng-show=\"!loading\"></span>\n" +
5288
5422
  "<nice-loader visible-when=\"!loading\"></nice-loader>\n" +
5289
5423
  "</button>\n" +
5290
- "<div class=\"dropdown-menu\" ng-class=\"{ 'dropdown-menu-fixed': positionFixed }\">\n" +
5424
+ "<div class=\"nice-dropdown-menu-wrapper\">\n" +
5425
+ "<div class=\"nice-dropdown-menu\" ng-if=\"isOpen\">\n" +
5291
5426
  "<div class=\"search-bar\" ng-if=\"searchFunction\">\n" +
5292
5427
  "<input ng-model=\"internal.search\" ng-model-options=\"{ debounce: 500 }\" ng-change=\"handleSearch()\" placeholder=\"{{ searchText }}\">\n" +
5293
5428
  "<span class=\"icon\"><i class=\"fa fa-search\"></i></span>\n" +
5294
5429
  "</div>\n" +
5430
+ "<div class=\"nice-dropdown-items\">\n" +
5295
5431
  "<div class=\"nice-no-data\" ng-if=\"internalList && internalList.length == 0\">{{ noDataText }}</div>\n" +
5296
- "<ul>\n" +
5297
- "<li class=\"null-item\" ng-if=\"nullable && internalList.length != 0\" ng-click=\"handleSelected(null, -1)\">\n" +
5432
+ "<div class=\"nice-dropdown-item null-item\" ng-if=\"nullable && internalList.length != 0\" ng-click=\"handleSelected(null, -1)\">\n" +
5298
5433
  "{{ nullableText }}\n" +
5299
- "</li>\n" +
5300
- "<li ng-repeat=\"item in internalList\" ng-click=\"handleSelected(item, $index)\" ng-class=\"{ 'selected': item._selected, 'hover': $index == selectedIndex }\">\n" +
5434
+ "</div>\n" +
5435
+ "<div class=\"nice-dropdown-item\" ng-repeat=\"item in internalList\" ng-click=\"handleSelected(item, $index)\" ng-class=\"{ 'selected': item._selected, 'hover': $index == selectedIndex }\">\n" +
5301
5436
  "<span class=\"choice-checkbox\" ng-if=\"multiple\"><i class=\"fa fa-check\"></i></span>\n" +
5302
5437
  "<span ng-transclude=\"option\">\n" +
5303
5438
  "<span ng-class=\"{ 'multiple-item': multiple }\">{{ item[objValue] }}</span>\n" +
5304
5439
  "</span>\n" +
5305
- "</li>\n" +
5306
- "</ul>\n" +
5440
+ "</div>\n" +
5441
+ "</div>\n" +
5442
+ "</div>\n" +
5307
5443
  "</div>\n" +
5308
5444
  "<button class=\"btn btn-primary add-btn\" type=\"button\" ng-if=\"addButtonFunction && !isDisabled\" ng-click=\"addButtonFunction()\">+</button>\n" +
5309
5445
  "</div>\n" +
@@ -5634,13 +5770,15 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
5634
5770
  "<nice-help class=\"nice-title-help\" ng-if=\"help\" text=\"{{ help }}\"></nice-help>\n" +
5635
5771
  "</div>\n" +
5636
5772
  "<div class=\"nice-field col-xs-12\" ng-class=\"[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]\" click-outside=\"close()\">\n" +
5637
- "<div class=\"input-group\" ng-class=\"{ 'disabled': isDisabled, 'has-warning': !isDisabled && form.$invalid && form.$dirty, 'has-success': !isDisabled && form.$valid && form.$dirty}\">\n" +
5773
+ "<div class=\"nice-search-button input-group\" ng-class=\"{ 'disabled': isDisabled, 'has-warning': !isDisabled && form.$invalid && form.$dirty, 'has-success': !isDisabled && form.$valid && form.$dirty}\">\n" +
5638
5774
  "<input class=\"form-control\" type=\"text\" id=\"{{ id }}\" ng-model=\"model\" placeholder=\"{{ placeholder }}\" ng-disabled=\"isDisabled\" ng-change=\"updateSearch()\" ng-focus=\"onFocus()\" tabindex=\"{{ tabIndex }}\">\n" +
5639
5775
  "<span class=\"input-group-addon clickable\" ng-click=\"onFocus()\">\n" +
5640
5776
  "<i ng-show=\"!loading\" class=\"fa fa-search\"></i>\n" +
5641
5777
  "<i ng-show=\"loading\" class=\"fa fa-refresh fa-spin\"></i>\n" +
5642
5778
  "</span>\n" +
5643
- "<div class=\"nice-dropdown\" ng-if=\"showDropdown && isOpen\">\n" +
5779
+ "</div>\n" +
5780
+ "<div class=\"nice-search-dropdown-wrapper\">\n" +
5781
+ "<div class=\"nice-search-dropdown\" ng-if=\"showDropdown && isOpen\">\n" +
5644
5782
  "<div class=\"nice-search-row nice-search-row-loading\" ng-if=\"loading && results.length == 0\">\n" +
5645
5783
  "<nice-loader visible-when=\"!loading\"></nice-loader>\n" +
5646
5784
  "</div>\n" +