1 2 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
|
var Windows = Class.create();
Windows.prototype = {
initialize : function(_Name,_Left,_Top,_Height,_Width) {
this.Name = _Name;
this.Bar_Name = this.Name+'Bar';
this.Min_Name = this.Name+'Min';
this.Close_Name = this.Name+'Close';
this.Left = _Left;
this.Top = _Top;
this.Height = _Height;
this.Width = _Width;
this.printW();
this.DOM = document.getElementById(this.Name);
this.DOM_Bar = document.getElementById(this.Bar_Name);
this.DOM_Min = document.getElementById(this.Min_Name);
this.DOM_Close = document.getElementById(this.Close_Name);
this.DOM_Bar.onmousedown = this.startDrag.bindAsEventListener(this);
this.DOM_Close.onclick = this.setHidden.bindAsEventListener(this);
},
printW : function() {
document.write('<div style="border-style:solid; border-width:1px; position: absolute; width: '+this.Width+'px; height: '+this.Height+'px; z-index: 1; left: '+this.Left+'px; top: '+this.Top+'px; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px" id="'+this.Name+'"><div style="border-style:solid; border-width:1px; position: absolute; width: '+this.Width+'px; height: 17px; z-index: 1; left: -1px; top: -1px; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px; background-color:#0000FF" id="'+this.Name+'Bar"><p align="right"><input type="button" value="_" id="'+this.Name+'Min"><input type="button" value="X" id="'+this.Name+'Close"></div></div>');
},
setVisible : function() {
this.DOM.style.visibility = 'visible';
},
setHidden : function() {
this.DOM.style.visibility = 'hidden';
},
setLeft : function(_left) {
this.DOM.style.left = _left;
},
setTop : function(_top) {
this.DOM.style.top = _top;
},
getLeft : function() {
return this.DOM.style.left;
},
getTop : function() {
return this.DOM.style.top;
},
startDrag : function(evt) {
window.lastX = evt.clientX;
window.lastY = evt.clientY;
// lance doDrag tant que l'on appuie sur le bouton de la souris en la bougeant
this.DOM_Bar.onmousemove= this.doDrag.bindAsEventListener(this);
// lance finirDrag quand on relache le bouton de la souris
this.DOM_Bar.onmouseup= this.endDrag.bindAsEventListener(this);
},
doDrag : function(evt) {
// Calcul de l'?cart de position de la souris
var difX=evt.clientX-window.lastX;
var difY=evt.clientY-window.lastY;
//R?cup?ration de la position du div et ajout de l'?cart de position de la souris
var newX1 = parseInt(this.getLeft())+difX;
var newY1 = parseInt(this.getTop())+difY;
// Assignation des nouvelles coordonn?es au div
this.setLeft(newX1+"px");
this.setTop(newY1+"px");
//Assignation de l'anci?nne position de la souris
window.lastX=evt.clientX;
window.lastY=evt.clientY;
},
endDrag : function(evt) {
this.DOM_Bar.onmousemove=null;
}
} |
Partager