weblog, content management & redaktion
RSS Feed für `JavaScript` Seite drucken

Mausposition global verfügbar & drag divs

var mouseX;
var mouseY;
var twmove=false, dx, dy;
if(!IE) document.captureEvents( Event.MOUSEMOVE );
document.onmousemove = setmousepos;
function setmousepos(e){
  try{
    mouseX = (IE?event.clientX:e.pageX);
    mouseY = (IE?event.clientY+document.body.scrollTop:e.pageY);
// move toolwins
    if(twmove&&dx&&dy&&O("toolwin")){
      O("toolwin").style.right="auto";
      O("toolwin").style.left=dx+mouseX+"px";
      O("toolwin").style.top=dy+mouseY+"px";
    }
  }catch(er){}
}
function moveToolWin(e){
  e=e||event;
  el = e.target || e.srcElement;
  if(el.tagName.toLowerCase()=="div" && el.className!="disableDrag"){
    if(O("toolwin")){
      dx=O("toolwin").offsetLeft-mouseX;  
      dy=O("toolwin").offsetTop-mouseY;
      twmove=true;
      disableSelection(document.body);
      resetLogout();
    }  
  }
 
}
function leaveToolWin(e){
  if(twmove && O("toolwin")){
    dx=false;dy=false;twmove=false;
    enableSelection(document.body);
  }
}
function disableSelection(el){
  el.onselectstart=function(){return false;};
  el.unselectable = "on";
  el.style.MozUserSelect = "none";
}
function enableSelection( el ){
  el.onselectstart=function(){return true;};
  el.unselectable = "off";
  el.style.MozUserSelect = "";
}
function createToolWin( html ){
  var toolwin = document.createElement("div");
  toolwin.id = "toolwin";
  toolwin.className = "toolWin";
  toolwin.innerHTML = html;
  toolwin.style.zIndex = 4999;
  toolwin.onmousedown = moveToolWin;
  toolwin.onmouseup = leaveToolWin;
  document.body.appendChild( toolwin );
}
function hideToolWin(){
  if(!O("toolwin")) return;
  document.body.removeChild( O("toolwin") );
}
function O(id){
  return document.getElementById(id);
}