nice-elements 1.16.0 → 1.16.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nice-elements",
3
- "version": "1.16.0",
3
+ "version": "1.16.2",
4
4
  "description": "Nice elements used in olaii angular 1.x webapps.",
5
5
  "main": "dist/nice.js",
6
6
  "license": "MIT",
@@ -1,9 +1,9 @@
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>
1
+ <div class="nice-notification" ng-class="{ 'has-icon': icon }">
2
+ <div class="nice-notification-inner">
3
+ <nice-icon ng-if="icon" class="nice-notification-icon" icon="{{ icon }}"></nice-icon>
4
+ <div class="nice-notification-content">
5
+ <div class="nice-notification-title" ng-show="title" ng-bind-html="title"></div>
6
+ <div class="nice-notification-message" ng-bind-html="message"></div>
7
7
  </div>
8
8
  </div>
9
9
  </div>
@@ -10,7 +10,7 @@
10
10
  display: flex;
11
11
  flex-direction: column;
12
12
  flex-wrap: wrap-reverse;
13
- align-items: flex-end;
13
+ align-items: flex-start;
14
14
  align-content: flex-start;
15
15
  column-gap: 10px;
16
16
  max-height: calc(100vh - var(--nice-notification-top));
@@ -49,7 +49,7 @@
49
49
  }
50
50
  }
51
51
 
52
- .notification {
52
+ .nice-notification {
53
53
  // Single grid row animated between 0fr and 1fr: lets the card collapse/expand
54
54
  // to its natural height so the cards below slide smoothly, without JS
55
55
  display: grid;
@@ -60,6 +60,7 @@
60
60
  border-radius: $border-radius-base;
61
61
  cursor: pointer;
62
62
  font-weight: normal;
63
+ max-width: 500px;
63
64
  min-width: 300px;
64
65
  color: $nice-notification-color;
65
66
  background: $nice-notification-bg;
@@ -83,7 +84,7 @@
83
84
  }
84
85
  }
85
86
 
86
- .notification-inner {
87
+ .nice-notification-inner {
87
88
  min-height: 0; // required for the 0fr collapse
88
89
  overflow: hidden;
89
90
  display: flex;
@@ -92,7 +93,7 @@
92
93
  }
93
94
 
94
95
  // Icon sits left of the title/message, aligned with the first line
95
- .notification-icon {
96
+ .nice-notification-icon {
96
97
  flex: 0 0 auto;
97
98
  width: 20px;
98
99
  height: 20px;
@@ -100,12 +101,12 @@
100
101
  flex-shrink: 0;
101
102
  }
102
103
 
103
- .notification-content {
104
+ .nice-notification-content {
104
105
  flex: 1 1 auto;
105
106
  min-width: 0;
106
107
  }
107
108
 
108
- .notification-title {
109
+ .nice-notification-title {
109
110
  display: block;
110
111
  text-align: left;
111
112
  font-size: 1em;
@@ -5,33 +5,31 @@
5
5
 
6
6
  <!------------------------- Field ------------------------->
7
7
  <div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
8
- <div class="input-group" ng-class="{ 'disabled': isDisabled }">
9
- <input class="form-control" type="text" id="{{ id }}" ng-model="modelString" ng-keypress="keypress($event)" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-required="required" tabindex="{{ tabIndex }}">
8
+ <div class="nice-search-field" click-outside="closeDropdown()" is-open="{{ results.length > 0 || noResults }}">
9
+ <div class="input-group" ng-class="{ 'disabled': isDisabled }">
10
+ <input class="form-control" type="text" id="{{ id }}" ng-model="modelString" ng-keypress="keypress($event)" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-required="required" tabindex="{{ tabIndex }}">
10
11
 
11
- <button type="button" class="btn input-group-addon" ng-click="search()" ng-if="!model" ng-disabled="isDisabled">
12
- <!-- <nice-icon ng-show="loading" icon="icon-loader" class="d-block nice-animation-spin"></nice-icon> -->
13
- <nice-icon ng-show="!loading" icon="icon-search"></nice-icon>
14
- <nice-loader ng-if="loading"></nice-loader>
15
- </button>
12
+ <button type="button" class="btn input-group-addon" ng-click="search()" ng-if="!model" ng-disabled="isDisabled">
13
+ <!-- <nice-icon ng-show="loading" icon="icon-loader" class="d-block nice-animation-spin"></nice-icon> -->
14
+ <nice-icon ng-show="!loading" icon="icon-search"></nice-icon>
15
+ <nice-loader ng-if="loading"></nice-loader>
16
+ </button>
16
17
 
17
- <button type="button" class="btn input-group-addon" ng-click="remove()" ng-if="model" ng-disabled="isDisabled">
18
- <nice-icon ng-show="!loading" icon="icon-x"></nice-icon>
19
- </button>
20
- </div>
21
- </div>
22
- </div>
18
+ <button type="button" class="btn input-group-addon" ng-click="remove()" ng-if="model" ng-disabled="isDisabled">
19
+ <nice-icon ng-show="!loading" icon="icon-x"></nice-icon>
20
+ </button>
21
+ </div>
23
22
 
24
- <div class="row" ng-if="noResults || results.length">
25
- <div ng-class="labelWidth ? labelWidth : 'col-sm-4'" ng-if="title"></div>
26
- <div class="nice-field col-xs-12" ng-class="fieldWidth ? fieldWidth : 'col-sm-8'">
27
- <div class="nice-dropdown-empty" ng-if="noResults">
28
- <div class="nice-search-row" translate translate-context="Nice">No results found.</div>
29
- </div>
23
+ <!------------------------- Dropdown ------------------------->
24
+ <div class="nice-dropdown-empty" ng-if="noResults">
25
+ <div class="nice-search-row" translate translate-context="Nice">No results found.</div>
26
+ </div>
30
27
 
31
- <div class="nice-dropdown" ng-if="results.length">
32
- <div ng-repeat="result in results" class="nice-search-row" ng-class="{'active': selectedIndex == $index}" ng-click="selectRow(result)">
33
- <span class="text-bold" ng-if="!hasRowTemplate">{{ result[keyForInputLabel] }}</span>
34
- <div ng-if="hasRowTemplate" nice-search-row-transclude></div>
28
+ <div class="nice-dropdown" ng-if="results.length">
29
+ <div ng-repeat="result in results" class="nice-search-row" ng-class="{'active': selectedIndex == $index}" ng-click="selectRow(result)">
30
+ <span class="text-bold" ng-if="!hasRowTemplate">{{ result[keyForInputLabel] }}</span>
31
+ <div ng-if="hasRowTemplate" nice-search-row-transclude></div>
32
+ </div>
35
33
  </div>
36
34
  </div>
37
35
  </div>
@@ -119,19 +119,12 @@ angular.module('niceElements')
119
119
  //scope.$apply();
120
120
  };
121
121
 
122
- // Close the dropdown if clicked outside
123
- const onClick = function (event) {
124
- const isClickedElementChildOfPopup = element.find(event.target).length > 0;
125
-
126
- if (isClickedElementChildOfPopup) return;
127
-
122
+ // Close the dropdown (called by click-outside in the template)
123
+ scope.closeDropdown = function () {
128
124
  scope.results = [];
129
125
  scope.noResults = false;
130
- scope.$apply();
131
126
  };
132
127
 
133
- angular.element(element).on('click', onClick);
134
-
135
128
  // Keyboard up/down on search results
136
129
  const onKeyDown = function (event) {
137
130
  if ((event.keyCode == 38 || event.keyCode == 40 || event.keyCode == 13 || event.keyCode == 27) && scope.results && scope.results.length > 0) {
@@ -163,7 +156,6 @@ angular.module('niceElements')
163
156
  angular.element(element).on('keydown', onKeyDown);
164
157
 
165
158
  scope.$on('$destroy', function () {
166
- angular.element(element).off('click', onClick);
167
159
  angular.element(element).off('keydown', onKeyDown);
168
160
  });
169
161
 
@@ -216,10 +208,15 @@ angular.module('niceElements')
216
208
  }
217
209
  $scope.requests = $scope.requests + 1;
218
210
  const requestNumber = angular.copy($scope.requests);
211
+ // $timeout so the view updates also when refreshFunction returns a native Promise
219
212
  $scope.refreshFunction($scope.modelString).then(function (response) {
220
- updateList(response, requestNumber);
213
+ $timeout(function () {
214
+ updateList(response, requestNumber);
215
+ });
221
216
  }, function (error) {
222
- $scope.loading = false;
217
+ $timeout(function () {
218
+ $scope.loading = false;
219
+ });
223
220
  });
224
221
  // Why was this here?
225
222
  // $scope.model = $scope.modelString;
@@ -24,13 +24,19 @@
24
24
  }
25
25
  }
26
26
 
27
+ // Positioning parent of the dropdown (wraps the input)
28
+ .nice-search-field {
29
+ position: relative;
30
+ }
31
+
32
+ // Dropdown sits right under the input, same width
27
33
  .nice-dropdown {
28
34
  position: absolute;
29
35
  z-index: 999;
30
- //top: 35px;
36
+ top: 100%;
31
37
  left: 0;
32
- // right: 0;
33
- //min-width: 340px;
38
+ right: 0;
39
+ margin-top: 4px;
34
40
  max-height: 300px;
35
41
  background-color: white;
36
42
  border-radius: $nice-border-radius;
@@ -40,10 +46,6 @@
40
46
  -webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.175);
41
47
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.175);
42
48
 
43
- top: -13px;
44
- margin: 15px;
45
- right: 0;
46
-
47
49
  .nice-search-row {
48
50
  padding: 10px 15px;
49
51
  z-index: 1000;
@@ -79,9 +81,6 @@
79
81
 
80
82
  .nice-dropdown-empty {
81
83
  @extend .nice-dropdown;
82
- top: -13px;
83
- margin: 15px;
84
- right: 0;
85
84
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
86
85
 
87
86
  .nice-search-row {
@@ -8,7 +8,7 @@
8
8
  <nice-popup trigger="manual" is-open="isOpen" placement="{{ placement }}" same-width="true">
9
9
  <nice-popup-target>
10
10
  <div class="nice-search-button input-group" ng-class="{ 'disabled': isDisabled }">
11
- <input class="form-control" type="text" id="{{ id }}" ng-model="model" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-focus="onFocus()" ng-required="required" tabindex="{{ tabIndex }}">
11
+ <input class="form-control" type="text" id="{{ id }}" ng-model="modelAccessor" ng-model-options="{ getterSetter: true }" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-focus="onFocus()" ng-required="required" tabindex="{{ tabIndex }}">
12
12
 
13
13
  <button type="button" class="btn input-group-addon" ng-disabled="isDisabled" ng-click="buttonClicked()">
14
14
  <nice-icon ng-show="!loading && model != ''" icon="icon-x"></nice-icon>
@@ -24,7 +24,7 @@ angular.module('niceElements')
24
24
  labelWidth: '@',
25
25
  refreshFunction: '=',
26
26
  refreshSelectedCallback: '=',
27
- onSelect: '=',
27
+ onSelect: '&?',
28
28
  onChange: '&?',
29
29
  noMargin: '@',
30
30
  tabIndex: '@',
@@ -48,6 +48,14 @@ angular.module('niceElements')
48
48
  if (!$scope.model) $scope.model = "";
49
49
  if (!$scope.placement) { $scope.placement = "bottom-start"; }
50
50
 
51
+ // ------------------- Model accessor -------------------
52
+ // Input lives inside nice-popup's transcluded (child) scope, so a plain ng-model="model"
53
+ // would write to the child scope only. Bind through a getter/setter instead.
54
+ $scope.modelAccessor = function (value) {
55
+ if (arguments.length) $scope.model = value;
56
+ return $scope.model;
57
+ };
58
+
51
59
  // ------------------- On focus -------------------
52
60
  $scope.onFocus = function () {
53
61
  if ($scope.showDropdown && $scope.results.length == 0) {
@@ -151,7 +159,10 @@ angular.module('niceElements')
151
159
  // ------------------------ Select item ------------------------
152
160
  $scope.selectItem = function (item) {
153
161
  if ($scope.onSelect) {
154
- $scope.onSelect(item);
162
+ // Supports on-select="fn(model)" (expression) and on-select="fn" (function reference):
163
+ // the expression form is evaluated directly, the reference form returns the function to call.
164
+ const result = $scope.onSelect({ model: item });
165
+ if (angular.isFunction(result)) result(item);
155
166
  $scope.clear();
156
167
  $scope.close();
157
168
  }
@@ -36,6 +36,12 @@ angular.module('niceElements')
36
36
  return;
37
37
  }
38
38
 
39
+ // the click removed its own target (e.g. a re-rendered ng-repeat calendar day),
40
+ // so we can't tell where it was - treat it as an inside click
41
+ if (!document.documentElement.contains(e.target)) {
42
+ return;
43
+ }
44
+
39
45
  // loop through the available elements, looking for classes in the class list that might match and so will eat
40
46
  for (element = e.target; element; element = element.parentNode) {
41
47
  // check if the element is the same element the directive is attached to and exit if so (props @CosticaPuntaru)
@@ -148,7 +148,7 @@ angular.module('niceElements')
148
148
 
149
149
  const service = {
150
150
  name: "Nice elements",
151
- version: "1.16.0",
151
+ version: "1.16.2",
152
152
  getHeader: function () {
153
153
  return {};
154
154
  },