laravel-jstools
Version:
JS tools for building front-side of Laravel applications
48 lines (47 loc) • 1.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const $ = require("jquery");
$.fn.omxInputFilter = function (inputFilter) {
return this.on('input keydown keyup mousedown mouseup select contextmenu drop', function () {
if (inputFilter(this.value)) {
this.oldValue = this.value;
this.oldSelectionStart = this.selectionStart;
this.oldSelectionEnd = this.selectionEnd;
}
else if (this.hasOwnProperty('oldValue')) {
this.value = this.oldValue;
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
}
else {
this.value = '';
}
});
};
$.fn.omxNumberRound = function (value, round, decimals) {
if (!round) {
return value;
}
if (!decimals) {
return Math.round(value);
}
return parseFloat(value.toFixed(decimals));
};
$.fn.omxNumberGet = function (fromData) {
if (fromData) {
return this.data('omxValue');
}
const val = this.val();
return val ? parseFloat(val.replace(',', '.').trim()) : 0;
};
$.fn.omxNumberSet = function (value, omxValue) {
this.data('omx-value', omxValue);
this.attr('data-omx-value', omxValue);
this.val(value);
return this;
};
$.fn.omxNumberFormat = function (value, decimals) {
const parts = (decimals ? value.toFixed(decimals).replace('.', ',') : value.toString()).split(',');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
return parts.join(',');
};
window.$ = $;