PDA

View Full Version : Object creation function not working - not the regular stuff



pilau
04-29-2007, 08:03 PM
I'm working on a window interface class, and this is the function that creates windows.
It has been through a few incarnations and I believe this to be the final, however, for some reason - It just won't show the DIV created, I have really no idea why.

The function recieves a parameters object, validates the given values and sets default values if necessary.

Aftwerwards, it creates the div element which is actually the window, and in case a requested parent element has been specified, the function will append the div to that node.

The final part, which I guess is what's causing all the trouble, is the part which sets all of the visual properties of the window - css class, size, and position attributes.

Maybe you could point out to principle errors or things like that, because I bet you the error is some coding problem I just don't know, since I'm not a big expert.


create_window({windowid: 'window2', class_name: 'popup_window', top: 323, left: 15});

// Window Creation Function
// windowid, controls, content, class_name, handle, transparent_drag, _width, _height, _parent, _position, _top, _left
function create_window(params)
{
// Set default values
var parent = ((typeof params.parent != 'object' || params.parent == null || params.parent == document) ? false : params.parent);
var width = (typeof params.width != 'number' ? false : params.width);
var height = (typeof params.height != 'number' ? false : params.height);
var position = (typeof params.position != 'string' ? false : ((params.position != 'relative' && params.position != 'absolute' && params.position != 'static') ? 'relative' : params.position));
var top = (typeof params.top != 'number' ? false : params.top);
var left = (typeof params.left != 'number' ? false : params.left);
var class_name = (typeof params.class_name != 'string' ? false : params.class_name);

var window_div = document.createElement('DIV');
if (parent)
{
parent.appendChild(window_div);
}

// Set optional basic CSS attributes
if (class_name) {window_div.className = class_name}
if (position) {set_style(window_div, 'position', position)}
if (width) {set_style(window_div, 'width', width + 'px')}
if (height) {set_style(window_div, 'height', height + 'px')}
if (top) {set_style(window_div, 'top', top + 'px')}
if (left) {set_style(window_div, 'left', left + 'px')}
}

Arty Effem
04-29-2007, 08:49 PM
I'm working on a window interface class, and this is the function that creates windows.
It has been through a few incarnations and I believe this to be the final, however, for some reason - It just won't show the DIV created, I have really no idea why.
If I've understood, in the absence of the parent parameter, the created div isn't being appended to anything, and therefore isn't going to appear.