jsp 表拉伸

来源:互联网 发布:淘宝运营每天工作内容 编辑:程序博客网 时间:2024/05/22 06:27






window.addEvent('domready', setScrolTable);


var globalValue = 0;


function setScrolTable(){

    var dataTable = $("dragColTable");
    if(dataTable == null){
    return ;
    }
    
    if(globalValue>0){
    return;
    }
    
    globalValue++;
    
    var ieVersion = getIEVersion();
    var row = dataTable.rows[0];
    if(row!=null){
   for(var i=0; i<row.cells.length;i++){
    var cellObj = row.cells[i];
    var temp = cellObj.innerHTML;
    cellObj.innerHTML = "";
    var spanElement = document.createElement('<div id=myCreateSpan class=resizeDivClass onmousedown=MouseDownToResize(this) onmousemove=MouseMoveToResize(this) onmouseup=MouseUpToResize(this)></div>');
    var imgElement = document.createElement('<img src="./images/common/box1.gif" width=3 height=20 style="display:block;" border="0"/>');
    spanElement.appendChild(imgElement);
    cellObj.appendChild(spanElement);
    cellObj.innerHTML = cellObj.innerHTML + temp;
   }
    }
}


function MouseDownToResize(obj){
setTableLayoutToFixed(); 
obj.mouseDownX=event.clientX; 
obj.pareneTdW=obj.parentElement.offsetWidth; 
obj.pareneTableW=dragColTable.offsetWidth; 
obj.setCapture(); 

function MouseMoveToResize(obj){ 
if(!obj.mouseDownX) return false; 
var newWidth=obj.pareneTdW*1+event.clientX*1-obj.mouseDownX; 
if(newWidth>0) 

obj.parentElement.style.width = newWidth; 
dragColTable.style.width=obj.pareneTableW*1+event.clientX*1-obj.mouseDownX; 


function MouseUpToResize(obj){ 
obj.releaseCapture(); 
obj.mouseDownX=0; 

function setTableLayoutToFixed() 

  if(dragColTable.style.tableLayout=='fixed') 
  return; 
var headerTr=dragColTable.rows[0]; 
for(var i=0;i<headerTr.cells.length;i++) 

headerTr.cells[i].styleOffsetWidth=headerTr.cells[i].offsetWidth; 

 
for(var i=0;i<headerTr.cells.length;i++) 

headerTr.cells[i].style.width=headerTr.cells[i].styleOffsetWidth; 

dragColTable.style.tableLayout='fixed'; 





var theobject = null; //This gets a value as soon as a resize start


function resizeObject() {
this.el        = null; //pointer to the object
this.dir    = "";      //type of current resize (n, s, e, w, ne, nw, se, sw)
this.grabx = null;     //Some useful values
this.graby = null;
this.width = null;
this.height = null;
this.left = null;
this.top = null;
}




//Find out what kind of resize! Return a string inlcluding the directions
function getDirection(el) {
var xPos, yPos, offset, dir;
dir = "";
offset = 8;
xPos = window.event.offsetX;
yPos = window.event.offsetY;




//The distance from the edge in pixels
var elm=window.event.srcElement






if(el.className=="dt_div"&&elm.className=="rollflag")
{
dir += "s";
}














return dir;
}


function doDown() {


var el = getReal(event.srcElement, "className", "dt_div");


if (el == null) {
   theobject = null;
   return;
}  


dir = getDirection(el);
if (dir == "") return;


theobject = new resizeObject();
  
theobject.el = el;
theobject.dir = dir;


theobject.grabx = window.event.clientX;
theobject.graby = window.event.clientY;
theobject.width = el.offsetWidth;
theobject.height = el.offsetHeight;
theobject.left = el.offsetLeft;
theobject.top = el.offsetTop;


window.event.returnValue = false;
window.event.cancelBubble = true;
}


function doUp() {
if (theobject != null) {
   theobject = null;
}
}


function doMove() {
var el, xPos, yPos, str, xMin, yMin;
xMin = 8; //The smallest width possible
yMin = 8; //             height


el = getReal(event.srcElement, "className", "dt_div");


var elm=window.event.srcElement
if (el.className == "dt_div"&&elm.className=="rollflag") {
   str = getDirection(el);
//Fix the cursor 
   if (str == "") str = "default";
   else 
  str += "-resize";


   elm.style.cursor = str;
}


//Dragging starts here




if(theobject != null) {
  




   if (dir.indexOf("s") != -1)
    theobject.el.style.height = Math.max(yMin, theobject.height + window.event.clientY - theobject.graby) + "px";


 
   if (dir.indexOf("n") != -1) {
    theobject.el.style.top = Math.min(theobject.top + window.event.clientY - theobject.graby, theobject.top + theobject.height - yMin) + "px";
    theobject.el.style.height = Math.max(yMin, theobject.height - window.event.clientY + theobject.graby) + "px";
   }
  
   window.event.returnValue = false;
   window.event.cancelBubble = true;

}




function getReal(el, type, value) {
//temp = el;
//while ((temp != null) && (temp.tagName != "BODY")) {
//   if (eval("temp." + type) == value) {
 //   el = temp;
//    return el;
//   }
//   temp = temp.parentElement;
//}
   var ieVersion = getIEVersion();
   if(ieVersion != "6"){
    temp=document.getElementById("displayTableDiv");
if(temp!=null)
 el=temp;
   }
return el;
}


document.onmousedown = doDown;
document.onmouseup   = doUp;
document.onmousemove = doMove;




function getIEVersion(){
var ua = navigator.userAgent; 
var s = "MSIE"; 
if ((i = ua.indexOf(s)) >= 0) { 
var version = parseFloat(ua.substr(i + s.length)); 
return version; 
}else{
return "other";
}
}
0 0