nice-elements 1.13.1 → 1.13.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.13.3 (3.4.2026)
4
+
5
+ - changed hideClear to showClear prop in nice upload component,
6
+ - worked on niceHighlight,
7
+ - fixed call nice upload uploadFunction on clear
8
+
9
+ ## v1.13.2 (3.4.2026)
10
+
11
+ - added clear button to nice upload,
12
+ - fixed nice upload no files error
13
+
3
14
  ## v1.13.1 (30.3.2026)
4
15
 
5
16
  - added transclude to nice upload,
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ![Nice elements](https://github.com/Klemen1337/angularjs-nice-elements/raw/master/demo/assets/logo.png)
2
2
 
3
- # Nice elements v1.13.1
3
+ # Nice elements v1.13.3
4
4
 
5
5
  Nice elements is an AngularJS v1.5.8 module that contains nice form elements like inputs, choice fields, search, toggle, dropdown, etc.
6
6
 
package/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nice-elements",
3
- "version": "1.13.1",
3
+ "version": "1.13.3",
4
4
  "authors": [
5
5
  "Klemen Kastelic <klemen@olaii.com>"
6
6
  ],
package/dist/nice.js CHANGED
@@ -5846,6 +5846,7 @@ angular.module('niceElements')
5846
5846
  callbackUrl: '=',
5847
5847
  isDisabled: '=',
5848
5848
  isInline: '=',
5849
+ showClear: '=',
5849
5850
  help: '@',
5850
5851
  maxFileSize: '@',
5851
5852
  required: '=',
@@ -5863,6 +5864,7 @@ angular.module('niceElements')
5863
5864
  scope.endDragging = function () { $timeout(function () { scope.dragging = false; }); };
5864
5865
  scope.startDraggingGlobal = function () { $timeout(function () { scope.draggingGlobal = true; }); };
5865
5866
  scope.endDraggingGlobal = function () { $timeout(function () { scope.dragging = false; scope.draggingGlobal = false; }); };
5867
+ scope.file = null;
5866
5868
 
5867
5869
  scope.dragging = false;
5868
5870
  scope.draggingGlobal = false;
@@ -5896,82 +5898,94 @@ angular.module('niceElements')
5896
5898
  }
5897
5899
 
5898
5900
  $timeout(function () {
5899
- scope.loading = true;
5900
- scope.error = null;
5901
5901
  const inputObj = changeEvent.target;
5902
5902
  const reader = new FileReader();
5903
+ if (!inputObj.files || !inputObj.files[0]) return;
5904
+ scope.loading = true;
5905
+ scope.error = null;
5903
5906
 
5904
- if (inputObj.files) {
5905
- try {
5906
- const fileSize = inputObj.files[0].size; // in bytes
5907
+ try {
5908
+ const fileSize = inputObj.files[0].size; // in bytes
5907
5909
 
5908
- reader.onload = function (event) {
5909
- $timeout(function () {
5910
- // file size must be smaller than XMB.
5911
- if (fileSize > (scope.maxFileSize * 1000000)) {
5912
- scope.error = gettextCatalog.getString("File must be smaller than {{size}}MB", { size: scope.maxFileSize }, "Nice");
5913
- scope.loading = false;
5914
- scope.imageSource = null;
5915
- return;
5916
- }
5910
+ reader.onload = function (event) {
5911
+ $timeout(function () {
5912
+ // file size must be smaller than XMB.
5913
+ if (fileSize > (scope.maxFileSize * 1000000)) {
5914
+ scope.error = gettextCatalog.getString("File must be smaller than {{size}}MB", { size: scope.maxFileSize }, "Nice");
5915
+ scope.loading = false;
5916
+ scope.imageSource = null;
5917
+ return;
5918
+ }
5917
5919
 
5918
- if (scope.callbackFunction != undefined) {
5919
- scope.loading = false;
5920
- scope.imageSource = null;
5921
- scope.callbackFunction(event.target.result);
5922
- scope.text = inputObj.files[0].name;
5923
- scope.form.$setDirty();
5924
- }
5920
+ if (scope.callbackFunction != undefined) {
5921
+ scope.loading = false;
5922
+ scope.imageSource = null;
5923
+ scope.callbackFunction(event.target.result);
5924
+ scope.text = inputObj.files[0].name;
5925
+ scope.form.$setDirty();
5926
+ }
5925
5927
 
5926
- if (scope.callbackFile != undefined) {
5928
+ if (scope.callbackFile != undefined) {
5929
+ scope.loading = false;
5930
+ scope.text = inputObj.files[0].name;
5931
+ scope.callbackFile(inputObj.files[0]);
5932
+ scope.form.$setDirty();
5933
+ }
5934
+
5935
+ if (scope.uploadFunction != undefined) {
5936
+ scope.uploadFunction(inputObj.files[0]).then(function (response) {
5927
5937
  scope.loading = false;
5928
- scope.text = inputObj.files[0].name;
5929
- scope.callbackFile(inputObj.files[0]);
5938
+ scope.imageSource = event.target.result;
5939
+ if (response.data && response.data.url) scope.model = response.data.url;
5940
+ if (response.file) scope.model = response.data.url;
5930
5941
  scope.form.$setDirty();
5942
+ }, function (error) {
5943
+ // Handle upload function error
5944
+ scope.error = error;
5945
+ scope.loading = false;
5946
+ scope.imageSource = null;
5947
+ });
5948
+ } else {
5949
+ // console.error("No upload function set!");
5950
+ if (event.target.result.substring(0, 10) == "data:image") {
5951
+ scope.imageSource = event.target.result;
5931
5952
  }
5953
+ }
5954
+ });
5955
+ };
5932
5956
 
5933
- if (scope.uploadFunction != undefined) {
5934
- scope.uploadFunction(inputObj.files[0]).then(function (response) {
5935
- scope.loading = false;
5936
- scope.imageSource = event.target.result;
5937
- if (response.data && response.data.url) scope.model = response.data.url;
5938
- if (response.file) scope.model = response.data.url;
5939
- scope.form.$setDirty();
5940
- }, function (error) {
5941
- // Handle upload function error
5942
- scope.error = error;
5943
- scope.loading = false;
5944
- scope.imageSource = null;
5945
- });
5946
- } else {
5947
- // console.error("No upload function set!");
5948
- if (event.target.result.substring(0, 10) == "data:image") {
5949
- scope.imageSource = event.target.result;
5950
- }
5951
- }
5952
- });
5953
- };
5954
-
5955
- } catch (err) {
5956
- // Handle try catch
5957
- scope.error = gettextCatalog.getString("Something went wrong", null, "Nice");
5958
- scope.loading = false;
5959
- scope.imageSource = null;
5960
- }
5961
-
5962
- // when the file is read it triggers the onload event above.
5963
- reader.readAsDataURL(inputObj.files[0]);
5964
-
5957
+ } catch (err) {
5958
+ // Handle try catch
5959
+ scope.error = gettextCatalog.getString("Something went wrong", null, "Nice");
5960
+ scope.loading = false;
5961
+ scope.imageSource = null;
5965
5962
  }
5963
+
5964
+ // when the file is read it triggers the onload event above.
5965
+ reader.readAsDataURL(inputObj.files[0]);
5966
5966
  });
5967
5967
 
5968
5968
  });
5969
5969
  },
5970
5970
 
5971
- controller: function ($scope) {
5972
- $scope.$watch("model", function (value) {
5971
+ controller: function ($scope, $element) {
5972
+ $scope.$watch("model", function () {
5973
5973
  $scope.imageSource = angular.copy($scope.model);
5974
5974
  });
5975
+
5976
+ $scope.clear = function () {
5977
+ $scope.model = null;
5978
+ $scope.imageSource = null;
5979
+ $scope.form.$setDirty();
5980
+ const inputElement = $element[0].querySelector(".input-file");
5981
+ if (inputElement) inputElement.value = null;
5982
+
5983
+ $scope.text = gettextCatalog.getString('Click to upload file', null, 'Nice');
5984
+ if ($scope.callbackFunction) $scope.callbackFunction();
5985
+ if ($scope.callbackFile) $scope.callbackFile();
5986
+ if ($scope.callbackUrl) $scope.callbackUrl();
5987
+ if ($scope.uploadFunction) $scope.uploadFunction();
5988
+ };
5975
5989
  }
5976
5990
 
5977
5991
  };
@@ -6261,12 +6275,21 @@ angular.module('niceElements').filter('niceDate', function () {
6261
6275
  * # niceHighlight
6262
6276
  * Filter in the niceElements.
6263
6277
  */
6264
- angular.module('niceElements').filter('niceHighlight', function () {
6265
- return function (value, highlightedText) {
6266
- if (!value || !highlightedText) return "";
6267
- const regex = new RegExp(highlightedText, 'gmi');
6268
- const newValue = String(value).replace(regex, "<span class='nice-highlight'>$&</span>");
6269
- return newValue;
6278
+ angular.module('niceElements').filter('niceHighlight', function ($sanitize, $sce) {
6279
+ return function (text, phrase) {
6280
+ if (!phrase || !text) return text;
6281
+
6282
+ // 1. Sanitize the original text to prevent XSS
6283
+ let cleanText = $sanitize(text);
6284
+
6285
+ // 2. Create the case-insensitive global Regex
6286
+ const regex = new RegExp('(' + phrase + ')', 'gi');
6287
+
6288
+ // 3. Replace matches with the h element
6289
+ const highlighted = cleanText.replace(regex, '<h>$1</h>');
6290
+
6291
+ // 4. Trust the result so ng-bind-html renders it
6292
+ return $sce.trustAsHtml(highlighted);
6270
6293
  };
6271
6294
  });
6272
6295
 
@@ -6525,7 +6548,7 @@ angular.module('niceElements')
6525
6548
  .service('NiceService', function ($rootScope) {
6526
6549
  const service = {
6527
6550
  name: "Nice elements",
6528
- version: "1.13.1",
6551
+ version: "1.13.3",
6529
6552
  getHeader: function () {
6530
6553
  return {};
6531
6554
  },
@@ -9204,6 +9227,7 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
9204
9227
  " \n" +
9205
9228
  " <div class=\"nice-field col-xs-12\" ng-class=\"[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]\">\n" +
9206
9229
  " <div class=\"nice-upload-area\">\n" +
9230
+ " \n" +
9207
9231
  " <div class=\"input-area\" ng-class=\"{ 'dragging': dragging || draggingGlobal }\">\n" +
9208
9232
  " <div class=\"middle-text\" ng-if=\"!imageSource && !loading\">\n" +
9209
9233
  " <nice-icon icon=\"icon-upload\"></nice-icon>\n" +
@@ -9215,7 +9239,16 @@ angular.module('niceElements').run(['$templateCache', function($templateCache) {
9215
9239
  " <img data-ng-src=\"{{ imageSource }}\">\n" +
9216
9240
  " </div>\n" +
9217
9241
  " </div>\n" +
9242
+ "\n" +
9243
+ " \n" +
9244
+ " <button type=\"button\" ng-click=\"clear()\" ng-if=\"imageSource && !loading && showClear\" class=\"btn btn-primary nice-upload-clear-button\">\n" +
9245
+ " <nice-icon icon=\"icon-x\"></nice-icon>\n" +
9246
+ " </button>\n" +
9247
+ "\n" +
9248
+ " \n" +
9218
9249
  " <input class=\"input-file\" type=\"file\" accept=\"{{ accept }}\" ng-model=\"file\" ng-required=\"required\" ng-disabled=\"isDisabled || loading\">\n" +
9250
+ "\n" +
9251
+ " \n" +
9219
9252
  " <nice-loader fulldiv=\"true\" ng-if=\"loading\"></nice-loader>\n" +
9220
9253
  " </div>\n" +
9221
9254
  " </div>\n" +