browserUtil_wev8.js 16.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
function openFullWindow(url){
  var redirectUrl = url ;
  var width = screen.width ;
  var height = screen.height ;
  if (height == 768 ) height -= 75 ;
  if (height == 600 ) height -= 60 ;
  var szFeatures = "top=0," ; 
  szFeatures +="left=0," ;
  szFeatures +="width="+width+"," ;
  szFeatures +="height="+height+"," ; 
  szFeatures +="directories=no," ;
  szFeatures +="status=yes," ;
  szFeatures +="menubar=no," ;
  if (height <= 600 ) szFeatures +="scrollbars=yes," ;
  else szFeatures +="scrollbars=no," ;
  szFeatures +="resizable=yes" ; //channelmode
  window.open(redirectUrl,"",szFeatures) ;
}

function openFullWindowHaveBar(url){
  var redirectUrl = url ;
  var width = screen.availWidth-10 ;
  var height = screen.availHeight-50 ;
  //if (height == 768 ) height -= 75 ;
  //if (height == 600 ) height -= 60 ;
   var szFeatures = "top=0," ;
  szFeatures +="left=0," ;
  szFeatures +="width="+width+"," ;
  szFeatures +="height="+height+"," ;
  szFeatures +="directories=no," ;
  szFeatures +="status=yes,toolbar=no,location=no," ;
  szFeatures +="menubar=no," ;
  szFeatures +="scrollbars=yes," ;
  szFeatures +="resizable=yes" ; //channelmode
  window.open(redirectUrl,"",szFeatures) ;
}

function openFullWindowHaveBarForWFList(url,requestid){
	try{
		document.getElementById("wflist_"+requestid+"span").innerHTML = "";
	}catch(e){}
	var redirectUrl = url ;
	var width = screen.availWidth-10 ;
	var height = screen.availHeight-50 ;
	//if (height == 768 ) height -= 75 ;
	//if (height == 600 ) height -= 60 ;
	var szFeatures = "top=0," ;
	szFeatures +="left=0," ;
	szFeatures +="width="+width+"," ;
	szFeatures +="height="+height+"," ;
	szFeatures +="directories=no," ;
	szFeatures +="status=yes,toolbar=no,location=no," ;
	szFeatures +="menubar=no," ;
	szFeatures +="scrollbars=yes," ;
	szFeatures +="resizable=yes" ; //channelmode
	window.open(redirectUrl,"",szFeatures) ;
}

//为了删除时用
function openFullWindow1(url){
  var redirectUrl = url ;
  var width = screen.width ;
  var height = screen.height ;
  if (height == 768 ) height -= 75 ;
  if (height == 600 ) height -= 60 ;
  var szFeatures = "top="+height/2+"," ; 
  szFeatures +="left="+width/2+"," ; 
  szFeatures +="width=181," ;
  szFeatures +="height=129," ; 
  szFeatures +="directories=no," ;
  szFeatures +="status=yes," ;
  szFeatures +="menubar=no," ;
  if (height <= 600 ) szFeatures +="scrollbars=yes," ;
  else szFeatures +="scrollbars=no," ;
  szFeatures +="resizable=no" ; //channelmode
  window.open(redirectUrl,"",szFeatures) ;
}


function openFullWindowForXtable(url){
  var redirectUrl = url ;
  var width = screen.width ;
  var height = screen.height ;
  //if (height == 768 ) height -= 75 ;
  //if (height == 600 ) height -= 60 ;
  var szFeatures = "top=100," ; 
  szFeatures +="left=400," ;
  szFeatures +="width="+width/2+"," ;
  szFeatures +="height="+height/2+"," ; 
  szFeatures +="directories=no," ;
  szFeatures +="status=yes," ;
  szFeatures +="menubar=no," ;
  szFeatures +="scrollbars=yes," ;
  szFeatures +="resizable=yes" ; //channelmode
  window.open(redirectUrl,"",szFeatures) ;
}

function  readCookie(name){  
   var  cookieValue  =  "7";  
   var  search  =  name  +  "=";
   try{
	   if(document.cookie.length  >  0) {    
	       offset  =  document.cookie.indexOf(search);  
	       if  (offset  !=  -1)  
	       {    
	           offset  +=  search.length;  
	           end  =  document.cookie.indexOf(";",  offset);  
	           if  (end  ==  -1)  end  =  document.cookie.length;  
	           cookieValue  =  unescape(document.cookie.substring(offset,  end))  
	       }  
	   }  
   }catch(exception){
   }
   return  cookieValue;  
} 

function setMenuDisabled(){
	var o, _disabled;
	switch(arguments.length){
		case 0 :
			o = window.frames["rightMenuIframe"].event.srcElement;
			_disabled = true;
			break;
		case 1 :
			o = arguments[0];
			_disabled = true;
			break;
		case 2 :
			o = arguments[0];
			_disabled = arguments[1];
			break;
	}
	o.disabled = _disabled;
}

/**
 * 根据标识(name或者id)获取元素,主要用于解决系统中很多元素没有id属性,
 * 却在js中使用document.getElementById(name)来获取元素的问题。
 * @param identity name或者id
 * @return 元素
 */
function $GetEle(identity, _document) {
	var rtnEle = null;
	if (_document == undefined || _document == null) _document = document;
	
	rtnEle = _document.getElementById(identity);
	if (rtnEle == undefined || rtnEle == null) {
		rtnEle = _document.getElementsByName(identity);
		if (rtnEle.length > 0) rtnEle = rtnEle[0];
		else rtnEle = null;
	}
	return rtnEle;
}

function $G(identity, _document) {
	return $GetEle(identity, _document);
}

function $GetEles(identity) {
	var rtnEle = null;
	
	rtnEle = document.getElementsByName(identity);
	
	if (rtnEle.length == 1) {
		return rtnEle[0]; 
	} else if (rtnEle.length == 0) {
		return document.getElementById(identity);
	}
	return rtnEle;
}

var wuiUtil = {
	/**
	 * isNotNull 目标值不为null || undefined,返回true,否则返回false
	 */
	isNotNull: function (target) {
		if (target == undefined || target == null) {
			return false;
		}
		return true;
	}, 
	/**
	 * isNullOrEmpty 目标值为null、undefined、空,返回true,否则返回false
	 */
	isNullOrEmpty : function (target) {
		if (target == undefined || target == null || target == "") {
			return true;
		}
		return false;
	}, 
	/**
	 * isNotEmpty 目标值不为null、undefined、空,返回true,否则返回false
	 */
	isNotEmpty : function (target) {
		if (target == undefined || target == null || target == "") {
			return false;
		}
		return true;
	},
	getJsonValueByIndex: function (josinobj, index) {
		var _index = 0;
		try {
			for(var key in josinobj){
				if (index == _index) {
					return josinobj[key]; 			
				}
				_index++;
			}
		} catch (e) {alert("browser return value is error!");}
		return "";
	}
};

//是否是chrome37+
var systemshowModalDialog = window._systemshowModalDialog;
//dialog返回值
var dialogReturnValue = void 0;
//showmodeldialog方法调用者
var dialogcaller = void 0;
//流程字段联动
var datainputCaller = void 0;
//字段联动方法
var datainputFun = void 0;
//showmodeldialog方法调用者参数
var dialogcallerArguments = void 0;


var othcaller = void 0;

var childWindow = void 0;
/**
 * 页面关闭时调用
 */
var closeHandle = function (rtvval) {
	if (dialogcaller) {
		//重写方法
		callerhandle(dialogcaller.toString(), datainputCaller);
	}
	var nfunarguments = new Array();
	nfunarguments.push(dialogReturnValue);
	
	//alert("test:"+ dialogcallerArguments.length);
	if (dialogcallerArguments) {
		for (var i=0; i<dialogcallerArguments.length; i++) {
			//alert(dialogcallerArguments[i]);
			//var argument = dialogcallerArguments[i];
			nfunarguments.push(dialogcallerArguments[i]);
		}
    }
	if (typeof(_callbackfunciton) == 'function') {
		_callbackfunciton.apply(null, nfunarguments);
	}
	
	if (!!datainputFun) {
		try {
			eval(datainputFun);
		} catch (e) {}
	}
	
	if (!!othcaller) {
		parentCallerHandle(dialogcaller.toString(), othcaller.toString(), dialogReturnValue);
	}
	
	//调用完毕,重置参数,保证下次调用的正确性
	resetDialog();
}

/**
 * 重写调用者方法
 */
var _callbackfunciton;
function callerhandle(callerstr, datainputCaller) {
	var funnameregex = /function +[^\(]*\(/;
	//var funnameregex = /function +.+\(/;
	var funnameendregex = /_callbackfunciton *= *function *\(_callbackobj, *\)/;
	
	callerstr = callerstr.replace(funnameregex, "_callbackfunciton = function (_callbackobj,");
	callerstr = callerstr.replace(funnameendregex, "_callbackfunciton = function (_callbackobj)");
	
	var _callerstrback = callerstr;
	//alert(callerstr);
	var callbackfun = "";
	//var regex = /=[ ]*window\.showModalDialog\(([^\(]+([\(][^\)]*\))*[^\)]+)*\)/g;
	var regex = /=[ ]*(window\.)?showModalDialog\([^\)]+\)/g;
	
	callerstr = callerstr.replace(regex, " = _callbackobj;//");
	
	//alert(callerstr);
	try {
		//不需要赋值的情况(比如:流程导入)
		var regex3 = /[ ]*(window\.)?showModalDialog\([^\)]+\)/g;
		//var regex = /=[ ]*window\.showModalDialog\(([^\(]+([\(][^\)]*\))*[^\)]+)*\)/g;
		callerstr = callerstr.replace(regex3, "//");
		//alert(callerstr);
		eval(callerstr);
		if (!!datainputCaller) {
			var datainputCallerstr = datainputCaller.toString();
			
			var diregex = /datainput\(\'field[\d]+\'\);?/;
			
			var rs = diregex.exec(datainputCallerstr);
			if (!!rs && rs.length > 0) {
				datainputFun = rs[0];
			} else {
				//明细字段的字段联动
				diregex = /datainputd\(\'field[\d]+_[\d]+\'\);?/;
				rs = diregex.exec(datainputCallerstr);
				if (!!rs && rs.length > 0) {
					datainputFun = rs[0];
				} 
			}
		}
	} catch (e) {
		try {
			var regexRs = regex.exec(_callerstrback);
			if (!!regexRs && regexRs.length > 0) {
				var rexindex = regex.lastIndex;
				
				var tempfunstr = _callerstrback.substr(rexindex);
				var temprightgindex = tempfunstr.indexOf(")");
				
				if (temprightgindex != -1 ) {
					tempfunstr = tempfunstr.substr(temprightgindex + 1);
				}
				
				var count = 0;
				
				var tempregex = /^[ ]*[\)]*[ ]*[+,]/;
				var temprs = tempregex.exec(tempfunstr);
				while (!!temprs && temprs.length > 0) {
					temprightgindex = tempfunstr.indexOf(")");
					if (temprightgindex == -1 ) {
						break;
					}
					tempfunstr = tempfunstr.substr(temprightgindex + 1);
					tempregex = /^[^\)]*[\)][\+,]/;
					temprs = tempregex.exec(tempfunstr);
					if (count++ == 20) {
						break;
					}
				}
				temprightgindex = tempfunstr.indexOf(")");
				if (temprightgindex != -1 ) {
					tempfunstr = tempfunstr.substr(temprightgindex + 1);
				}
				tempfunstr = tempfunstr.replace(/^[ ]*;/g, "");
				var tempfunbeforestr = _callerstrback.substring(0, rexindex);
				
				
				tempfunbeforestr = tempfunbeforestr.replace(regex, " = _callbackobj;//");
				_callerstrback = tempfunbeforestr + "\r\n" + tempfunstr;
			}
			//不需要赋值的情况(比如:流程导入)
			var regex3 = /[ ]*(window\.)?showModalDialog\([^\)]+\)/g;
			//var regex = /=[ ]*window\.showModalDialog\(([^\(]+([\(][^\)]*\))*[^\)]+)*\)/g;
			_callerstrback = _callerstrback.replace(regex3, "//");
			eval(_callerstrback);
		} catch (e10) {
		}
	}
}

function parentCallerHandle(_callerstr, of, _dialogReturnValue) {
	try {
		if (!!!_dialogReturnValue || !!!of) return; 
		
		var _pcallerstr = of.toString();
		
		var callerfnname = getFuncName(_callerstr);
		var ofname = getFuncName(of);
		
		if (callerfnname == 'onSetRejectNode' && ofname == 'doReject') {
			var rjnoderegex = /onSetRejectNode\(\)/g;
			_pcallerstr = _pcallerstr.replace(rjnoderegex, "true");
			
			var funnameregex = /function +[^\(]*\(/;
			_pcallerstr = _pcallerstr.replace(funnameregex, "_parentcallbackfun = function (");
			eval(_pcallerstr);
			//执行
			_parentcallbackfun();
		}
		
	} catch (e) {alert(e);}
}

/**
 * 重置dialog参数
 */
function resetDialog() {
	_callbackfunciton = void 0;
	dialogReturnValue = void 0;
	dialogcaller = void 0;
	datainputCaller = void 0;
	datainputFun = void 0;
	
	othcaller = void 0;
} 

function getFuncName(func){
    var funcName = String(func) ;
    return funcName.replace(/^function(\s|\n)+(.+)\((.|\n)+$/,'$2');
}
//-----------------------------------------
// 选择框用转换程序 start
//-----------------------------------------
if (typeof(SYSTEM_SHOW_MODAL_DIALOG) == "undefined" && typeof(SYSTEM_SHOW_MODAL_DIALOG) != "fucntion") {
	var SYSTEM_SHOW_MODAL_DIALOG = null;
	if (!!!window._isNotFirstInit) {
		window._isNotFirstInit = true;
		//系统模态窗口
		SYSTEM_SHOW_MODAL_DIALOG = window.showModalDialog;
		//chrome37+
		if (!systemshowModalDialog && !!!SYSTEM_SHOW_MODAL_DIALOG) {
			systemshowModalDialog = true;
			window._systemshowModalDialog = true;
		}
	}
	
	if (window.showModalDialog == SYSTEM_SHOW_MODAL_DIALOG) {
		//重写系统模态窗口
		window.showModalDialog = function () {
			var url	= arguments[0];
			var parent = arguments[1];
			var dialogParent = arguments[2];

			if (!parent) {
				parent = "";
			}
			
			//ff下窗口不剧中问题统一处理
			if (!systemshowModalDialog) {
				if (!dialogParent) {
					dialogParent = "dialogWidth:550px;dialogHeight:550px;" + "dialogTop:" + (window.screen.availHeight - 30 - parseInt(550))/2 + "px" + ";dialogLeft:" + (window.screen.availWidth - 10 - parseInt(550))/2 + "px" + ";";
				} else if (dialogParent != "" && dialogParent.indexOf("dialogTop") == -1) {
					dialogParent += ";dialogTop:" + (window.screen.availHeight - 30 - parseInt(550))/2 + "px" + ";dialogLeft:" + (window.screen.availWidth - 10 - parseInt(550))/2 + "px" + ";";
				}
			}
			//alert(systemshowModalDialog);
			//alert(window.showModalDialog.caller);
			//alert(systemshowModalDialog);
			//只有chrome37+才处理
			if (systemshowModalDialog) {
				//打开当前窗口的同时,关闭其他弹出窗口,并重置参数
				if(childWindow){   
			         childWindow.close(); 
			         childWindow = undefined;
			         resetDialog();
			    }
				dialogcaller = window.showModalDialog.caller;
				//处理字段联动
				if (!!dialogcaller && !!dialogcaller.caller ) {
					if (dialogcaller.caller.toString().indexOf("datainput(") != -1) {
						datainputCaller = dialogcaller.caller;
					}
					if (dialogcaller.caller.toString().indexOf("datainputd(") != -1) {
						datainputCaller = dialogcaller.caller;
					}
					
					othcaller = dialogcaller.caller;
					//alert(getFuncName(dialogcaller));
					/*
					if (getFuncName(dialogcaller.caller.toString()).indexOf("datainput(") != -1) {
					
					}
					*/
				}
				
				//alert(dialogcaller.caller);
				if (dialogcaller) {
					dialogcallerArguments = dialogcaller.arguments;
				}
				//alert(dialogcaller.arguments);
				//var dialog = window.open(url);
				childWindow = window.open(url, "", "width=560px,height=580px,resizable=no,scroll=no,status=no,top=" + (window.screen.availHeight - 30 - parseInt(550))/2 + ",left=" + (window.screen.availWidth - 10 - parseInt(550))/2);   
//  				window.childWindow.focus();  
				//timeoutDialog(dialog);
				//setTimeout(function () );
				return ;
			}
			
			var returnValue2;
			//调用系统模态窗口弹出function
			var rtnValue = SYSTEM_SHOW_MODAL_DIALOG(url, parent, dialogParent); 
			//ie下如果调用的是js,而返回值是vb则转换成json
			if (window.ActiveXObject) {
				//返回值是vb
				if (rtnValue != undefined && rtnValue != null && typeof(rtnValue) == "unknown") {
					var func = window.showModalDialog.caller;
					//判断调用模态窗口者是否是js
					if (typeof(func) == "function") {
						var tempArray = new VBArray(rtnValue).toArray();
						var tempJsonData = "{";
						if (tempArray != null) {
							for (var i=0; i<tempArray.length; i++) {
								if (i == 0) {
									tempJsonData += "id:\"" + tempArray[i] + "\"";
								} else if (i == 1) {
									tempJsonData += "name:\"" + tempArray[i] + "\"";
								} else {
									tempJsonData += "key" + i + ":\"" + tempArray[i] + "\"";
								}
								
								if (i < tempArray.length - 1) {
									tempJsonData += ", ";
								}
							}
						}
						tempJsonData += "}";
						
						returnValue2 =  eval('(' + tempJsonData + ')');
						return returnValue2;
					}
				} else if (typeof(rtnValue) == "object"){
					//alert(window.showModalDialog.caller.caller);
					var func = window.showModalDialog.caller;
					try {
						window.console.log("href:" + window.location.href);
						window.console.log("caller type:" + typeof(func));
						window.console.log("caller content:" + func);
					} catch (e) {}
					//判断调用模态窗口者是否是vb
					if ((typeof(func) == "function" && func.toString().indexOf("function onclick()") != -1) || typeof(func) == "object") {
						return string2VbArray(json2String(rtnValue));
					} else {
						var	regex = new RegExp("jsid[ ]{0,}=[ ]{0,}new VBArray[\(]id[\)].toArray[\(][\)]", "g"); // 创建正则表达式对象。  
						var r = func.toString().match(regex);
					   if (r != null && r != undefined && r != "") {
						 	return string2VbArray(json2String(rtnValue));
					 	}
					}
				}
			}
			return rtnValue;
		};
	}
}

function json2String(josinobj) {
	if (josinobj == undefined || josinobj == null) {
		return "";
	}
	var ary = "";
	var _index = 0;
	try {
		for(var key in josinobj){
			if (_index++ > 0) {
				ary += "(~!@#$%^&*)";
			}
			ary += josinobj[key];
		}
	} catch (e) {}
	return ary;
}
//-----------------------------------------
//选择框用转换程序 END
//-----------------------------------------