123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- $.extend({
- round : function(n, digit) {
- if (isNaN(n) || isNaN(digit))
- return 0;
- return Math.round(n * Math.pow(10, digit)) / Math.pow(10, digit);
- },
- toFloat : function(str) {
- var r = parseFloat(str.replace(/,/g, ''));
- if (isNaN(r))
- return 0;
- return r;
- },
- formatCurrency : function(d, digit) {
- var s = this.round(d, digit).toString();
- var hasSymbol = s.charAt(0) == '-' || s.charAt(0) == '+';
- var integerStr = hasSymbol ? s.substr(1) : s;
- var digitPos = integerStr.indexOf(".");
- var result = "";
- var digitStr = "";
- if (digitPos != -1) {
- integerStr = s.substr(hasSymbol ? 1 : 0, digitPos);
- digitStr = s.substr(digitPos + 1 + (hasSymbol ? 1 : 0));
- }
- for (var i = integerStr.length; i >= 0; i = i - 3) {
- result = integerStr
- .substr(i - 3 < 0 ? 0 : i - 3, i - 3 < 0 ? i : 3)
- + result;
- if (i - 3 > 0)
- result = "," + result;
- }
- if (digit > 0) {
- result += "." + digitStr;
- for (var i = digitStr.length; i < digit; i++) {
- result += '0';
- }
- }
- if (hasSymbol)
- result = s.charAt(0) + result;
- return result;
- },
- opennewwin : function(url, name, height, width, options) {
- if (height < 1) {
- height = Math.round(screen.availHeight * height);
- }
- if (width < 1) {
- width = Math.round(screen.availWidth * width);
- }
- var top = (screen.availHeight - height) / 2;
- var left = (screen.availWidth - width) / 2;
- if (!$.browser.msie) {
- var features = "resizable=1,status=1,scrollbars=1,height=" + height
- + ",width=" + width + ",top=" + top + ",left=" + left;
- for (key in options) {
- features += "," + key + "=" + options[key];
- }
- return window.open(url, name, features);
- } else {
- var features = "resizable:1;status:1;scroll:1;center:1;dialogHeight:"
- + height
- + "px;dialogWidth:"
- + width
- + "px;dialogTop:"
- + top + "px;dialogLeft:" + left + "px";
- if (options && options.modal) {
- return window.showModalDialog(url, window, features);
- }
- return window.showModelessDialog(url, window, features);
- }
- },
- getFormParams : function(form) {
- var r = {};
- $(":text, :hidden, :password, select", form).each(function() {
- if (typeof(this.name) != "undefined" && this.name.length > 0
- && $(this).visible()) {
- r[this.name] = this.value;
- }
- });
- $(":radio:checked, :checkbox:checked", form).each(function() {
- r[this.name] = true;
- });
- return r;
- },
- querystring : function(qs) {
- var params = {};
- if (qs == null)
- qs = location.search.substring(1, location.search.length);
- if (qs.length > 0) {
- qs = qs.replace(/\+/g, ' ');
- var args = qs.split('&'); // parse out name/value pairs separated
- // via &
- for (var i = 0; i < args.length; i++) {
- var pair = args[i].split('=');
- var name = decodeURIComponent(pair[0]);
- var value = (pair.length == 2)
- ? decodeURIComponent(pair[1])
- : name;
- params[name] = value;
- }
- }
- var parray = {
- get : function(name) {
- return params[name];
- },
- set : function(name, v) {
- if (typeof(v) == 'undefined' || v.length == 0)
- params[v] = null;
- else
- params[name] = v;
- return this;
- },
- toString : function() {
- var u = "";
- for (var name in params) {
- if (params[name] != null)
- u += name + "=" + encodeURIComponent(params[name])
- + "&";
- }
- return u.substring(0, u.length - 1);
- }
- }
- return parray;
- },
- getCookie : function(sName) {
- // cookies are separated by semicolons
- var aCookie = document.cookie.split("; ");
- for (var i = 0; i < aCookie.length; i++) {
- // a name/value pair (a crumb) is separated by an equal sign
- var aCrumb = aCookie[i].split("=");
- if (sName == aCrumb[0])
- return unescape(aCrumb[1]);
- }
- return null;
- },
- setCookie : function(sName, sValue, date) {
- document.cookie = sName + "=" + escape(sValue) + "; expires="
- + date.toGMTString();
- },
- loadXML : function(xmlFile, async) {
- var xmlDoc;
- if (window.ActiveXObject) {// for ie
- xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
- } else if (document.implementation
- && document.implementation.createDocument) {// for moz
- xmlDoc = document.implementation.createDocument('', '', null);
- } else {
- alert('xml read ERROR!');
- return null;
- }
- xmlDoc.async = async;
- xmlDoc.preserveWhiteSpace = false;
- xmlDoc.load(xmlFile);
- return xmlDoc;
- }
- });
- $.fn.extend({
- blockUI : function(opts) {
- var topDoc = window.document;
- var tw = topDoc.documentElement.clientWidth;
- var th = topDoc.documentElement.clientHeight;
- var el = $(this);
- var st = document.documentElement.scrollTop;
- var sl = document.documentElement.scrollLeft;
- var ww = document.documentElement.scrollWidth;
- var wh = document.documentElement.scrollHeight;
- if (ww < tw)
- ww = tw;
- if (wh < th)
- wh = th;
- var lay = $("#hcks_overlay");
- if (lay.length == 0) {
- var overlay = topDoc.createElement('DIV');
- overlay.id = 'hcks_overlay';
- overlay.style.position = 'absolute';
- overlay.style.left = '0px';
- overlay.style.top = '0px';
- overlay.style.width = (ww + sl) + 'px';
- overlay.style.height = (wh + st) + 'px';
- overlay.style.zIndex = 100;
- overlay.style.backgroundColor = '#000';
- overlay.className = 'overlay';
- // fix ie 6-- bug
- if ($.browser.msie && $.browser.version < 7) {
- var overlayFrame = topDoc.createElement("IFRAME");
- overlayFrame.id = 'hcks_overlayFrame';
- overlayFrame.style.position = 'absolute';
- overlayFrame.style.left = '0px';
- overlayFrame.style.top = '0px';
- overlayFrame.style.width = (ww + sl) + 'px';
- overlayFrame.style.height = (wh + st) + 'px';
- overlayFrame.style.zIndex = 99;
- overlayFrame.allowTransparency = true;
- overlayFrame.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
- topDoc.body.appendChild(overlayFrame);
- }
- topDoc.body.appendChild(overlay);
- } else {
- if (lay.is(":hidden")) {
- $("#hcks_overlayFrame").css({
- width : (ww + sl),
- height : (wh + st)
- }).show();
- lay.css({
- width : (ww + sl),
- height : (wh + st)
- }).show();
- }
- }
- var t = (th - el.height()) / 2 + st;
- var l = (tw - el.width()) / 2 + sl;
- if (t < 0)
- t = 10;
- if (l < 0)
- l = 10;
- el.revertValidation();
- el.css("position", "absolute").css('zIndex', 101).css("left", l + "px")
- .css("top", t + "px").show();
- return el;
- },
- unblockUI : function() {
- var overlay = $("#hcks_overlay");
- overlay.hide();
- $("#hcks_overlayFrame").hide();
- $(this).hide();
- },
- visible : function() {
- var v = ((this.attr("tagName") == 'INPUT' && this.attr("type") == 'hidden') || $(this)
- .is(":visible"))
- && $(this).parents(":hidden").length == 0;
- return v;
- }
- });
- Number.prototype.add = function(arg) {
- var r1, r2, m;
- try {
- r1 = this.toString().split(".")[1].length
- } catch (e) {
- r1 = 0
- }
- try {
- r2 = arg.toString().split(".")[1].length
- } catch (e) {
- r2 = 0
- }
- m = Math.pow(10, Math.max(r1, r2));
- return (this * m + arg * m) / m;
- }
- Number.prototype.sub = function(arg) {
- return this.add(-arg);
- }
- Number.prototype.mul = function(arg) {
- var m = 0, s1 = this.toString(), s2 = arg.toString();
- try {
- m += s1.split(".")[1].length
- } catch (e) {
- }
- try {
- m += s2.split(".")[1].length
- } catch (e) {
- }
- return Number(s1.replace(".", "")) * Number(s2.replace(".", ""))
- / Math.pow(10, m);
- }
- Number.prototype.div = function(arg) {
- var t1 = 0, t2 = 0, r1, r2;
- try {
- t1 = this.toString().split(".")[1].length
- } catch (e) {
- }
- try {
- t2 = arg.toString().split(".")[1].length
- } catch (e) {
- }
- with (Math) {
- r1 = Number(this.toString().replace(".", ""))
- r2 = Number(arg.toString().replace(".", ""))
- return (r1 / r2) * pow(10, t2 - t1);
- }
- }
- Number.prototype.round = function(arg) {
- return $.round(this, arg);
- }
- Date.prototype.format = function(fm) {
- if (!fm)
- fm = "yyyy-MM-dd";
- return fm.replace(/yyyy/g, this.getFullYear().toString()).replace(
- /MM/g,
- this.getMonth() < 9 ? "0" + (this.getMonth() + 1) : this.getMonth()
- .toString()).replace(
- /dd/g,
- this.getDate() < 10 ? "0" + this.getDate() : this.getDate()
- .toString()).replace(/yy/g,
- this.getFullYear().toString().substr(2)).replace(/M/g,
- this.getMonth() + 1).replace(/d/g, this.getDate().toString());
- }
- /**
- * 判断是否出现纵向滚动条
- * @return {}
- */
- function getIsScroll() {
- var xScroll, yScroll;
- if (window.innerHeight && window.scrollMaxY) {
- xScroll = document.body.scrollWidth;
- yScroll = window.innerHeight + window.scrollMaxY;
- } else if (document.body.scrollHeight > document.body.offsetHeight) { // all
- // but
- // Explorer
- // Mac
- xScroll = document.body.scrollWidth;
- yScroll = document.body.scrollHeight;
- } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla
- // and Safari
- xScroll = document.body.offsetWidth;
- yScroll = document.body.offsetHeight;
- }
- var windowWidth, windowHeight;
- if (self.innerHeight) { // all except Explorer
- windowWidth = self.innerWidth;
- windowHeight = self.innerHeight;
- } else if (document.documentElement
- && document.documentElement.clientHeight) { // Explorer 6 Strict
- // Mode
- windowWidth = document.documentElement.clientWidth;
- windowHeight = document.documentElement.clientHeight;
- } else if (document.body) { // other Explorers
- windowWidth = document.body.clientWidth;
- windowHeight = document.body.clientHeight;
- }
- // for small pages with total height less then height of the viewport
- if (yScroll < windowHeight) {
- pageHeight = windowHeight;
- } else {
- pageHeight = yScroll;
- }
- if (xScroll < windowWidth) {
- pageWidth = windowWidth;
- } else {
- pageWidth = xScroll;
- }
- // alert(pageWidth);
- // alert(pageHeight);
- // alert(windowWidth);
- // alert(windowHeight);
- return pageHeight - windowHeight > 0;
- }
|