﻿jQuery.fn.showLoading = function (a) { var b; var c = { addClass: "", beforeShow: "", afterShow: "", hPos: "center", vPos: "center", indicatorZIndex: 5001, overlayZIndex: 5e3, parent: "", marginTop: 0, marginLeft: 0, overlayWidth: null, overlayHeight: null }; jQuery.extend(c, a); var d = jQuery("<div></div>"); var e = jQuery("<div></div>"); if (c.indicatorID) { b = c.indicatorID } else { b = jQuery(this).attr("id") } jQuery(d).attr("id", "loading-indicator-" + b); jQuery(d).addClass("loading-indicator"); if (c.addClass) { jQuery(d).addClass(c.addClass) } jQuery(e).css("display", "none"); jQuery(document.body).append(e); jQuery(e).attr("id", "loading-indicator-" + b + "-overlay"); jQuery(e).addClass("loading-indicator-overlay"); if (c.addClass) { jQuery(e).addClass(c.addClass + "-overlay") } var f; var g; var h = jQuery(this).css("border-top-width"); var i = jQuery(this).css("border-left-width"); h = isNaN(parseInt(h)) ? 0 : h; i = isNaN(parseInt(i)) ? 0 : i; var j = jQuery(this).offset().left + parseInt(i); var k = jQuery(this).offset().top + parseInt(h); if (c.overlayWidth !== null) { f = c.overlayWidth } else { f = parseInt(jQuery(this).width()) + parseInt(jQuery(this).css("padding-right")) + parseInt(jQuery(this).css("padding-left")) } if (c.overlayHeight !== null) { g = c.overlayWidth } else { g = parseInt(jQuery(this).height()) + parseInt(jQuery(this).css("padding-top")) + parseInt(jQuery(this).css("padding-bottom")) } jQuery(e).css("width", f.toString() + "px"); jQuery(e).css("height", g.toString() + "px"); jQuery(e).css("left", j.toString() + "px"); jQuery(e).css("position", "absolute"); jQuery(e).css("top", k.toString() + "px"); jQuery(e).css("z-index", c.overlayZIndex); if (c.overlayCSS) { jQuery(e).css(c.overlayCSS) } jQuery(d).css("display", "none"); jQuery(document.body).append(d); jQuery(d).css("position", "absolute"); jQuery(d).css("z-index", c.indicatorZIndex); var l = k; if (c.marginTop) { l += parseInt(c.marginTop) } var m = j; if (c.marginLeft) { m += parseInt(c.marginTop) } if (c.hPos.toString().toLowerCase() == "center") { jQuery(d).css("left", (m + (jQuery(e).width() - parseInt(jQuery(d).width())) / 2).toString() + "px") } else if (c.hPos.toString().toLowerCase() == "left") { jQuery(d).css("left", (m + parseInt(jQuery(e).css("margin-left"))).toString() + "px") } else if (c.hPos.toString().toLowerCase() == "right") { jQuery(d).css("left", (m + (jQuery(e).width() - parseInt(jQuery(d).width()))).toString() + "px") } else { jQuery(d).css("left", (m + parseInt(c.hPos)).toString() + "px") } if (c.vPos.toString().toLowerCase() == "center") { jQuery(d).css("top", (l + (jQuery(e).height() - parseInt(jQuery(d).height())) / 2).toString() + "px") } else if (c.vPos.toString().toLowerCase() == "top") { jQuery(d).css("top", l.toString() + "px") } else if (c.vPos.toString().toLowerCase() == "bottom") { jQuery(d).css("top", (l + (jQuery(e).height() - parseInt(jQuery(d).height()))).toString() + "px") } else { jQuery(d).css("top", (l + parseInt(c.vPos)).toString() + "px") } if (c.css) { jQuery(d).css(c.css) } var n = { overlay: e, indicator: d, element: this }; if (typeof c.beforeShow == "function") { c.beforeShow(n) } jQuery(e).show(); jQuery(d).show(); if (typeof c.afterShow == "function") { c.afterShow(n) } return this }; jQuery.fn.hideLoading = function (a) { var b = {}; jQuery.extend(b, a); if (b.indicatorID) { indicatorID = b.indicatorID } else { indicatorID = jQuery(this).attr("id") } jQuery(document.body).find("#loading-indicator-" + indicatorID).remove(); jQuery(document.body).find("#loading-indicator-" + indicatorID + "-overlay").remove(); return this }
