$(document).ready(function () {
initCommonJS();
});
function initCommonJS() {
setScreenSize();
$(document).keydown(function (e) { return disableF5(e); });
$(document).ajaxStart(function () { showLoading(); });
$(document).ajaxStop(function () { hideLoading(); });
$('input[data=digits],input[data-type=digits]').keydown(function (e) {
var keycode = e.keyCode ? e.keyCode : e.which;
// Allow: backspace, delete, tab, escape, enter || Ctrl+A, Ctrl+C, Ctrl+V, Command+A || home, end, left, right, down, up
if ($.inArray(keycode, [46, 8, 9, 27, 13]) !== -1 || (keycode === 65 || keycode === 86 || keycode === 67) && (e.ctrlKey === true || e.metaKey === true) || keycode >= 35 && keycode <= 40) { return true; }
// Ensure that it is a number otherwise stop the keypress
if ((e.shiftKey || (keycode < 48 || keycode > 57)) && (keycode < 96 || keycode > 105)) { return false; }
//if (keycode >= 48 && keycode <= 57) return true; else return false;
});
$('input[data=amount],input[data-type=amount]').keydown(function (e) {
var keycode = e.keyCode ? e.keyCode : e.which;
// Allow: backspace, delete, tab, escape, enter || Ctrl+A, Ctrl+C, Ctrl+V, Command+A || home, end, left, right, down, up
if ($.inArray(keycode, [46, 8, 9, 27, 13]) !== -1 || (keycode === 65 || keycode === 86 || keycode === 67) && (e.ctrlKey === true || e.metaKey === true) || keycode >= 35 && keycode <= 40) { return true; }
if ((e.which || e.keyCode) >= 48 && (e.which || e.keyCode) <= 57 || (e.which || e.keyCode) === 46) return true;
else return false;
});
if ($("#capsWarning").length > 0) { CapsLock.addListener(function (status) { if (status) { $("#capsWarning").show().text('Warning: you have turned caps lock on'); } else { $("#capsWarning").hide(); } }); }
// Show/ Hide Password
$("").insertAfter("input[type=password].toggle-password").parent().css("position", "relative");
$(document).on('click', '.toggle-show-password', function () { $(this).toggleClass("fa-eye fa-eye-slash"); var elem = $(this).prev(); if (!elem.hasClass("toggle-password")) elem = elem.find('input.toggle-password'); if ($(this).hasClass("fa-eye-slash")) { elem.prop("type", "text"); } else { elem.prop("type", "password"); } });
//$(document).click(function (event) {
// if (!$(event.target).closest('.toggle-show-password').length) {
// var elem = $(this).prev(); if (!elem.hasClass("toggle-password")) elem = elem.find('input.toggle-password');
// elem.toggleProp("type", "text password");
// $(this).toggleClass("fa-eye fa-eye-slash");
// }
//});
$(window).resize(function () { setScreenSize(); $("table.dataTable").css("max-width", "100%"); });
$("table.dataTable").css('max-width', '100%');
$('.form-control:visible:enabled:not([readonly]):not([value]):first').focus();
$(document, '.panel-group').on('show.bs.collapse', function (n) {
$(n.target).siblings('.panel-heading').find('.panel-title i').toggleClass('fa-minus fa-plus');
});
$(document, '.panel-group').on('hide.bs.collapse', function (n) {
$(n.target).siblings('.panel-heading').find('.panel-title i').toggleClass('fa-plus fa-minus');
});
}
function showClock(control) {
if (control !== undefined) {
var today = new Date();
var d = today.getDate();
var M = today.getMonth() + 1;
var y = today.getFullYear();
var h = today.getHours();
var m = today.getMinutes();
//var s = today.getSeconds();
var t = h < 12 ? "AM" : "PM";
h = h > 12 ? h % 12 : h;
d = d < 10 ? "0" + d : d;
M = M < 10 ? "0" + M : M;
h = h < 10 ? "0" + h : h;
m = m < 10 ? "0" + m : m;
//s = s < 10 ? "0" + s : s;
if ($(window).width() > 767)
control.text("Current Date and Time: " + d + "-" + M + "-" + y + " " + h + ":" + m + " " + t); // + ":" + s;
else
control.text(d + "-" + M + "-" + y + " " + h + ":" + m + " " + t); // + ":" + s;
}
}
function setScreenSize() {
$('#main_content #ls-canvas').css("height", $(window).height() - 78);
$('#main_content #ls-canvas .main_content').css("height", $(window).height() - 115);
}
function setCenter(whichDiv) {
$(whichDiv).css({
left: ($(window).width() - $(whichDiv).width()) / 2,
top: ($(window).height() - $(whichDiv).height()) / 2
});
}
function setGridViewHeight() {
$('.gridview').css("max-height", $('#ls-canvas').height() * .70);
}
function ShowAlert(message) {
ShowMessage('Alert', message, null, 'OK', null);
}
function ShowMessage(title, msg, url, btntext, type) {
$('.modal-backdrop').hide();
BootstrapDialog.show({
title: title,
type: BootstrapDialog.TYPE_PRIMARY,
//size: BootstrapDialog.SIZE_SMALL,
draggable: true,
closable: false,
message: msg,
cssClass: 'message-box',
onhidden: function (dialog) {
$('.form-control:visible:enabled:not([readonly]):first').focus();
},
buttons: [{
label: 'OK',
hotkey: 13, // Enter
cssClass: 'btn-primary',
action: function (dialog) {
dialog.close();
if (url !== null && url !== '') {
if (top !== self) top.location.href = url; else window.location = url;
}
}
}]
});
}
function ShowModelPopup(type, content, title, cssClass) {
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DEFAULT,
//size: BootstrapDialog.SIZE_MEDIUM,
cssClass: cssClass,
draggable: true,
closable: true,
closeByBackdrop: type === 'image',
closeByKeyboard: type === 'image',
title: function (dialog) {
if (title === null || title.length === 0) {
dialog.getModalHeader().hide();
//dialog.getModalFooter().hide();
}
else
return title;
},
message: function (dialog) {
if (type === 'iframe') {
var style = '';
if (cssClass === 'modal-iframe') { style = "style='height:" + $(document).innerHeight() * .5 + 'px' + ";max-height:" + $(document).innerHeight() * .5 + 'px' + "'"; }
return "";
}
else if (type === 'image') {
return "";
}
if (type === 'application/pdf') {
return "";
}
else {
return content;
}
}
});
}
function ShowModelDialog(content, title, hideOnEsc, cssClass) {
BootstrapDialog.show({
type: BootstrapDialog.TYPE_DEFAULT,
//size: BootstrapDialog.SIZE_MEDIUM,
cssClass: cssClass,
draggable: true,
closable: true,
closeByBackdrop: hideOnEsc,
closeByKeyboard: hideOnEsc,
title: function (dialog) {
if (title === null || title.length === 0) {
dialog.getModalHeader().hide();
//dialog.getModalFooter().hide();
}
else
return title;
},
message: function (dialog) {
return $(content).html();
}
});
}
function ShowAlertBox(message) {
BootstrapDialog.show({
title: 'Alert',
cssClass: 'message-box',
type: BootstrapDialog.TYPE_DEFAULT,
//size: BootstrapDialog.SIZE_SMALL,
draggable: true,
message: message,
buttons: [{
label: 'OK',
hotkey: 13, // Enter
cssClass: 'btn-primary',
action: function (dialog) {
dialog.close();
}
}]
});
}
function ShowConfirmBox(message, okLabel, cancelLabel, e) {
var target = e.srcElement ? e.srcElement : e.target;
if (!$(target).hasClass('clicked')) {
e.preventDefault();
$(target).addClass('clicked');
BootstrapDialog.configDefaultOptions({
cssClass: 'message-box confirm-box',
btnsOrder: BootstrapDialog.BUTTONS_ORDER_OK_CANCEL
});
BootstrapDialog.confirm({
title: 'Confirmation',
message: message,
size: BootstrapDialog.SIZE_SMALL,
type: BootstrapDialog.TYPE_PRIMARY,
closable: false,
draggable: true,
btnCancelLabel: cancelLabel,
btnCancelClass: 'btn-primary',
btnOKLabel: okLabel,
callback: function (result) {
//if (result) { __doPostBack(target_name, ''); }
if (result) { $(target).click(); }
else { $(target).removeClass('clicked'); }
}
});
}
}
function ShowNotification(type, message) {
if ($(".notify").length) $(".notify").remove();
if (!$(".notify").length) {
var notify = '
' +
'
' +
'
' + message + '
';
$('body').append(notify);
$("#notifycolse").click(function (e) { $(".notify").remove(); });
}
}
function CloseOnEsc(divPopup) {
if (divPopup.is(':visible')) {
$(document).on('keydown', function (event) {
if (event.keyCode === 13 || event.keyCode === 27) { // ENTER OR ESC
CloseModelPopup(divPopup);
}
});
}
}
function CloseModelPopup(divPopup) {
if (divPopup) {
divPopup.css("display", "none");
}
else {
$('.modelPopup').css("display", "none");
}
}
function RemoveModelPopup() { $('.modal').remove(); $('.modal-backdrop').remove(); }
function showLoading() {
var loading = '';
$('body').append(loading);
$('.small-loading').show();
}
function hideLoading() {
$('.small-loading').remove();
}
function printDiv(div, css) {
var contents = div.html();
var frame1 = $('
');
frame1[0].name = "frame1";
frame1.css({ "position": "absolute", "top": "-1000000px" });
$("body").append(frame1);
var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
frameDoc.document.open();
//Create a new HTML document.
frameDoc.document.write('
Print');
frameDoc.document.write(css);
frameDoc.document.write('');
//Append the external CSS file.
//frameDoc.document.write('
');
//Append the DIV contents.
frameDoc.document.write(contents);
frameDoc.document.write('');
frameDoc.document.close();
setTimeout(function () {
window.frames["frame1"].focus();
window.frames["frame1"].print();
frame1.remove();
}, 500);
}
// Regular Expression Validation
function isValidRegx(data, regx) {
var pattern = new RegExp(regx);
return pattern.test(data);
}
function getPageName(url) {
if (!url || url && url.length === 0) { return ""; }
var index = url.lastIndexOf("/") + 1;
var filenameWithExtension = url.substr(index);
var basename = filenameWithExtension.split(/[.?]+/)[0];
// Handle '/mypage/' type paths
if (basename.length === 0) {
url = url.substr(0, index - 1);
basename = getBaseName(url);
}
return basename ? basename : "";
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
function jsRedirect(url) {
if (top !== self) top.location.href = url; else window.location = url;
}
function doClick(buttonName, e) {
if (e.which === 13 || e.keyCode === 13) {
var btn = document.getElementById(buttonName);
if (btn !== null) { //If we find the button click it
enc();
btn.click();
e.keyCode = 0;
}
return false;
}
return true;
}
function disableF5(e) { if ((116 === (e.which || e.keyCode) || e.ctrlKey && 82 === (e.which || e.keyCode)) && e.preventDefault(), !window.jQuery || "undefined" === typeof jQuery) { var t = document.createElement("script"); t.type = "text/javascript", t.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js", document.getElementsByTagName("head")[0].appendChild(t); } }
// Use as => if ($("#capsWarning").length > 0) { CapsLock.addListener(function (status) { if (status) { $("#capsWarning").show().text('Warning: you have turned caps lock on'); } else { $("#capsWarning").hide(); } }); }
var CapsLock = (function () { var _1 = false; var _2 = []; var _3 = /Mac/.test(navigator.platform); function _4() { return _1; } function _5(_6) { _2.push(_6); } function _7(e) { if (!e) { e = window.event; } var _8 = _1; var _9 = e.charCode ? e.charCode : e.keyCode; if (_9 >= 97 && _9 <= 122) { _1 = e.shiftKey; } else { if (_9 >= 65 && _9 <= 90 && !(e.shiftKey && _3)) { _1 = !e.shiftKey; } } if (_1 !== _8) { for (var _a = 0; _a < _2.length; _a++) { _2[_a](_1); } } } if (window.addEventListener) { window.addEventListener("keypress", _7, false); } else { document.documentElement.attachEvent("onkeypress", _7); } return { isOn: _4, addListener: _5 }; })();
// $.QueryString["d"]
(function ($) { $.QueryString = (function (a) { if (a === "") return {}; var b = {}; for (var i = 0; i < a.length; ++i) { var p = a[i].split('='); if (p.length !== 2) continue; b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); } return b; })(window.location.search.substr(1).split('&')); })(jQuery);
jQuery.fn.extend({ live: function (event, callback) { if (this.selector) { jQuery(document).on(event, this.selector, callback); } } });
// Use as $('#form1').preventDoubleSubmission();
jQuery.fn.preventDoubleSubmission = function () {
//$('input[type="submit"]').text('
Loading...');
$(this).on('submit', function (e) {
var $form = $(this);
$('input[type="submit"]').text('
Loading...');
$('input[type="submit"]', $form).button('loading');
if ($form.data('submitted') === true) {
// Previously submitted - don't submit again
e.preventDefault();
$('input[type="submit"]').addClass("btn-loading");
} else {
// Mark it so that the next submit can be ignored
$form.data('submitted', true);
$form.setFormTimeout();
}
});
// Keep chainability
return this;
};
jQuery.fn.setFormTimeout = function () { var $form = $(this); setTimeout(function () { $('input[type="submit"]', $form).button('reset'); $('input[type="submit"]', $form).removeClass('btn-loading'); }, 5000); };
// Detect if library loaded
function isLoadedScript(lib) { return document.querySelectorAll('[src="' + lib + '"]').length > 0; }
// Load library
//function loadScript(lib) { $("head").append(""); }
function loadScript(src) { loadExternalFile("js", src, "last"); }
function loadExternalFile(type, src, position) {
var htag;
if (type === "js") { //if file is a external JavaScript file
htag = document.createElement('script');
htag.setAttribute("type", "text/javascript");
htag.setAttribute("src", src);
}
else if (type === "css") { //if file is an external CSS file
htag = document.createElement("link");
htag.setAttribute("rel", "stylesheet");
htag.setAttribute("type", "text/css");
htag.setAttribute("href", src);
}
else if (type === "inline") {
htag = src;
}
if (typeof htag !== "undefined") {
if (typeof position !== "undefined") {
switch (position) {
case "insertBefore": $("head").insertBefore(htag, relTo); break;
case "first": $("head").insertBefore(htag, head.firstChild); break;
case "last": $("head").append(htag); break;
case "lastBody": $("body").append(htag); break;
}
}
else {
$("head").append(htag);
}
}
}
// Use as => var welcome = 'Hello {0}!'.format(name);
String.prototype.format = String.prototype.f = function () {
var s = this, i = arguments.length;
while (i--) { s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]); }
return s;
};
// Use as => if('String'.startsWith(prefix));
String.prototype.startsWith = function (prefix) {
return this.substr(0, prefix.length) === prefix;
};
// Use as => if('String'.endsWith(suffix));
String.prototype.endsWith = function (suffix) {
return this.substr(this.length - suffix.length) === suffix;
};
// Use as => 'dd-MM-yyyy'.toDate('-');
String.prototype.toDate = function (seprator) {
var parts = dateStr.split(seprator);
return new Date(parts[2], parts[1] - 1, parts[0]);
};
// For Searching Use as => search(elems, keyword)
function search(i, n) { i.removeHighlight(); var s; "" !== n ? (s = n, i.hide(), i.filter(function (i, n) { return !!$(this).is(":contains('" + s + "')") }).show()) : i.show(); if (n) i.highlight(n); }
$.expr[":"].contains = $.expr.createPseudo(function (arg) { return function (elem) { return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0; }; });
// Use as => $('body').highlight(keyword); $('body').removeHighlight();
jQuery.fn.highlight = function (e) { return this.each(function () { !function e(t, i) { var n = 0; if (3 == t.nodeType) { var a, l, d, h = t.data.toUpperCase().indexOf(i); 0 <= h && ((a = document.createElement("span")).className = "highlight bg-warning", (l = t.splitText(h)).splitText(i.length), d = l.cloneNode(!0), a.appendChild(d), l.parentNode.replaceChild(a, l), n = 1) } else if (1 == t.nodeType && t.childNodes && !/(script|style)/i.test(t.tagName)) for (var s = 0; s < t.childNodes.length; ++s)s += e(t.childNodes[s], i); return n }(this, e.toUpperCase()) }) };
jQuery.fn.removeHighlight = function () { return this.find("span.highlight").each(function () { var e = this.parentNode; e.replaceChild(this.firstChild, this), function e(n) { for (var i = 0, o = n.childNodes, t = o.length; i < t; i++) { var d, r, h = o[i]; 1 != h.nodeType ? 3 != h.nodeType || null != (d = h.nextSibling) && 3 == d.nodeType && (r = h.nodeValue + d.nodeValue, new_node = n.ownerDocument.createTextNode(r), n.insertBefore(new_node, h), n.removeChild(h), n.removeChild(d), i-- , t--) : e(h) } }(e) }).end() };
// Use as- $.PostData({ url: "https://ssotest.rajasthan.gov.in/sso", target: "_blank", params: { "userdetails": token }, message: "Please wait while you are being redirected back to", appName: "Rajasthan Single Sign-On" });
!function (p) { p.PostData = function (a) { var t, e, n = { position: "fixed", top: "0", left: "0", width: "100%", height: "100%", "z-index": "99999", background: "#fff" }, s = { position: "absolute", left: "50%", top: "50%", "-webkit-transform": "translate(-50%,-50%)", "-moz-transform": "translate(-50%,-50%)", "-o-transform": "translate(-50%,-50%)", "-ms-transform": "translate(-50%,-50%)", transform: "translate(-50%,-50%)", "text-align": "center", "font-family": "Arial", "font-size": "30px" }, r = a.target ? a.target : "_parent", i = p("