nice-elements 1.13.0 → 1.13.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.13.0",
3
+ "version": "1.13.2",
4
4
  "description": "Nice elements used in olaii angular 1.x webapps.",
5
5
  "main": "dist/nice.js",
6
6
  "license": "MIT",
@@ -93,6 +93,7 @@ angular.module('niceElements')
93
93
  }
94
94
 
95
95
  const getFilter = function (item) {
96
+ if (!item) return;
96
97
  // Create filter for finding object by objValue with _.where()
97
98
  const filter = {};
98
99
  if (item.hasOwnProperty($scope.objKey))
@@ -33,7 +33,7 @@ angular.module('niceElements')
33
33
  objValue: '@', // Optional - default is 'value'
34
34
  objKey: '@?', // Optional - default is 'id'. Used only when returnOnlyKey=true.
35
35
  selectedIsKey: '@?',
36
- nullable: '@', // No selection is possible
36
+ nullable: '=', // No selection is possible
37
37
  required: '=', // Model cannot be NULL
38
38
  noMargin: '@', // margin-bottom: 0px
39
39
  multiple: '@', // Can select multiple items
@@ -66,7 +66,6 @@ angular.module('niceElements')
66
66
  if (!$scope.selectedText) { $scope.selectedText = gettextCatalog.getString("selected", null, "Nice"); }
67
67
  if (!$scope.addButtonFunction) { $scope.addButtonFunction = null; }
68
68
  if (!$scope.placement) { $scope.placement = "bottom-start"; }
69
- $scope.nullable = $scope.nullable === 'true' || $scope.nullable === true;
70
69
  $scope.noMargin = $scope.noMargin === 'true' || $scope.noMargin === true;
71
70
  $scope.multiple = $scope.multiple === 'true' || $scope.multiple === true;
72
71
  $scope.clearOnSelect = $scope.clearOnSelect === 'true' || $scope.clearOnSelect === true;
@@ -13,8 +13,13 @@
13
13
  <div class="text text-placeholder" ng-if="dragging" translate translate-group="Nice">Drop file here</div>
14
14
  <div class="error" ng-if="error">{{ error }}</div>
15
15
  </div>
16
- <img ng-if="imageSource" data-ng-src="{{ imageSource }}" />
16
+ <div ng-if="imageSource" ng-transclude>
17
+ <img data-ng-src="{{ imageSource }}" />
18
+ </div>
17
19
  </div>
20
+ <button type="button" ng-click="clear()" ng-if="imageSource && !loading && !hideClear" class="btn btn-primary nice-upload-clear-button">
21
+ <nice-icon icon="icon-x"></nice-icon>
22
+ </button>
18
23
  <input class="input-file" type="file" accept="{{ accept }}" ng-model="file" ng-required="required" ng-disabled="isDisabled || loading" />
19
24
  <nice-loader fulldiv="true" ng-if="loading"></nice-loader>
20
25
  </div>
@@ -28,6 +28,7 @@ angular.module('niceElements')
28
28
  callbackUrl: '=',
29
29
  isDisabled: '=',
30
30
  isInline: '=',
31
+ hideClear: '=',
31
32
  help: '@',
32
33
  maxFileSize: '@',
33
34
  required: '=',
@@ -78,73 +79,71 @@ angular.module('niceElements')
78
79
  }
79
80
 
80
81
  $timeout(function () {
81
- scope.loading = true;
82
- scope.error = null;
83
82
  const inputObj = changeEvent.target;
84
83
  const reader = new FileReader();
84
+ if (!inputObj.files || !inputObj.files[0]) return;
85
+ scope.loading = true;
86
+ scope.error = null;
85
87
 
86
- if (inputObj.files) {
87
- try {
88
- const fileSize = inputObj.files[0].size; // in bytes
89
-
90
- reader.onload = function (event) {
91
- $timeout(function () {
92
- // file size must be smaller than XMB.
93
- if (fileSize > (scope.maxFileSize * 1000000)) {
94
- scope.error = gettextCatalog.getString("File must be smaller than {{size}}MB", { size: scope.maxFileSize }, "Nice");
95
- scope.loading = false;
96
- scope.imageSource = null;
97
- return;
98
- }
99
-
100
- if (scope.callbackFunction != undefined) {
88
+ try {
89
+ const fileSize = inputObj.files[0].size; // in bytes
90
+
91
+ reader.onload = function (event) {
92
+ $timeout(function () {
93
+ // file size must be smaller than XMB.
94
+ if (fileSize > (scope.maxFileSize * 1000000)) {
95
+ scope.error = gettextCatalog.getString("File must be smaller than {{size}}MB", { size: scope.maxFileSize }, "Nice");
96
+ scope.loading = false;
97
+ scope.imageSource = null;
98
+ return;
99
+ }
100
+
101
+ if (scope.callbackFunction != undefined) {
102
+ scope.loading = false;
103
+ scope.imageSource = null;
104
+ scope.callbackFunction(event.target.result);
105
+ scope.text = inputObj.files[0].name;
106
+ scope.form.$setDirty();
107
+ }
108
+
109
+ if (scope.callbackFile != undefined) {
110
+ scope.loading = false;
111
+ scope.text = inputObj.files[0].name;
112
+ scope.callbackFile(inputObj.files[0]);
113
+ scope.form.$setDirty();
114
+ }
115
+
116
+ if (scope.uploadFunction != undefined) {
117
+ scope.uploadFunction(inputObj.files[0]).then(function (response) {
101
118
  scope.loading = false;
102
- scope.imageSource = null;
103
- scope.callbackFunction(event.target.result);
104
- scope.text = inputObj.files[0].name;
119
+ scope.imageSource = event.target.result;
120
+ if (response.data && response.data.url) scope.model = response.data.url;
121
+ if (response.file) scope.model = response.data.url;
105
122
  scope.form.$setDirty();
106
- }
107
-
108
- if (scope.callbackFile != undefined) {
123
+ }, function (error) {
124
+ // Handle upload function error
125
+ scope.error = error;
109
126
  scope.loading = false;
110
- scope.text = inputObj.files[0].name;
111
- scope.callbackFile(inputObj.files[0]);
112
- scope.form.$setDirty();
113
- }
114
-
115
- if (scope.uploadFunction != undefined) {
116
- scope.uploadFunction(inputObj.files[0]).then(function (response) {
117
- scope.loading = false;
118
- scope.imageSource = event.target.result;
119
- if (response.data && response.data.url) scope.model = response.data.url;
120
- if (response.file) scope.model = response.data.url;
121
- scope.form.$setDirty();
122
- }, function (error) {
123
- // Handle upload function error
124
- scope.error = error;
125
- scope.loading = false;
126
- scope.imageSource = null;
127
- });
128
- } else {
129
- // console.error("No upload function set!");
130
- if (event.target.result.substring(0, 10) == "data:image") {
131
- scope.imageSource = event.target.result;
132
- }
127
+ scope.imageSource = null;
128
+ });
129
+ } else {
130
+ // console.error("No upload function set!");
131
+ if (event.target.result.substring(0, 10) == "data:image") {
132
+ scope.imageSource = event.target.result;
133
133
  }
134
- });
135
- };
136
-
137
- } catch (err) {
138
- // Handle try catch
139
- scope.error = gettextCatalog.getString("Something went wrong", null, "Nice");
140
- scope.loading = false;
141
- scope.imageSource = null;
142
- }
143
-
144
- // when the file is read it triggers the onload event above.
145
- reader.readAsDataURL(inputObj.files[0]);
146
-
134
+ }
135
+ });
136
+ };
137
+
138
+ } catch (err) {
139
+ // Handle try catch
140
+ scope.error = gettextCatalog.getString("Something went wrong", null, "Nice");
141
+ scope.loading = false;
142
+ scope.imageSource = null;
147
143
  }
144
+
145
+ // when the file is read it triggers the onload event above.
146
+ reader.readAsDataURL(inputObj.files[0]);
148
147
  });
149
148
 
150
149
  });
@@ -154,6 +153,16 @@ angular.module('niceElements')
154
153
  $scope.$watch("model", function (value) {
155
154
  $scope.imageSource = angular.copy($scope.model);
156
155
  });
156
+
157
+ $scope.clear = function () {
158
+ $scope.model = null;
159
+ $scope.imageSource = null;
160
+ $scope.form.$setDirty();
161
+ $scope.text = gettextCatalog.getString('Click to upload file', null, 'Nice');
162
+ if ($scope.callbackFunction) $scope.callbackFunction(null);
163
+ if ($scope.callbackFile) $scope.callbackFile(null);
164
+ if ($scope.callbackUrl) $scope.callbackUrl(null);
165
+ };
157
166
  }
158
167
 
159
168
  };
@@ -32,6 +32,18 @@
32
32
  }
33
33
  }
34
34
 
35
+ .nice-upload-clear-button {
36
+ position: absolute;
37
+ top: 5px;
38
+ right: 5px;
39
+ z-index: 10;
40
+ padding: 5px;
41
+ background: #ffffff90;
42
+ border-color: transparent;
43
+ color: var(--nice-font-color);
44
+ min-height: auto;
45
+ }
46
+
35
47
  .input-area {
36
48
  width: 100%;
37
49
  height: 100%;
@@ -77,7 +89,10 @@
77
89
  }
78
90
  }
79
91
 
80
- img {
92
+ img, video {
93
+ position: absolute;
94
+ top: 0;
95
+ left: 0;
81
96
  width: 100%;
82
97
  height: 100%;
83
98
  object-fit: contain;
@@ -8,9 +8,28 @@
8
8
  */
9
9
  angular.module('niceElements').filter('niceHighlight', function () {
10
10
  return function (value, highlightedText) {
11
- if (!value) return "";
11
+ if (!value || !highlightedText) return "";
12
12
  const regex = new RegExp(highlightedText, 'gmi');
13
- const newValue = String(value).replace(regex, "<span class='nice-highligh'>$&</span>");
13
+ const newValue = String(value).replace(regex, "<span class='nice-highlight'>$&</span>");
14
14
  return newValue;
15
15
  };
16
16
  });
17
+
18
+ angular.module('niceElements')
19
+ .filter('h', function ($sce, $sanitize) {
20
+ return function (text, phrase) {
21
+ if (!phrase || !text) return text;
22
+
23
+ // 1. Sanitize the original text to prevent XSS
24
+ let cleanText = $sanitize(text);
25
+
26
+ // 2. Create the case-insensitive global Regex
27
+ const regex = new RegExp('(' + phrase + ')', 'gi');
28
+
29
+ // 3. Replace matches with the h element
30
+ const highlighted = cleanText.replace(regex, '<h>$1</h>');
31
+
32
+ // 4. Trust the result so ng-bind-html renders it
33
+ return $sce.trustAsHtml(highlighted);
34
+ };
35
+ });
@@ -10,7 +10,7 @@ angular.module('niceElements')
10
10
  .service('NiceService', function ($rootScope) {
11
11
  const service = {
12
12
  name: "Nice elements",
13
- version: "1.13.0",
13
+ version: "1.13.2",
14
14
  getHeader: function () {
15
15
  return {};
16
16
  },
@@ -452,7 +452,7 @@ p.nice {
452
452
  }
453
453
  }
454
454
 
455
- .nice-highligh {
455
+ h, .nice-highlight {
456
456
  background: yellow;
457
457
  }
458
458