1/* eslint-disable */ 2this.BX = this.BX || {}; 3(function (exports,main_core) { 4 'use strict'; 5 6 var MoneyEditor = /*#__PURE__*/function () { 7 function MoneyEditor() { 8 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 9 babelHelpers.classCallCheck(this, MoneyEditor); 10 this.input = options.input; 11 this.callback = options.callback; 12 this.currency = options.currency; 13 this.value = options.value || ''; 14 this.valueEditHandler = this.valueEdit.bind(this); 15 main_core.Event.ready(this.init.bind(this)); 16 } 17 babelHelpers.createClass(MoneyEditor, [{ 18 key: "init", 19 value: function init() { 20 this.formatValue(); 21 main_core.Event.bind(this.input, 'bxchange', this.valueEditHandler); 22 main_core.Event.unbind(this.input, 'change', this.valueEditHandler); 23 } 24 }, { 25 key: "clean", 26 value: function clean() { 27 main_core.Event.unbind(this.input, 'bxchange', this.valueEditHandler); 28 this.input = null; 29 } 30 }, { 31 key: "valueEdit", 32 value: function valueEdit(e) { 33 if (!!e && e.type === 'keyup' && e.code === 'Tab') { 34 return; 35 } 36 this.formatValue(); 37 } 38 }, { 39 key: "setCurrency", 40 value: function setCurrency(currency) { 41 this.value = MoneyEditor.getUnFormattedValue(this.input.value, this.currency); 42 this.currency = currency; 43 this.input.value = MoneyEditor.getFormattedValue(this.value, this.currency); 44 this.callValueChangeCallback(); 45 } 46 }, { 47 key: "formatValue", 48 value: function formatValue() { 49 var cursorPos = BX.getCaretPosition(this.input); 50 var originalValue = this.input.value; 51 this.changeValue(); 52 if (originalValue.length > 0) { 53 BX.setCaretPosition(this.input, cursorPos - originalValue.length + this.input.value.length); 54 } 55 } 56 }, { 57 key: "changeValue", 58 value: function changeValue() { 59 this.value = MoneyEditor.getUnFormattedValue(this.input.value, this.currency); 60 this.input.value = MoneyEditor.getFormattedValue(this.value, this.currency); 61 this.callValueChangeCallback(); 62 } 63 }, { 64 key: "callValueChangeCallback", 65 value: function callValueChangeCallback() { 66 if (!!this.callback) { 67 this.callback.apply(this, [this.value]); 68 } 69 BX.onCustomEvent(this, 'Currency::Editor::change', [this.value]); 70 } 71 }], [{ 72 key: "getCurrencyFormat", 73 value: function getCurrencyFormat(currency) { 74 var list = this.getCurrencyList(); 75 if (typeof list[currency] !== 'undefined') { 76 return list[currency]; 77 } 78 return this.defaultFormat; 79 } 80 }, { 81 key: "getCurrencyList", 82 value: function getCurrencyList() { 83 if (this.currencyList === null) { 84 this.currencyList = main_core.Loc.getMessage('CURRENCY'); 85 } 86 return this.currencyList; 87 } 88 }, { 89 key: "getBaseCurrencyId", 90 value: function getBaseCurrencyId() { 91 var listCurrency = this.getCurrencyList(); 92 for (var key in listCurrency) { 93 if (!listCurrency.hasOwnProperty(key)) { 94 continue; 95 } 96 if (BX.prop.getString(listCurrency[key], 'BASE', 'N') === 'Y') { 97 return key; 98 } 99 } 100 return ''; 101 } 102 }, { 103 key: "trimTrailingZeros", 104 value: function trimTrailingZeros(formattedValue, currency) { 105 formattedValue = String(formattedValue); 106 var currentFormat = this.getCurrencyFormat(currency); 107 var ch = BX.prop.getString(currentFormat, 'DEC_POINT', ''); 108 return ch !== '' ? formattedValue.replace(new RegExp('\\' + ch + '0+$'), '') : formattedValue; 109 } 110 }, { 111 key: "escapeRegExp", 112 value: function escapeRegExp(text) { 113 text = String(text); 114 return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); 115 } 116 }, { 117 key: "getUnFormattedValue", 118 value: function getUnFormattedValue(formattedValue, currency) { 119 formattedValue = String(formattedValue); 120 var currentFormat = this.getCurrencyFormat(currency); 121 if (currentFormat['SEPARATOR'].length === 1) { 122 return formattedValue.replace(new RegExp('[' + currentFormat['SEPARATOR'] + ']', 'g'), '').replace(currentFormat['DEC_POINT'], '.').replace(new RegExp('[^0-9\.]', 'g'), ''); 123 } else if (currentFormat['SEPARATOR'].length > 1) { 124 return formattedValue.replace(new RegExp(this.escapeRegExp(currentFormat['SEPARATOR']), 'g'), '').replace(currentFormat['DEC_POINT'], '.').replace(new RegExp('[^0-9\.]', 'g'), ''); 125 } else { 126 return formattedValue.replace(currentFormat['DEC_POINT'], '.').replace(new RegExp('[^0-9\.]', 'g'), ''); 127 } 128 } 129 }, { 130 key: "getFormattedValue", 131 value: function getFormattedValue(baseValue, currency) { 132 baseValue = String(baseValue); 133 if (baseValue === '') { 134 return ''; 135 } 136 baseValue = baseValue.replace(/^0+/, ''); 137 if (baseValue === '') { 138 baseValue = '0'; 139 } else if (baseValue.charAt(0) === '.') { 140 baseValue = '0' + baseValue; 141 } 142 var sign = ''; 143 if (baseValue.charAt(0) === '-') { 144 sign = '-'; 145 baseValue = baseValue.slice(1); 146 } 147 var currentFormat = this.getCurrencyFormat(currency); 148 var decPoint = currentFormat.DEC_POINT; 149 var decimals = currentFormat.DECIMALS; 150 var separator = currentFormat.SEPARATOR || currentFormat.THOUSANDS_SEP; 151 var gecPointMask = decPoint === ',' || decPoint === '.' ? new RegExp('[.,]') : new RegExp('[' + decPoint + '.,]'); 152 var digitMask = new RegExp('\D', 'g'); 153 var wholePart; 154 var fraction; 155 var decimalPoint; 156 var decPointPosition = baseValue.match(gecPointMask); 157 if (decPointPosition === null) { 158 wholePart = baseValue.replaceAll(digitMask, ''); 159 fraction = ''; 160 decimalPoint = ''; 161 } else { 162 wholePart = baseValue.slice(0, decPointPosition.index).replaceAll(digitMask, ''); 163 fraction = baseValue.slice(decPointPosition.index + 1).replaceAll(digitMask, ''); 164 decimalPoint = decPoint; 165 } 166 if (decimals === 0) { 167 fraction = ''; 168 decimalPoint = ''; 169 } 170 var result = sign; 171 if (this.checkInrFormat(currency)) { 172 if (wholePart.length <= 3) { 173 result = result + wholePart; 174 } else { 175 var rightTriad = separator + wholePart.slice(-3); 176 var leftBlock = wholePart.slice(0, -3); 177 var j = leftBlock.length > 2 ? leftBlock.length % 2 : 0; 178 result = result + (j ? leftBlock.slice(0, j) + separator : '') + leftBlock.slice(j).replace(/(\d{2})(?=\d)/g, "$1" + separator) + rightTriad; 179 } 180 } else { 181 var _j = wholePart.length > 3 ? wholePart.length % 3 : 0; 182 result = result + (_j ? wholePart.slice(0, _j) + separator : '') + wholePart.slice(_j).replace(/(\d{3})(?=\d)/g, "$1" + separator); 183 } 184 if (decimals > 0) { 185 result = result + decimalPoint; 186 if (fraction !== '') { 187 if (decimals < fraction.length) { 188 fraction = fraction.slice(0, decimals); 189 } 190 result = result + fraction; 191 } 192 } 193 return result; 194 } 195 }, { 196 key: "initRegion", 197 value: function initRegion() { 198 if (this.region === '') { 199 var settings = main_core.Extension.getSettings('currency.money-editor'); 200 this.region = settings.get('region') || '-'; 201 } 202 } 203 }, { 204 key: "checkInrFormat", 205 value: function checkInrFormat(currency) { 206 this.initRegion(); 207 return currency === 'INR' && (this.region === 'hi' || this.region === '
207in'); 208 } 209 }]); 210 return MoneyEditor; 211 }(); 212 213 /** @deprecated use import { MoneyEditor } from 'currency.money-editor' */ 214 babelHelpers.defineProperty(MoneyEditor, "currencyList", null); 215 babelHelpers.defineProperty(MoneyEditor, "defaultFormat", { 216 CURRENCY: '', 217 NAME: '', 218 FORMAT_STRING: '#', 219 DEC_POINT: '.', 220 THOUSANDS_VARIANT: null, 221 THOUSANDS_SEP: ' ', 222 DECIMALS: 2, 223 HIDE_ZERO: 'N', 224 BASE: 'N', 225 SEPARATOR: ' ' 226 }); 227 babelHelpers.defineProperty(MoneyEditor, "region", ''); 228 main_core.Reflection.namespace('BX.Currency').Editor = MoneyEditor; 229 230 exports.MoneyEditor = MoneyEditor; 231 232}((this.BX.Currency = this.BX.Currency || {}),BX)); 233//# sourceMappingURL=money-editor.bundle.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.