Commit af383691 authored by Julien Cigar's avatar Julien Cigar
Browse files

allow width/height in percent

parent fea716c0
......@@ -16,6 +16,7 @@
onscroll : 'scroll',
overlay : true,
title : '',
body : null,
width : 300,
height : 300
}
......@@ -23,6 +24,7 @@
if (this.options.onscroll == 'scroll') {
Yeti.Evt.bind(window, 'scroll', function() {
_self.set_sizes();
_self.set_position();
});
}
......@@ -31,7 +33,12 @@
this.frame = document.createElement('div');
this.header = document.createElement('div');
this.title = document.createElement('span');
if (this.options.body === null) {
this.body = document.createElement('div');
} else {
this.body = Yeti.Element(this.options.body);
}
this.frame.style.zIndex = this.options.zindex;
this.frame.style.position = 'absolute';
......@@ -68,11 +75,9 @@
this.frame.appendChild(this.header);
this.frame.appendChild(this.body);
this.frame.style.width = this.options.width + 'px';
this.frame.style.height = this.options.height + 'px';
this.set_title(this.options.title);
this.set_body(this.options.body);
this.set_sizes();
this.set_position();
}
......@@ -82,6 +87,43 @@
}
}
UI.Frame.prototype.get_frame_size = function() {
var size = new Object(),
props = ['width', 'height']
;
for (var i=0, _len = props.length; i<_len; i++) {
var key = props[i],
value = this.options[key]
;
switch(typeof(value)) {
case 'number':
size[key] = value;
break;
case 'string':
var idx_percent = value.lastIndexOf('%');
if (idx_percent == -1) {
size[key] = parseInt(value);
} else {
var window_size = Yeti.DOM.getWindowSize();
size[key] = window_size[key] * (parseInt(value.substring(0, idx_percent)) / 100);
}
break;
}
}
return size;
}
UI.Frame.prototype.set_sizes = function() {
var size = this.get_frame_size();
this.frame.style.width = size.width + 'px';
this.frame.style.height = size.height + 'px';
this.body.style.height = (size.height - this.header.offsetHeight) -20 + 'px';
}
UI.Frame.prototype.get_position = function() {
var window_size = Yeti.DOM.getWindowSize(),
scroll_offset = Yeti.DOM.getScrollXY()
......@@ -89,7 +131,8 @@
if (this.options.position == 'center') {
var left = window_size.width / 2 + scroll_offset.X,
top = window_size.height / 2 + scroll_offset.Y
top = window_size.height / 2 + scroll_offset.Y,
frame_size = this.get_frame_size()
;
/* Additional border/padding/... ? */
......@@ -99,14 +142,14 @@
}
return {
left : left - this.options.width / 2,
top : top - this.options.height / 2
left : left - frame_size.width / 2,
top : top - frame_size.height / 2
}
}
}
UI.Frame.prototype.set_position = function(position) {
var position = position || this.get_position();
UI.Frame.prototype.set_position = function() {
var position = this.get_position();
this.frame.style.left = position.left + 'px';
this.frame.style.top = position.top + 'px';
......@@ -117,22 +160,12 @@
this.title.appendChild(document.createTextNode(value));
}
UI.Frame.prototype.set_body = function(value) {
var content = Yeti.Element(value);
if (content) {
Yeti.DOM.removeNodes(this.body);
if (content.style.display == 'none') {
content.style.display = 'block';
}
this.body.appendChild(content);
}
}
UI.Frame.prototype.attach = function() {
if (this.overlay) {
this.container.appendChild(this.overlay);
}
this.container.appendChild(this.frame);
this.body.style.display = 'block';
this.attached = true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment