|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- export class SovTools {
-
- static log(value) {
- try {
- console.log(value);
- } catch {
- }
- }
-
- static arrayRemove(arr, value) {
- return arr.filter(function (ele) {
- return ele != value;
- });
- }
-
- static toPlainText(html) {
- let scratchDiv = document.createElement('div');
- scratchDiv.innerHTML = html;
- return scratchDiv.textContent;
- }
-
- static getDateFormatted(date, separator) {
- if (date) {
- var date = new Date(date);
- var _d = date.getDate(),
- d = _d > 9 ? _d : '0' + _d,
- _m = date.getMonth() + 1,
- m = _m > 9 ? _m : '0' + _m,
- formatted = d + separator + m + separator + date.getFullYear();
- return formatted;
- } else {
- return '';
- }
- }
-
- static getUrlParameter(sParam) {
- var sPageURL = window.location.search.substring(1),
- sURLVariables = sPageURL.split('&'),
- sParameterName,
- i;
-
- for (i = 0; i < sURLVariables.length; i++) {
- sParameterName = sURLVariables[i].split('=');
-
- if (sParameterName[0] === sParam) {
- return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
- }
- }
- }
-
- static indexOfFirstDigit(input) {
- let i = 0;
- for (; input[i] < '0' || input[i] > '9'; i++) ;
- return i == input.length ? -1 : i;
- }
-
- static indexOfLastDigit(input) {
- let i = input.length - 1;
- for (; input[i] < '0' || input[i] > '9'; i--) ;
- return i == input.length ? -1 : i;
- }
-
- static formatNumber(number, toFixed) {
- if (number) return Number(number.replace(',', '.')).toFixed(toFixed);
- else return null;
- }
-
- static formatNumberWithoutFixed(number) {
- if (typeof number == 'string') number = number.replace(',', '.');
- if (number) return Number(number);
- else return null;
- }
-
- static getUrlParameter(sParam) {
- var sPageURL = window.location.search.substring(1),
- sURLVariables = sPageURL.split('&'),
- sParameterName,
- i;
-
- for (i = 0; i < sURLVariables.length; i++) {
- sParameterName = sURLVariables[i].split('=');
-
- if (sParameterName[0] === sParam) {
- return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
- }
- }
- };
-
- static readFlashMessages(flashMessages) {
- var currentFlash = new Array();
- for (var type in flashMessages) {
- for (var key in flashMessages[type]) {
- if (!currentFlash.includes(flashMessages[type][key])) {
- currentFlash.push(flashMessages[type][key]);
- SovNotification.add(type, flashMessages[type][key]);
- }
- }
- }
- }
-
- static checkFormValidity(formId) {
- if (!document.getElementById(formId.substr(1)).checkValidity()) {
- document.getElementById(formId.substr(1)).reportValidity()
- return false;
- } else {
- return true;
- }
- }
-
- static initCountSmsCharacter(countSmsTextareaClass) {
- $(countSmsTextareaClass).each(function () {
- $(this).after('<div class="count-sms-character-info"></div>');
- SovTools.displaySmsTotalCharacter($(this));
- $(this).on('keyup', function () {
- SovTools.displaySmsTotalCharacter($(this));
- });
- })
- }
-
- static displaySmsTotalCharacter($textarea) {
- var totalCharacter = $textarea.val().length;
- var totalCharacterCurrentSms = totalCharacter % 160;
- if (totalCharacterCurrentSms == 0 && totalCharacter > 0) {
- totalCharacterCurrentSms = 160;
- }
- let totalSms = Math.ceil(totalCharacter / 160);
- $textarea.next().html(totalCharacterCurrentSms + '/160 -<strong>' + totalSms + ' sms</strong>');
-
- }
- }
|