| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 
 | function PopUp(url, on_off, title, width, height, positionX, positionY, timeout, debug) {
 
	// variable globale pour appel de la fermeture de la fenetre dans une autre sous-fonction
	var my_window;
 
	function Ouvre(on){
		var options	= 'toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,menubar=0';	
			if (on == true) {
				my_window = window.open(url, title, options+',top='+PosY+',left='+PosX+',width='+width+',height='+height);
				alert('Debug: ouverture de ' + my_window + ', avec url= '+ url);
			}
		}
 
	function Ferme(off){
		//alert('debug: tentative fermeture');
		if (off == true) {
			//alert('debug: demande fermeture popup');
			if (my_window.document) {
				//alert('debug: fermeture popup');
				my_window.close();
			}
		}
	}
 
	// Init et controle des parametres d'entrée
	timeout	= (timeout == 0 )? timeout = 1000 : timeout;
	var marginX	= 20;
	var marginY	= 20;
	var ScreenX = screen.availWidth;
	var ScreenY = screen.availHeight;
 
	if ((positionX != 'center') && (positionX != 'left') && (positionX != 'right')) {
		positionX = 'center' ;
	}
	if ((positionY != 'top') && (positionY != 'center') && (positionY != 'bottom')) {
		positionY = 'center' ;
	}
 
	// debug
	if (debug) { alert('X:' + positionX + ' Y:' + positionY); }
 
 
	// Calcul de la position (PosX,PosY) d'affichage de la fenetre selon les parametres user
	// methode: Xa: coin sup gauche, Xo: centre de la fenetre => on cherche Xo puis on deduit Xa (ou PosX)
	// même principe pour PosY
 
	if (positionX == 'center') {
		PosX	= Math.round((ScreenX-width)/2);
	}
 
	if (positionX == 'left') {
		PosX	= (Math.round((ScreenX/2-width)/2) > marginX )? Math.round((ScreenX/2-width)/2) : marginX ;
	}
 
	if (positionX == 'right') {
		PosX	= (Math.round(ScreenX*3/4 - width/2) < ( ScreenX - marginX - width) )? Math.round(ScreenX*3/4 - width/2 ) : ScreenX - marginX - width ;
	}
 
	if (positionY == 'top') {
		PosY	= (Math.round(ScreenY/4 - height/2) > marginY )? Math.round(ScreenY/4 - height/2) : marginY ;
	}
 
	if (positionY == 'center') {
		PosY	= Math.round((ScreenY-height)/2);
	}
 
	if (positionY == 'bottom') {
		PosY	= (Math.round(ScreenY *3/4 - height/2) < ScreenY - marginY - height )?  Math.round(ScreenY *3/4 - height/2) : ScreenY - marginY - height ;
	}
 
	// debug
	// alert('url: '+url+' Open: '+on_off+' TimeOut (ms): '+timeout);
 
	// Actions à mener
	if (on_off == 'open')	{
			Ouvre(true);
			//alert('timeout = ' + timeout);
			setTimeout(function(){Ferme(true)}, timeout); // Après un délai de 'timeout' millisecondes, on ferme la fenetre
	}
 
	if (on_off == 'close')	{
			Ferme(true);
	}
//return false;
} | 
Partager