616 lines
20 KiB
JavaScript
616 lines
20 KiB
JavaScript
/*
|
|
* BusMgr Control - Main scripts.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
win.sbc = win.sbc || {};
|
|
|
|
//--------------------------------------------------------------
|
|
// Utilities.
|
|
sbc.isDef = function (obj)
|
|
{
|
|
return obj === null || typeof obj == "undefined" ? false : true;
|
|
}
|
|
sbc.isFn = function (fn)
|
|
{
|
|
return fn != null && typeof fn == typeof Function;
|
|
}
|
|
sbc.isNumeric = function (n)
|
|
{
|
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
}
|
|
sbc.getTime = function ()
|
|
{
|
|
return (new Date()).getTime();
|
|
}
|
|
sbc.zeroPad = function (num, count)
|
|
{
|
|
var val = num + '';
|
|
while (val.length < count) val = "0" + val;
|
|
return val;
|
|
}
|
|
sbc.toInt = function (value, defaultValue)
|
|
{
|
|
return sbc.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);
|
|
});
|
|
}
|
|
}());
|
|
sbc.getFileType = function (file)
|
|
{
|
|
if (!file) return "";
|
|
if (file.type) return file.type;
|
|
if (file.filename) return filename.split('.').pop();
|
|
return "";
|
|
}
|
|
sbc.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';
|
|
}
|
|
sbc.escapeRegExp = function (val)
|
|
{
|
|
return (val || '').replace(/[[{}()*+?^$|\]\.\\]/g, "\\$&");
|
|
}
|
|
sbc.haltEvent = function (evt)
|
|
{
|
|
evt.preventDefault();
|
|
evt.stopPropagation();
|
|
}
|
|
sbc.debug = sbc.debugMode ? win.console.log.bind(win.console) : function () { };
|
|
|
|
//--------------------------------------------------------------
|
|
sbc.compareCI = function (a, b)
|
|
{
|
|
var comparison = a.toLowerCase().localeCompare(b.toLowerCase());
|
|
if (comparison === 0)
|
|
return a.localeCompare(b);
|
|
return comparison;
|
|
}
|
|
sbc.arraySortCI = function ()
|
|
{
|
|
if (!this) return this;
|
|
this.sort(function (a, b) { return sbc.compareCI(a, b); });
|
|
return this;
|
|
};
|
|
|
|
//--------------------------------------------------------------
|
|
sbc.setOddDataRowClass = function (rowSel, cName)
|
|
{
|
|
$(rowSel).addClass(function (index, currentClasses)
|
|
{
|
|
return index % 2 == 1 ? (cName || "other") : "";
|
|
});
|
|
}
|
|
sbc.selectOrAdd = function ($sel, code, desc)
|
|
{
|
|
$sel = $($sel);
|
|
if ($sel.val(code).val() == code) return;
|
|
$sel.append($('<option>').prop('value', code).text(desc));
|
|
$sel.val(code);
|
|
}
|
|
sbc.populateSelect = function ($sel, values, code, desc)
|
|
{
|
|
code = code || 'code';
|
|
desc = desc || 'desc';
|
|
$sel = $($sel).empty();
|
|
for (const value of values || [])
|
|
$sel.append($('<option>').prop('value', value[code]).text(value[desc]));
|
|
}
|
|
sbc.populateSelectCodeDesc = function ($sel, values)
|
|
{
|
|
sbc.populateSelect($($sel), values);
|
|
}
|
|
sbc.checkTextAreaMaxLength = function (ctrl, len)
|
|
{
|
|
if (ctrl == null || ctrl.value == null) return;
|
|
if (ctrl.value.length > len) ctrl.value = ctrl.value.substring(0, len);
|
|
}
|
|
sbc.setAvailableCharsInfo = function ($if, max, $info)
|
|
{
|
|
let info = '';
|
|
if (max > 0)
|
|
{
|
|
let avail = Math.max(0, max - $if.val().length);
|
|
info = (avail == 1 ? sbc.lbl.charAvailable : sbc.lbl.charsAvailable.replace(/\{0\}/g, avail));
|
|
}
|
|
($info || $('.sbc-info', $if.closest('.sbc-form-control'))).text(info);
|
|
}
|
|
sbc.setItemsSelectedInfo = function ($sel, $info)
|
|
{
|
|
var sel = $(':selected', $sel).length;
|
|
($info || $('.sbc-info', $sel.closest('.sbc-form-control'))).text(sel == 0 ? sbc.lbl.noneSelected : sbc.lbl.numberSelected.replace(/\{0\}/g, sel));
|
|
}
|
|
sbc.offsetSelectedOption = ($sel, offset) =>
|
|
{
|
|
var currentIndex = $sel.prop('selectedIndex');
|
|
var optionsCount = $sel.find('option').length;
|
|
if (optionsCount === 0) return;
|
|
var newIndex = currentIndex + offset;
|
|
if (newIndex < 0) newIndex = 0;
|
|
if (newIndex >= optionsCount) newIndex = optionsCount - 1;
|
|
if (newIndex != currentIndex)
|
|
$sel.prop('selectedIndex', newIndex).trigger('change');
|
|
}
|
|
|
|
|
|
sbc.initCalendars = function (sel, opt)
|
|
{
|
|
return $(sel).datepicker(opt || {});
|
|
}
|
|
sbc.allowClearCalendar = function (sel)
|
|
{
|
|
$(sel).datepicker().on('keyup', function (e)
|
|
{
|
|
if (e.key == 'Backspace' || e.key == 'Delete')
|
|
$(this).datepicker('setDate', null).datepicker('hide').trigger('change');
|
|
});
|
|
}
|
|
|
|
sbc.refreshPaging = function (response, context, refreshFn)
|
|
{
|
|
if (sbc.resultsPaging.fn.refreshPaging)
|
|
sbc.resultsPaging.fn.refreshPaging(response.paging, context, refreshFn);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sbc.configureItemTable = function (cfg, $sel)
|
|
{
|
|
//sbc.debug('configureItemTable', cfg, $sel);
|
|
let col = cfg.column || {};
|
|
let $cell = $('th,td', $sel).removeClass('hidden');
|
|
(col.hide || []).forEach(function (v, i, a) { $cell.filter('.' + col.prefix + v).addClass('hidden'); });
|
|
}
|
|
sbc.populateItemValues = function (cfg, $item, val)
|
|
{
|
|
//sbc.debug('populateItemValues', cfg, $item, val);
|
|
for (var name in val || []) { $item.find('.' + cfg.column.prefix + name).text(val[name]); };
|
|
}
|
|
sbc.clearItemForm = function ($frm)
|
|
{
|
|
//sbc.clearControlErrors($frm);
|
|
$('.sbc-input,.sbc-textarea,.sbc-select', $frm).val('').prop('readonly', false).prop('disabled', false);
|
|
$('.sbc-checkbox', $frm).prop('readonly', false).prop('disabled', false).removeAttr('checked');
|
|
}
|
|
sbc.configureItemControls = function (cfg, $frm)
|
|
{
|
|
//sbc.debug('configureItemControls', cfg);
|
|
let fld = cfg.field || {};
|
|
let $ctrl = $('.sbc-form-control', $frm).show();
|
|
for (var name in fld.label || {}) { /* ... */ };
|
|
(fld.hide || []).forEach(function (v, i, a) { $ctrl.filter('.' + fld.prefix + v).hide().find('.sbc-input,.sbc-textarea,.sbc-select,.sbc-checkbox').prop('disabled', true); });
|
|
(fld.readonly || []).forEach(function (v, i, a) { $ctrl.filter('.' + fld.prefix + v).find('.sbc-input,.sbc.textarea,.sbc-select,.sbc-checkbox').prop('readonly', true).prop('disabled', true); });
|
|
}
|
|
sbc.populateFormValues = function (cfg, $frm, val)
|
|
{
|
|
//sbc.debug('populateFormValues', cfg, $frm, val);
|
|
let $ctrl = $('.sbc-form-control', $frm);
|
|
for (var name in val || {}) { $ctrl.filter('.' + cfg.field.prefix + name).find('.sbc-input,.sbc-textarea,.sbc-select').filter('.sbc-auto-val').val(val[name]).end().find('.sbc-checkbox').prop('checked', !!val[name]); };
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Page navigation.
|
|
sbc.navigateTo = function (action)
|
|
{
|
|
sbc.doPleaseWait();
|
|
$('#frmNavigate').prop('action', sbc.url.base + action).trigger('submit');
|
|
}
|
|
sbc.goToPage = function (action)
|
|
{
|
|
sbc.doPleaseWait();
|
|
location = sbc.url.base + action;
|
|
}
|
|
|
|
// Security.
|
|
sbc.redirectHome = function ()
|
|
{
|
|
sbc.goToPage('');
|
|
}
|
|
sbc.redirectHomeExp = function ()
|
|
{
|
|
sbc.doPleaseWait();
|
|
document.location = sbc.url.sesionExpired;
|
|
}
|
|
sbc.onSignOut = function ()
|
|
{
|
|
sbc.doConfirm(sbc.dlg.title.signOut, sbc.msg.signOutConfirm, sbc.doSignOut);
|
|
}
|
|
sbc.doSignOut = function ()
|
|
{
|
|
sbc.doAjaxRequest({ url: sbc.url.base + 'Security/Ajax/SignOut', formId: 'frmNavigate' }, 50);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Dialogs.
|
|
sbc.openDialog = function ($dlg, width, height)
|
|
{
|
|
let $win = $(win);
|
|
$dlg.dialog(
|
|
{
|
|
minWidth: null, maxWidth: null, width: Math.min(width || 400, $win.width() * .98),
|
|
minHeight: null, maxHeight: null, height: Math.min(height || 320, $win.innerHeight() * .98)
|
|
}).dialog('open');
|
|
return $dlg;
|
|
}
|
|
sbc.dlgOpts = function ()
|
|
{
|
|
return { autoOpen: false, modal: true, show: 'clip', hide: 'clip', minWidth: 320, maxWidth: 480, width: 'auto', resizable: false, draggable: false, closeOnEscape: false, dialogClass: "no-close center-buttons", buttons: {} };
|
|
}
|
|
sbc.dlgOptsClose = function ()
|
|
{
|
|
var opts = sbc.dlgOpts();
|
|
opts.buttons[sbc.lbl.close] = function () { $(this).dialog('close'); };
|
|
return opts;
|
|
}
|
|
sbc.doAlert = function (title, msg, onOk)
|
|
{
|
|
if (!msg)
|
|
{
|
|
msg = title;
|
|
title = null;
|
|
}
|
|
if (!sbc.isDef(sbc.$dlg.alert))
|
|
{
|
|
var opt = sbc.dlgOpts();
|
|
sbc.$dlg.alert = $('<div id="dlgAlert"><div id="dlgAlertMsg"></div></div>').dialog(opt);
|
|
}
|
|
$('#dlgAlertMsg', sbc.$dlg.alert).html(msg.replace(/\n/g, '<br>'));
|
|
let btns = {};
|
|
btns[sbc.lbl.ok] = function () { $(this).dialog('close'); if (onOk) onOk(); };
|
|
sbc.$dlg.alert.dialog('option', { title: title || sbc.dlg.title.alert, buttons: btns });
|
|
sbc.openDialog(sbc.$dlg.alert);
|
|
}
|
|
sbc.doConfirm = function (title, msg, onOk, onCancel)
|
|
{
|
|
if (!msg)
|
|
{
|
|
msg = title;
|
|
title = null;
|
|
}
|
|
if (!sbc.isDef(sbc.$dlg.confirm))
|
|
{
|
|
var opt = sbc.dlgOpts();
|
|
sbc.$dlg.confirm = $('<div id="dlgConfirm"><div class="spacer2"></div><div id="dlgConfirmMsg"></div></div>').dialog(opt);
|
|
}
|
|
let btns = {};
|
|
btns[sbc.lbl.yes] = function () { $(this).dialog('close'); if (onOk) onOk(); };
|
|
btns[sbc.lbl.no] = function () { $(this).dialog('close'); if (onCancel) onCancel(); };
|
|
sbc.$dlg.confirm.dialog('option', { title: title || sbc.dlg.title.confirm, buttons: btns });
|
|
$('#dlgConfirmMsg').html(msg.replace(/\n/g, '<br>'));
|
|
sbc.openDialog(sbc.$dlg.confirm);
|
|
}
|
|
sbc.doProgress = function (title, msg, delay)
|
|
{
|
|
if (!msg)
|
|
{
|
|
msg = title;
|
|
title = null;
|
|
}
|
|
clearTimeout(sbc.toShowProgress);
|
|
if (!sbc.isDef(sbc.$dlg.progress))
|
|
{
|
|
var opt = sbc.dlgOpts();
|
|
opt.show = { effect: 'fade', duration: 200 };
|
|
opt.hide = { effect: 'fade', duration: 200 };
|
|
sbc.$dlg.progress = $('<div id="dlgProgress"><div id="dlgProgressMsg"></div></div>').dialog(opt);
|
|
}
|
|
$('#dlgProgressMsg').html(msg.replace(/\n/g, '<br>'));
|
|
sbc.$dlg.progress.dialog('option', { title: title || sbc.dlg.title.progress });
|
|
if (delay > 0) sbc.toShowProgress = setTimeout(function () { sbc.$dlg.progress.dialog('open'); }, delay);
|
|
else sbc.$dlg.progress.dialog('open');
|
|
}
|
|
sbc.hideProgress = function ()
|
|
{
|
|
clearTimeout(sbc.toShowProgress);
|
|
sbc.$dlg.progress.dialog('close');
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Notifications.
|
|
sbc.showNotification = function (title, msg)
|
|
{
|
|
win.clearTimeout(sbc.toNotification);
|
|
var $win = $(win);
|
|
var $not = $('#sbc-notification').hide();
|
|
var $main = $('#sbc-page-body main');
|
|
if (!$not.length)
|
|
{
|
|
$not = $('<div id="sbc-notification"><div class="content"><div class="heading"><div class="close" onclick="sbc.hideNotification()">✖</div><div class="title"></div></div><div class="message"></div></div></div>');
|
|
($main.length ? $main : $('body')).append($not);
|
|
}
|
|
var $hdr = $('.heading', $not).css({ 'background-color': 'rgba(247,217,0,0.7)' });
|
|
$not.find('.title').html(title).end().find('.message').html(msg);
|
|
$not.show(500, function () { $hdr.delay(1500).animate({ backgroundColor: '#f0f0f0' }, 500); });
|
|
sbc.toNotification = setTimeout(sbc.hideNotification, 4000);
|
|
}
|
|
sbc.hideNotification = function ()
|
|
{
|
|
win.clearTimeout(sbc.toNotification);
|
|
$('#sbc-notification').hide(500);
|
|
}
|
|
sbc.doPleaseWait = function ()
|
|
{
|
|
sbc.$pleaseWait = sbc.$pleaseWait || $('#sbc-please-wait');
|
|
sbc.$pleaseWait.stop(true, false).animate({ "null": 1 }, 200).fadeTo(200, 1);
|
|
}
|
|
sbc.hidePleaseWait = function ()
|
|
{
|
|
if (sbc.$pleaseWait) sbc.$pleaseWait.stop(true, false).fadeOut(200);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Ajax.
|
|
sbc.doAjaxRequest = (ajax, delay) =>
|
|
{
|
|
win.clearTimeout(ajax.timeout);
|
|
if (!ajax.noWaitIcon) sbc.doPleaseWait();
|
|
ajax.timeout = setTimeout(function () { sbc.execAjaxRequest(ajax); }, Math.max(50, parseInt(delay || 0, 10)));
|
|
}
|
|
sbc.cancelAjaxRequest = (ajax) =>
|
|
{
|
|
win.clearTimeout(ajax?.timeout);
|
|
}
|
|
sbc.execAjaxRequest = (ajax) =>
|
|
{
|
|
win.clearTimeout(ajax.timeout);
|
|
delete ajax.timeout;
|
|
if (ajax.request) ajax.request.abort();
|
|
var cfgAjax =
|
|
{
|
|
url: ajax.url,
|
|
type: 'POST',
|
|
cache: false,
|
|
//enctype: 'multipart/form-data',
|
|
data: ajax.formData || $(ajax.formSel || "#" + ajax.formId).serialize(),
|
|
dataType: 'json',
|
|
success: function (response, status, jqXHR)
|
|
{
|
|
if (!ajax.noWaitIcon) sbc.hidePleaseWait();
|
|
ajax.status = status;
|
|
if (response.notification)
|
|
sbc.showNotification(response.notification.title, response.notification.message);
|
|
if (response.message)
|
|
{
|
|
var fnCloseAlert = function ()
|
|
{
|
|
if (response.sessionExpired) return sbc.redirectHomeExp();
|
|
if (response.goHome) return sbc.redirectHome();
|
|
if (ajax.callbackFn) ajax.callbackFn(response);
|
|
}
|
|
sbc.doAlert(response.message.title, response.message.text, function () { fnCloseAlert(); });
|
|
}
|
|
else if (response.sessionExpired)
|
|
return sbc.redirectHomeExp();
|
|
else if (response.goHome)
|
|
return sbc.redirectHome();
|
|
else if (response.error && ajax.errFn) ajax.errFn(response);
|
|
else if (ajax.callbackFn) ajax.callbackFn(response);
|
|
},
|
|
error: function (jqXHR, status, errorThrown)
|
|
{
|
|
if (!ajax.noWaitIcon) sbc.hidePleaseWait();
|
|
ajax.status = status;
|
|
if (status == "abort") return;
|
|
sbc.doAlert(sbc.dlg.title.alert, sbc.msg.somethingGoneWrong, sbc.redirectHome);
|
|
},
|
|
complete: function (jqXHR, textStatus)
|
|
{
|
|
if (!ajax.noWaitIcon) sbc.hidePleaseWait();
|
|
ajax.formData = null;
|
|
ajax.complete = true;
|
|
}
|
|
}
|
|
if (ajax.formData)
|
|
{
|
|
//for (var pair of ajax.formData.entries()) sbc.debug(pair[0] + ': ' + pair[1]);
|
|
cfgAjax.processData = false;
|
|
cfgAjax.contentType = false;
|
|
}
|
|
ajax.request = $.ajax(cfgAjax);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Session.
|
|
sbc.configureKeepLoggedIn = function (single)
|
|
{
|
|
//sbc.debug('KeepLoggedIn Configuring');
|
|
let kli = sbc.kli;
|
|
if (!kli.timeout) kli.timeout = setTimeout(function () { sbc.doKeepLoggedIn(single); }, Math.max(30000, kli.interval || 300000));
|
|
}
|
|
sbc.doKeepLoggedIn = function (single)
|
|
{
|
|
//sbc.debug('KeepLoggedIn Calling');
|
|
let kli = sbc.kli;
|
|
delete kli.timeout;
|
|
var onKeepLoggedIn = function (response)
|
|
{
|
|
//sbc.debug('KeepLoggedIn Responded', response);
|
|
kli.lastAt = sbc.getTime();
|
|
if (!single) sbc.configureKeepLoggedIn();
|
|
}
|
|
sbc.doAjaxRequest({ url: sbc.url.base + 'Security/Ajax/KeepLoggedIn', formId: 'frmNavigate', noWaitIcon: true, callbackFn: onKeepLoggedIn }, 1000)
|
|
}
|
|
sbc.configureSessionRefresh = function ()
|
|
{
|
|
//sbc.debug('SessionRefresh Configuring');
|
|
$(document).on('mousedown mousemove touchstart scroll keydown', sbc.triggeRefreshSession);
|
|
}
|
|
sbc.triggeRefreshSession = function ()
|
|
{
|
|
if (sbc.kli.timeout) return;
|
|
//sbc.debug('SessionRefresh Triggering');
|
|
sbc.configureKeepLoggedIn(1);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Data entry.
|
|
sbc.hasControlErrors = function (context)
|
|
{
|
|
return $('.sbc-form-control', $(context || doc.body)).hasClass('sbc-error');
|
|
}
|
|
sbc.clearControlErrors = function (context)
|
|
{
|
|
var $ctrls = $('.sbc-form-control', $(context || doc.body)).removeClass('sbc-error');
|
|
$('.sbc-message', $ctrls).empty();
|
|
}
|
|
sbc.clearControlError = function (sel)
|
|
{
|
|
var $ctrl = $(sel).closest('.sbc-form-control').removeClass('sbc-error');
|
|
$('.sbc-message', $ctrl).empty();
|
|
}
|
|
sbc.setControlError = function (sel, error)
|
|
{
|
|
//sbc.debug(sel, error);
|
|
var $ctrl = $(sel).closest('.sbc-form-control').addClass('sbc-error');
|
|
$('.sbc-message', $ctrl).text(error);
|
|
}
|
|
sbc.refreshControlValues = function (controlValues, context)
|
|
{
|
|
var $frmCtrls = $('.sbc-form-control', $(context || doc.body)).removeClass('sbc-error');
|
|
sbc.clearControlErrors(context);
|
|
for (let ctrlValue of controlValues || [])
|
|
{
|
|
$frmCtrls.each(function (idx, frmCtrl)
|
|
{
|
|
var $frmCtrl = $(frmCtrl);
|
|
if (!$frmCtrl.hasClass(ctrlValue.controlName)) return;
|
|
var $ctrl = $('sbc-input,sbc-textarea,sbc-select', $frmCtrl);
|
|
if ($ctrl.length && sbc.isDef(ctrlValue.value))
|
|
$ctrl.val(ctrlValue.value);
|
|
if (ctrlValue.error)
|
|
$frmCtrl.addClass('sbc-error').find('.sbc-message').text(ctrlValue.error);
|
|
});
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Elements.
|
|
sbc.objBtm = function (sel)
|
|
{
|
|
var $obj = $(sel);
|
|
return Math.floor($obj.offset().top + $obj.outerHeight(true));
|
|
}
|
|
sbc.innerBtm = function (sel)
|
|
{
|
|
var $obj = $(sel);
|
|
return Math.floor($obj.offset().top + $obj.outerHeight() - sbc.bottomSurround($obj));
|
|
}
|
|
sbc.innerTop = function (sel)
|
|
{
|
|
var $obj = $(sel);
|
|
return Math.floor($obj.offset().top + sbc.topSurround($obj));
|
|
}
|
|
sbc.topMargin = function (sel)
|
|
{
|
|
var $obj = $(sel);
|
|
return parseInt($obj.css('margin-top'), 10);
|
|
}
|
|
sbc.topSurround = function (sel)
|
|
{
|
|
var $obj = $(sel);
|
|
return parseInt($obj.css('margin-top'), 10) + parseInt($obj.css('border-top-width'), 10) + parseInt($obj.css('padding-top'), 10);
|
|
}
|
|
sbc.bottomSurround = function (sel)
|
|
{
|
|
var $obj = $(sel);
|
|
return parseInt($obj.css('margin-bottom'), 10) + parseInt($obj.css('border-bottom-width'), 10) + parseInt($obj.css('padding-bottom'), 10);
|
|
}
|
|
sbc.marginHeight = function (sel)
|
|
{
|
|
var $obj = $(sel);
|
|
return parseInt($obj.css('margin-top'), 10) + parseInt($obj.css('margin-bottom'), 10);
|
|
}
|
|
sbc.borderHeight = function (sel)
|
|
{
|
|
var $obj = $(sel);
|
|
return parseInt($obj.css('border-top-width'), 10) + parseInt($obj.css('border-bottom-width'), 10);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Viewport - Desktop or Mobile.
|
|
sbc.isMob = function () { return $('body.mob').length > 0; };
|
|
sbc.onChangeViewport = function (viewport)
|
|
{
|
|
var $body = $('body');
|
|
$body.removeClass('mob dsk');
|
|
if (viewport.is('xs')) $body.addClass('mob');
|
|
else if (viewport.current() != 'unrecognized') $body.addClass('dsk');
|
|
}
|
|
sbc.isAutoHeight = function () { return ($(win).width() < 360 || $(win).height() < 560 || sbc.isMob()); }
|
|
sbc.onWinResizePage = function () { };
|
|
sbc.onWinResize = function ()
|
|
{
|
|
$('body').toggleClass('sbc-layout-flex', !sbc.isAutoHeight()).toggleClass('sbc-layout-flow', sbc.isAutoHeight());
|
|
sbc.onWinResizePage();
|
|
}
|
|
setTimeout(sbc.onWinResize, 50);
|
|
|
|
//--------------------------------------------------------------
|
|
$(function ()
|
|
{
|
|
$(win).on('resize', function () { sbc.onWinResize(); });
|
|
|
|
$('.sbc-button-cta,.sbc-button-action,.sbc-action-link,.sbc-social-icon.sbc-action').prop('tabindex', 0);
|
|
|
|
$(win).on('resize', function () { sbc.onWinResize(); });
|
|
setTimeout(function () { $(win).trigger('resize') }, 200);
|
|
|
|
$.fn.visible = function () { return this.css('visibility', 'visible'); };
|
|
$.fn.invisible = function () { return this.css('visibility', 'hidden'); };
|
|
$.fn.toggleVisibility = function ()
|
|
{
|
|
return this.css('visibility', function (i, visibility) { return (visibility == 'visible') ? 'hidden' : 'visible'; });
|
|
};
|
|
|
|
$.fn.removeStatusClasses = function ()
|
|
{
|
|
return this.removeClass(function (idx, name) { return (name.match(/(^|\s)sbc-status-\S+/g) || []).join(' '); });
|
|
};
|
|
|
|
if (sbc.kli.active)
|
|
sbc.configureKeepLoggedIn();
|
|
else if (!sbc.awaitingLogin)
|
|
sbc.configureSessionRefresh();
|
|
|
|
$.datepicker.setDefaults({
|
|
showOn: 'both',
|
|
buttonImageOnly: true,
|
|
buttonImage: '../img/action/calendar32.png',
|
|
buttonText: sbc.lbl.calendar,
|
|
dateFormat: sbc.form.calendarDateFormat,
|
|
changeMonth: true,
|
|
changeYear: false,
|
|
yearRange: '-14:+01',
|
|
firstDay: 1,
|
|
//defaultDate: 0,
|
|
});
|
|
});
|
|
|
|
}(window, window.document));
|
|
|
|
//--------------------------------------------------------------
|
|
(function ()
|
|
{
|
|
if (typeof Object.defineProperty === 'function')
|
|
{
|
|
try { Object.defineProperty(Array.prototype, 'sortCI', { value: sbc.arraySortCI }); } catch (e) { }
|
|
}
|
|
if (!Array.prototype.sortBy) Array.prototype.sortCI = sbc.arraySortCI;
|
|
})();
|
|
|
|
/* The End */ |