nice-elements 1.11.1 → 1.11.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/.vscode/settings.json +18 -18
- package/CHANGELOG.md +515 -510
- package/LICENSE.md +21 -21
- package/README.md +98 -98
- package/bower.json +10 -10
- package/dist/nice.js +8357 -8387
- package/dist/nice.min.js +1 -1
- package/dist/style.css +14 -11
- package/dist/style.css.map +1 -1
- package/dist/style.min.css +8 -8
- package/eslint.config.mjs +32 -32
- package/package.json +45 -45
- package/src/components/nice-button/nice-button.html +4 -4
- package/src/components/nice-button/nice-button.js +41 -41
- package/src/components/nice-button/nice-button.scss +16 -16
- package/src/components/nice-button-toggle/nice-button-toggle.html +9 -9
- package/src/components/nice-button-toggle/nice-button-toggle.js +23 -23
- package/src/components/nice-button-toggle/nice-button-toggle.scss +2 -2
- package/src/components/nice-calendar/nice-calendar.html +91 -91
- package/src/components/nice-calendar/nice-calendar.js +346 -336
- package/src/components/nice-calendar/nice-calendar.scss +288 -285
- package/src/components/nice-checkbox/nice-checkbox.html +5 -5
- package/src/components/nice-checkbox/nice-checkbox.js +34 -34
- package/src/components/nice-checkbox/nice-checkbox.scss +91 -91
- package/src/components/nice-choice/nice-choice.html +18 -18
- package/src/components/nice-choice/nice-choice.js +212 -212
- package/src/components/nice-choice/nice-choice.scss +110 -110
- package/src/components/nice-click-outside/nice-click-outside.js +105 -105
- package/src/components/nice-comment/nice-comment.html +10 -10
- package/src/components/nice-comment/nice-comment.js +71 -71
- package/src/components/nice-comment/nice-comment.scss +39 -39
- package/src/components/nice-date/nice-date.html +79 -79
- package/src/components/nice-date/nice-date.js +333 -333
- package/src/components/nice-date/nice-date.scss +305 -305
- package/src/components/nice-date-input/nice-date-input.html +41 -41
- package/src/components/nice-date-input/nice-date-input.js +111 -111
- package/src/components/nice-date-input/nice-date-input.scss +45 -45
- package/src/components/nice-date-range/nice-date-range.html +15 -15
- package/src/components/nice-date-range/nice-date-range.js +78 -78
- package/src/components/nice-date-range/nice-date-range.scss +390 -390
- package/src/components/nice-datetime-picker/nice-datetime-picker.html +29 -29
- package/src/components/nice-datetime-picker/nice-datetime-picker.js +89 -89
- package/src/components/nice-datetime-picker/nice-datetime-picker.scss +428 -428
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.html +55 -55
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.js +248 -248
- package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.scss +73 -73
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +44 -44
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +175 -175
- package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.scss +127 -127
- package/src/components/nice-dropdown/nice-dropdown.html +61 -61
- package/src/components/nice-dropdown/nice-dropdown.js +517 -517
- package/src/components/nice-dropdown/nice-dropdown.scss +262 -262
- package/src/components/nice-dropdown-date/nice-dropdown-date.html +28 -28
- package/src/components/nice-dropdown-date/nice-dropdown-date.js +132 -132
- package/src/components/nice-dropdown-date/nice-dropdown-date.scss +87 -87
- package/src/components/nice-dropdown-old/nice-dropdown-old.html +44 -44
- package/src/components/nice-dropdown-old/nice-dropdown-old.js +330 -330
- package/src/components/nice-dropdown-old/nice-dropdown-old.scss +129 -129
- package/src/components/nice-dtp/nice-dtp.html +91 -91
- package/src/components/nice-dtp/nice-dtp.js +835 -835
- package/src/components/nice-help/nice-help.html +6 -6
- package/src/components/nice-help/nice-help.js +58 -58
- package/src/components/nice-help/nice-help.scss +78 -78
- package/src/components/nice-input/nice-input.html +48 -48
- package/src/components/nice-input/nice-input.js +246 -246
- package/src/components/nice-input/nice-input.scss +130 -130
- package/src/components/nice-label/nice-label.html +10 -10
- package/src/components/nice-label/nice-label.js +32 -32
- package/src/components/nice-loader/nice-loader.html +6 -6
- package/src/components/nice-loader/nice-loader.js +28 -28
- package/src/components/nice-loader/nice-loader.scss +47 -47
- package/src/components/nice-no-data/nice-no-data.html +3 -3
- package/src/components/nice-no-data/nice-no-data.js +27 -27
- package/src/components/nice-no-data/nice-no-data.scss +26 -26
- package/src/components/nice-notification/nice-notification.html +3 -3
- package/src/components/nice-notification/nice-notification.js +124 -124
- package/src/components/nice-notification/nice-notification.scss +66 -66
- package/src/components/nice-number/nice-number.html +40 -40
- package/src/components/nice-number/nice-number.js +172 -172
- package/src/components/nice-number/nice-number.scss +18 -18
- package/src/components/nice-on-scroll/nice-on-scroll.js +17 -17
- package/src/components/nice-percent/nice-percent.html +24 -24
- package/src/components/nice-percent/nice-percent.js +95 -95
- package/src/components/nice-pill/nice-pill.html +3 -3
- package/src/components/nice-pill/nice-pill.js +29 -29
- package/src/components/nice-pill/nice-pill.scss +25 -25
- package/src/components/nice-popup/nice-popup.html +6 -6
- package/src/components/nice-popup/nice-popup.js +122 -122
- package/src/components/nice-popup/nice-popup.scss +43 -43
- package/src/components/nice-progress-bar/nice-progress-bar.html +15 -15
- package/src/components/nice-progress-bar/nice-progress-bar.js +55 -55
- package/src/components/nice-progress-bar/nice-progress-bar.scss +47 -47
- package/src/components/nice-quantity/nice-quantity.html +22 -22
- package/src/components/nice-quantity/nice-quantity.js +57 -57
- package/src/components/nice-quantity/nice-quantity.scss +51 -51
- package/src/components/nice-search/nice-search.html +44 -44
- package/src/components/nice-search/nice-search.js +243 -243
- package/src/components/nice-search/nice-search.scss +90 -90
- package/src/components/nice-search2/nice-search2.html +32 -32
- package/src/components/nice-search2/nice-search2.js +267 -267
- package/src/components/nice-search2/nice-search2.scss +80 -80
- package/src/components/nice-slot/nice-slot.html +10 -10
- package/src/components/nice-slot/nice-slot.js +31 -31
- package/src/components/nice-steps/nice-steps.scss +81 -81
- package/src/components/nice-svgs/nice-svgs.html +1275 -1275
- package/src/components/nice-svgs/nice-svgs.js +19 -19
- package/src/components/nice-table/nice-table.html +38 -38
- package/src/components/nice-table/nice-table.js +60 -60
- package/src/components/nice-table/nice-table.scss +112 -112
- package/src/components/nice-time-picker/nice-time-picker.html +43 -43
- package/src/components/nice-time-picker/nice-time-picker.js +85 -85
- package/src/components/nice-time-picker/nice-time-picker.scss +37 -37
- package/src/components/nice-title/nice-title.html +3 -3
- package/src/components/nice-title/nice-title.js +21 -21
- package/src/components/nice-toast/nice-toast.html +2 -2
- package/src/components/nice-toast/nice-toast.js +56 -56
- package/src/components/nice-toast/nice-toast.scss +74 -74
- package/src/components/nice-toggle/nice-toggle.html +12 -12
- package/src/components/nice-toggle/nice-toggle.js +55 -55
- package/src/components/nice-toggle/nice-toggle.scss +131 -131
- package/src/components/nice-tooltip/_nice-tooltip.scss +55 -55
- package/src/components/nice-tooltip/nice-tooltip.js +84 -84
- package/src/components/nice-upload/nice-upload.html +22 -22
- package/src/components/nice-upload/nice-upload.js +159 -159
- package/src/components/nice-upload/nice-upload.scss +85 -85
- package/src/components/nice-view/_nice-view.scss +62 -62
- package/src/components/nice-view/nice-view.html +12 -12
- package/src/components/nice-view/nice-view.js +30 -30
- package/src/components/nice-virtual-scroll/_nice-virtual-scroll.scss +17 -17
- package/src/components/nice-virtual-scroll/nice-virtual-scroll.html +12 -12
- package/src/components/nice-virtual-scroll/nice-virtual-scroll.js +70 -70
- package/src/components/nice-wrapper/_nice-wrapper.scss +87 -87
- package/src/components/nice-wrapper/nice-wrapper.html +12 -12
- package/src/components/nice-wrapper/nice-wrapper.js +44 -44
- package/src/components/nice-yesno/nice-yesno.html +14 -14
- package/src/components/nice-yesno/nice-yesno.js +111 -111
- package/src/components/nice-yesno/nice-yesno.scss +95 -95
- package/src/filters/nice-date.js +17 -17
- package/src/filters/nice-highlight.js +16 -16
- package/src/modals/nice-multilangual-modal/nice-multilangual-modal.html +30 -30
- package/src/modals/nice-multilangual-modal/nice-multilangual-modal.js +67 -67
- package/src/modals/nice-multilangual-modal/nice-multilangual-modal.scss +19 -19
- package/src/nice.js +2 -2
- package/src/services/nice-service.js +22 -22
- package/src/styles/_bootstrap-variables.scss +178 -178
- package/src/styles/_nice-buttons.scss +612 -612
- package/src/styles/_nice-common.scss +471 -471
- package/src/styles/_nice-ngdialog.scss +85 -85
- package/src/styles/_nice-spacing.scss +283 -283
- package/src/styles/_nice.scss +70 -70
- package/src/styles/_variables.scss +191 -191
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
<ng-form class="nice-component nice-input nice-search2" ng-class="{ 'margin-bottom-0' : noMargin, 'nice-component-inline': isInline }" name="form">
|
|
2
|
-
<div class="row">
|
|
3
|
-
<!------------------------- Title ------------------------->
|
|
4
|
-
<nice-title text="title || niceTitle" help="help" required="required" label-width="labelWidth"></nice-title>
|
|
5
|
-
|
|
6
|
-
<!------------------------- Field ------------------------->
|
|
7
|
-
<div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]" click-outside="close()">
|
|
8
|
-
<div class="nice-search-button input-group" ng-class="{ 'disabled': isDisabled }">
|
|
9
|
-
<input class="form-control" type="text" id="{{ id }}" ng-model="model" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-focus="onFocus()" tabindex="{{ tabIndex }}">
|
|
10
|
-
|
|
11
|
-
<button type="button" class="btn input-group-addon" ng-disabled="isDisabled" ng-click="buttonClicked()">
|
|
12
|
-
<nice-icon ng-show="!loading && model != ''" icon="icon-x"></nice-icon>
|
|
13
|
-
<nice-icon ng-show="!loading && model == ''" icon="icon-search"></nice-icon>
|
|
14
|
-
<nice-loader ng-if="loading"></nice-loader>
|
|
15
|
-
</button>
|
|
16
|
-
</div>
|
|
17
|
-
|
|
18
|
-
<div class="nice-search-dropdown-wrapper">
|
|
19
|
-
<div class="nice-search-dropdown" ng-if="showDropdown && isOpen">
|
|
20
|
-
<div class="nice-search-row nice-search-row-loading" ng-if="loading && results.length == 0">
|
|
21
|
-
<nice-loader ng-if="loading"></nice-loader>
|
|
22
|
-
</div>
|
|
23
|
-
|
|
24
|
-
<div class="nice-search-row nice-search-row-empty" ng-if="!loading && results.length == 0" translate translate-context="Nice">No results found.</div>
|
|
25
|
-
|
|
26
|
-
<div ng-repeat="result in results" class="nice-search-row" ng-class="{'active': selectedIndex == $index}" ng-click="selectItem(result)">
|
|
27
|
-
<ng-transclude>{{ result[keyForInputLabel] }}</ng-transclude>
|
|
28
|
-
</div>
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
1
|
+
<ng-form class="nice-component nice-input nice-search2" ng-class="{ 'margin-bottom-0' : noMargin, 'nice-component-inline': isInline }" name="form">
|
|
2
|
+
<div class="row">
|
|
3
|
+
<!------------------------- Title ------------------------->
|
|
4
|
+
<nice-title text="title || niceTitle" help="help" required="required" label-width="labelWidth"></nice-title>
|
|
5
|
+
|
|
6
|
+
<!------------------------- Field ------------------------->
|
|
7
|
+
<div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]" click-outside="close()">
|
|
8
|
+
<div class="nice-search-button input-group" ng-class="{ 'disabled': isDisabled }">
|
|
9
|
+
<input class="form-control" type="text" id="{{ id }}" ng-model="model" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-focus="onFocus()" tabindex="{{ tabIndex }}">
|
|
10
|
+
|
|
11
|
+
<button type="button" class="btn input-group-addon" ng-disabled="isDisabled" ng-click="buttonClicked()">
|
|
12
|
+
<nice-icon ng-show="!loading && model != ''" icon="icon-x"></nice-icon>
|
|
13
|
+
<nice-icon ng-show="!loading && model == ''" icon="icon-search"></nice-icon>
|
|
14
|
+
<nice-loader ng-if="loading"></nice-loader>
|
|
15
|
+
</button>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<div class="nice-search-dropdown-wrapper">
|
|
19
|
+
<div class="nice-search-dropdown" ng-if="showDropdown && isOpen">
|
|
20
|
+
<div class="nice-search-row nice-search-row-loading" ng-if="loading && results.length == 0">
|
|
21
|
+
<nice-loader ng-if="loading"></nice-loader>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<div class="nice-search-row nice-search-row-empty" ng-if="!loading && results.length == 0" translate translate-context="Nice">No results found.</div>
|
|
25
|
+
|
|
26
|
+
<div ng-repeat="result in results" class="nice-search-row" ng-class="{'active': selectedIndex == $index}" ng-click="selectItem(result)">
|
|
27
|
+
<ng-transclude>{{ result[keyForInputLabel] }}</ng-transclude>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
33
|
</ng-form>
|
|
@@ -1,267 +1,267 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @ngdoc directive
|
|
5
|
-
* @name niceElements.directive:niceSearch2
|
|
6
|
-
* @description
|
|
7
|
-
* # niceSearch2
|
|
8
|
-
*/
|
|
9
|
-
angular.module('niceElements')
|
|
10
|
-
.directive('niceSearch2', function () {
|
|
11
|
-
return {
|
|
12
|
-
transclude: true,
|
|
13
|
-
templateUrl: 'src/components/nice-search2/nice-search2.html',
|
|
14
|
-
restrict: 'E',
|
|
15
|
-
scope: {
|
|
16
|
-
model: '=',
|
|
17
|
-
isDisabled: '=',
|
|
18
|
-
showDropdown: '=',
|
|
19
|
-
title: '@?',
|
|
20
|
-
niceTitle: '@?',
|
|
21
|
-
placeholder: '@',
|
|
22
|
-
fieldWidth: '@',
|
|
23
|
-
labelWidth: '@',
|
|
24
|
-
refreshFunction: '=',
|
|
25
|
-
refreshSelectedCallback: '=',
|
|
26
|
-
onSelect: '=',
|
|
27
|
-
onChange: '&?',
|
|
28
|
-
noMargin: '@',
|
|
29
|
-
tabIndex: '@',
|
|
30
|
-
keyForInputLabel: '@',
|
|
31
|
-
debounceTime: '@',
|
|
32
|
-
isInline: '=',
|
|
33
|
-
help: '@',
|
|
34
|
-
placement: '@', // Describes the preferred placement of the popper
|
|
35
|
-
},
|
|
36
|
-
controller: function ($scope, $timeout, $element) {
|
|
37
|
-
$scope.loading = false;
|
|
38
|
-
$scope.isOpen = false;
|
|
39
|
-
$scope.debounce = null;
|
|
40
|
-
$scope.results = [];
|
|
41
|
-
$scope.noResults = false;
|
|
42
|
-
$scope.selectedIndex = 0;
|
|
43
|
-
$scope.requestNumber = 0;
|
|
44
|
-
|
|
45
|
-
if (!$scope.debounceTime) $scope.debounceTime = 500;
|
|
46
|
-
if (!$scope.model) $scope.model = "";
|
|
47
|
-
if (!$scope.placement) { $scope.placement = "bottom-start"; }
|
|
48
|
-
|
|
49
|
-
// Setup popper
|
|
50
|
-
// https://popper.js.org/docs/v2/constructors/
|
|
51
|
-
$scope.setupPopper = function () {
|
|
52
|
-
const button = $element[0].getElementsByClassName('nice-search-button')[0];
|
|
53
|
-
const tooltip = $element[0].getElementsByClassName('nice-search-dropdown-wrapper')[0];
|
|
54
|
-
$scope.popper = Popper.createPopper(button, tooltip, {
|
|
55
|
-
strategy: 'fixed',
|
|
56
|
-
placement: $scope.placement,
|
|
57
|
-
modifiers: [
|
|
58
|
-
{
|
|
59
|
-
name: 'offset',
|
|
60
|
-
options: {
|
|
61
|
-
offset: [0, 5],
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: "sameWidth",
|
|
66
|
-
enabled: true,
|
|
67
|
-
phase: "beforeWrite",
|
|
68
|
-
requires: ["computeStyles"],
|
|
69
|
-
fn: function (e) {
|
|
70
|
-
const state = e.state;
|
|
71
|
-
state.styles.popper.width = state.rects.reference.width + "px";
|
|
72
|
-
},
|
|
73
|
-
effect: function (e) {
|
|
74
|
-
const state = e.state;
|
|
75
|
-
state.elements.popper.style.width = state.elements.reference.offsetWidth + "px";
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
],
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
$timeout(function () {
|
|
83
|
-
$scope.setupPopper();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// ------------------- On focus -------------------
|
|
88
|
-
$scope.onFocus = function () {
|
|
89
|
-
if ($scope.showDropdown && $scope.results.length == 0) {
|
|
90
|
-
$scope.getData($scope.model);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
$scope.open();
|
|
94
|
-
|
|
95
|
-
const input = $element[0].getElementsByTagName('input')[0];
|
|
96
|
-
if (input) input.focus();
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// ------------------- On blur -------------------
|
|
101
|
-
$scope.onBlur = function () {
|
|
102
|
-
$scope.close();
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// ------------------- On focus -------------------
|
|
107
|
-
$scope.open = function () {
|
|
108
|
-
$scope.isOpen = true;
|
|
109
|
-
$timeout(function () {
|
|
110
|
-
if ($scope.popper) $scope.popper.update();
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// ------------------- On blur -------------------
|
|
116
|
-
$scope.close = function () {
|
|
117
|
-
$scope.isOpen = false;
|
|
118
|
-
|
|
119
|
-
const input = $element[0].getElementsByTagName('input')[0];
|
|
120
|
-
if (input) input.blur();
|
|
121
|
-
|
|
122
|
-
$timeout(function () {
|
|
123
|
-
$scope.popper.update();
|
|
124
|
-
})
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// ------------------- Update search -------------------
|
|
129
|
-
$scope.updateSearch = function () {
|
|
130
|
-
if ($scope.debounce) {
|
|
131
|
-
$timeout.cancel($scope.debounce);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
$scope.debounce = $timeout(function () {
|
|
135
|
-
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
136
|
-
$scope.getData($scope.model);
|
|
137
|
-
}, $scope.debounceTime);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// ------------------- Get data -------------------
|
|
142
|
-
$scope.getData = function (keywords) {
|
|
143
|
-
if ($scope.refreshFunction != null) {
|
|
144
|
-
$scope.loading = true;
|
|
145
|
-
$scope.requestNumber += 1;
|
|
146
|
-
const requestNumber = angular.copy($scope.requestNumber);
|
|
147
|
-
$scope.refreshFunction(keywords).then(function (results) {
|
|
148
|
-
if ($scope.requestNumber == requestNumber) {
|
|
149
|
-
$timeout(function () {
|
|
150
|
-
$scope.open();
|
|
151
|
-
$scope.loading = false;
|
|
152
|
-
|
|
153
|
-
$scope.noResults = results.length == 0;
|
|
154
|
-
$scope.results = results;
|
|
155
|
-
|
|
156
|
-
if (!$scope.noResults) {
|
|
157
|
-
$scope.selectedIndex = 0;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}, function () {
|
|
162
|
-
$scope.loading = false;
|
|
163
|
-
$scope.close();
|
|
164
|
-
});
|
|
165
|
-
} else {
|
|
166
|
-
$scope.loading = false;
|
|
167
|
-
// $scope.close();
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
// ------------------------ Button clicked ------------------------
|
|
172
|
-
$scope.buttonClicked = function () {
|
|
173
|
-
if (!$scope.loading && $scope.model != '') $scope.clear();
|
|
174
|
-
if (!$scope.loading && $scope.model == '') $scope.onFocus();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// ------------------------ If search button is clicked set focus or make request ------------------------
|
|
178
|
-
$scope.search = function () {
|
|
179
|
-
if (!$scope.isDisabled) {
|
|
180
|
-
if ($scope.showDropdown) {
|
|
181
|
-
$scope.updateSearch();
|
|
182
|
-
}
|
|
183
|
-
$scope.focus();
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// ------------------------ Clear search ------------------------
|
|
189
|
-
$scope.clear = function () {
|
|
190
|
-
$scope.model = "";
|
|
191
|
-
$timeout(function () {
|
|
192
|
-
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// ------------------------ Select item ------------------------
|
|
198
|
-
$scope.selectItem = function (item) {
|
|
199
|
-
if ($scope.onSelect) {
|
|
200
|
-
$scope.onSelect(item);
|
|
201
|
-
$scope.clear();
|
|
202
|
-
$scope.close();
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// ----------------------------------- Scroll to hover -----------------------------------
|
|
208
|
-
$scope.scrollToHover = function (notSmooth) {
|
|
209
|
-
const dropdownMenu = $element[0].getElementsByClassName("nice-dropdown")[0];
|
|
210
|
-
const hoverItem = dropdownMenu.getElementsByClassName("active")[0];
|
|
211
|
-
if (hoverItem) {
|
|
212
|
-
const topPos = hoverItem.offsetTop;
|
|
213
|
-
dropdownMenu.scroll({
|
|
214
|
-
top: topPos - 120,
|
|
215
|
-
left: 0,
|
|
216
|
-
behavior: notSmooth ? 'auto' : 'smooth'
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
// ----------------------------------- Watch for keydown and keypress -----------------------------------
|
|
223
|
-
$element.bind("keydown keypress", function (event) {
|
|
224
|
-
// Arrow Up
|
|
225
|
-
if (event.keyCode == 38) {
|
|
226
|
-
event.preventDefault();
|
|
227
|
-
$timeout(function () {
|
|
228
|
-
if ($scope.selectedIndex > 0) {
|
|
229
|
-
$scope.selectedIndex -= 1;
|
|
230
|
-
$timeout(function () {
|
|
231
|
-
$scope.scrollToHover();
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Arrow Down
|
|
238
|
-
if (event.keyCode == 40) {
|
|
239
|
-
event.preventDefault();
|
|
240
|
-
$timeout(function () {
|
|
241
|
-
if ($scope.results && $scope.selectedIndex < $scope.results.length - 1) {
|
|
242
|
-
$scope.selectedIndex += 1;
|
|
243
|
-
$timeout(function () {
|
|
244
|
-
$scope.scrollToHover();
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Enter
|
|
251
|
-
if (event.keyCode == 13) {
|
|
252
|
-
event.preventDefault();
|
|
253
|
-
$timeout(function () {
|
|
254
|
-
$scope.selectItem($scope.results[$scope.selectedIndex], $scope.selectedIndex);
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Escape
|
|
259
|
-
if (event.keyCode == 27) {
|
|
260
|
-
$timeout(function () {
|
|
261
|
-
$scope.close();
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @ngdoc directive
|
|
5
|
+
* @name niceElements.directive:niceSearch2
|
|
6
|
+
* @description
|
|
7
|
+
* # niceSearch2
|
|
8
|
+
*/
|
|
9
|
+
angular.module('niceElements')
|
|
10
|
+
.directive('niceSearch2', function () {
|
|
11
|
+
return {
|
|
12
|
+
transclude: true,
|
|
13
|
+
templateUrl: 'src/components/nice-search2/nice-search2.html',
|
|
14
|
+
restrict: 'E',
|
|
15
|
+
scope: {
|
|
16
|
+
model: '=',
|
|
17
|
+
isDisabled: '=',
|
|
18
|
+
showDropdown: '=',
|
|
19
|
+
title: '@?',
|
|
20
|
+
niceTitle: '@?',
|
|
21
|
+
placeholder: '@',
|
|
22
|
+
fieldWidth: '@',
|
|
23
|
+
labelWidth: '@',
|
|
24
|
+
refreshFunction: '=',
|
|
25
|
+
refreshSelectedCallback: '=',
|
|
26
|
+
onSelect: '=',
|
|
27
|
+
onChange: '&?',
|
|
28
|
+
noMargin: '@',
|
|
29
|
+
tabIndex: '@',
|
|
30
|
+
keyForInputLabel: '@',
|
|
31
|
+
debounceTime: '@',
|
|
32
|
+
isInline: '=',
|
|
33
|
+
help: '@',
|
|
34
|
+
placement: '@', // Describes the preferred placement of the popper
|
|
35
|
+
},
|
|
36
|
+
controller: function ($scope, $timeout, $element) {
|
|
37
|
+
$scope.loading = false;
|
|
38
|
+
$scope.isOpen = false;
|
|
39
|
+
$scope.debounce = null;
|
|
40
|
+
$scope.results = [];
|
|
41
|
+
$scope.noResults = false;
|
|
42
|
+
$scope.selectedIndex = 0;
|
|
43
|
+
$scope.requestNumber = 0;
|
|
44
|
+
|
|
45
|
+
if (!$scope.debounceTime) $scope.debounceTime = 500;
|
|
46
|
+
if (!$scope.model) $scope.model = "";
|
|
47
|
+
if (!$scope.placement) { $scope.placement = "bottom-start"; }
|
|
48
|
+
|
|
49
|
+
// Setup popper
|
|
50
|
+
// https://popper.js.org/docs/v2/constructors/
|
|
51
|
+
$scope.setupPopper = function () {
|
|
52
|
+
const button = $element[0].getElementsByClassName('nice-search-button')[0];
|
|
53
|
+
const tooltip = $element[0].getElementsByClassName('nice-search-dropdown-wrapper')[0];
|
|
54
|
+
$scope.popper = Popper.createPopper(button, tooltip, {
|
|
55
|
+
strategy: 'fixed',
|
|
56
|
+
placement: $scope.placement,
|
|
57
|
+
modifiers: [
|
|
58
|
+
{
|
|
59
|
+
name: 'offset',
|
|
60
|
+
options: {
|
|
61
|
+
offset: [0, 5],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "sameWidth",
|
|
66
|
+
enabled: true,
|
|
67
|
+
phase: "beforeWrite",
|
|
68
|
+
requires: ["computeStyles"],
|
|
69
|
+
fn: function (e) {
|
|
70
|
+
const state = e.state;
|
|
71
|
+
state.styles.popper.width = state.rects.reference.width + "px";
|
|
72
|
+
},
|
|
73
|
+
effect: function (e) {
|
|
74
|
+
const state = e.state;
|
|
75
|
+
state.elements.popper.style.width = state.elements.reference.offsetWidth + "px";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
$timeout(function () {
|
|
83
|
+
$scope.setupPopper();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
// ------------------- On focus -------------------
|
|
88
|
+
$scope.onFocus = function () {
|
|
89
|
+
if ($scope.showDropdown && $scope.results.length == 0) {
|
|
90
|
+
$scope.getData($scope.model);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
$scope.open();
|
|
94
|
+
|
|
95
|
+
const input = $element[0].getElementsByTagName('input')[0];
|
|
96
|
+
if (input) input.focus();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
// ------------------- On blur -------------------
|
|
101
|
+
$scope.onBlur = function () {
|
|
102
|
+
$scope.close();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
// ------------------- On focus -------------------
|
|
107
|
+
$scope.open = function () {
|
|
108
|
+
$scope.isOpen = true;
|
|
109
|
+
$timeout(function () {
|
|
110
|
+
if ($scope.popper) $scope.popper.update();
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
// ------------------- On blur -------------------
|
|
116
|
+
$scope.close = function () {
|
|
117
|
+
$scope.isOpen = false;
|
|
118
|
+
|
|
119
|
+
const input = $element[0].getElementsByTagName('input')[0];
|
|
120
|
+
if (input) input.blur();
|
|
121
|
+
|
|
122
|
+
$timeout(function () {
|
|
123
|
+
$scope.popper.update();
|
|
124
|
+
})
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
// ------------------- Update search -------------------
|
|
129
|
+
$scope.updateSearch = function () {
|
|
130
|
+
if ($scope.debounce) {
|
|
131
|
+
$timeout.cancel($scope.debounce);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
$scope.debounce = $timeout(function () {
|
|
135
|
+
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
136
|
+
$scope.getData($scope.model);
|
|
137
|
+
}, $scope.debounceTime);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
// ------------------- Get data -------------------
|
|
142
|
+
$scope.getData = function (keywords) {
|
|
143
|
+
if ($scope.refreshFunction != null) {
|
|
144
|
+
$scope.loading = true;
|
|
145
|
+
$scope.requestNumber += 1;
|
|
146
|
+
const requestNumber = angular.copy($scope.requestNumber);
|
|
147
|
+
$scope.refreshFunction(keywords).then(function (results) {
|
|
148
|
+
if ($scope.requestNumber == requestNumber) {
|
|
149
|
+
$timeout(function () {
|
|
150
|
+
$scope.open();
|
|
151
|
+
$scope.loading = false;
|
|
152
|
+
|
|
153
|
+
$scope.noResults = results.length == 0;
|
|
154
|
+
$scope.results = results;
|
|
155
|
+
|
|
156
|
+
if (!$scope.noResults) {
|
|
157
|
+
$scope.selectedIndex = 0;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}, function () {
|
|
162
|
+
$scope.loading = false;
|
|
163
|
+
$scope.close();
|
|
164
|
+
});
|
|
165
|
+
} else {
|
|
166
|
+
$scope.loading = false;
|
|
167
|
+
// $scope.close();
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// ------------------------ Button clicked ------------------------
|
|
172
|
+
$scope.buttonClicked = function () {
|
|
173
|
+
if (!$scope.loading && $scope.model != '') $scope.clear();
|
|
174
|
+
if (!$scope.loading && $scope.model == '') $scope.onFocus();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ------------------------ If search button is clicked set focus or make request ------------------------
|
|
178
|
+
$scope.search = function () {
|
|
179
|
+
if (!$scope.isDisabled) {
|
|
180
|
+
if ($scope.showDropdown) {
|
|
181
|
+
$scope.updateSearch();
|
|
182
|
+
}
|
|
183
|
+
$scope.focus();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
// ------------------------ Clear search ------------------------
|
|
189
|
+
$scope.clear = function () {
|
|
190
|
+
$scope.model = "";
|
|
191
|
+
$timeout(function () {
|
|
192
|
+
if ($scope.onChange) $scope.onChange({ model: $scope.model });
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
// ------------------------ Select item ------------------------
|
|
198
|
+
$scope.selectItem = function (item) {
|
|
199
|
+
if ($scope.onSelect) {
|
|
200
|
+
$scope.onSelect(item);
|
|
201
|
+
$scope.clear();
|
|
202
|
+
$scope.close();
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
// ----------------------------------- Scroll to hover -----------------------------------
|
|
208
|
+
$scope.scrollToHover = function (notSmooth) {
|
|
209
|
+
const dropdownMenu = $element[0].getElementsByClassName("nice-dropdown")[0];
|
|
210
|
+
const hoverItem = dropdownMenu.getElementsByClassName("active")[0];
|
|
211
|
+
if (hoverItem) {
|
|
212
|
+
const topPos = hoverItem.offsetTop;
|
|
213
|
+
dropdownMenu.scroll({
|
|
214
|
+
top: topPos - 120,
|
|
215
|
+
left: 0,
|
|
216
|
+
behavior: notSmooth ? 'auto' : 'smooth'
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
// ----------------------------------- Watch for keydown and keypress -----------------------------------
|
|
223
|
+
$element.bind("keydown keypress", function (event) {
|
|
224
|
+
// Arrow Up
|
|
225
|
+
if (event.keyCode == 38) {
|
|
226
|
+
event.preventDefault();
|
|
227
|
+
$timeout(function () {
|
|
228
|
+
if ($scope.selectedIndex > 0) {
|
|
229
|
+
$scope.selectedIndex -= 1;
|
|
230
|
+
$timeout(function () {
|
|
231
|
+
$scope.scrollToHover();
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Arrow Down
|
|
238
|
+
if (event.keyCode == 40) {
|
|
239
|
+
event.preventDefault();
|
|
240
|
+
$timeout(function () {
|
|
241
|
+
if ($scope.results && $scope.selectedIndex < $scope.results.length - 1) {
|
|
242
|
+
$scope.selectedIndex += 1;
|
|
243
|
+
$timeout(function () {
|
|
244
|
+
$scope.scrollToHover();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Enter
|
|
251
|
+
if (event.keyCode == 13) {
|
|
252
|
+
event.preventDefault();
|
|
253
|
+
$timeout(function () {
|
|
254
|
+
$scope.selectItem($scope.results[$scope.selectedIndex], $scope.selectedIndex);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Escape
|
|
259
|
+
if (event.keyCode == 27) {
|
|
260
|
+
$timeout(function () {
|
|
261
|
+
$scope.close();
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|