/* * Main scripts. */ (function (win, doc, undef) { "use strict"; win.sbm = win.sbm || {}; //-------------------------------------------------------------- // Utilities. sbm.isDef = function (obj) { return obj === null || typeof obj == "undefined" ? false : true; } sbm.isFn = function (fn) { return fn != null && typeof fn == typeof Function; } sbm.isNumeric = function (n) { return !isNaN(parseFloat(n)) && isFinite(n); } sbm.getTime = function () { return (new Date()).getTime(); } sbm.zeroPad = function (num, count) { var val = num + ''; while (val.length < count) val = "0" + val; return val; } sbm.toInt = function (value, defaultValue) { return sbm.isNumeric(value) ? parseInt(value, 10) : defaultValue || 0; } if ("function" != typeof "".format) String.prototype.format = (function () { var rx1 = /\{(\d|\d\d)\}/g, rx2 = /\d+/; return function () { var args = arguments; return this.replace(rx1, function ($0) { var idx = 1 * $0.match(rx2)[0]; return args[idx] !== undefined ? args[idx] : (args[idx] === "" ? "" : $0); }); } }()); sbm.getFileType = function (file) { if (!file) return ""; if (file.type) return file.type; if (file.filename) return filename.split('.').pop(); return ""; } sbm.formatFileSize = function (size, decimals = 0) { if (size / 10 ** 9 > 1) return (size / 10.0 ** 9).toFixed(decimals) + ' Gb'; if (size / 10 ** 6 > 1) return (size / 10.0 ** 6).toFixed(decimals) + ' Mb'; if (size / 10 ** 3 > 1) return (size / 10.0 ** 3).toFixed(decimals) + ' Kb'; return size + ' bytes'; } sbm.escapeRegExp = function (val) { return (val || '').replace(/[[{}()*+?^$|\]\.\\]/g, "\\$&"); } sbm.haltEvent = function (evt) { evt.preventDefault(); evt.stopPropagation(); } sbm.debug = sbm.debugMode ? win.console.log.bind(win.console) : function () { }; //-------------------------------------------------------------- sbm.compareCI = function (a, b) { var comparison = a.toLowerCase().localeCompare(b.toLowerCase()); if (comparison === 0) return a.localeCompare(b); return comparison; } sbm.arraySortCI = function () { if (!this) return this; this.sort(function (a, b) { return sbm.compareCI(a, b); }); return this; }; //-------------------------------------------------------------- sbm.setOddDataRowClass = function (rowSel, cName) { $(rowSel).addClass(function (index, currentClasses) { return index % 2 == 1 ? (cName || "other") : ""; }); } sbm.selectOrAdd = function ($sel, code, desc) { $sel = $($sel); if ($sel.val(code).val() == code) return; $sel.append($('