Tfe

Ongi etorri tfe-ren webgunera...

Projects/kmymoney basic viewer/js/tools.js

(Deskargatu)
// Ajout d'event
function addEvent(oElem, sEvType, fn, bCapture)
{
   return oElem.addEventListener?
      oElem.addEventListener(sEvType, fn, bCapture):
      oElem.attachEvent?
         oElem.attachEvent('on' + sEvType, fn):
         oElem['on' + sEvType] = fn;
}

function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
} 
// Fonction au demarrage
function addLoadEvent(func)
{
   var oldonload = window.onload;
   if(typeof window.onload != 'function')
   {
      window.onload = func;
   }
   else
   {
      window.onload = function()
      {
         oldonload();
         func();
      }
   }
}

// Trouver la position d'un element en absolute depuis le haut
function findPos(e) {
	var left = 0;
	var top  = 0;

	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
		e     = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;
	return {x:left, y:top};
}


function fadein(elt){   fade(elt,0,1,0.1); }
function fadeout(elt){   fade(elt,1,0,-0.1); }

function fade(elt,start,stop,step)
{
    if(elt && !elt.style.opacity)  { elt.style.opacity=start; }
    if(elt && elt.style.opacity>stop)
    {
	var op=Number(elt.style.opacity)+step;
	elt.style.opacity=op;
	elt.style.filter="alpha(opacity="+(op*100)+")";
	setTimeout(function() { fade(elt,start,stop,step);},50);
    }
}


var dragelt=false;
var drageltx=0;
var dragelty=0;

function movemouse(elt)
{
    elt.style.cursor="move";
    elt.style.position="absolute";
    addEvent(elt, 
	     "mousedown",
	     function()
	     {
	        var xy=findPos(elt);
	        dragelt=elt;
		drageltx=mouseX-xy.x;
		dragelty=mouseY-xy.y;
	     }, false);
    addEvent(elt,"mouseup",function() { dragelt=false; },false);
}

function ajax(method,url,send,waiting,final)
{
    http= gethttp();
    http.open(method,url,true);
    if(method=="POST")
    {
    http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length",send.length);
    http.send(send);
    }
    else
    {
	http.send(null);
    }
    http.onreadystatechange= function()
    {
	if(http.readyState!=4) {if(waiting) {  waiting(http); }}
	else { final(http); }
    }
}

function gethttp()
{
    try { http = new XMLHttpRequest(); }
    catch(e) { try { http = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (e) { http= false ; }}
    return http;
}


/* Gestion de la souris */
var IE = document.all?true:false
var mouseX=0;
var mouseY=0;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = mouseposition;
function mouseposition(e)
{
  if (IE) { 
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } 
  else {  
    tempX = e.pageX
    tempY = e.pageY
  } 
  mouseX=tempX;
  mouseY=tempY;
  
  if(dragelt)
  {
    dragelt.style.left=(mouseX - drageltx)+'px';
    dragelt.style.top=(mouseY - dragelty)+'px';
  }
}