Click to See Complete Forum and Search --> : Need help understand this construct function
SugarGirl
02-12-2003, 04:17 PM
function ConstructObject(obj,nest){
nest=(!nest) ? '':'document.'+nest+'.'
//what are these two lines of code doing???
this.el = document.getElementById( obj );
this.css = this.el.style;
this.scrollHeight = this.el.offsetHeight
this.clipHeight = this.el.offsetHeight
this.up = MoveAreaUp;
this.down = MoveAreaDown;
this.MoveArea = MoveArea;
this.x;
this.y;
this.obj = obj + "Object"
eval(this.obj + "=this")
return this;
}
AdamBrill
02-12-2003, 04:51 PM
This line:
this.el = document.getElementById( obj );
loads the element with the id of whatever is in the obj tag into this.el
Then, this line:
this.css = this.el.style;
loads the element that you loaded above's style into this.css
I hope that helps...
SugarGirl
02-13-2003, 12:14 AM
What would be an appropriate parameter to pass to the ConstructObject function given the lines of code the function has??
var attribs = _eat_attrib(document.all[i].getAttribute("menu"));
-or-
document.all[i]
I don't know what to use, because I don't understand what ConstructObject is doing???
Please help :confused:
Charles
02-13-2003, 06:19 AM
To add a note of clarification. ConstructObject() is an object constructructor. It's used to define a class of objects. By itself it does very little but somewhere else you should see something like ConstructObject.prototype.toString(), that defines a class method, and you should see something like var o = new ConstructObject(), that assigns a new object to o. Once an object of this class has been constructed, one can call its methods thus o.toString(). By the way, the programmer is not following the naming convention. Class names ought to be nouns, something more like HappyObject. Now you have to say "o is a new ConstructObject" when you want to be able to say "o is a new HappyObject."
But that isn't going to help you very much. You want to know what the object is doing in the context of the rest of the script. Your guess is better than mine. You've got access to the rest of the script.
AdamBrill
02-13-2003, 07:44 AM
Sorry... I thought you were only wondering about those two lines. :) Where did you get this code? Do you have the rest of the code from the page? It won't do anything unless you have the rest of the code... There should be more functions that go with it(MoveAreaUp, MoveAreaDown, and MoveArea), do you have those? There should also be some objects that it is referencing in it; when the function is called, you have to give it the id of an object(for the obj variable). Without having those things, all you get is errors... ;)
SugarGirl
02-13-2003, 12:25 PM
Here is website for the code: http://members.cox.net/jmcdonald101/
I am trying to understand that code to see if I can add it to my current menus to make them scrollable. Here is where my menus are created currently and I have included the entire javascript also.
//creates my menus (6 menus each with 2 sublevels)
function _init(){
for(var i=0;i<document.all.length;i++){
if(document.all[i].getAttribute("menu")){
var attribs = _eat_attrib(document.all[i].getAttribute("menu"));
var tree = new Array();
var src = document.all.item(attribs["src"]).innerText;
src = _strip(src);
tree = _compile(tree,src); //takes the scr data and stores all of the menu data in an array called tree
var menuId = _menus.length;
document.all[i].menuId = menuId;
document.all[i].onmouseover = _rootmouseover;
document.all[i].onmouseout = _rootmouseout;
//below sets up my current menus
//I think this is where I should create the scrollable menu
//object but I don't know what parameter to pass the
//constructobject function because I don't understand that
//function (see below)
//doesn't work
objContainer=new ConstructObject('attribs');
var attribs = _eat_attrib(document.all[i].getAttribute("menu"));
attribs["border-width"] = (attribs["border-width"]!=null?attribs["border-width"]:1);
attribs["border-color"] = (attribs["border-color"]!=null?attribs["border-color"]:"black");
attribs["background"] = (attribs["background"]!=null?attribs["background"]:"#9C9A9C");
attribs["highlight"] = (attribs["highlight"]!=null?attribs["highlight"]:"#336699");
attribs["font-size"] = (attribs["font-size"]!=null?attribs["font-size"]:"10");
attribs["font-family"] = (attribs["font-family"]!=null?attribs["font-family"]:"verdana");
attribs["font-color"] = (attribs["font-color"]!=null?attribs["font-color"]:"White");
attribs["icon-color"] = (attribs["icon-color"]!=null?attribs["icon-color"]:"black");
attribs["arrow"] = (attribs["arrow"]!=null?attribs["arrow"]:true);
attribs["showrow"] = (attribs["showrow"]!=null?attribs["showrow"]:true);
attribs["height"] = (attribs["height"]!=null?attribs["height"]:22);
attribs["width"] = (attribs["width"]!=null?attribs["width"]:150);
attribs["arrow-offset"] = (attribs["arrow-offset"]!=null?Number(attribs["arrow-offset"]):135);
attribs["menu-offset"] = (attribs["menu-offset"]!=null?Number(attribs["menu-offset"]):1);
attribs["menu-topoffset"] = (attribs["menu-topoffset"]!=null?Number(attribs["menu-topoffset"]):0);
attribs["wait"] = (attribs["wait"]!=null?Number(attribs["wait"]):1000);
document.all[i].attribs = attribs;
//tree is a multilevel array that contains all of the menu data
//and create associates the data to the menu
_create(document.all[i],tree);
//need to create objScroller and pass it the menu and the
//data, but I don't know what to pass as parameters
//I think the attribs and maybe the create function data???
objScroller=new ConstructObject()
objScroller.MoveArea(0,0)
objContainer.css.visibility='visible'
initialised=true;
}
}
}
:confused:
AdamBrill
02-13-2003, 08:08 PM
Could you post a link where your site is online? Without the HTML part of the code, the javascript doesn't do anything. Thanks.
SugarGirl
02-13-2003, 09:01 PM
http://members.cox.net/menu/
Here is the html for my menu.
AdamBrill
02-13-2003, 09:25 PM
Well, it looks like you used ASP, and I don't know that, so... ;) But, I'll do my best. I am including a couple of files. They are off of the http://members.cox.net/jmcdonald101/ site. I marked in there where you can edit to put your code in there. I have to comments:
<!--everything from here-->
<!--to here scrolls-->
Change the code in between those comments to what you want to scroll. Let me know if you have any problem, and I'll do my best. But remember, I don't know ASP. :D
SugarGirl
02-13-2003, 09:42 PM
Thanks for your help, Ill give it a shot. I don't know asp I just got thrown into this project and I am trying to survive :p
AdamBrill
02-13-2003, 09:48 PM
LOL Well, good luck!! ;)
SugarGirl
02-13-2003, 10:36 PM
I am sorry but I don't think that I explained what I am trying to do very well.
http://members.cox.net/menu/ is my current menus that I am trying to edit to make them scroll like the menu found on http://members.cox.net/jmcdonald101/
I would like my menus to scroll, so what I am trying to do is take the javascript from the jmcdonald101 site and implement that into the javascript for the menu site.
My problem is that for a menu to scroll you have to create an objContainer and objScroller using the ConstructObject function (found on jmcdonald101 site) and I don't know how to edit the ConstructObject function or what parameters to pass it so that it will work with how my menus are setup currently (found on menu site).
Any advice as to how to create the Container and Scroller from my current menus???
AdamBrill
02-13-2003, 11:01 PM
On this site, http://members.cox.net/menu/, all that is there is a bunch of image placeholders. What do you want to scroll? Is it supposed to scroll horizontally instead of vertically?
SugarGirl
02-13-2003, 11:19 PM
The menus are vertical and I would like them scroll vertically, but the problem is that http://members.cox.net/menu/ is just the html could for the navigation bar, and doesn't have the links to the rest of the pages or access to the database because all of that happens on a webpage is that requries a username and password to login.
http://members.cox.net/menu/ is just the code that I am working with right now, and image placeholders are the titles of the 6 menus which are linked to submenus that are created in the java script.
What I want to scroll is what is created in the javascript.
SugarGirl
02-13-2003, 11:26 PM
The menu that I am working on similiar in structure to this one: http://members.cox.net/menuexp/
Meaning that it is horizontal like that and the submenus are like the ones found under News Sites.
Where it lists all of the news sites image that menu being so long that it falls of the page, and that is why I would like to make the menu scrollable so that everything fits in the window and the user doesn't have to scroll the entire window to view menu contents only the individual menu of interest.