How to use cur method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

structure_tree.js

Source:structure_tree.js Github

copy

Full Screen

1if (document.all) {n=0;ie=1;fShow="visible";fHide="hidden";}2if (document.layers) {n=1;ie=0;fShow="show"; fHide="hide";}3// Node Class Constructor.4/*5 * Global Varibles6 */7var rightX, bottomY, leftX, topY; //Rect of floating menu of which id is actionbar8// array to store the node need to adapt position , only when the view mode is "chart", it is useful .9var adaptNodes = new Array();10var adaptImages = new Array();11// array to store the level information.only when the view mode is "chart",it is useful .12var levelNodes = new Array(); //store the viewNodes of each level13var levelMaxHeight = new Array(); //store the maxHeight value of each level14var levelAdaptedCount = new Array(); //store hadAdapted node count of each level15/*16 * A organiztion unit node17 */18function Node(oid,code,name,type,level,open,codeOrder,chiefJobOid,chiefJobName,managerName,historyOid) {19 this.oid = oid;20 this.historyOid = historyOid;21 this.code = code;22 this.name = name;23 this.type = type;24 this.level = level;25 this.open = open;26 this.codeOrder = codeOrder;27 this.chiefJobOid = chiefJobOid;28 //this.chiefJobCode = chiefJobCode;29 this.chiefJobName = chiefJobName;30 this.managerName = managerName;31 this.parent = null;32 this.viewNode =null;33 this.subnode = null;34 this.addSubnode = NodeAddSubnode;35 this.getSubnode = NodeGetSubnode;36 this.createAllNode = NodeCreateAllNodes;37 this.createAllNodeH = NodeCreateAllNodesH;38 this.createAllNodeV = NodeCreateAllNodesV;39 this.createAllNodeT = NodeCreateAllNodesT;40 this.createViewNode = NodeCreateViewNode;41 this.createViewNodeV = NodeCreateViewNodeV;42 this.createViewNodeH = NodeCreateViewNodeH;43 this.createViewNodeT = NodeCreateViewNodeT;44}45// Node Class Methods.46function NodeAddSubnode(node) {47 if( this.subnode==null )48 this.subnode =new Array();49 this.subnode[this.subnode.length] = node;50 node.parent = this;51}52function NodeGetSubnode(index){53 if( this.subnode==null)54 return null;55 if( index<0 || index>=this.subnode.length )56 return null;57 return this.subnode[index];58}59// createAllNode-----------------------------------------------------------------------------60function NodeCreateAllNodes(inParentIndex,parentChildCount){61 if( mode=="chart" ){62 return this.createAllNodeH(inParentIndex,parentChildCount);63 }else{64 return this.createAllNodeT(inParentIndex,parentChildCount);65 }66}67function NodeCreateAllNodesT(inParentIndex,parentChildCount,level,isLast,emptyPrexCount){68 //set level value69 if( this.parent==null ){70 level=0;71 isLast = new Array();72 emptyPrexCount = new Array();73 }74 isLast[level] = (inParentIndex+1==parentChildCount);75 if( this.parent==null )76 emptyPrexCount[level] = 0;77 else78 emptyPrexCount[level] = this.level - this.parent.level - 1;79 //create whole table;80 var wholeTable = document.createElement("<table width='100%' height='1' border='0' cellpadding='0' cellspacing='0' >");81 var curRow = wholeTable.insertRow();82 //create all the prex image83 //modify by liudq, to show the level relation84 var i,curCell,curImage;85 for(i=0;i<level;i++){86 for(var j=0;j<emptyPrexCount[i];j++){87 curCell = curRow.insertCell();88 curCell.width = "1";89 curCell.noWrap = true;90 curImage = document.createElement( "<img src='' border='0' width='40' height='36' >" );91 curCell.appendChild(curImage);92 curImage.src = contextPath + "/images/orgtreeempty.gif";93 }94 curCell = curRow.insertCell();95 curCell.width = "1";96 curCell.noWrap = true;97 curImage = document.createElement( "<img src='' border='0' width='40' height='36' >" );98 curCell.appendChild(curImage);99 if( i==level-1 ){100 if( inParentIndex+1==parentChildCount )101 curImage.src = contextPath + "/images/orgtreebottom.gif";102 else103 curImage.src = contextPath + "/images/orgtreecenter.gif";104 }else{105 if( isLast[i+1] )106 curImage.src = contextPath + "/images/orgtreeempty.gif";107 else108 curImage.src = contextPath + "/images/orgtreevertical.gif";109 }110 }111 for(var j=0;j<emptyPrexCount[level];j++){112 curCell = curRow.insertCell();113 curCell.width = "1";114 curCell.noWrap = true;115 curImage = document.createElement( "<img src='' border='0' width='40' height='36' >" );116 curCell.appendChild(curImage);117 curImage.src = contextPath + "/images/orgtreehorizontal.gif";118 }119 //create the open image120 curCell = curRow.insertCell();121 curCell.width = "1";122 curCell.noWrap = true;123 if( this.subnode!=null && this.subnode.length>0 ){124 curImage = document.createElement( "<img src='' onclick='doOpen(this.viewNode);' style='cursor:hand' border='0' width='40' height='36'>" );125 if( this.open ){126 if( this.parent==null )127 curImage.src = contextPath + "/images/orgtreerootopen.gif";128 else129 curImage.src = contextPath + "/images/orgtreeopen.gif";130 }else{131 if( this.parent==null )132 curImage.src = contextPath + "/images/orgtreerootclose.gif";133 else134 curImage.src = contextPath + "/images/orgtreeclose.gif";135 }136 }else{137 curImage = document.createElement( "<img src='' border='0' width='40' height='36'>" );138 if( this.parent!=null )139 curImage.src = contextPath + "/images/orgtreehorizontal.gif";140 else141 curImage.src = contextPath + "/images/orgtreeempty.gif";142 }143 curCell.appendChild(curImage);144 //create viewnode145 curCell = curRow.insertCell();146 curCell.width = "1";147 curCell.noWrap = true;148 var viewNode = this.createViewNode(this.oid);149 curCell.appendChild(viewNode);150 viewNode.openImage = curImage;151 curImage.viewNode = viewNode;152 curCell = curRow.insertCell();153 curCell.width = "90%";154 //create subnode's row155 var subTable,colSpan;156 colSpan = curRow.cells.length;157 if( this.subnode!=null && this.subnode.length>0 ){158 curRow = wholeTable.insertRow();159 curRow.style.display = this.open?"block":"none";160 curCell = curRow.insertCell();161 curCell.colSpan = colSpan;162 for( i=0;i<this.subnode.length;i++){163 subTable = this.getSubnode(i).createAllNodeT(i, this.subnode.length, level+1, isLast, emptyPrexCount);164 curCell.appendChild(subTable);165 }166 }167 return wholeTable;168}169function NodeCreateAllNodesV(inParentIndex,parentChildCount){170 //create wholetable and init171 var length;172 if( this.subnode == null || this.subnode.length==0 )173 length=1;174 else175 length=this.subnode.length;176 var wholeTable = document.createElement("<table border='0' cellpadding='0' cellspacing='0' >");177 var i,curRow,curCell,j;178 for(i=0;i<length;i++){179 curRow = wholeTable.insertRow();180 curCell = curRow.insertCell();181 curCell.width = "20";182 curCell.noWrap = true;183 curRow.insertCell();184 curRow.insertCell();185 if( i!=length-1 ){186 curRow = wholeTable.insertRow();187 curCell = curRow.insertCell();188 curCell.width = "20";189 curCell.noWrap = true;190 curRow.insertCell();191 curRow.insertCell();192 if( !(length%2==0 && i==length/2-1) )193 curCell.height="13";194 }195 }196 for(i=0;i< wholeTable.rows.length;i++){197 wholeTable.rows[i].cells[2].align = "left";198 }199 //create viewNode200 var viewNode = this.createViewNode(this.oid);201 wholeTable.rows[length-1].cells[1].appendChild(viewNode);202 wholeTable.rows[length-1].cells[1].align="center";203 wholeTable.rows[length-1].cells[1].vAlign="center";204 //create top line205 var curImage;206 if( this.parent!=null ){207 if( inParentIndex==0 ){208 if( parentChildCount==1 ){209 //insert " | "210 curImage = document.createElement("<img src='" +contextPath+ "/images/orghorizontalshort.gif' width='20' height='60'>");211 wholeTable.rows[length-1].cells[0].appendChild(curImage);212 wholeTable.rows[length-1].cells[0].align="center";213 wholeTable.rows[length-1].cells[0].vAlign="center";214 }else{215 //insert " ©°©¤©¤"216 subTable = document.createElement("<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0'>");217 curRow = subTable.insertRow();218 curCell = curRow.insertCell();219 curCell.height="50%";220 curRow = subTable.insertRow();221 curCell = curRow.insertCell();222 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticaltop.gif' width='20' height='60'>");223 curCell.appendChild(curImage);224 curRow = subTable.insertRow();225 curCell = curRow.insertCell();226 curCell.height="50%";227 curCell.background = contextPath + "/images/orgverticallong.gif";228 wholeTable.rows[length-1].cells[0].appendChild(subTable);229 wholeTable.rows[length-1].cells[0].height="100%";230 wholeTable.rows[length-1].cells[0].align="center";231 for(i=length;i<length*2-1;i++)232 wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";233 }234 }else if( parentChildCount%2==1 && inParentIndex==(parentChildCount-1)/2 ){235 //insert "©¤©¤©à©¤©¤"236 for(i=0;i<length*2-1;i++){237 if( i==length-1 ) {238 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalcross.gif' width='20' height='60'>");239 wholeTable.rows[length-1].cells[0].appendChild(curImage);240 wholeTable.rows[length-1].cells[0].align="center";241 }242 wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";243 }244 }else if( inParentIndex==parentChildCount-1 ){245 //insert "©¤©¤©´"246 subTable = document.createElement("<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0'>");247 curRow = subTable.insertRow();248 curCell = curRow.insertCell();249 curCell.height="50%";250 curCell.background = contextPath + "/images/orgverticallong.gif";251 curRow = subTable.insertRow();252 curCell = curRow.insertCell();253 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalbottom.gif' width='20' height='60'>");254 curCell.appendChild(curImage);255 curRow = subTable.insertRow();256 curCell = curRow.insertCell();257 curCell.height="50%";258 wholeTable.rows[length-1].cells[0].appendChild(subTable);259 wholeTable.rows[length-1].cells[0].height="100%";260 wholeTable.rows[length-1].cells[0].align="center";261 for(i=0;i<length-1;i++)262 wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";263 }else{264 //insert "©¤©¤©Ð©¤©¤"265 for(i=0;i<length*2-1;i++){266 if( i==length-1 ){267 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalcenter.gif' width='20' height='60'>");268 wholeTable.rows[i].cells[0].appendChild(curImage);269 wholeTable.rows[i].cells[0].align="center";270 }271 wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";272 }273 }274 }275 //create bottomY line276 var subTable;277 if( this.subnode!=null && this.subnode.length>0 ){278 for(i=0;i<wholeTable.rows.length;i++)279 wholeTable.rows[i].cells[2].style.display = this.open?"block":"none";280 for(i=0;i<length-1;i++){281 if( length%2==0 && i==length/2-1 ){282 //insert "©¤©¤©Ø©¤©¤"283 subTable = document.createElement("<table height='100%' width='20' border='0' cellspacing='0' cellpadding='0'>");284 wholeTable.rows[i*2+1].cells[2].appendChild(subTable);285 wholeTable.rows[i*2+1].cells[2].height="100%";286 curCell = subTable.insertRow().insertCell();287 curCell.width="20";288 curCell.height="100%";289 curCell.vAlign="center";290 curCell.background = contextPath + "/images/orgverticallong.gif";291 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalcenter2.gif' width='20' height='60'>");292 curCell.appendChild( curImage );293 }else{294 //insert "©¤©¤©¤©¤©¤"295 subTable = document.createElement("<table height='100%' width='20' border='0' cellspacing='0' cellpadding='0'>");296 wholeTable.rows[i*2+1].cells[2].appendChild(subTable);297 curCell = subTable.insertRow().insertCell();298 curCell.width="100%";299 curCell.height="100%";300 curCell.background = contextPath + "/images/orgverticallong.gif";301 }302 }303 //call the child's createAllNode() method304 if( this.open ){305 var subViewNode;306 for(i=0;i<length;i++){307 subViewNode = this.getSubnode(i).createAllNodeV(i,length);308 wholeTable.rows[i*2].cells[2].appendChild(subViewNode);309 }310 }311 }312 return wholeTable;313}314function adaptPosition(){315 var childViewNode ;316 for(var i=adaptNodes.length-1;i>=0;i--){317 if( adaptNodes[i].treeNode.open){318 if (adaptNodes[i].offsetHeight == 0) continue;319 adaptNodes[i].parentNode.height = adaptNodes[i].offsetHeight;320 adaptNodes[i].parentNode.width = adaptNodes[i].offsetWidth;321 adaptNodes[i].style.position = "absolute";322 childViewNode = adaptNodes[i].treeNode.subnode[(adaptNodes[i].treeNode.subnode.length-1)/2].viewNode;323 if( childViewNode.style.position!="absolute" )324 adaptNodes[i].style.left = calculateSumOffset(childViewNode, "offsetLeft");325 else326 adaptNodes[i].style.left = childViewNode.style.left;327 adaptNodes[i].style.top = calculateSumOffset(adaptNodes[i].parentNode, "offsetTop");328 if( adaptImages[i]!=null ){329 adaptImages[i].parentNode.height = adaptImages[i].offsetHeight;330 adaptImages[i].parentNode.width = adaptImages[i].offsetWidth;331 adaptImages[i].style.position = "absolute";332 adaptImages[i].style.left = parseInt(adaptNodes[i].style.left) + ( parseInt(adaptNodes[i].offsetWidth)-parseInt(adaptImages[i].offsetWidth) )/2;333 adaptImages[i].style.top = calculateSumOffset(adaptImages[i].parentNode, "offsetTop" );334 }335 }else{336 adaptNodes[i].style.position = "static";337 if( adaptImages[i]!=null )338 adaptImages[i].style.position = "static";339 }340 }341}342function NodeCreateAllNodesH(inParentIndex,parentChildCount){343 var needAdapt=false;344 if( this.subnode!=null && this.subnode.length!=0 && this.subnode.length%2==1 ){345 var child = this.subnode[(this.subnode.length-1)/2];346 needAdapt = (child.subnode!=null && child.subnode.length>0) ;347 }348 //create wholetable and init349 var length;350 if( this.subnode == null || this.subnode.length==0 )351 length=1;352 else353 length=this.subnode.length;354 var wholeTable = document.createElement("<table border='0' cellpadding='0' cellspacing='0' >");355 var i,curRow,curCell,j;356 for(i=0;i<3;i++){357 if (i<=1) {358 curRow = wholeTable.insertRow();359 if (length == 1) {360 curCell = curRow.insertCell();361 curCell.noWrap = false;362 } else {363 curCell = curRow.insertCell();364 curCell.noWrap = false;365 curCell.colSpan=length-1;366 curCell.style.display="none";367 curCell = curRow.insertCell();368 curCell.noWrap = true;369 curCell = curRow.insertCell();370 curCell.noWrap = false;371 curCell.colSpan=length-1;372 curCell.style.display="none";373 }374 } else {375 curRow = wholeTable.insertRow();376 for(j=0;j<length;j++){377 curCell = curRow.insertCell();378 curCell.noWrap = false;379 if( j!=length-1 ){380 curCell = curRow.insertCell();381 curCell.noWrap = true;382 if( !(length%2==0 && j==length/2-1) )383 curCell.width="13";384 }385 }386 }387 }388 wholeTable.rows[0].cells[0].height="20";389 curRow = wholeTable.rows[2];390 for(i=0;i< curRow.cells.length;i++){391 curRow.cells[i].vAlign = "top";392 }393 //create viewNode394 var viewNode = this.createViewNode(this.oid);395 if (length == 1) {396 initLevelViewNode(wholeTable.rows[1].cells[0] ,viewNode);397 wholeTable.rows[1].cells[0].align="center";398 } else {399 initLevelViewNode(wholeTable.rows[1].cells[1] ,viewNode);400 wholeTable.rows[1].cells[1].align="center";401 }402 if( needAdapt ){403 adaptNodes[adaptNodes.length] = viewNode;404 }405 //create top line406 var curImage = null ;407 if( this.parent!=null ){408 curRow = wholeTable.rows[0];409 if( inParentIndex==0 ){410 if( parentChildCount==1 ){411 //insert " | "412 curImage = document.createElement("<img src='" +contextPath+ "/images/orgvertical.gif' width='100' height='20'>");413 if (length == 1) {414 curRow.cells[0].appendChild(curImage);415 curRow.cells[0].align="center";416 } else {417 curRow.cells[1].appendChild(curImage);418 curRow.cells[1].align="center";419 }420 }else{421 //insert " ©°©¤©¤"422 subTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");423 subTable.insertRow();424 subTable.rows[0].insertCell().width="50%";425 subTable.rows[0].insertCell();426 subTable.rows[0].insertCell().width="50%";427 curImage = document.createElement("<img src='" +contextPath+ "/images/orgleft.gif' width='100' height='20'>");428 subTable.rows[0].cells[1].appendChild(curImage);429 subTable.rows[0].cells[2].background = contextPath + "/images/orghorizontal.gif";430 if (length == 1) {431 curRow.cells[0].appendChild(subTable);432 curRow.cells[0].align="center";433 } else {434 curRow.cells[1].appendChild(subTable);435 curRow.cells[1].align="center";436 curRow.cells[2].background = contextPath + "/images/orghorizontal.gif";437 }438 }439 }else if( parentChildCount%2==1 && inParentIndex==(parentChildCount-1)/2 ){440 //insert "©¤©¤©à©¤©¤"441 if (length == 1) {442 curImage = document.createElement("<img src='" +contextPath+ "/images/orgcross.gif' width='100' height='20'>");443 curRow.cells[0].appendChild(curImage);444 curRow.cells[0].align="center";445 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";446 } else {447 curImage = document.createElement("<img src='" +contextPath+ "/images/orgcross.gif' width='100' height='20'>");448 curRow.cells[1].appendChild(curImage);449 curRow.cells[1].align="center";450 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";451 curRow.cells[1].background = contextPath + "/images/orghorizontal.gif";452 curRow.cells[2].background = contextPath + "/images/orghorizontal.gif";453 }454 }else if( inParentIndex==parentChildCount-1 ){455 //insert "©¤©¤©´"456 subTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");457 subTable.insertRow();458 subTable.rows[0].insertCell().width="50%";459 subTable.rows[0].insertCell();460 subTable.rows[0].insertCell().width="50%";461 curImage = document.createElement("<img src='" +contextPath+ "/images/orgright.gif' width='100' height='20'>");462 subTable.rows[0].cells[1].appendChild(curImage);463 subTable.rows[0].cells[0].background = contextPath + "/images/orghorizontal.gif";464 if (length == 1) {465 curRow.cells[0].appendChild(subTable);466 curRow.cells[0].align="center";467 } else {468 curRow.cells[1].appendChild(subTable);469 curRow.cells[1].align="center";470 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";471 }472 }else{473 //insert "©¤©¤©Ð©¤©¤"474 if (length == 1) {475 curImage = document.createElement("<img src='" +contextPath+ "/images/orgcenter.gif' width='100' height='20'>");476 curRow.cells[0].appendChild(curImage);477 curRow.cells[0].align="center";478 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";479 } else {480 curImage = document.createElement("<img src='" +contextPath+ "/images/orgcenter.gif' width='100' height='20'>");481 curRow.cells[1].appendChild(curImage);482 curRow.cells[1].align="center";483 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";484 curRow.cells[1].background = contextPath + "/images/orghorizontal.gif";485 curRow.cells[2].background = contextPath + "/images/orghorizontal.gif";486 }487 }488 }489 if( needAdapt ){490 adaptImages[adaptImages.length] = curImage;491 }492 //create bottomY line493 var subTable;494 if( this.subnode!=null && this.subnode.length>0 ){495 curRow = wholeTable.rows[2];496 wholeTable.rows[2].style.display = this.open?"block":"none";497 if (wholeTable.rows[0].cells.length > 1) {498 wholeTable.rows[0].cells[0].style.display=this.open?"block":"none";499 wholeTable.rows[0].cells[2].style.display=this.open?"block":"none";500 wholeTable.rows[1].cells[0].style.display=this.open?"block":"none";501 wholeTable.rows[1].cells[2].style.display=this.open?"block":"none";502 }503 for(i=0;i<length-1;i++){504 if( length%2==0 && i==length/2-1 ){505 //insert "©¤©¤©Ø©¤©¤"506 subTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");507 curRow.cells[i*2+1].appendChild(subTable);508 subTable.insertRow();509 curCell = subTable.rows[0].insertCell();510 curCell.width="50%";511 curCell = subTable.rows[0].insertCell();512 curCell.align="center";513 curCell = subTable.rows[0].insertCell();514 curCell.width="50%";515 subTable.rows[0].cells[0].background = contextPath + "/images/orghorizontal.gif";516 curImage = document.createElement("<img src='" +contextPath+ "/images/orgtop.gif' width='100' height='20'>");517 subTable.rows[0].cells[1].appendChild(curImage);518 subTable.rows[0].cells[2].background = contextPath + "/images/orghorizontal.gif";519 }else{520 //insert "©¤©¤©¤©¤©¤"521 subTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");522 curRow.cells[i*2+1].appendChild(subTable);523 curCell = subTable.insertRow().insertCell();524 curCell.height="20";525 curCell.background = contextPath + "/images/orghorizontal.gif";526 }527 }528 //call the child's createAllNode() method529 if( this.open ){530 var subViewNode;531 for(i=0;i<length;i++){532 subViewNode = this.getSubnode(i).createAllNodeH(i,length);533 wholeTable.rows[2].cells[i*2].appendChild(subViewNode);534 }535 }536 }537 return wholeTable;538}539//create view Node --------------------------------------------------------------------------------------------------------540function NodeCreateViewNode(oid){541 if( mode=="chart" ){542 return this.createViewNodeH(oid);543 }else{544 return this.createViewNodeT(oid);545 }546}547//show organization unit by tree model548function NodeCreateViewNodeT(oid){549 var idUnitItem = "unititem" + oid;550 var idItem = "item" + oid;551 var aDiv = document.createElement("<div ondragstart='doDragStart(this);' ondrag='doDrag(this);' ondragend='doDragEnd(this);' ondragenter='doDragEnter(this);' ondragover='doDragOver(this);' ondragleave='doDragLeave(this);' ondrop='doDrop(this);' onmousedown='doMouseDown(this);' onmousemove='doMouseMove(this);' onmouseup='doMouseUp(this);' id='" + idUnitItem + "' class='orgunitchartitemcell'>");552 aDiv.treeNode = this;553 this.viewNode = aDiv;554 //create the Whole table555 var wholeTable = document.createElement("<table width='100%' height='25' border='0' cellspacing='0' cellpadding='0' style='PADDING-RIGHT: 4px; PADDING-LEFT: 4px' >");556 aDiv.appendChild(wholeTable);557 var curRow = wholeTable.insertRow();558 //create the first col559 var curCell = curRow.insertCell();560 curCell.height = "25";561 curCell.width = "1%";562 curCell.noWrap = true;563 curCell.className = "subtableheader";564 if( isEHR ){565 var clickHandle = "doEditNode(this.viewNode," + "this" + ");";566 var curImage = document.createElement("<img id='" + idItem + "' onmouseover='" +clickHandle+ "' src='" +contextPath+ "/images/edit.gif' width='16' height='16' border='0' style='cursor:hand;' >");567 curCell.appendChild( curImage );568 curImage.viewNode = aDiv;569 aDiv.editImage = curImage;570 }571 if( isCEO ){//panhe modified this function on 2.29.2004(¸²¸Ç¼´¿É)572 var clickHandle = "javascript:CEOviewEmployees(" + oid +");";573 var curImage = document.createElement("<img id='" + idItem + "' onclick='" + clickHandle + "' alt='" + CEOMessage + "' src='" +contextPath+ "/images/begro.gif' width='16' height='16' border='0' style='cursor:hand;' >");574 curCell.appendChild( curImage );575 curImage.viewNode = aDiv;576 aDiv.editImage = curImage;577 }578 //create the second col579 curCell = curRow.insertCell();580 curCell.width = "50%";581 curCell.height = "25";582 curCell.noWrap = true;583 curCell.innerText = this.name;584 //create the third col585 curCell = curRow.insertCell();586 curCell.width = "49%";587 curCell.height = "25";588 curCell.noWrap = true;589 if( this.chiefJobOid=="-1" ){590 curCell.innerText = noJobMessage591 }else{592 //modify by lily593 if(this.managerName == "")594 curCell.innerText = this.chiefJobName;595 else596 curCell.innerText = this.chiefJobName + "(" + this.managerName + ")";597 }598 return aDiv;599}600function NodeCreateViewNodeV(oid){601 var idUnitItem = "unititem" + oid;602 var idItem = "item" + oid;603 var aDiv = document.createElement("<div ondragstart='doDragStart(this);' ondrag='doDrag(this);' ondragend='doDragEnd(this);' ondragenter='doDragEnter(this);' ondragover='doDragOver(this);' ondragleave='doDragLeave(this);' ondrop='doDrop(this);' onmousedown='doMouseDown(this);' onmousemove='doMouseMove(this);' onmouseup='doMouseUp(this);' id='" + idUnitItem + "' class='orgunitchartitemcell'>");604 aDiv.treeNode = this;605 this.viewNode = aDiv;606 //create the Whole table607 var wholeTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0' style='PADDING-RIGHT: 2px; PADDING-LEFT: 2px' >");608 aDiv.appendChild(wholeTable);609 var curRow = wholeTable.insertRow();610 //create the first col of whole table.611 var curCell = curRow.insertCell();612 curCell.className = "subtableheader";613 curCell.noWrap = true;614 //create the subtable of first col615 var subTable = document.createElement( "<table width='1' border='0' cellspacing='0' cellpadding='0'>" );616 curCell.appendChild(subTable);617 curRow = subTable.insertRow();618 curRow.align="center";619 curCell = curRow.insertCell();620 curCell.height = "16";621 var clickHandle = "doEditNode(this.viewNode," + "this" + ");";622 var curImage = document.createElement("<img id='" + idItem + "' onmouseover='" +clickHandle+ "' src='" +contextPath+ "/images/edit.gif' width='16' height='16' border='0' style='cursor:hand;' >");623 curCell.appendChild( curImage );624 curImage.viewNode = aDiv;625 aDiv.editImage = curImage;626 curRow = subTable.insertRow();627 curRow.align="center";628 curCell = curRow.insertCell();629 curCell.height = "16"630 clickHandle = 'assignJob(this.viewNode.treeNode.oid);';631 curImage = document.createElement("<img onclick='" +clickHandle + "' src='" +contextPath+ "/images/userbro.gif' width='16' height='16' border='0' style='cursor:hand;' >");632 curImage.alt = assignJobAltLabel;633 curCell.appendChild( curImage );634 curImage.viewNode = aDiv;635 aDiv.assignJobImage = curImage;636 /*curRow = subTable.insertRow();637 curRow.align="center";638 curCell = curRow.insertCell();639 curCell.height = "16"640 clickHandle = 'viewChiefJob(this.viewNode);';641 curImage = document.createElement("<img onclick='" +clickHandle + "' src='" +contextPath+ "/images/beser.gif' width='16' height='16' border='0' style='cursor:hand;' >");642 curImage.alt = viewEmployeeAltLabel;643 curCell.appendChild( curImage );644 curImage.viewNode = aDiv;645 aDiv.chiefJobImage = curImage;*/646 //create the second col of whole table647 curCell = wholeTable.rows[0].insertCell();648 curCell.className = "subalterbar";649 curCell.noWrap = true;650 //create subtable of second col651 subTable = document.createElement( "<table width='100' border='0' cellspacing='0' cellpadding='2'>" );652 curCell.appendChild(subTable);653 if( !isCompact ){654 curRow = subTable.insertRow();655 curCell = curRow.insertCell();656 curCell.width = "1%";657 curCell.align = "right";658 curCell.noWrap = true;659 curCell.innerText = codeKeyValue;660 curCell = curRow.insertCell();661 curCell.width = "100%";662 curCell.noWrap = true;663 curCell.innerText = this.code;664 }665 curRow = subTable.insertRow();666 if( !isCompact ){667 curCell = curRow.insertCell();668 curCell.width = "1%";669 curCell.align = "right";670 curCell.vAlign = "top";671 curCell.noWrap = true;672 curCell.innerText = nameKeyValue;673 }674 curCell = curRow.insertCell();675 curCell.width = "100%";676 curCell.noWrap = true;677 curCell.innerText = this.name;678 if( !isCompact ){679 curRow = subTable.insertRow();680 curCell = curRow.insertCell();681 curCell.width = "1%";682 curCell.align = "right";683 curCell.vAlign = "top";684 curCell.noWrap = true;685 curCell.innerText = typeKeyValue;686 curCell = curRow.insertCell();687 curCell.width = "100%";688 curCell.noWrap = true;689 curCell.innerText = getUnitTypeLabel(this.type);690 }691 //create subtable of second col692 subTable = document.createElement( "<table width='100' border='0' cellspacing='0' cellpadding='2'>" );693 wholeTable.rows[0].cells[1].appendChild(subTable);694 aDiv.chiefJobTable = subTable;695 curRow = subTable.insertRow();696 curCell = curRow.insertCell();697 curCell.width = "100%";698 curCell.align = "left";699 curCell.vAlign = "center";700 curCell.noWrap = true;701 if( this.chiefJobOid=="-1" ){702 curCell.innerText = noJobMessage703 }else{704 //modify by lily705 if(this.managerName == "")706 curCell.innerText = this.chiefJobName;707 else708 curCell.innerText = this.chiefJobName + "(" + this.managerName + ")";709 }710 //create the third col of whole table711 curCell = wholeTable.rows[0].insertCell();712 curCell.noWrap = true;713 curCell.align = "center";714 curCell.vAlign = "center";715 curCell.className = "subalterbar";716 if( this.subnode!=null && this.subnode.length>0 ){717 if( this.open )718 curImage = document.createElement("<img onclick='doOpen(this.viewNode);' src='" +contextPath+ "/images/expand.gif' width='18' height='18' style='cursor=hand;' >");719 else720 curImage = document.createElement("<img onclick='doOpen(this.viewNode);' src='" +contextPath+ "/images/shrink.gif' width='18' height='18' style='cursor=hand;' >");721 curImage.viewNode = aDiv;722 aDiv.openImage = curImage;723 curCell.appendChild(curImage);724 }else{725 curCell.width="18";726 }727 return aDiv;728}729//show organization unit by char model730function NodeCreateViewNodeH(oid){731 var idUnitItem = "unititem" + oid;732 var idItem = "item" + oid;733 var aDiv = document.createElement("<div ondragstart='doDragStart(this);' ondrag='doDrag(this);' ondragend='doDragEnd(this);' ondragenter='doDragEnter(this);' ondragover='doDragOver(this);' ondragleave='doDragLeave(this);' ondrop='doDrop(this);' onmousedown='doMouseDown(this);' onmousemove='doMouseMove(this);' onmouseup='doMouseUp(this);' id='" + idUnitItem + "' class='orgunitchartitemcell'>");734 aDiv.treeNode = this;735 this.viewNode = aDiv;736 //create the Whole table737 var wholeTable = document.createElement("<table width='100' height='100%' border='0' cellpadding='0' cellspacing='0'>");738 aDiv.appendChild(wholeTable);739 //create the first Row of whole table.740 var curRow = wholeTable.insertRow();741 var curCell = curRow.insertCell();742 curCell.className = "subtableheader";743 curCell.align = "right";744 //create the subtable of first row745 var subTable = document.createElement( "<table style='padding-left:2px;padding-right:2px;' width='100' border='0' cellspacing='0' cellpadding='0'>" );746 curCell.appendChild(subTable);747 curRow = subTable.insertRow();748 curRow.align="center";749 if(isEHR){750 curCell = curRow.insertCell();751 curCell.width = "33%"752 var clickHandle = "doEditNode(this.viewNode," + "this" + ");";753 var curImage = document.createElement("<img id='" + idItem + "' onmouseover='" +clickHandle+ "' src='" +contextPath+ "/images/edit.gif' width='16' height='16' border='0' style='cursor:hand;' >");754 curCell.appendChild( curImage );755 curImage.viewNode = aDiv;756 aDiv.editImage = curImage;757 curCell = curRow.insertCell();758 curCell.width = "33%"759 /* modify by lily 2003-12-31760 if( !isHistoryChart ){761 clickHandle = 'assignJob(this.viewNode.treeNode.oid);';762 curImage = document.createElement("<img onclick='" +clickHandle + "' src='" +contextPath+ "/images/userbro.gif' width='16' height='16' border='0' style='cursor:hand;' >");763 curImage.alt = assignJobAltLabel;764 }else{765 clickHandle = 'viewEditUnit(this.viewNode.treeNode.oid,this.viewNode.treeNode.historyOid);' ;766 curImage = document.createElement("<img onclick='" +clickHandle + "' src='" +contextPath+ "/images/component.gif' width='16' height='16' border='0' style='cursor:hand;' >");767 curImage.alt = viewOrgUnitAltLabel;768 }769 curCell.appendChild( curImage );770 curImage.viewNode = aDiv;771 aDiv.assignJobImage = curImage;772 */773 curCell = curRow.insertCell();774 curCell.width = "33%"775 if( !isHistoryChart )776 clickHandle = 'viewEmployees(this.viewNode.treeNode.oid);';777 else778 clickHandle = 'viewEmployees(this.viewNode.treeNode.oid,this.viewNode.treeNode.historyOid);';779 curImage = document.createElement("<img onclick='" +clickHandle + "' src='" +contextPath+ "/images/begro.gif' width='16' height='16' border='0' style='cursor:hand;' >");780 curImage.alt = viewEmployeeAltLabel;781 curCell.appendChild( curImage );782 curImage.viewNode = aDiv;783 aDiv.viewEmployeesImage = curImage;784 }785 //create the second row of whole table786 curRow = wholeTable.insertRow();787 curCell = curRow.insertCell();788 curCell.className = "subalterbar";789 //create subtable of second row790 subTable = document.createElement( "<table style='padding-left:2px;padding-right:2px;' width='100' border='0' cellspacing='0' cellpadding='2'>" );791 curCell.appendChild(subTable);792 if( !isCompact ){793 curRow = subTable.insertRow();794 curCell = curRow.insertCell();795 curCell.width = "1%";796 curCell.align = "right";797 curCell.noWrap = true;798 curCell.innerText = codeKeyValue;799 curCell = curRow.insertCell();800 curCell.width = "100%";801 curCell.noWrap = false;802 curCell.innerText = this.code;803 }804 curRow = subTable.insertRow();805 if( !isCompact ){806 curCell = curRow.insertCell();807 curCell.width = "1%";808 curCell.align = "right";809 curCell.vAlign = "top";810 curCell.noWrap = true;811 curCell.innerText = nameKeyValue;812 }813 curCell = curRow.insertCell();814 curCell.width = "100%";815 curCell.noWrap = false;816 curCell.innerText = this.name;817 if( !isCompact ){818 curRow = subTable.insertRow();819 curCell = curRow.insertCell();820 curCell.width = "1%";821 curCell.align = "right";822 curCell.vAlign = "top";823 curCell.noWrap = true;824 curCell.innerText = typeKeyValue;825 curCell = curRow.insertCell();826 curCell.width = "49%";827 curCell.noWrap = false;828 curCell.innerText = getUnitTypeLabel(this.type);829 }830 //create the third row of whole table831 curRow = wholeTable.insertRow();832 curCell = curRow.insertCell();833 curCell.className = "subalterbar";834 //create subtable of third row835 subTable = document.createElement( "<table style='padding-left:2px;padding-right:2px;' width='100' border='0' cellspacing='0' cellpadding='2'>" );836 curCell.appendChild(subTable);837 aDiv.chiefJobTable = subTable;838 curRow = subTable.insertRow();839 curCell = curRow.insertCell();840 curCell.width = "100%";841 curCell.align = "left";842 curCell.vAlign = "center";843 curCell.noWrap = false;844 if( this.chiefJobOid=="-1" ){845 curCell.innerText = noJobMessage846 }else{847 //modify by lily848 if(this.managerName == "")849 curCell.innerText = this.chiefJobName;850 else851 curCell.innerText = this.chiefJobName + "(" + this.managerName + ")";852 }853 /* delete by lily 2003-12-31854 curRow = subTable.insertRow();855 curCell = curRow.insertCell();856 curCell.width = "100%";857 curCell.align = "left";858 curCell.vAlign = "center";859 curCell.noWrap = false;860 if( this.chiefJobOid=="-1" ){861 curCell.height = "20";862 }else{863 curCell.innerText = this.chiefJobName;864 }865 */866 //create the fourth row of whole table867 curRow = wholeTable.insertRow();868 curCell = curRow.insertCell();869 curCell.align = "center";870 curCell.className = "subalterbar";871 if( this.subnode!=null && this.subnode.length>0 ){872 if( this.open )873 curImage = document.createElement("<img onclick='doOpen(this.viewNode);' src='" +contextPath+ "/images/expand.gif' width='18' height='18' style='cursor=hand;' >");874 else875 curImage = document.createElement("<img onclick='doOpen(this.viewNode);' src='" +contextPath+ "/images/shrink.gif' width='18' height='18' style='cursor=hand;' >");876 curImage.viewNode = aDiv;877 aDiv.openImage = curImage;878 curCell.appendChild(curImage);879 }else{880 curCell.height = "18";881 }882 return aDiv;883}884function initLevelViewNode(td,aDiv){885 //deal with level886 var treeNode = aDiv.treeNode;887 var curLevelIndex = treeNode.level-1 ;888 var curNodes,curMax;889 if( levelNodes.length<=curLevelIndex || levelNodes[curLevelIndex]==null )890 levelNodes[curLevelIndex] = new Array();891 curNodes = levelNodes[curLevelIndex];892 curNodes[curNodes.length] = aDiv;893 if( treeNode.parent!=null ){894 for(var i=treeNode.parent.level;i<treeNode.level-1;i++){895 if( levelNodes.length<=i || levelNodes[i]==null )896 levelNodes[i] = new Array();897 curNodes = levelNodes[i];898 var tempDiv = document.createElement("<div align='center'></div>");899 tempDiv.style.height = (isCompact?"100":"120");900 var tempTable = document.createElement("<table width='100' height='100%' ></table>");901 tempTable.insertRow().insertCell();902 tempDiv.appendChild(tempTable);903 tempTable.background = contextPath + "/images/orgvertical.gif";904 curNodes[curNodes.length] = tempDiv ;905 td.appendChild(tempDiv);906 td.appendChild( document.createElement("<img border='0' src='" + contextPath + "/images/orgvertical.gif' >") );907 }908 }909 td.appendChild(aDiv);910}911function adaptLevelViewNode(){912 var adaptedCount,curNodes,curMax;913 var tempMax;914 for(var i=0;i<levelNodes.length;i++){915 if( levelAdaptedCount.length<=i || levelAdaptedCount[i]==null )916 levelAdaptedCount[i] = 0;917 adaptedCount = levelAdaptedCount[i];918 if( levelNodes.length<=i || levelNodes[i]==null )919 levelNodes[i] = new Array();920 curNodes = levelNodes[i];921 if( levelMaxHeight.length<=i || levelMaxHeight[i]==null )922 levelMaxHeight[i] = 0;923 curMax = levelMaxHeight[i];924 if( adaptedCount<curNodes.length ){925 tempMax = curMax;926 for(var j=adaptedCount;j<curNodes.length;j++){927 if( tempMax<curNodes[j].offsetHeight )928 tempMax = curNodes[j].offsetHeight;929 }930 if( tempMax>curMax ){931 for(var j=0;j<adaptedCount;j++)932 curNodes[j].style.height = tempMax;933 }934 for( var j=adaptedCount;j<curNodes.length;j++)935 curNodes[j].style.height = tempMax;936 levelMaxHeight[i] = tempMax;937 levelAdaptedCount[i] = curNodes.length;938 }939 }940}941//Global Var942var contextPath = ".";943var codeKeyValue = "code";944var nameKeyValue = "name";945var typeKeyValue = "type";946//var noJobMessage = "no chief Job"947var noJobMessage = ""948var chartVersion = "";949var structureOid = "";950var hiberarchyOid = "";951var hiberarchyType = "organizational";952var isCompact=true;953var mode="chart";954var rootNode = null;955var selectedNode = null;956//Global method957function doEditNode(viewNode, idItem){958 if(actionbar.style.display=="none"){959 actionbar.treeNode = viewNode.treeNode;960 showActionbar(viewNode, idItem);961 }else{962 if( actionbar.treeNode != viewNode.treeNode ){963 actionbar.treeNode = viewNode.treeNode;964 showActionbar(viewNode, idItem);965 }966 }967}968function showActionbar(viewNode, idItem){969 //shig change for show the actionbar to up when therer is no space in the end page, 2003.07.26970 //actionbar.style.top = calculateSumOffset(idItem, 'offsetTop') + 16;971 //yangc change for show the actionbar to up when therer is no space in the end page, 2003.10.16972 //var actionbarHeight = 130;973 var actionbarHeight = 150;974 var y = document.body.scrollTop + document.body.clientHeight;975 var currenty = eval( calculateSumOffset(idItem, 'offsetTop') + 16 + actionbarHeight);976 if( currenty > y){977 //yangc change for show the actionbar to up when therer is no space in the end page, 2003.10.16978 actionbar.style.top = y - actionbarHeight;979 }else{980 actionbar.style.top = calculateSumOffset(idItem, 'offsetTop') + 16;981 }982 //shig change for end, 2003.07.26983 actionbar.style.left = calculateSumOffset(idItem, 'offsetLeft');984 actionbar.style.display="block";985 leftX = document.all["actionbar"].style.posLeft;986 rightX = leftX + document.all["actionbar"].offsetWidth;987 //shig change for show the actionbar to up when therer is no space in the end page, 2003.07.26988 if( currenty > y){989 topY = document.all["actionbar"].style.posTop;990 bottomY = topY + document.all["actionbar"].offsetHeight;991 }else{992 topY = document.all["actionbar"].style.posTop - 18 ;993 bottomY = topY + document.all["actionbar"].offsetHeight + 18 ;994 }995 //topY = document.all["actionbar"].style.posTop - 18;996 //bottomY = topY + document.all["actionbar"].offsetHeight + 18;997 //shig change for end, 2003.07.26998}999function calculateSumOffset(idItem, offsetName)1000{1001 var totalOffset = 0;1002 var item = idItem;1003 do1004 {1005 totalOffset += eval('item.'+offsetName);1006 item = eval('item.offsetParent');1007 } while (item != null);1008 return totalOffset;1009}1010function hideActionbar(){1011 actionbar.style.display="none";1012}1013function doOpen(viewNode){1014 if( mode=="chart" )1015 doOpenH(viewNode)1016 else1017 doOpenT(viewNode)1018 adaptPosition();1019 chartInnerText.innerText = chartTd.innerHTML;1020 hideActionbar();1021}1022function doOpenH(viewNode){1023 var atable=viewNode;1024 var i;1025 do{1026 atable=atable.parentElement;1027 }while(atable.tagName!="TABLE");1028 if( viewNode.treeNode.open){1029 atable.rows[2].style.display="none";1030 if (atable.rows[0].cells.length > 1) {1031 atable.rows[0].cells[0].style.display="none";1032 atable.rows[0].cells[2].style.display="none";1033 atable.rows[1].cells[0].style.display="none";1034 atable.rows[1].cells[2].style.display="none";1035 }1036 viewNode.treeNode.open=false;1037 viewNode.openImage.src = contextPath+"/images/shrink.gif";1038 }else{1039 var treeNode = viewNode.treeNode;1040 var needAdapt = false;1041 if( treeNode.getSubnode(0).viewNode==null ){1042 var subViewNode;1043 needAdapt = true;1044 for(i=0;i<treeNode.subnode.length;i++){1045 subViewNode = treeNode.getSubnode(i).createAllNode(i,treeNode.subnode.length);1046 atable.rows[2].cells[i*2].appendChild(subViewNode);1047 }1048 }1049 atable.rows[2].style.display="block";1050 if (atable.rows[0].cells.length > 1) {1051 atable.rows[0].cells[0].style.display="block";1052 atable.rows[0].cells[2].style.display="block";1053 atable.rows[1].cells[0].style.display="block";1054 atable.rows[1].cells[2].style.display="block";1055 }1056 viewNode.treeNode.open=true;1057 viewNode.openImage.src = contextPath+"/images/expand.gif";1058 if( needAdapt )1059 adaptLevelViewNode();1060 }1061}1062function doOpenV(viewNode){1063 var atable=viewNode;1064 var i;1065 do{1066 atable=atable.parentElement;1067 }while(atable.tagName!="TABLE");1068 if( viewNode.treeNode.open){1069 for(i=0;i<atable.rows.length;i++)1070 atable.rows[i].cells[2].style.display = "none";1071 viewNode.treeNode.open=false;1072 viewNode.openImage.src = contextPath+"/images/shrink.gif";1073 }else{1074 var treeNode = viewNode.treeNode;1075 if( treeNode.getSubnode(0).viewNode==null ){1076 var subViewNode;1077 for(i=0;i<treeNode.subnode.length;i++){1078 subViewNode = treeNode.getSubnode(i).createAllNode(i,treeNode.subnode.length);1079 atable.rows[i*2].cells[2].appendChild(subViewNode);1080 }1081 }1082 for(i=0;i<atable.rows.length;i++)1083 atable.rows[i].cells[2].style.display = "block";1084 viewNode.treeNode.open=true;1085 viewNode.openImage.src = contextPath+"/images/expand.gif";1086 }1087}1088function doOpenT(viewNode){1089 var atable=viewNode;1090 do{1091 atable=atable.parentElement;1092 }while(atable.tagName!="TABLE");1093 viewNode.treeNode.open = !viewNode.treeNode.open;1094 atable.rows[1].style.display = viewNode.treeNode.open?"block":"none";1095 if( viewNode.treeNode.parent==null )1096 viewNode.openImage.src = contextPath + (viewNode.treeNode.open?"/images/orgtreerootopen.gif":"/images/orgtreerootclose.gif");1097 else1098 viewNode.openImage.src = contextPath + (viewNode.treeNode.open?"/images/orgtreeopen.gif":"/images/orgtreeclose.gif");1099}1100function hideAll(){1101 if (actionbar != null) {hideActionbar();actionbar.left = 0;}1102}1103function updateIt(e){1104 if (ie)1105 {1106 var x = window.event.clientX + document.body.scrollLeft;1107 var y = window.event.clientY + document.body.scrollTop;1108 if (x > rightX || x < leftX) {1109 hideAll();1110 }1111 else if (y > bottomY || y < topY) {1112 hideAll();1113 }1114 }1115 if (n)1116 {1117 var x = e.pageX+document.body.scrollLeft;1118 var y = e.pageY+document.body.scrollTop;1119 if (x > rightX || x < leftX) hideAll();1120 else if (y > bottomY || y < topY) hideAll();1121 }1122}1123if (document.all){1124 if( document.body !=null ){1125 document.body.onclick=hideAll;1126 document.body.onscroll=hideAll;1127 document.body.onmousemove=updateIt;1128 }1129}1130if (document.layers){1131 document.onmousedown=hideAll;1132 window.captureEvents(Event.MOUSEMOVE);1133 window.onmousemove=updateIt;1134}1135function getUnitTypeLabel(unitType){1136 var i,select;1137 select = window.allUnitType;1138 for(i=0;i<select.options.length;i++){1139 if(select.options[i].value==unitType)1140 return select.options[i].innerText;1141 }1142 return "unDefine";...

Full Screen

Full Screen

structure.js

Source:structure.js Github

copy

Full Screen

1if (document.all) {n=0;ie=1;fShow="visible";fHide="hidden";}2if (document.layers) {n=1;ie=0;fShow="show"; fHide="hide";}3// Node Class Constructor.4/*5 * Global Varibles6 */7var rightX, bottomY, leftX, topY; //Rect of floating menu of which id is actionbar8// array to store the node need to adapt position , only when the view mode is "chart", it is useful .9var adaptNodes = new Array();10var adaptImages = new Array();11// array to store the level information.only when the view mode is "chart",it is useful .12var levelNodes = new Array(); //store the viewNodes of each level13var levelMaxHeight = new Array(); //store the maxHeight value of each level14var levelAdaptedCount = new Array(); //store hadAdapted node count of each level15/*16 * A organiztion unit node17 */18function Node(oid,code,name,level,open) {19 this.oid = oid;20 this.code = code;21 this.name = name;22 this.level = level;23 this.open = open; 24 this.parent = null;25 this.viewNode =null;26 this.subnode = null;27 this.addSubnode = NodeAddSubnode;28 this.getSubnode = NodeGetSubnode;29 this.createAllNode = NodeCreateAllNodes;30 this.createAllNodeH = NodeCreateAllNodesH;31 this.createAllNodeV = NodeCreateAllNodesV;32 this.createAllNodeT = NodeCreateAllNodesT;33 this.createViewNode = NodeCreateViewNode;34 this.createViewNodeV = NodeCreateViewNodeV;35 this.createViewNodeH = NodeCreateViewNodeH;36 this.createViewNodeT = NodeCreateViewNodeT;37}38// Node Class Methods.39function NodeAddSubnode(node) {40 if( this.subnode==null )41 this.subnode =new Array();42 this.subnode[this.subnode.length] = node;43 node.parent = this;44}45function NodeGetSubnode(index){46 if( this.subnode==null)47 return null;48 if( index<0 || index>=this.subnode.length )49 return null;50 return this.subnode[index];51}52// createAllNode-----------------------------------------------------------------------------53function NodeCreateAllNodes(inParentIndex,parentChildCount){54 if( mode=="chart" ){55 return this.createAllNodeH(inParentIndex,parentChildCount);56 }else{57 return this.createAllNodeT(inParentIndex,parentChildCount);58 }59}60function NodeCreateAllNodesT(inParentIndex,parentChildCount,level,isLast,emptyPrexCount){61 //set level value62 if( this.parent==null ){63 level=0;64 isLast = new Array();65 emptyPrexCount = new Array();66 }67 isLast[level] = (inParentIndex+1==parentChildCount);68 if( this.parent==null )69 emptyPrexCount[level] = 0;70 else71 emptyPrexCount[level] = this.level - this.parent.level - 1;72 //create whole table;73 var wholeTable = document.createElement("<table width='100%' height='1' border='0' cellpadding='0' cellspacing='0' >");74 var curRow = wholeTable.insertRow();75 //create all the prex image76 //modify by liudq, to show the level relation77 var i,curCell,curImage;78 for(i=0;i<level;i++){79 for(var j=0;j<emptyPrexCount[i];j++){80 curCell = curRow.insertCell();81 curCell.width = "1";82 curCell.noWrap = true;83 curImage = document.createElement( "<img src='' border='0' width='40' height='36' >" );84 curCell.appendChild(curImage);85 curImage.src = contextPath + "/images/orgtreeempty.gif";86 }87 curCell = curRow.insertCell();88 curCell.width = "1";89 curCell.noWrap = true;90 curImage = document.createElement( "<img src='' border='0' width='40' height='36' >" );91 curCell.appendChild(curImage);92 if( i==level-1 ){93 if( inParentIndex+1==parentChildCount )94 curImage.src = contextPath + "/images/orgtreebottom.gif";95 else96 curImage.src = contextPath + "/images/orgtreecenter.gif";97 }else{98 if( isLast[i+1] )99 curImage.src = contextPath + "/images/orgtreeempty.gif";100 else101 curImage.src = contextPath + "/images/orgtreevertical.gif";102 }103 }104 for(var j=0;j<emptyPrexCount[level];j++){105 curCell = curRow.insertCell();106 curCell.width = "1";107 curCell.noWrap = true;108 curImage = document.createElement( "<img src='' border='0' width='40' height='36' >" );109 curCell.appendChild(curImage);110 curImage.src = contextPath + "/images/orgtreehorizontal.gif";111 }112 //create the open image113 curCell = curRow.insertCell();114 curCell.width = "1";115 curCell.noWrap = true;116 if( this.subnode!=null && this.subnode.length>0 ){117 curImage = document.createElement( "<img src='' onclick='doOpen(this.viewNode);' style='cursor:hand' border='0' width='40' height='36'>" );118 if( this.open ){119 if( this.parent==null )120 curImage.src = contextPath + "/images/orgtreerootopen.gif";121 else122 curImage.src = contextPath + "/images/orgtreeopen.gif";123 }else{124 if( this.parent==null )125 curImage.src = contextPath + "/images/orgtreerootclose.gif";126 else127 curImage.src = contextPath + "/images/orgtreeclose.gif";128 }129 }else{130 curImage = document.createElement( "<img src='' border='0' width='40' height='36'>" );131 if( this.parent!=null )132 curImage.src = contextPath + "/images/orgtreehorizontal.gif";133 else134 curImage.src = contextPath + "/images/orgtreeempty.gif";135 }136 curCell.appendChild(curImage);137 //create viewnode138 curCell = curRow.insertCell();139 curCell.width = "1";140 curCell.noWrap = true;141 var viewNode = this.createViewNode(this.oid);142 curCell.appendChild(viewNode);143 viewNode.openImage = curImage;144 curImage.viewNode = viewNode;145 curCell = curRow.insertCell();146 curCell.width = "90%";147 //create subnode's row148 var subTable,colSpan;149 colSpan = curRow.cells.length;150 if( this.subnode!=null && this.subnode.length>0 ){151 curRow = wholeTable.insertRow();152 curRow.style.display = this.open?"block":"none";153 curCell = curRow.insertCell();154 curCell.colSpan = colSpan;155 for( i=0;i<this.subnode.length;i++){156 subTable = this.getSubnode(i).createAllNodeT(i, this.subnode.length, level+1, isLast, emptyPrexCount);157 curCell.appendChild(subTable);158 }159 }160 return wholeTable;161}162function NodeCreateAllNodesV(inParentIndex,parentChildCount){163 //create wholetable and init164 var length;165 if( this.subnode == null || this.subnode.length==0 )166 length=1;167 else168 length=this.subnode.length;169 var wholeTable = document.createElement("<table border='0' cellpadding='0' cellspacing='0' >");170 var i,curRow,curCell,j;171 for(i=0;i<length;i++){172 curRow = wholeTable.insertRow();173 curCell = curRow.insertCell();174 curCell.width = "20";175 curCell.noWrap = true;176 curRow.insertCell();177 curRow.insertCell();178 if( i!=length-1 ){179 curRow = wholeTable.insertRow();180 curCell = curRow.insertCell();181 curCell.width = "20";182 curCell.noWrap = true;183 curRow.insertCell();184 curRow.insertCell();185 if( !(length%2==0 && i==length/2-1) )186 curCell.height="13";187 }188 }189 for(i=0;i< wholeTable.rows.length;i++){190 wholeTable.rows[i].cells[2].align = "left";191 }192 //create viewNode193 var viewNode = this.createViewNode(this.oid);194 wholeTable.rows[length-1].cells[1].appendChild(viewNode);195 wholeTable.rows[length-1].cells[1].align="center";196 wholeTable.rows[length-1].cells[1].vAlign="center";197 //create top line198 var curImage;199 if( this.parent!=null ){200 if( inParentIndex==0 ){201 if( parentChildCount==1 ){202 //insert " | "203 curImage = document.createElement("<img src='" +contextPath+ "/images/orghorizontalshort.gif' width='20' height='60'>");204 wholeTable.rows[length-1].cells[0].appendChild(curImage);205 wholeTable.rows[length-1].cells[0].align="center";206 wholeTable.rows[length-1].cells[0].vAlign="center";207 }else{208 //insert " ©°©¤©¤"209 subTable = document.createElement("<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0'>");210 curRow = subTable.insertRow();211 curCell = curRow.insertCell();212 curCell.height="50%";213 curRow = subTable.insertRow();214 curCell = curRow.insertCell();215 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticaltop.gif' width='20' height='60'>");216 curCell.appendChild(curImage);217 curRow = subTable.insertRow();218 curCell = curRow.insertCell();219 curCell.height="50%";220 curCell.background = contextPath + "/images/orgverticallong.gif";221 wholeTable.rows[length-1].cells[0].appendChild(subTable);222 wholeTable.rows[length-1].cells[0].height="100%";223 wholeTable.rows[length-1].cells[0].align="center";224 for(i=length;i<length*2-1;i++)225 wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";226 }227 }else if( parentChildCount%2==1 && inParentIndex==(parentChildCount-1)/2 ){228 //insert "©¤©¤©à©¤©¤"229 for(i=0;i<length*2-1;i++){230 if( i==length-1 ) {231 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalcross.gif' width='20' height='60'>");232 wholeTable.rows[length-1].cells[0].appendChild(curImage);233 wholeTable.rows[length-1].cells[0].align="center";234 }235 wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";236 }237 }else if( inParentIndex==parentChildCount-1 ){238 //insert "©¤©¤©´"239 subTable = document.createElement("<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0'>");240 curRow = subTable.insertRow();241 curCell = curRow.insertCell();242 curCell.height="50%";243 curCell.background = contextPath + "/images/orgverticallong.gif";244 curRow = subTable.insertRow();245 curCell = curRow.insertCell();246 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalbottom.gif' width='20' height='60'>");247 curCell.appendChild(curImage);248 curRow = subTable.insertRow();249 curCell = curRow.insertCell();250 curCell.height="50%";251 wholeTable.rows[length-1].cells[0].appendChild(subTable);252 wholeTable.rows[length-1].cells[0].height="100%";253 wholeTable.rows[length-1].cells[0].align="center";254 for(i=0;i<length-1;i++)255 wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";256 }else{257 //insert "©¤©¤©Ð©¤©¤"258 for(i=0;i<length*2-1;i++){259 if( i==length-1 ){260 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalcenter.gif' width='20' height='60'>");261 wholeTable.rows[i].cells[0].appendChild(curImage);262 wholeTable.rows[i].cells[0].align="center";263 }264 wholeTable.rows[i].cells[0].background = contextPath + "/images/orgverticallong.gif";265 }266 }267 }268 //create bottomY line269 var subTable;270 if( this.subnode!=null && this.subnode.length>0 ){271 for(i=0;i<wholeTable.rows.length;i++)272 wholeTable.rows[i].cells[2].style.display = this.open?"block":"none";273 for(i=0;i<length-1;i++){274 if( length%2==0 && i==length/2-1 ){275 //insert "©¤©¤©Ø©¤©¤"276 subTable = document.createElement("<table height='100%' width='20' border='0' cellspacing='0' cellpadding='0'>");277 wholeTable.rows[i*2+1].cells[2].appendChild(subTable);278 wholeTable.rows[i*2+1].cells[2].height="100%";279 curCell = subTable.insertRow().insertCell();280 curCell.width="20";281 curCell.height="100%";282 curCell.vAlign="center";283 curCell.background = contextPath + "/images/orgverticallong.gif";284 curImage = document.createElement("<img src='" +contextPath+ "/images/orgverticalcenter2.gif' width='20' height='60'>");285 curCell.appendChild( curImage );286 }else{287 //insert "©¤©¤©¤©¤©¤"288 subTable = document.createElement("<table height='100%' width='20' border='0' cellspacing='0' cellpadding='0'>");289 wholeTable.rows[i*2+1].cells[2].appendChild(subTable);290 curCell = subTable.insertRow().insertCell();291 curCell.width="100%";292 curCell.height="100%";293 curCell.background = contextPath + "/images/orgverticallong.gif";294 }295 }296 //call the child's createAllNode() method297 if( this.open ){298 var subViewNode;299 for(i=0;i<length;i++){300 subViewNode = this.getSubnode(i).createAllNodeV(i,length);301 wholeTable.rows[i*2].cells[2].appendChild(subViewNode);302 }303 }304 }305 return wholeTable;306}307function adaptPosition(){308 var childViewNode ;309 for(var i=adaptNodes.length-1;i>=0;i--){310 if( adaptNodes[i].treeNode.open){311 if (adaptNodes[i].offsetHeight == 0) continue;312 adaptNodes[i].parentNode.height = adaptNodes[i].offsetHeight;313 adaptNodes[i].parentNode.width = adaptNodes[i].offsetWidth;314 adaptNodes[i].style.position = "absolute";315 childViewNode = adaptNodes[i].treeNode.subnode[(adaptNodes[i].treeNode.subnode.length-1)/2].viewNode;316 if( childViewNode.style.position!="absolute" )317 adaptNodes[i].style.left = calculateSumOffset(childViewNode, "offsetLeft");318 else319 adaptNodes[i].style.left = childViewNode.style.left;320 adaptNodes[i].style.top = calculateSumOffset(adaptNodes[i].parentNode, "offsetTop");321 if( adaptImages[i]!=null ){322 adaptImages[i].parentNode.height = adaptImages[i].offsetHeight;323 adaptImages[i].parentNode.width = adaptImages[i].offsetWidth;324 adaptImages[i].style.position = "absolute";325 adaptImages[i].style.left = parseInt(adaptNodes[i].style.left) + ( parseInt(adaptNodes[i].offsetWidth)-parseInt(adaptImages[i].offsetWidth) )/2;326 adaptImages[i].style.top = calculateSumOffset(adaptImages[i].parentNode, "offsetTop" );327 }328 }else{329 adaptNodes[i].style.position = "static";330 if( adaptImages[i]!=null )331 adaptImages[i].style.position = "static";332 }333 }334}335function NodeCreateAllNodesH(inParentIndex,parentChildCount){336 var needAdapt=false;337 if( this.subnode!=null && this.subnode.length!=0 && this.subnode.length%2==1 ){338 var child = this.subnode[(this.subnode.length-1)/2];339 needAdapt = (child.subnode!=null && child.subnode.length>0) ;340 }341 //create wholetable and init342 var length;343 if( this.subnode == null || this.subnode.length==0 )344 length=1;345 else346 length=this.subnode.length;347 var wholeTable = document.createElement("<table border='0' cellpadding='0' cellspacing='0' >");348 var i,curRow,curCell,j;349 for(i=0;i<3;i++){350 if (i<=1) {351 curRow = wholeTable.insertRow();352 if (length == 1) {353 curCell = curRow.insertCell();354 curCell.noWrap = false;355 } else {356 curCell = curRow.insertCell();357 curCell.noWrap = false;358 curCell.colSpan=length-1;359 curCell.style.display="none";360 curCell = curRow.insertCell();361 curCell.noWrap = true;362 curCell = curRow.insertCell();363 curCell.noWrap = false;364 curCell.colSpan=length-1;365 curCell.style.display="none";366 }367 } else {368 curRow = wholeTable.insertRow();369 for(j=0;j<length;j++){370 curCell = curRow.insertCell();371 curCell.noWrap = false;372 if( j!=length-1 ){373 curCell = curRow.insertCell();374 curCell.noWrap = true;375 if( !(length%2==0 && j==length/2-1) )376 curCell.width="13";377 }378 }379 }380 }381 wholeTable.rows[0].cells[0].height="20";382 curRow = wholeTable.rows[2];383 for(i=0;i< curRow.cells.length;i++){384 curRow.cells[i].vAlign = "top";385 }386 //create viewNode387 var viewNode = this.createViewNode(this.oid);388 if (length == 1) {389 initLevelViewNode(wholeTable.rows[1].cells[0] ,viewNode);390 wholeTable.rows[1].cells[0].align="center";391 } else {392 initLevelViewNode(wholeTable.rows[1].cells[1] ,viewNode);393 wholeTable.rows[1].cells[1].align="center";394 }395 if( needAdapt ){396 adaptNodes[adaptNodes.length] = viewNode;397 }398 //create top line399 var curImage = null ;400 if( this.parent!=null ){401 curRow = wholeTable.rows[0];402 if( inParentIndex==0 ){403 if( parentChildCount==1 ){404 //insert " | "405 curImage = document.createElement("<img src='" +contextPath+ "/images/orgvertical.gif' width='100' height='20'>");406 if (length == 1) {407 curRow.cells[0].appendChild(curImage);408 curRow.cells[0].align="center";409 } else {410 curRow.cells[1].appendChild(curImage);411 curRow.cells[1].align="center";412 }413 }else{414 //insert " ©°©¤©¤"415 subTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");416 subTable.insertRow();417 subTable.rows[0].insertCell().width="50%";418 subTable.rows[0].insertCell();419 subTable.rows[0].insertCell().width="50%";420 curImage = document.createElement("<img src='" +contextPath+ "/images/orgleft.gif' width='100' height='20'>");421 subTable.rows[0].cells[1].appendChild(curImage);422 subTable.rows[0].cells[2].background = contextPath + "/images/orghorizontal.gif";423 if (length == 1) {424 curRow.cells[0].appendChild(subTable);425 curRow.cells[0].align="center";426 } else {427 curRow.cells[1].appendChild(subTable);428 curRow.cells[1].align="center";429 curRow.cells[2].background = contextPath + "/images/orghorizontal.gif";430 }431 }432 }else if( parentChildCount%2==1 && inParentIndex==(parentChildCount-1)/2 ){433 //insert "©¤©¤©à©¤©¤"434 if (length == 1) {435 curImage = document.createElement("<img src='" +contextPath+ "/images/orgcross.gif' width='100' height='20'>");436 curRow.cells[0].appendChild(curImage);437 curRow.cells[0].align="center";438 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";439 } else {440 curImage = document.createElement("<img src='" +contextPath+ "/images/orgcross.gif' width='100' height='20'>");441 curRow.cells[1].appendChild(curImage);442 curRow.cells[1].align="center";443 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";444 curRow.cells[1].background = contextPath + "/images/orghorizontal.gif";445 curRow.cells[2].background = contextPath + "/images/orghorizontal.gif";446 }447 }else if( inParentIndex==parentChildCount-1 ){448 //insert "©¤©¤©´"449 subTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");450 subTable.insertRow();451 subTable.rows[0].insertCell().width="50%";452 subTable.rows[0].insertCell();453 subTable.rows[0].insertCell().width="50%";454 curImage = document.createElement("<img src='" +contextPath+ "/images/orgright.gif' width='100' height='20'>");455 subTable.rows[0].cells[1].appendChild(curImage);456 subTable.rows[0].cells[0].background = contextPath + "/images/orghorizontal.gif";457 if (length == 1) {458 curRow.cells[0].appendChild(subTable);459 curRow.cells[0].align="center";460 } else {461 curRow.cells[1].appendChild(subTable);462 curRow.cells[1].align="center";463 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";464 }465 }else{466 //insert "©¤©¤©Ð©¤©¤"467 if (length == 1) {468 curImage = document.createElement("<img src='" +contextPath+ "/images/orgcenter.gif' width='100' height='20'>");469 curRow.cells[0].appendChild(curImage);470 curRow.cells[0].align="center";471 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";472 } else {473 curImage = document.createElement("<img src='" +contextPath+ "/images/orgcenter.gif' width='100' height='20'>");474 curRow.cells[1].appendChild(curImage);475 curRow.cells[1].align="center";476 curRow.cells[0].background = contextPath + "/images/orghorizontal.gif";477 curRow.cells[1].background = contextPath + "/images/orghorizontal.gif";478 curRow.cells[2].background = contextPath + "/images/orghorizontal.gif";479 }480 }481 }482 if( needAdapt ){483 adaptImages[adaptImages.length] = curImage;484 }485 //create bottomY line486 var subTable;487 if( this.subnode!=null && this.subnode.length>0 ){488 curRow = wholeTable.rows[2];489 wholeTable.rows[2].style.display = this.open?"block":"none";490 if (wholeTable.rows[0].cells.length > 1) {491 wholeTable.rows[0].cells[0].style.display=this.open?"block":"none";492 wholeTable.rows[0].cells[2].style.display=this.open?"block":"none";493 wholeTable.rows[1].cells[0].style.display=this.open?"block":"none";494 wholeTable.rows[1].cells[2].style.display=this.open?"block":"none";495 }496 for(i=0;i<length-1;i++){497 if( length%2==0 && i==length/2-1 ){498 //insert "©¤©¤©Ø©¤©¤"499 subTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");500 curRow.cells[i*2+1].appendChild(subTable);501 subTable.insertRow();502 curCell = subTable.rows[0].insertCell();503 curCell.width="50%";504 curCell = subTable.rows[0].insertCell();505 curCell.align="center";506 curCell = subTable.rows[0].insertCell();507 curCell.width="50%";508 subTable.rows[0].cells[0].background = contextPath + "/images/orghorizontal.gif";509 curImage = document.createElement("<img src='" +contextPath+ "/images/orgtop.gif' width='100' height='20'>");510 subTable.rows[0].cells[1].appendChild(curImage);511 subTable.rows[0].cells[2].background = contextPath + "/images/orghorizontal.gif";512 }else{513 //insert "©¤©¤©¤©¤©¤"514 subTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");515 curRow.cells[i*2+1].appendChild(subTable);516 curCell = subTable.insertRow().insertCell();517 curCell.height="20";518 curCell.background = contextPath + "/images/orghorizontal.gif";519 }520 }521 //call the child's createAllNode() method522 if( this.open ){523 var subViewNode;524 for(i=0;i<length;i++){525 subViewNode = this.getSubnode(i).createAllNodeH(i,length);526 wholeTable.rows[2].cells[i*2].appendChild(subViewNode);527 }528 }529 }530 return wholeTable;531}532//create view Node --------------------------------------------------------------------------------------------------------533function NodeCreateViewNode(oid){534 if( mode=="chart" ){535 return this.createViewNodeH(oid);536 }else{537 return this.createViewNodeT(oid);538 }539}540//show organization unit by tree model541function NodeCreateViewNodeT(oid){542 var idUnitItem = "unititem" + oid;543 var idItem = "item" + oid;544 var aDiv = document.createElement("<div class='orgunitchartitemcell'>");545 aDiv.treeNode = this;546 this.viewNode = aDiv;547 //create the Whole table548 var wholeTable = document.createElement("<table width='100%' height='25' border='0' cellspacing='0' cellpadding='0' style='PADDING-RIGHT: 4px; PADDING-LEFT: 4px' >");549 aDiv.appendChild(wholeTable);550 var curRow = wholeTable.insertRow();551 //create the first col552 var curCell = curRow.insertCell();553 curCell.height = "25";554 curCell.width = "1%";555 curCell.noWrap = true;556 curCell.className = "subtableheader";557 558 var clickHandle = "doEditNode(this.viewNode," + "this" + ");"; 559 var curImage = document.createElement("<img id='" + idItem + "' onmouseover='" +clickHandle+ "' src='" +contextPath+ "/images/edit.gif' width='16' height='16' border='0' style='cursor:hand;' >");560 curCell.appendChild( curImage );561 curImage.viewNode = aDiv;562 aDiv.editImage = curImage;563 564 //create the second col565 curCell = curRow.insertCell();566 curCell.width = "50%";567 curCell.height = "25";568 curCell.noWrap = true;569 curCell.innerText = this.name;570 //create the third col571 curCell = curRow.insertCell();572 curCell.width = "49%";573 curCell.height = "25";574 curCell.noWrap = true;575 return aDiv;576}577function NodeCreateViewNodeV(oid){578 var idUnitItem = "unititem" + oid;579 var idItem = "item" + oid;580 var aDiv = document.createElement("<div class='orgunitchartitemcell'>");581 aDiv.treeNode = this;582 this.viewNode = aDiv;583 //create the Whole table584 var wholeTable = document.createElement("<table width='100%' border='0' cellspacing='0' cellpadding='0' style='PADDING-RIGHT: 2px; PADDING-LEFT: 2px' >");585 aDiv.appendChild(wholeTable);586 //create the first col of whole table.587 var curCell = curRow.insertCell();588 curCell.className = "subtableheader";589 curCell.noWrap = true;590 //create the subtable of first col591 var subTable = document.createElement( "<table width='1' border='0' cellspacing='0' cellpadding='0'>" );592 curCell.appendChild(subTable);593 594 595 curRow = subTable.insertRow();596 curRow.align="center";597 curCell = curRow.insertCell();598 curCell.height = "16";599 var clickHandle = "doEditNode(this.viewNode," + "this" + ");";600 var curImage = document.createElement("<img id='" + idItem + "' onmouseover='" +clickHandle+ "' src='" +contextPath+ "/images/edit.gif' width='16' height='16' border='0' style='cursor:hand;' >");601 curCell.appendChild( curImage );602 curImage.viewNode = aDiv;603 aDiv.editImage = curImage;604 605 curRow = subTable.insertRow();606 curRow.align="center";607 curCell = curRow.insertCell();608 curCell.height = "16"609 clickHandle = 'assignJob(this.viewNode.treeNode.oid);';610 curImage = document.createElement("<img onclick='" +clickHandle + "' src='" +contextPath+ "/images/userbro.gif' width='16' height='16' border='0' style='cursor:hand;' >");611// curImage.alt = assignJobAltLabel;612 curCell.appendChild( curImage );613 curImage.viewNode = aDiv;614 aDiv.assignJobImage = curImage;615 //create the second col of whole table616 curCell = wholeTable.rows[0].insertCell();617 curCell.className = "subalterbar";618 curCell.noWrap = true;619 620 //create subtable of second col621 subTable = document.createElement( "<table width='100' border='0' cellspacing='0' cellpadding='2'>" );622 curCell.appendChild(subTable);623 624 if( !isCompact ){625 curRow = subTable.insertRow();626 curCell = curRow.insertCell();627 curCell.width = "1%";628 curCell.align = "right";629 curCell.noWrap = true;630 curCell.innerText = codeKeyValue;631 curCell = curRow.insertCell();632 curCell.width = "100%";633 curCell.noWrap = true;634 curCell.innerText = this.code;635 }636 curRow = subTable.insertRow();637 if( !isCompact ){638 curCell = curRow.insertCell();639 curCell.width = "1%";640 curCell.align = "right";641 curCell.vAlign = "top";642 curCell.noWrap = true;643 curCell.innerText = nameKeyValue;644 }645 curCell = curRow.insertCell();646 curCell.width = "100%";647 curCell.noWrap = true;648 curCell.innerText = this.name;649 if( !isCompact ){650 curRow = subTable.insertRow();651 curCell = curRow.insertCell();652 curCell.width = "1%";653 curCell.align = "right";654 curCell.vAlign = "top";655 curCell.noWrap = true; 656 curCell = curRow.insertCell();657 curCell.width = "100%";658 curCell.noWrap = true; 659 }660 //create subtable of second col661 subTable = document.createElement( "<table width='100' border='0' cellspacing='0' cellpadding='2'>" );662 wholeTable.rows[0].cells[1].appendChild(subTable);663 aDiv.chiefJobTable = subTable;664 665 curRow = subTable.insertRow();666 curCell = curRow.insertCell();667 curCell.width = "100%";668 curCell.align = "left";669 curCell.vAlign = "center";670 curCell.noWrap = true;671 //create the third col of whole table672 curCell = wholeTable.rows[0].insertCell();673 curCell.noWrap = true;674 curCell.align = "center";675 curCell.vAlign = "center";676 curCell.className = "subalterbar";677 if( this.subnode!=null && this.subnode.length>0 ){678 if( this.open )679 curImage = document.createElement("<img onclick='doOpen(this.viewNode);' src='" +contextPath+ "/images/expand.gif' width='18' height='18' style='cursor=hand;' >");680 else681 curImage = document.createElement("<img onclick='doOpen(this.viewNode);' src='" +contextPath+ "/images/shrink.gif' width='18' height='18' style='cursor=hand;' >");682 curImage.viewNode = aDiv;683 aDiv.openImage = curImage;684 curCell.appendChild(curImage);685 }else{686 curCell.width="18";687 }688 return aDiv;689}690//show organization unit by char model691function NodeCreateViewNodeH(oid){692 var idUnitItem = "unititem" + oid;693 var idItem = "item" + oid;694 var aDiv = document.createElement("<div class='orgunitchartitemcell'>");695 aDiv.treeNode = this;696 this.viewNode = aDiv;697 //create the Whole table698 var wholeTable = document.createElement("<table width='100' height='100%' border='0' cellpadding='0' cellspacing='0'>");699 aDiv.appendChild(wholeTable);700 //create the first Row of whole table.701 var curRow = wholeTable.insertRow();702 var curCell = curRow.insertCell();703 curCell.className = "subtableheader";704 curCell.align = "right";705 706 //create the subtable of first row707 var subTable = document.createElement( "<table style='padding-left:2px;padding-right:2px;' width='100' border='0' cellspacing='0' cellpadding='0'>" );708 curCell.appendChild(subTable);709 curRow = subTable.insertRow();710 curRow.align="center";711 712 curCell = curRow.insertCell();713 curCell.width = "33%"714 var clickHandle = "viewUnitInfo(this.viewNode.treeNode.oid);";715 var curImage = document.createElement("<img id='" + idItem + "' onclick='" +clickHandle+ "' src='" +contextPath+ "/images/edit.gif' width='16' height='16' border='0' style='cursor:hand;' >");716 curImage.alt = viewUnitInfoAltLabel;717 curCell.appendChild( curImage );718 curImage.viewNode = aDiv;719 aDiv.editImage = curImage;720 721 curCell = curRow.insertCell();722 curCell.width = "33%"723 724 curCell = curRow.insertCell();725 curCell.width = "33%"726 727 clickHandle = 'viewEmployees(this.viewNode.treeNode.oid);';728 curImage = document.createElement("<img onclick='" +clickHandle + "' src='" +contextPath+ "/images/begro.gif' width='16' height='16' border='0' style='cursor:hand;' >");729 curImage.alt = viewEmployeeAltLabel;730 curCell.appendChild( curImage );731 curImage.viewNode = aDiv;732 aDiv.viewEmployeesImage = curImage;733 //create the second row of whole table734 curRow = wholeTable.insertRow();735 curCell = curRow.insertCell();736 curCell.className = "subalterbar";737 738 //create subtable of second row739 subTable = document.createElement( "<table style='padding-left:2px;padding-right:2px;' width='100' border='0' cellspacing='0' cellpadding='2'>" );740 curCell.appendChild(subTable);741 if( !isCompact ){742 curRow = subTable.insertRow();743 curCell = curRow.insertCell();744 curCell.width = "1%";745 curCell.align = "right";746 curCell.noWrap = true;747 curCell.innerText = codeKeyValue;748 curCell = curRow.insertCell();749 curCell.width = "100%";750 curCell.noWrap = false;751 curCell.innerText = this.code;752 }753 754 curRow = subTable.insertRow();755 if( !isCompact ){756 curCell = curRow.insertCell();757 curCell.width = "1%";758 curCell.align = "right";759 curCell.vAlign = "top";760 curCell.noWrap = true;761 curCell.innerText = nameKeyValue;762 }763 curCell = curRow.insertCell();764 curCell.width = "100%";765 curCell.noWrap = false;766 curCell.innerText = this.name;767 if( !isCompact ){768 curRow = subTable.insertRow();769 curCell = curRow.insertCell();770 curCell.width = "1%";771 curCell.align = "right";772 curCell.vAlign = "top";773 curCell.noWrap = true; 774 curCell = curRow.insertCell();775 curCell.width = "49%";776 curCell.noWrap = false; 777 }778 779 //create the third row of whole table780 curRow = wholeTable.insertRow();781 curCell = curRow.insertCell();782 curCell.className = "subalterbar";783 //create subtable of third row784 subTable = document.createElement( "<table style='padding-left:2px;padding-right:2px;' width='100' border='0' cellspacing='0' cellpadding='2'>" );785 curCell.appendChild(subTable);786 aDiv.chiefJobTable = subTable;787 788 curRow = subTable.insertRow();789 curCell = curRow.insertCell();790 curCell.width = "100%";791 curCell.align = "left";792 curCell.vAlign = "center";793 curCell.noWrap = false;794 795 796 //create the fourth row of whole table797 curRow = wholeTable.insertRow();798 curCell = curRow.insertCell();799 curCell.align = "center";800 curCell.className = "subalterbar";801 if( this.subnode!=null && this.subnode.length>0 ){802 if( this.open )803 curImage = document.createElement("<img onclick='doOpen(this.viewNode);' src='" +contextPath+ "/images/expand.gif' width='18' height='18' style='cursor=hand;' >");804 else805 curImage = document.createElement("<img onclick='doOpen(this.viewNode);' src='" +contextPath+ "/images/shrink.gif' width='18' height='18' style='cursor=hand;' >");806 curImage.viewNode = aDiv;807 aDiv.openImage = curImage;808 curCell.appendChild(curImage);809 }else{810 curCell.height = "18";811 }812 return aDiv;813}814function initLevelViewNode(td,aDiv){815 //deal with level816 var treeNode = aDiv.treeNode;817 var curLevelIndex = treeNode.level-1 ;818 var curNodes,curMax;819 if( levelNodes.length<=curLevelIndex || levelNodes[curLevelIndex]==null )820 levelNodes[curLevelIndex] = new Array();821 curNodes = levelNodes[curLevelIndex];822 curNodes[curNodes.length] = aDiv;823 if( treeNode.parent!=null ){824 for(var i=treeNode.parent.level;i<treeNode.level-1;i++){825 if( levelNodes.length<=i || levelNodes[i]==null )826 levelNodes[i] = new Array();827 curNodes = levelNodes[i];828 var tempDiv = document.createElement("<div align='center'></div>");829 tempDiv.style.height = (isCompact?"100":"120");830 var tempTable = document.createElement("<table width='100' height='100%' ></table>");831 tempTable.insertRow().insertCell();832 tempDiv.appendChild(tempTable);833 tempTable.background = contextPath + "/images/orgvertical.gif";834 curNodes[curNodes.length] = tempDiv ;835 td.appendChild(tempDiv);836 td.appendChild( document.createElement("<img border='0' src='" + contextPath + "/images/orgvertical.gif' >") );837 }838 }839 td.appendChild(aDiv);840}841function adaptLevelViewNode(){842 var adaptedCount,curNodes,curMax;843 var tempMax;844 for(var i=0;i<levelNodes.length;i++){845 if( levelAdaptedCount.length<=i || levelAdaptedCount[i]==null )846 levelAdaptedCount[i] = 0;847 adaptedCount = levelAdaptedCount[i];848 if( levelNodes.length<=i || levelNodes[i]==null )849 levelNodes[i] = new Array();850 curNodes = levelNodes[i];851 if( levelMaxHeight.length<=i || levelMaxHeight[i]==null )852 levelMaxHeight[i] = 0;853 curMax = levelMaxHeight[i];854 if( adaptedCount<curNodes.length ){855 tempMax = curMax;856 for(var j=adaptedCount;j<curNodes.length;j++){857 if( tempMax<curNodes[j].offsetHeight )858 tempMax = curNodes[j].offsetHeight;859 }860 if( tempMax>curMax ){861 for(var j=0;j<adaptedCount;j++)862 curNodes[j].style.height = tempMax;863 }864 for( var j=adaptedCount;j<curNodes.length;j++)865 curNodes[j].style.height = tempMax;866 levelMaxHeight[i] = tempMax;867 levelAdaptedCount[i] = curNodes.length;868 }869 }870}871//Global Var872var contextPath = ".";873var codeKeyValue = "code";874var nameKeyValue = "name";875var isCompact=true;876var mode="chart";877var rootNode = null;878var selectedNode = null;879//Global method880function doEditNode(viewNode, idItem){881 if(actionbar.style.display=="none"){882 actionbar.treeNode = viewNode.treeNode;883 showActionbar(viewNode, idItem);884 }else{885 if( actionbar.treeNode != viewNode.treeNode ){886 actionbar.treeNode = viewNode.treeNode;887 showActionbar(viewNode, idItem);888 }889 }890}891function showActionbar(viewNode, idItem){892 893 var actionbarHeight = 150;894 var y = document.body.scrollTop + document.body.clientHeight;895 var currenty = eval( calculateSumOffset(idItem, 'offsetTop') + 16 + actionbarHeight);896 if( currenty > y){897 //yangc change for show the actionbar to up when therer is no space in the end page, 2003.10.16898 actionbar.style.top = y - actionbarHeight;899 }else{900 actionbar.style.top = calculateSumOffset(idItem, 'offsetTop') + 16;901 }902 //shig change for end, 2003.07.26903 actionbar.style.left = calculateSumOffset(idItem, 'offsetLeft');904 actionbar.style.display="block";905 leftX = document.all["actionbar"].style.posLeft;906 rightX = leftX + document.all["actionbar"].offsetWidth;907 //shig change for show the actionbar to up when therer is no space in the end page, 2003.07.26908 if( currenty > y){909 topY = document.all["actionbar"].style.posTop;910 bottomY = topY + document.all["actionbar"].offsetHeight;911 }else{912 topY = document.all["actionbar"].style.posTop - 18 ;913 bottomY = topY + document.all["actionbar"].offsetHeight + 18 ;914 }915}916function calculateSumOffset(idItem, offsetName)917{918 var totalOffset = 0;919 var item = idItem;920 do921 {922 totalOffset += eval('item.'+offsetName);923 item = eval('item.offsetParent');924 } while (item != null);925 return totalOffset;926}927function hideActionbar(){928 actionbar.style.display="none";929}930function doOpen(viewNode){931 if( mode=="chart" )932 doOpenH(viewNode)933 else934 doOpenT(viewNode)935 adaptPosition(); 936 hideActionbar();937}938function doOpenH(viewNode){939 var atable=viewNode;940 var i;941 do{942 atable=atable.parentElement;943 }while(atable.tagName!="TABLE");944 if( viewNode.treeNode.open){945 atable.rows[2].style.display="none";946 if (atable.rows[0].cells.length > 1) {947 atable.rows[0].cells[0].style.display="none";948 atable.rows[0].cells[2].style.display="none";949 atable.rows[1].cells[0].style.display="none";950 atable.rows[1].cells[2].style.display="none";951 }952 viewNode.treeNode.open=false;953 viewNode.openImage.src = contextPath+"/images/shrink.gif";954 }else{955 var treeNode = viewNode.treeNode;956 var needAdapt = false;957 if( treeNode.getSubnode(0).viewNode==null ){958 var subViewNode;959 needAdapt = true;960 for(i=0;i<treeNode.subnode.length;i++){961 subViewNode = treeNode.getSubnode(i).createAllNode(i,treeNode.subnode.length);962 atable.rows[2].cells[i*2].appendChild(subViewNode);963 }964 }965 atable.rows[2].style.display="block";966 if (atable.rows[0].cells.length > 1) {967 atable.rows[0].cells[0].style.display="block";968 atable.rows[0].cells[2].style.display="block";969 atable.rows[1].cells[0].style.display="block";970 atable.rows[1].cells[2].style.display="block";971 }972 viewNode.treeNode.open=true;973 viewNode.openImage.src = contextPath+"/images/expand.gif";974 if( needAdapt )975 adaptLevelViewNode();976 }977}978function doOpenV(viewNode){979 var atable=viewNode;980 var i;981 do{982 atable=atable.parentElement;983 }while(atable.tagName!="TABLE");984 if( viewNode.treeNode.open){985 for(i=0;i<atable.rows.length;i++)986 atable.rows[i].cells[2].style.display = "none";987 viewNode.treeNode.open=false;988 viewNode.openImage.src = contextPath+"/images/shrink.gif";989 }else{990 var treeNode = viewNode.treeNode;991 if( treeNode.getSubnode(0).viewNode==null ){992 var subViewNode;993 for(i=0;i<treeNode.subnode.length;i++){994 subViewNode = treeNode.getSubnode(i).createAllNode(i,treeNode.subnode.length);995 atable.rows[i*2].cells[2].appendChild(subViewNode);996 }997 }998 for(i=0;i<atable.rows.length;i++)999 atable.rows[i].cells[2].style.display = "block";1000 viewNode.treeNode.open=true;1001 viewNode.openImage.src = contextPath+"/images/expand.gif";1002 }1003}1004function doOpenT(viewNode){1005 var atable=viewNode;1006 do{1007 atable=atable.parentElement;1008 }while(atable.tagName!="TABLE");1009 viewNode.treeNode.open = !viewNode.treeNode.open;1010 atable.rows[1].style.display = viewNode.treeNode.open?"block":"none";1011 if( viewNode.treeNode.parent==null )1012 viewNode.openImage.src = contextPath + (viewNode.treeNode.open?"/images/orgtreerootopen.gif":"/images/orgtreerootclose.gif");1013 else1014 viewNode.openImage.src = contextPath + (viewNode.treeNode.open?"/images/orgtreeopen.gif":"/images/orgtreeclose.gif");1015}1016function hideAll(){1017 if (actionbar != null) {hideActionbar();actionbar.left = 0;}1018}1019function updateIt(e){1020 if (ie)1021 {1022 var x = window.event.clientX + document.body.scrollLeft;1023 var y = window.event.clientY + document.body.scrollTop;1024 if (x > rightX || x < leftX) {1025 hideAll();1026 }1027 else if (y > bottomY || y < topY) {1028 hideAll();1029 }1030 }1031 if (n)1032 {1033 var x = e.pageX+document.body.scrollLeft;1034 var y = e.pageY+document.body.scrollTop;1035 if (x > rightX || x < leftX) hideAll();1036 else if (y > bottomY || y < topY) hideAll();1037 }1038}1039if (document.all){1040 if( document.body !=null ){1041 document.body.onclick=hideAll;1042 document.body.onscroll=hideAll;1043 document.body.onmousemove=updateIt;1044 }1045}1046if (document.layers){1047 document.onmousedown=hideAll;1048 window.captureEvents(Event.MOUSEMOVE);1049 window.onmousemove=updateIt;...

Full Screen

Full Screen

Magnifier.js

Source:Magnifier.js Github

copy

Full Screen

1/**2* Magnifier.js is a Javascript library enabling magnifying glass effect on an images.3*4* Features5*6* Zoom in / out functionality using mouse wheel7* Setting options via Javascript or data attributes8* Magnified image can be displayed in the lens itself or outside of it in a wrapper9* Attachment to multiple images with single call10* Attachment of user defined functions for thumbnail entering, moving and leaving and image zooming events11* Display loading text while the large image is being loaded, and switch to lens once its loaded12*13* Magnifier.js uses Event.js as a cross-browser event handling wrapper, which is available at14* Github and JSClasses.org:15*16* Github - https://github.com/mark-rolich/Event.js17* JS Classes - http://www.jsclasses.org/package/212-JavaScript-Handle-events-in-a-browser-independent-manner.html18*19* Works in Chrome, Firefox, Safari, IE 7, 8, 9 & 10.20*21* @author Mark Rolich <mark.rolich@gmail.com>22*/23var Magnifier = function (evt, options) {24 "use strict";25 var gOptions = options || {},26 curThumb = null,27 curData = {28 x: 0,29 y: 0,30 w: 0,31 h: 0,32 lensW: 0,33 lensH: 0,34 lensBgX: 0,35 lensBgY: 0,36 largeW: 0,37 largeH: 0,38 largeL: 0,39 largeT: 0,40 zoom: 2,41 zoomMin: 1.1,42 zoomMax: 5,43 mode: 'outside',44 largeWrapperId: (gOptions.largeWrapper !== undefined)45 ? (gOptions.largeWrapper.id || null)46 : null,47 status: 0,48 zoomAttached: false,49 zoomable: (gOptions.zoomable !== undefined)50 ? gOptions.zoomable51 : false,52 onthumbenter: (gOptions.onthumbenter !== undefined)53 ? gOptions.onthumbenter54 : null,55 onthumbmove: (gOptions.onthumbmove !== undefined)56 ? gOptions.onthumbmove57 : null,58 onthumbleave: (gOptions.onthumbleave !== undefined)59 ? gOptions.onthumbleave60 : null,61 onzoom: (gOptions.onzoom !== undefined)62 ? gOptions.onzoom63 : null64 },65 pos = {66 t: 0,67 l: 0,68 x: 0,69 y: 070 },71 gId = 0,72 status = 0,73 curIdx = '',74 curLens = null,75 curLarge = null,76 gZoom = (gOptions.zoom !== undefined)77 ? gOptions.zoom78 : curData.zoom,79 gZoomMin = (gOptions.zoomMin !== undefined)80 ? gOptions.zoomMin81 : curData.zoomMin,82 gZoomMax = (gOptions.zoomMax !== undefined)83 ? gOptions.zoomMax84 : curData.zoomMax,85 gMode = gOptions.mode || curData.mode,86 data = {},87 inBounds = false,88 isOverThumb = 0,89 getElementsByClass = function (className) {90 var list = [],91 elements = null,92 len = 0,93 pattern = '',94 i = 0,95 j = 0;96 if (document.getElementsByClassName) {97 list = document.getElementsByClassName(className);98 } else {99 elements = document.getElementsByTagName('*');100 len = elements.length;101 pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");102 for (i, j; i < len; i += 1) {103 if (pattern.test(elements[i].className)) {104 list[j] = elements[i];105 j += 1;106 }107 }108 }109 return list;110 },111 $ = function (selector) {112 var idx = '',113 type = selector.charAt(0),114 result = null;115 if (type === '#' || type === '.') {116 idx = selector.substr(1, selector.length);117 }118 if (idx !== '') {119 switch (type) {120 case '#':121 result = document.getElementById(idx);122 break;123 case '.':124 result = getElementsByClass(idx);125 break;126 }127 }128 return result;129 },130 createLens = function (thumb, idx) {131 var lens = document.createElement('div');132 lens.id = idx + '-lens';133 lens.className = 'magnifier-loader';134 thumb.parentNode.appendChild(lens);135 },136 updateLensOnZoom = function () {137 curLens.style.left = pos.l + 'px';138 curLens.style.top = pos.t + 'px';139 curLens.style.width = curData.lensW + 'px';140 curLens.style.height = curData.lensH + 'px';141 curLens.style.backgroundPosition = '-' + curData.lensBgX + 'px -' +142 curData.lensBgY + 'px';143 curLarge.style.left = '-' + curData.largeL + 'px';144 curLarge.style.top = '-' + curData.largeT + 'px';145 curLarge.style.width = curData.largeW + 'px';146 curLarge.style.height = curData.largeH + 'px';147 },148 updateLensOnLoad = function (idx, thumb, large, largeWrapper) {149 var lens = $('#' + idx + '-lens'),150 textWrapper = null;151 if (data[idx].status === 1) {152 textWrapper = document.createElement('div');153 textWrapper.className = 'magnifier-loader-text';154 lens.className = 'magnifier-loader hidden';155 textWrapper.appendChild(document.createTextNode('Loading...'));156 lens.appendChild(textWrapper);157 } else if (data[idx].status === 2) {158 lens.className = 'magnifier-lens hidden';159 lens.removeChild(lens.childNodes[0]);160 lens.style.background = 'url(' + thumb.src + ') no-repeat 0 0 scroll';161 large.id = idx + '-large';162 large.style.width = data[idx].largeW + 'px';163 large.style.height = data[idx].largeH + 'px';164 large.className = 'magnifier-large hidden';165 if (data[idx].mode === 'inside') {166 lens.appendChild(large);167 } else {168 largeWrapper.appendChild(large);169 }170 }171 lens.style.width = data[idx].lensW + 'px';172 lens.style.height = data[idx].lensH + 'px';173 },174 getMousePos = function () {175 var xPos = pos.x - curData.x,176 yPos = pos.y - curData.y,177 t = 0,178 l = 0;179 inBounds = (180 xPos < 0 ||181 yPos < 0 ||182 xPos > curData.w ||183 yPos > curData.h184 )185 ? false186 : true;187 l = xPos - (curData.lensW / 2);188 t = yPos - (curData.lensH / 2);189 if (curData.mode !== 'inside') {190 if (xPos < curData.lensW / 2) {191 l = 0;192 }193 if (yPos < curData.lensH / 2) {194 t = 0;195 }196 if (xPos - curData.w + (curData.lensW / 2) > 0) {197 l = curData.w - (curData.lensW + 2);198 }199 if (yPos - curData.h + (curData.lensH / 2) > 0) {200 t = curData.h - (curData.lensH + 2);201 }202 }203 pos.l = Math.round(l);204 pos.t = Math.round(t);205 curData.lensBgX = pos.l + 1;206 curData.lensBgY = pos.t + 1;207 if (curData.mode === 'inside') {208 curData.largeL = Math.round(xPos * (curData.zoom - (curData.lensW / curData.w)));209 curData.largeT = Math.round(yPos * (curData.zoom - (curData.lensH / curData.h)));210 } else {211 curData.largeL = Math.round(curData.lensBgX * curData.zoom * (curData.largeWrapperW / curData.w));212 curData.largeT = Math.round(curData.lensBgY * curData.zoom * (curData.largeWrapperH / curData.h));213 }214 },215 zoomInOut = function (e) {216 var delta = (e.wheelDelta > 0 || e.detail < 0) ? 0.1 : -0.1,217 handler = curData.onzoom,218 multiplier = 1,219 w = 0,220 h = 0;221 if (e.preventDefault) {222 e.preventDefault();223 }224 e.returnValue = false;225 curData.zoom = Math.round((curData.zoom + delta) * 10) / 10;226 if (curData.zoom >= curData.zoomMax) {227 curData.zoom = curData.zoomMax;228 } else if (curData.zoom >= curData.zoomMin) {229 curData.lensW = Math.round(curData.w / curData.zoom);230 curData.lensH = Math.round(curData.h / curData.zoom);231 if (curData.mode === 'inside') {232 w = curData.w;233 h = curData.h;234 } else {235 w = curData.largeWrapperW;236 h = curData.largeWrapperH;237 multiplier = curData.largeWrapperW / curData.w;238 }239 curData.largeW = Math.round(curData.zoom * w);240 curData.largeH = Math.round(curData.zoom * h);241 getMousePos();242 updateLensOnZoom();243 if (handler !== null) {244 handler({245 thumb: curThumb,246 lens: curLens,247 large: curLarge,248 x: pos.x,249 y: pos.y,250 zoom: Math.round(curData.zoom * multiplier * 10) / 10,251 w: curData.lensW,252 h: curData.lensH253 });254 }255 } else {256 curData.zoom = curData.zoomMin;257 }258 },259 onThumbEnter = function () {260 curData = data[curIdx];261 curLens = $('#' + curIdx + '-lens');262 if (curData.status === 2) {263 curLens.className = 'magnifier-lens';264 if (curData.zoomAttached === false) {265 if (curData.zoomable !== undefined && curData.zoomable === true) {266 evt.attach('mousewheel', curLens, zoomInOut);267 if (window.addEventListener) {268 curLens.addEventListener('DOMMouseScroll', function (e) {269 zoomInOut(e);270 });271 }272 }273 curData.zoomAttached = true;274 }275 curLarge = $('#' + curIdx + '-large');276 curLarge.className = 'magnifier-large';277 } else if (curData.status === 1) {278 curLens.className = 'magnifier-loader';279 }280 },281 onThumbLeave = function () {282 if (curData.status > 0) {283 var handler = curData.onthumbleave;284 if (handler !== null) {285 handler({286 thumb: curThumb,287 lens: curLens,288 large: curLarge,289 x: pos.x,290 y: pos.y291 });292 }293 if (curLens.className.indexOf('hidden') === -1) {294 curLens.className += ' hidden';295 curThumb.className = curData.thumbCssClass;296 if (curLarge !== null) {297 curLarge.className += ' hidden';298 }299 }300 }301 },302 move = function () {303 if (status !== curData.status) {304 onThumbEnter();305 }306 if (curData.status > 0) {307 curThumb.className = curData.thumbCssClass + ' opaque';308 if (curData.status === 1) {309 curLens.className = 'magnifier-loader';310 } else if (curData.status === 2) {311 curLens.className = 'magnifier-lens';312 curLarge.className = 'magnifier-large';313 curLarge.style.left = '-' + curData.largeL + 'px';314 curLarge.style.top = '-' + curData.largeT + 'px';315 }316 curLens.style.left = pos.l + 'px';317 curLens.style.top = pos.t + 'px';318 curLens.style.backgroundPosition = '-' +319 curData.lensBgX + 'px -' +320 curData.lensBgY + 'px';321 var handler = curData.onthumbmove;322 if (handler !== null) {323 handler({324 thumb: curThumb,325 lens: curLens,326 large: curLarge,327 x: pos.x,328 y: pos.y329 });330 }331 }332 status = curData.status;333 },334 setThumbData = function (thumb, thumbData) {335 var thumbBounds = thumb.getBoundingClientRect(),336 w = 0,337 h = 0;338 thumbData.x = thumbBounds.left;339 thumbData.y = thumbBounds.top;340 thumbData.w = Math.round(thumbBounds.right - thumbData.x);341 thumbData.h = Math.round(thumbBounds.bottom - thumbData.y);342 thumbData.lensW = Math.round(thumbData.w / thumbData.zoom);343 thumbData.lensH = Math.round(thumbData.h / thumbData.zoom);344 if (thumbData.mode === 'inside') {345 w = thumbData.w;346 h = thumbData.h;347 } else {348 w = thumbData.largeWrapperW;349 h = thumbData.largeWrapperH;350 }351 thumbData.largeW = Math.round(thumbData.zoom * w);352 thumbData.largeH = Math.round(thumbData.zoom * h);353 };354 this.attach = function (options) {355 if (options.thumb === undefined) {356 throw {357 name: 'Magnifier error',358 message: 'Please set thumbnail',359 toString: function () {return this.name + ": " + this.message; }360 };361 }362 var thumb = $(options.thumb),363 i = 0;364 if (thumb.length !== undefined) {365 for (i; i < thumb.length; i += 1) {366 options.thumb = thumb[i];367 this.set(options);368 }369 } else {370 options.thumb = thumb;371 this.set(options);372 }373 };374 this.setThumb = function (thumb) {375 curThumb = thumb;376 };377 this.set = function (options) {378 if (data[options.thumb.id] !== undefined) {379 curThumb = options.thumb;380 return false;381 }382 var thumbObj = new Image(),383 largeObj = new Image(),384 thumb = options.thumb,385 idx = thumb.id,386 zoomable = null,387 largeUrl = null,388 largeWrapper = (389 $('#' + options.largeWrapper) ||390 $('#' + thumb.getAttribute('data-large-img-wrapper')) ||391 $('#' + curData.largeWrapperId)392 ),393 zoom = options.zoom || thumb.getAttribute('data-zoom') || gZoom,394 zoomMin = options.zoomMin || thumb.getAttribute('data-zoom-min') || gZoomMin,395 zoomMax = options.zoomMax || thumb.getAttribute('data-zoom-max') || gZoomMax,396 mode = options.mode || thumb.getAttribute('data-mode') || gMode,397 onthumbenter = (options.onthumbenter !== undefined)398 ? options.onthumbenter399 : curData.onthumbenter,400 onthumbleave = (options.onthumbleave !== undefined)401 ? options.onthumbleave402 : curData.onthumbleave,403 onthumbmove = (options.onthumbmove !== undefined)404 ? options.onthumbmove405 : curData.onthumbmove,406 onzoom = (options.onzoom !== undefined)407 ? options.onzoom408 : curData.onzoom;409 if (options.large === undefined) {410 largeUrl = (options.thumb.getAttribute('data-large-img-url') !== null)411 ? options.thumb.getAttribute('data-large-img-url')412 : options.thumb.src;413 } else {414 largeUrl = options.large;415 }416 if (largeWrapper === null && mode !== 'inside') {417 throw {418 name: 'Magnifier error',419 message: 'Please specify large image wrapper DOM element',420 toString: function () {return this.name + ": " + this.message; }421 };422 }423 if (options.zoomable !== undefined) {424 zoomable = options.zoomable;425 } else if (thumb.getAttribute('data-zoomable') !== null) {426 zoomable = (thumb.getAttribute('data-zoomable') === 'true');427 } else if (curData.zoomable !== undefined) {428 zoomable = curData.zoomable;429 }430 if (thumb.id === '') {431 idx = thumb.id = 'magnifier-item-' + gId;432 gId += 1;433 }434 createLens(thumb, idx);435 data[idx] = {436 zoom: zoom,437 zoomMin: zoomMin,438 zoomMax: zoomMax,439 mode: mode,440 zoomable: zoomable,441 thumbCssClass: thumb.className,442 zoomAttached: false,443 status: 0,444 largeUrl: largeUrl,445 largeWrapperId: mode === 'outside' ? largeWrapper.id : null,446 largeWrapperW: mode === 'outside' ? largeWrapper.offsetWidth : null,447 largeWrapperH: mode === 'outside' ? largeWrapper.offsetHeight : null,448 onzoom: onzoom,449 onthumbenter: onthumbenter,450 onthumbleave: onthumbleave,451 onthumbmove: onthumbmove452 };453 evt.attach('mouseover', thumb, function (e, src) {454 if (curData.status !== 0) {455 onThumbLeave();456 }457 curIdx = src.id;458 curThumb = src;459 onThumbEnter(src);460 setThumbData(curThumb, curData);461 pos.x = e.clientX;462 pos.y = e.clientY;463 getMousePos();464 move();465 var handler = curData.onthumbenter;466 if (handler !== null) {467 handler({468 thumb: curThumb,469 lens: curLens,470 large: curLarge,471 x: pos.x,472 y: pos.y473 });474 }475 }, false);476 evt.attach('mousemove', thumb, function (e, src) {477 isOverThumb = 1;478 });479 evt.attach('load', thumbObj, function () {480 data[idx].status = 1;481 setThumbData(thumb, data[idx]);482 updateLensOnLoad(idx);483 evt.attach('load', largeObj, function () {484 data[idx].status = 2;485 updateLensOnLoad(idx, thumb, largeObj, largeWrapper);486 });487 largeObj.src = data[idx].largeUrl;488 });489 thumbObj.src = thumb.src;490 };491 evt.attach('mousemove', document, function (e) {492 pos.x = e.clientX;493 pos.y = e.clientY;494 getMousePos();495 if (inBounds === true) {496 move();497 } else {498 if (isOverThumb !== 0) {499 onThumbLeave();500 }501 isOverThumb = 0;502 }503 }, false);504 evt.attach('scroll', window, function () {505 if (curThumb !== null) {506 setThumbData(curThumb, curData);507 }508 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2fc.assert(3 fc.property(fc.integer(), (n) => n >= 0)4);5const fc = require('fast-check');6fc.assert(7 fc.property(fc.integer(), (n) => n >= 0)8);9const fc = require('fast-check');10fc.assert(11 fc.property(fc.integer(), (n) => n >= 0)12);13const fc = require('fast-check');14fc.assert(15 fc.property(fc.integer(), (n) => n >= 0)16);17const fc = require('fast-check');18fc.assert(19 fc.property(fc.integer(), (n) => n >= 0)20);21const fc = require('fast-check');22fc.assert(23 fc.property(fc.integer(), (n) => n >= 0)24);25const fc = require('fast-check');26fc.assert(27 fc.property(fc.integer(), (n) => n >= 0)28);29const fc = require('fast-check');30fc.assert(31 fc.property(fc.integer(), (n) => n >= 0)32);33const fc = require('fast-check');34fc.assert(35 fc.property(fc.integer(), (n) => n >= 0)36);37const fc = require('fast-check');38fc.assert(39 fc.property(fc.integer(), (n) => n >= 0)40);41const fc = require('fast-check');42fc.assert(43 fc.property(fc.integer(), (n) => n >= 0)44);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2fc.assert(3 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),4 { numRuns: 1000 }5);6const fc = require('fast-check');7fc.assert(8 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),9 { numRuns: 1000 }10);11const fc = require('fast-check');12fc.assert(13 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),14 { numRuns: 1000 }15);16const fc = require('fast-check');17fc.assert(18 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),19 { numRuns: 1000 }20);21const fc = require('fast-check');22fc.assert(23 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),24 { numRuns: 1000 }25);26const fc = require('fast-check');27fc.assert(28 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),29 { numRuns: 1000 }30);31const fc = require('fast-check');32fc.assert(33 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),34 { numRuns: 1000 }35);36const fc = require('fast-check');37fc.assert(38 fc.property(fc.integer(), fc.integer(), (a, b) => a + b >= a),39 { numRuns: 1000 }40);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { cur } = require('cur');3const add = (a, b) => a + b;4const add3 = (a, b, c) => a + b + c;5const addCur = cur(add);6const add3Cur = cur(add3);7fc.assert(8 fc.property(fc.integer(), fc.integer(), fc.integer(), (a, b, c) => {9 return addCur(a)(b) === add(a, b) && add3Cur(a)(b)(c) === add3(a, b, c);10 })11);12const fc = require('fast-check');13const { cur } = require('cur');14const add = (a, b) => a + b;15const add3 = (a, b, c) => a + b + c;16const addCur = cur(add);17const add3Cur = cur(add3);18fc.assert(19 fc.property(fc.integer(), fc.integer(), fc.integer(), (a, b, c) => {20 return addCur(a)(b) === add(a, b) && add3Cur(a)(b)(c) === add3(a, b, c);21 })22);23const fc = require('fast-check');24const { cur } = require('cur');25const add = (a, b) => a + b;26const add3 = (a, b, c) => a + b + c;27const addCur = cur(add);28const add3Cur = cur(add3);29fc.assert(30 fc.property(fc.integer(), fc.integer(), fc.integer(), (a, b, c) => {31 return addCur(a)(b) === add(a, b) && add3Cur(a)(b)(c) === add3(a, b, c);32 })33);34const fc = require('fast-check');35const { cur } = require('cur');36const add = (a, b) => a + b;37const add3 = (a, b, c) => a + b + c;38const addCur = cur(add);39const add3Cur = cur(add3);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check-monorepo/lib/fast-check');2const fc = require('fast-check-monorepo/lib/fast-check');3const assert = require('assert');4const isEven = (n) => n % 2 === 0;5const arbEven = fc.nat().filter(isEven);6fc.assert(7 fc.property(arbEven, (n) => {8 assert.ok(isEven(n));9 })10);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require("fast-check");2fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => {3 return a + b === b + a;4}));5 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)6 at Function.Module._load (internal/modules/cjs/loader.js:508:25)7 at Module.require (internal/modules/cjs/loader.js:637:17)8 at require (internal/modules/cjs/helpers.js:22:18)9 at Object.<anonymous> (/Users/xxx/fast-check-monorepo/test3.js:1:14)10 at Module._compile (internal/modules/cjs/loader.js:689:30)11 at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)12 at Module.load (internal/modules/cjs/loader.js:599:32)13 at tryModuleLoad (internal/modules/cjs/loader.js:538:12)14 at Function.Module._load (internal/modules/cjs/loader.js:530:3)15function getFormattedDate(date) {16 const day = date.getDate();17 const month = date.getMonth() + 1;18 const year = date.getFullYear();19 return `${year}-${month}-${day}`;20}21it("getFormattedDate should return a date with a specific format", () => {22 const date = new Date("2019-02-01");23 const formattedDate = getFormattedDate(date);24 expect(formattedDate).toEqual("2019-2-1");25});26it("getFormattedDate should return a date with a specific format", () => {27 const date = new Date("2019-02-01");

Full Screen

Using AI Code Generation

copy

Full Screen

1const {cur} = require('fast-check');2const {fc} = cur;3const {property} = fc;4const {string} = fc;5module.exports = property(string(), (s) => {6 return s === s;7});8const {cur} = require('fast-check');9const {fc} = cur;10const {property} = fc;11const {string} = fc;12module.exports = property(string(), (s) => {13 return s === s;14});15const {cur} = require('fast-check');16const {fc} = cur;17const {property} = fc;18const {string} = fc;19module.exports = property(string(), (s) => {20 return s === s;21});22const {cur} = require('fast-check');23const {fc} = cur;24const {property} = fc;25const {string} = fc;26module.exports = property(string(), (s) => {27 return s === s;28});29const {cur} = require('fast-check');30const {fc} = cur;31const {property} = fc;32const {string} = fc;33module.exports = property(string(), (s) => {34 return s === s;35});36const {cur} = require('fast-check');37const {fc} = cur;38const {property} = fc;39const {string} = fc;40module.exports = property(string(), (s) => {41 return s === s;42});43const {cur} = require('fast-check');44const {fc} = cur;45const {property} = fc;46const {string} = fc;47module.exports = property(string(), (s) => {48 return s === s;49});50const {cur} = require('fast-check');51const {fc} =

Full Screen

Using AI Code Generation

copy

Full Screen

1const {cur} = require('fast-check');2const {cur} = require('fast-check/lib/runner/cur');3const {cur} = require('fast-check/lib/runner/cur');4const {cur} = require('fast-check');5const {cur} = require('fast-check/lib/runner/cur');6const {cur} = require('fast-check/lib/runner/cur');7const {cur} = require('fast-check');8const {cur} = require('fast-check/lib/runner/cur');9const {cur} = require('fast-check/lib/runner/cur');10const {cur} = require('fast-check');11const {cur} = require('fast-check/lib/runner/cur');12const {cur} = require('fast-check/lib/runner/cur');13const {cur} = require('fast-check');14const {cur} = require('fast-check/lib/runner/cur');15const {cur} = require('fast-check/lib/runner/cur');16const {cur} = require('fast-check');17const {cur} = require('fast-check/lib/runner/cur');18const {cur} = require('fast-check/lib/runner/cur');19const {cur} = require('fast-check');20const {cur} = require('fast-check/lib/runner/cur');21const {cur} = require('fast-check/lib/runner/cur');22const {cur} = require('fast-check');23const {cur} = require('fast-check/lib/runner/cur');24const {cur} = require('fast-check/lib/runner/cur');25const {cur} = require('fast-check');26const {cur} = require('fast-check/lib/runner/cur');27const {cur} = require('fast-check/lib/runner/cur');28const {cur} = require('fast-check');29const {cur} = require('fast-check/lib/

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const {cur} = require('fast-check-monorepo');3const {curried} = require('./curried');4const {curriedFunctions} = curried;5const {curry} = cur;6const {curry2, curry3, curry4, curry5} = curry;7const {curry2: curried2, curry3: curried3, curry4: curried4, curry5: curried5} = curriedFunctions;8const {curry2: fastCurried2, curry3: fastCurried3, curry4: fastCurried4, curry5: fastCurried5} = fc.cur;9const curried2Test = () => {10 const curried2Add = curried2((a, b) => a + b);11 const fastCurried2Add = fastCurried2((a, b) => a + b);12 fc.assert(13 fc.property(fc.integer(), fc.integer(), (a, b) => {14 const curried2Result = curried2Add(a)(b);15 const fastCurried2Result = fastCurried2Add(a)(b);16 return curried2Result === fastCurried2Result;17 })18 );19};20const curried3Test = () => {21 const curried3Add = curried3((a, b, c) => a + b + c);22 const fastCurried3Add = fastCurried3((a, b, c) => a + b + c);23 fc.assert(24 fc.property(fc.integer(), fc.integer(), fc.integer(), (a, b, c) => {25 const curried3Result = curried3Add(a)(b)(c);26 const fastCurried3Result = fastCurried3Add(a)(b)(c);27 return curried3Result === fastCurried3Result;28 })29 );30};31const curried4Test = () => {32 const curried4Add = curried4((a, b, c, d) => a + b + c + d);33 const fastCurried4Add = fastCurried4((a, b, c, d) => a + b + c + d);34 fc.assert(35 fc.property(fc.integer(), fc.integer(), fc.integer(), fc.integer(), (

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful