You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 satır
4.0KB

  1. export class SovTools {
  2. static log(value) {
  3. try {
  4. console.log(value);
  5. } catch {
  6. }
  7. }
  8. static arrayRemove(arr, value) {
  9. return arr.filter(function (ele) {
  10. return ele != value;
  11. });
  12. }
  13. static toPlainText(html) {
  14. let scratchDiv = document.createElement('div');
  15. scratchDiv.innerHTML = html;
  16. return scratchDiv.textContent;
  17. }
  18. static getDateFormatted(date, separator) {
  19. if (date) {
  20. var date = new Date(date);
  21. var _d = date.getDate(),
  22. d = _d > 9 ? _d : '0' + _d,
  23. _m = date.getMonth() + 1,
  24. m = _m > 9 ? _m : '0' + _m,
  25. formatted = d + separator + m + separator + date.getFullYear();
  26. return formatted;
  27. } else {
  28. return '';
  29. }
  30. }
  31. static getUrlParameter(sParam) {
  32. var sPageURL = window.location.search.substring(1),
  33. sURLVariables = sPageURL.split('&'),
  34. sParameterName,
  35. i;
  36. for (i = 0; i < sURLVariables.length; i++) {
  37. sParameterName = sURLVariables[i].split('=');
  38. if (sParameterName[0] === sParam) {
  39. return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
  40. }
  41. }
  42. }
  43. static indexOfFirstDigit(input) {
  44. let i = 0;
  45. for (; input[i] < '0' || input[i] > '9'; i++) ;
  46. return i == input.length ? -1 : i;
  47. }
  48. static indexOfLastDigit(input) {
  49. let i = input.length - 1;
  50. for (; input[i] < '0' || input[i] > '9'; i--) ;
  51. return i == input.length ? -1 : i;
  52. }
  53. static formatNumber(number, toFixed) {
  54. if (number) return Number(number.replace(',', '.')).toFixed(toFixed);
  55. else return null;
  56. }
  57. static formatNumberWithoutFixed(number) {
  58. if (typeof number == 'string') number = number.replace(',', '.');
  59. if (number) return Number(number);
  60. else return null;
  61. }
  62. static getUrlParameter(sParam) {
  63. var sPageURL = window.location.search.substring(1),
  64. sURLVariables = sPageURL.split('&'),
  65. sParameterName,
  66. i;
  67. for (i = 0; i < sURLVariables.length; i++) {
  68. sParameterName = sURLVariables[i].split('=');
  69. if (sParameterName[0] === sParam) {
  70. return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
  71. }
  72. }
  73. };
  74. static readFlashMessages(flashMessages) {
  75. var currentFlash = new Array();
  76. for (var type in flashMessages) {
  77. for (var key in flashMessages[type]) {
  78. if (!currentFlash.includes(flashMessages[type][key])) {
  79. currentFlash.push(flashMessages[type][key]);
  80. SovNotification.add(type, flashMessages[type][key]);
  81. }
  82. }
  83. }
  84. }
  85. static checkFormValidity(formId) {
  86. if (!document.getElementById(formId.substr(1)).checkValidity()) {
  87. document.getElementById(formId.substr(1)).reportValidity()
  88. return false;
  89. } else {
  90. return true;
  91. }
  92. }
  93. static initCountSmsCharacter(countSmsTextareaClass) {
  94. $(countSmsTextareaClass).each(function () {
  95. $(this).after('<div class="count-sms-character-info"></div>');
  96. SovTools.displaySmsTotalCharacter($(this));
  97. $(this).on('keyup', function () {
  98. SovTools.displaySmsTotalCharacter($(this));
  99. });
  100. })
  101. }
  102. static displaySmsTotalCharacter($textarea) {
  103. var totalCharacter = $textarea.val().length;
  104. var totalCharacterCurrentSms = totalCharacter % 160;
  105. if (totalCharacterCurrentSms == 0 && totalCharacter > 0) {
  106. totalCharacterCurrentSms = 160;
  107. }
  108. let totalSms = Math.ceil(totalCharacter / 160);
  109. $textarea.next().html(totalCharacterCurrentSms + '/160 -<strong>' + totalSms + ' sms</strong>');
  110. }
  111. }