/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
function DIALOG(close_cb, title, content, id) {
    var node = document.createElement("div");
    cssSetClass(node, "dialog");

    if (typeof "id" == "string") {
	node.setAttribute("id", id);
    }
    
    node.style.display = "none";
    node.style.left = "0px";
    node.style.top = "0px";

    var label = document.createElement("span");
    label.appendChild(document.createTextNode(title));

    var lnode = document.createElement("div");
    
    lnode.appendChild(label);
    cssSetClass(lnode, "titlebar");
    
    var cnode = document.createElement("div");
    cssSetClass(cnode, "close");

    var onode = document.createElement("div");
    cssSetClass(onode, "maximize");

    var mnode = document.createElement("div");
    cssSetClass(mnode, "content");

    if (typeof css_class != "undefined") cssSetClass(mnode, css_class);
    if (typeof content == "string")
	mnode.innerHTML = content;
    else
	mnode.appendChild(content);
	
    node.appendChild(cnode);
    node.appendChild(onode);
    node.appendChild(lnode);
    node.appendChild(mnode);


    if (isIE()) {
	var comment = document.createElement("div");
	comment.innerHTML = "<!--[if lte IE 6.5]><iframe></iframe><![endif]-->";
	node.appendChild(comment);

	this.iframe = comment;
    }

    this.CloseBind = close_cb.bindAsEventListener( this );
    
    this.node = node;
    this.close_node = cnode;
    this.maximize_node = onode;
    this.titlebar = lnode;
    this.label = label;
    this.content = mnode;
    this.parent = null;

    this.dragger = new DIALOG_DRAGGER(this);
}

DIALOG.prototype.AlterContent = function(content) {
	// Fixing size
    if ((!this.node.style.height)||(!this.node.style.width))
	this.Resize(this.node.offsetWidth, this.node.offsetHeight, true);	

	// Altering content
    if (typeof content == "string")
	this.content.innerHTML = content;
    else
	this.content.replaceChild(content, this.content.firstChild);
}

DIALOG.prototype.Setup = function(default_x, default_y) {
    this.node.style.display = "block";

    domAlignNode(this.node, adei.cfg.window_border, default_x, default_y, this.ResizeFunction(this, true));

//    new Draggable(this.node, {handle: this.titlebar});
    Event.observe(this.close_node, 'click', this.CloseBind );
    
    this.dragger.Setup();
}

DIALOG.prototype.Clean = function() {
    this.dragger.Clean();
    
    Event.stopObserving(this.node, 'click', this.LegendCloseBind );
}

DIALOG.prototype.Show = function(parent, instead_of, default_x, default_y) {
    if (this.parent) return;
    
    if ((typeof instead_of != "undefined")&&(instead_of)) {
	instead_of.Clean();
	parent.replaceChild(this.node, instead_of.node);
	instead_of.parent = null;
    } else {
	parent.appendChild(this.node);
    }

    this.parent = parent;
    
    setTimeout(this.SetupFunction(this,default_x, default_y), adei.cfg.parse_delay);
}

DIALOG.prototype.Hide = function() {
    if (this.parent) {
	this.Clean();
	this.parent.removeChild(this.node);
	this.parent = null;
    }
}

DIALOG.prototype.Resize = function(size_x, size_y, offset_sizes) {
    var node = this.node;
    
    if (size_x) {
	node.style.width = size_x + "px";

	if (offset_sizes) {
	    var diff = (node.offsetWidth - size_x);
	    if (diff) node.style.width = (size_x - diff) + "px";
	}
    }
    
    if (size_y) {
	var orig = node.offsetHeight;
	var corig = this.content.offsetHeight;
	
	this.content.style.height = "0px";
	node.style.height = size_y + "px";

	if (offset_sizes) {
	    var diff = (node.offsetHeight - size_y);
	    if (diff) node.style.height = (size_y - diff) + "px";
	}

	corig += (node.offsetHeight - orig); 
	
	this.content.style.height = corig + "px";
	diff =  this.content.offsetHeight - corig;
	this.content.style.height = (corig - diff) + "px";
    }
}

DIALOG.prototype.CheckReusability = function() {
    if ((this.dragger.is_moved)) {
	var node = this.node;
	
	var left = parseInt(domGetStyleProp(node, node.style.left, "left") ,10);
	left += this.dragger.minimumWidth + adei.cfg.window_border;
	var top = parseInt(domGetStyleProp(node, node.style.top, "top"), 10);
	top += this.dragger.minimumHeight + adei.cfg.window_border;

        if ((left < windowGetWidth())&&(top <  windowGetHeight())) return true;
    }
    
    return false;
}


DIALOG.prototype.ResizeFunction = function (self, offset_sizes) {
    return function(node, size_x, size_y) {
	self.Resize(size_x, size_y, offset_sizes);	
    }
}

DIALOG.prototype.SetupFunction = function (self, x, y) {
    return function() {
	self.Setup(x,y);
    }
}