PDA

Click to See Complete Forum and Search --> : javascript problem


tZ
12-07-2007, 08:36 AM
What is happening when my script is executed is somewhat strange and I was wondering if anyone else has run into the same problem.

When I initially run the page to the browser – for the first time – my script is functioning awkwardly. For example, the script is suppose to find the height and width of a box then the reposition the box to match another width and height from that one. However, the boxes width and height is just increasing or decreasing infinitely.

However, when the page is reloaded the script runs as expected.

Anyone have any ideas?

Danger_Mouse
12-07-2007, 12:03 PM
IE as the browser, or does it do it in all browsers?

I think yoiu would have to post the script. Not that I can help you...iM pretty jr on web design (but learning fast). Could be anything really.

tZ
12-07-2007, 12:05 PM
I've just tested in firefox.

It doesn't even work in safari which I'm looking into.

However, I think regardless this is awkward for any browser to do.

Danger_Mouse
12-07-2007, 12:14 PM
ah so your on a Mac...test it on a PC. I been working on my first website for work and had issues with the java nav bar..on PC it would work, on mac it would appear not to. It actually just took some tweaking of the CSS, not the java, to get it to work on all browsers.

As I said, if you posted the page code, someone might be able to spot it. I am probably not the best to spot errors just learning myself.

also note: as a junior on this, I may or may not know what IM talking about. heh

tZ
12-07-2007, 01:34 PM
Its close to 700 lines long I don't think posting it is going to help anyone…

I was just sort of looking for some general recommendations. Posting my code will probably just give someone a headache.

tZ
12-07-2007, 01:38 PM
but here…

html – index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Frame Extender</title>
<meta http-equiv="content-type"
content="text/html; charset=utf-8" />
<!-- <link rel="stylesheet" type="text/css" href="form.css" /> -->
<script language="javascript" type="text/javascript" src="interfaceclass.js"></script>
<script language="javascript" type="text/javascript" src="frameextenderclass.js"></script>
</head>
<body>
<ul id="PhotographMenu">
<li><a href="photographs/pig-one.jpg">Photo of a piggie</a></li>
<li><a href="photographs/penguin-one.jpg">Photo of a penguin</a></li>
<li><a href="photographs/chicken-one.jpg">Photo of a chicken</a></li>
<li><a href="photographs/cat-one.jpg">Photo of a cat</a></li>
<li><a href="photographs/dog-one.jpg">Photo of a dog</a></li>
<li><a href=<?php echo '"'. $_SERVER['PHP_SELF'].'?image=hotels.jpg"'; ?>>Typography work</a></li>
<li><a href="photographs/being-human-cover-spread.jpg">Publication work</a></li>
</ul> <!-- end of PhotographMenu unordered list -->
<div id="PictureFrame" style="border:3px solid black;">
<img src="photographs/pig-one.jpg" <?php $size = getimagesize("photographs/pig-one.jpg"); echo $size[3]; ?> alt="" />
</div> <!-- end of PictureFrame div -->
</body>
</html>


javascript – frameextenderclass.js

function FrameExtender() {
this.startWidth; // starting width of element property
this.startHeight; // starting height of element property

this.oldWidth;
this.oldHeight;

this.setoldWidth = setoldWidth; // method to set oldWidth property
function setoldWidth(x) {
this.oldWidth = x;
}

this.setoldHeight = setoldHeight; // method to set oldHeight property
function setoldHeight(x) {
this.oldHeight = x;
}

this.setoldWH = setoldWH; // method to set both oldHeight and oldWidth properties
function setoldWH(w,h) {
this.oldWidth = w; // call to setoldWidth
this.oldHeight = h; // call setoldHeight
}

this.getoldWidth = getoldWidth; // method to get oldWidth
function getoldWidth() {
return this.oldWidth; // returns oldWidth property
}

this.getoldHeight = getoldHeight; // method gets oldHeight property
function getoldHeight() {
return this.oldHeight; // returns oldHeight property
}

this.element; // element to attach Frame extender property. This element should have one image child.
this.image; // property holds reference to image element that is a child of element

this.setElement = setElement; // method to set element property
function setElement(x) {
if(x.nodeType != 1) return alert("Element can only be an element node."); // Robust - verifies argument is a element node
this.element = x;
this.setImage();
}

this.setstartWidth = setstartWidth; // method to set startWidth property
function setstartWidth(x) {
this.startWidth = x;
}

this.setstartHeight = setstartHeight; // method to set startHeight property
function setstartHeight(x) {
this.startHeight = x;
}

this.setHeightWidth = setHeightWidth; // method to set startHeight and startWidth properties
function setHeightWidth(w,h) {
this.startWidth = w;
this.startHeight = h;
}

this.getElement = getElement; // method gets element property
function getElement() {
return this.element;
}

this.getstartHeight = getstartHeight; // method gets startHeight property
function getstartHeight() {
return this.startHeight;
}

this.getstartWidth = getstartWidth; // method gets startWidth property
function getstartWidth() {
return this.startWidth;
}

this.setImage = setImage;
function setImage() {
if(this.element.nodeType != 1) return alert("An element property must be assigned before image."); // Robust - verifies that element has been assigned a value and that value is a element node.
if(!this.element.getElementsByTagName('img')) return("Element assignment must have a image child node."); // Robust - verfiies that element has a img child node
if(this.element.getElementsByTagName('img').length != 1) alert("Property element is only allowed one img child."); // Robust - verifies that element property only has one img child.
this.image = this.element.getElementsByTagName('img')[0]; // Assigns value to image property.
this.setImageWidth(); // Call: calls setImageWidth
this.setImageHeight(); // Call: calls setImageHeight
}

this.getImage = getImage; // method gets Image property
function getImage() {
return this.image;
}

this.setImageWidth = setImageWidth; // method to set startWidth by referencing image property. Calls setstartWidth.
function setImageWidth() {
if(this.image.nodeType != 1) return alert("setImageWidth method can't be called unless image has been assigned a value."); // Robust - verifies that image property has been assigned a value.
if(!this.image.getAttribute("width")) return alert("image property does not have a width attribute. Therefore, setImageWidth method is unable to finish."); // Robust - verifies that a width property of image value exists in html.
if(typeof parseFloat(this.image.getAttribute("width")) != 'number') return alert("The width attribute of image must be a number."); // Robust - verifies that width attribute of value image in html contains a number value.
this.setstartWidth(this.image.getAttribute('width' )); // Call: calls setstartWidth method and passes width attribute of image node value.
}

this.setImageHeight = setImageHeight; // method to set startHeight by referencing image property. Calls setstartHeight.
function setImageHeight() {
if(this.image.nodeType != 1) return alert("setImageHeight method can't be called unless image has been assigned a value."); // Robust - verifies that image property has been assigned a value.
if(!this.image.getAttribute("height")) return alert("image property does not have a height attribute. Therefore, setImageHeight method is unable to finish."); // Robust - verifies that a height property of image value exists in html.
if(typeof parseFloat(this.image.getAttribute("height")) != 'number') return alert("The height attribute of image must be a number."); // Robust - verifies that height attribute of value image in html contains a number value.
this.setstartHeight(this.image.getAttribute('heigh t')); // Call: calls setstartheight method and passes height attribute of image node value.
}

this.setFrameHeight = setFrameHeight; // method that sets frame height px
function setFrameHeight() {
var h = this.getstartHeight();
this.element.style.height = h+"px";
}

this.setFrameWidth = setFrameWidth; // method that sets frame width px
function setFrameWidth() {
var w = this.getstartWidth();
this.element.style.width = w +"px";
}

this.setFrameSize = setFrameSize; // method sets frame width and height by calling setFrameHeight and setFrameWidth methods
function setFrameSize() {
this.setFrameWidth();
this.setFrameHeight();
}

/*................................................. .....................*/

this.setoldFrameHeight = setoldFrameHeight; // method that sets old frame height px
function setoldFrameHeight() {
var h = this.getoldHeight();
this.element.style.height = h+"px";
}

this.setoldFrameWidth = setoldFrameWidth; // method that sets old frame width px
function setoldFrameWidth() {
var w = this.getoldWidth();
this.element.style.width = w +"px";
}

this.setoldFrameSize = setoldFrameSize; // method sets old frame width and height by calling setoldFrameHeight and setoldFrameWidth methods
function setoldFrameSize() {
this.setoldFrameWidth();
this.setoldFrameHeight();
}

this.interval; // hold reference to animation interval so that it can be cleared/stopped

this.trackWidth; // track width of element property during animation
this.trackHeight; // track height of element property during animation

this.widthdif; // difference between oldWidth and newWidth property
this.heightdif; // difference between oldHeight and newHeight property

this.settrackWidth = settrackWidth; // method sets trackWidth property
function settrackWidth(x) {
this.trackWidth = x;
}

this.settrackHeight = settrackHeight; // method sets trackHeight property
function settrackHeight(x) {
this.trackHeight = x;
}

this.setwidthDif = setwidthDif; // method sets widthdif property
function setwidthDif(x) {
var ow; var nw; // local variables
ow = this.getoldWidth(); nw = this.getstartWidth(); // Call: sets ow and nw equal to oldWidth and startWidth property value
this.widthdif = nw-ow;
}

this.setheightDif = setheightDif; // method sets heightdif property
function setheightDif() {
var oh; var nh; // local variables
oh = this.getoldHeight(); nh = this.getstartHeight(); // Call: sets oh and nh equal to oldHeight and startHeight property value
this.heightdif = nh-oh;
}

this.gettrackWidth = gettrackWidth; // method gets trackWidth property
function gettrackWidth() {
return this.trackWidth;
}

this.gettrackHeight = gettrackHeight; // method gets trackHeight property
function gettrackHeight() {
return this.trackHeight;
}

this.getwidthDif = getwidthDif; // method gets widthDif property
function getwidthDif() {
return this.widthdif;
}

this.getheightDif = getheightDif; // method gets heightDif
function getheightDif() {
return this.heightdif;
}

this.setwhDif = setwhDif; // method that calls setwidthDif and setheightDif
function setwhDif() {
this.setwidthDif(); // Call: sets widthDif property to difference between new and old width
this.setheightDif(); // Call: sets heightDif property to difference between new and old height
}

this.animateElement = animateElement; // method that begins animation
function animateElement() {
this.setwhDif();
//alert([this.getwidthDif(),this.getheightDif()]);
this.decreaseSizeWidth(); // !IMPORTANT IMPORTANT
}

this.initialvector; // property holds value of inital hypotonus of element property
this.currentvector; // property holds value of current hypotonus size of element property

this.setinitialVector = setinitialVector; // method sets initialvector property
function setinitialVector() {
var h;var ow; var oh; // local variables
ow = this.getoldWidth(); // Call: get oldWidth property
oh = this.getoldHeight(); // Call: get oldheight property
h = Math.sqrt(((ow*ow)+(oh*oh))); // calculates length of hypotoneus of rectangle with oldheight and oldWidth proportions
this.initialvector = h; // Assignment: Assigns value of variable h to initalVector property
//alert(this.getinitialVector());
}

this.getinitialVector = getinitialVector; // method gets initialvector property
function getinitialVector() {
return this.initialvector;
}

this.displacement; // main property hld displacement
this.wdisplacement; // property holds w value of displacement for interval
this.hdisplacement; // property holds h value of displacement for interval
this.initialprop; // initial proportional value of y/x or oldHeight/oldWidth property

this.setDisplacement = setDisplacement; // method sets main displacement
function setDisplacement(x) {
this.setwDisplacement(x); // Call: sets wdisplacement property to argument value
this.sethDisplacement(x); // Call: sets hdisplacement property to argument value
}

this.setwDisplacement = setwDisplacement; // method sets displacement property
function setwDisplacement(x) {
this.wdisplacement = x;
}

this.sethDisplacement = sethDisplacement; // method sets displacement property
function sethDisplacement(x) {
this.hdisplacement = x;
}

this.getwDisplacement = getwDisplacement; // method gets displacement
function getwDisplacement() {
if(typeof this.wdisplacement != 'number') return 5; else return this.wdisplacement;
}

this.gethDisplacement = gethDisplacement; // method gets displacement
function gethDisplacement() {
if(typeof this.hdisplacement != 'number') return 5; else return this.hdisplacement;
}

this.setinitialProp = setinitialProp; // method sets initialprop property to oldheight/oldWidth or y/x
function setinitialProp() {
var p; var ow; var oh; // local variables
ow = this.getoldWidth(); // Call: gets oldWidth property from getoldWidth method
oh = this.getoldHeight(); // Call: gets oldHeight property from getoldHeight method
p = oh/ow; // calculates for old proportions
this.initialprop = p; // Assignment: assigns value of variable p to initialprop property
}

this.getinitialProp = getinitialProp; // method gets initialprop property
function getinitialProp() {
return this.initialprop;
}

this.decreaseSizeProp = decreaseSizeProp; // method decrease width and height propotionally - called from interval
function decreaseSizeProp() {
//this.setinitialVector(); // Call: calls method setinitialVector to set initialvector property to hypotonus size of element
this.settrackWidth(this.getoldWidth()); // Call: sets trackWidth property to value of oldWidth property
this.settrackHeight(this.getoldHeight()); // Call: sets trackHeight property to value of oldHeight property
this.setDisplacement(20); // IMPORTANT- Call: sets displacement value as argument
this.setinitialProp(); // Call: sets initialprop property equal to oldHeight/oldWidth or y/x
this.setcurrentFrame(0); // Call: sets currentframe property to zero by calling setcurrentFrame property
this.startAnimationProp();
}

this.typeDisplacement = typeDisplacement; // methods calls both wtypeDisplacement and htypeDisplacement methods
function typeDisplacement() {
this.wtypeDisplacement(); // Call: calls wtypeDisplacement method to set wdisplacement property
this.htypeDisplacement(); // Call: calls htypeDisplacement method to set hdisplacement property
}

this.wtypeDisplacement = wtypeDisplacement; // method determines if the width is a negative or positive change
function wtypeDisplacement() {
var wd; var d; // local variable
wd = this.getwidthDif(); // Call: gets widthdif property by calling getwidthDif property
d = this.getwDisplacement();
if(wd < 0) this.setwDisplacement(((1-2)*d));
}

tZ
12-07-2007, 01:41 PM
frameextenderclass.js cont.

this.htypeDisplacement = htypeDisplacement; // method determines if the height is a negative or positive change
function htypeDisplacement() {
var hd; var d; // local variable
hd = this.getheightDif(); // Call: gets heightdif property by calling getheightDif property
d = this.gethDisplacement();
if(hd < 0) this.sethDisplacement(((1-2)*d));
}

this.decreaseSizeWidth = decreaseSizeWidth; // method decrease width then height - called from interval
function decreaseSizeWidth() {
//this.setinitialVector(); // Call: calls method setinitialVector to set initialvector property to hypotonus size of element
this.settrackWidth(this.getoldWidth()); // Call: sets trackWidth property to value of oldWidth property
this.settrackHeight(this.getoldHeight()); // Call: sets trackHeight property to value of oldHeight property
this.setDisplacement(10); // IMPORTANT- Call: sets displacement value as argument
//this.setinitialProp(); // Call: sets initialprop property equal to oldHeight/oldWidth or y/x
this.setcurrentFrame(0,0); // Call: sets currentframe property to zero by calling setcurrentFrame property
this.typeDisplacement(); // Call: method calls both wtypeDisplacement and htypeDisplacement methods to set appropriate negative or positive values for properties wdisplacement and hdisplacement - safeguard is one is negative and other is positive although rare
this.endframeDisplacement(); // Call: calls endframeDisplacement method. endframeDisplacement calls endframewDisplacement and endframehdisplacement methods to set wendframe and hendframe properties to appropriate values
this.startAnimationWidth();
}

this.wcurrentframe=0; // property hold frame that animation is currently on
this.hcurrentframe=0; // property hold frame that animation is currently on
this.wendframe; // how many frames in width animation
this.hendframe; // how many frames in height animation sequence

this.setwcurrentFrame = setwcurrentFrame; // methos sets wcurrentframe property
function setwcurrentFrame(x) {
this.wcurrentframe = x;
}

this.getwcurrentFrame = getwcurrentFrame; // method gets wcurrentframe property value
function getwcurrentFrame() {
return this.wcurrentframe;
}

this.sethcurrentFrame = sethcurrentFrame; // methos sets hcurrentframe property
function sethcurrentFrame(x) {
this.hcurrentframe = x;
}

this.gethcurrentFrame = gethcurrentFrame; // method gets wcurrentframe property value
function gethcurrentFrame() {
return this.hcurrentframe;
}

this.setcurrentFrame = setcurrentFrame; // method calls setwcurrentFrame and sethcurrentFrame methods
function setcurrentFrame(w,h) {
this.setwcurrentFrame(w); // Call: calls setwcurrentFrame which sets wcurrentframe property to value of w
this.sethcurrentFrame(h); // Call: calls sethcurrentFrame which sets hcurrentFrame property to value of h
}

this.setwendFrame = setwendFrame; // method set wendframe property
function setwendFrame(x) {
this.wendframe = x; // x is how many frames are in one animated width sequence
}

this.sethendFrame = sethendFrame; // method set hendframe property
function sethendFrame(x) {
this.hendframe = x; // x is how many frames are in one animated height sequence
}

this.wleftover; // property holds width remainder
this.hleftover; // property hold height remainer

this.setwleftOver = setwleftOver; // method sets wleftover property
function setwleftOver(x) {
this.wleftover = x;
}

this.getwleftOver = getwleftOver; // method gets wleftover property
function getwleftOver() {
return this.wleftover;
}

this.sethleftOver = sethleftOver; // method sets hleftover property
function sethleftOver(x) {
this.hleftover = x;
}

this.gethleftOver = gethleftOver; // method gets hleftover property
function gethleftOver() {
return this.hleftover;
}

/* This method determines how many times wdisplacement prioperty can be divided into widthDif. */
this.endframewDisplacement = endframewDisplacement; // method will set wendframe property based on how many times wdisplacement can be divided into widthdif property
function endframewDisplacement() {
var wd; var d;var v;var l; // local variable
wd = this.getwidthDif(); // Call: gets widthdif property by calling getwidthDif method
d = this.getwDisplacement(); // Call: gets wdisplacement property by calling getwDisplacement method
v = Math.floor((wd/d)); // hack: adding one for some reason each time this evaluates
if(v < 1) { // v number of times displacement can be divided into widthdif property
l = wd%d;
// alert(l);
if(l != 0) { this.setwendFrame(0); return this.setwleftOver(l); } else { this.setwleftOver(0); return this.setwendFrame(0); }
} else {
//v += 1;
this.setwendFrame(v); // Call: sets wendframe property equal to the number of times wdisplacement can be evenly divided into widthdif property
l = wd%d;
if( l != 0) { this.setwleftOver(l); } else { this.setwleftOver(0); } // Call: sets wleftover property equal to the remainder of widthd property divided by wdisplacement property
}
}

/* This method determines how many times hdisplacement prioperty can be divided into heightDif. */
this.endframehDisplacement = endframehDisplacement; // method will set hendframe property based on how many times hdisplacement can be divided into heightdif property
function endframehDisplacement() {
var hd; var d;var v;var l; // local variable
hd = this.getheightDif(); // Call: gets heightdif property by calling getheightDif method
d = this.gethDisplacement(); // Call: gets hdisplacement property by calling gethDisplacement method
v = Math.floor((hd/d)); // hack: adding one for some reason each time this evaluates
if(v <= 1) {
l = hd%d;
// alert(l);
if(l != 0) { this.sethendFrame(0); return this.sethleftOver(l); } else { this.sethleftOver(0);return this.sethendFrame(0); }
} else {
//v +=1;
this.sethendFrame(v); // Call: sets hendframe property equal to the number of times hdisplacement can be evenly divided into heightdif property
l = hd%d;
if( l != 0) this.sethleftOver(l); else this.sethleftOver(0); // Call: sets hleftover property equal to the remainder of heighthd property divided by hdisplacement property
}
}

this.endframeDisplacement = endframeDisplacement; // method calls endframehDisplacement and endframewDisplacement methods
function endframeDisplacement() {
this.endframewDisplacement(); // Call: calls endframewDisplacement method to set wendframe property
this.endframehDisplacement(); // Call: calls endframeDisplacement method to set hendframe property
//alert([this.wendframe,this.hendframe]);
}

this.incrementwcurrentFrame = incrementwcurrentFrame; // method increments wcurrenframe property by one
function incrementwcurrentFrame() {
this.wcurrentframe++; // increments wcurrentframe property by one
}

this.incrementhcurrentFrame = incrementhcurrentFrame; // method increments hcurrenframe property by one
function incrementhcurrentFrame() {
this.hcurrentframe++; // increments hcurrentframe property by one
}

this.applydisplacementWidth = applydisplacementWidth; // method apply width displcement change
function applydisplacementWidth(ob) {
if(ob.wcurrentframe == ob.wendframe) {
var sw = ob.getstartWidth();
var ow = ob.getoldWidth();
var wd = ob.getwidthDif();
var e = ob.wendframe;
var l = ob.wleftover;
var tra = ob.gettrackWidth();
var s = sw + ' ' + ow + ' ' + wd + ' ' + e + ' ' + l+' ' + tra;
ob.setwcurrentFrame(0); // Call: sets wcurrentframe property to zero
ob.wfreezeFrame(); // Call: method freezes animation
//return alert(s);
return;
} else {
var tw; var th;var d; // local variables
d = ob.getwDisplacement(); // Call: sets d local variable equal to wdisplacement property value
if(ob.wcurrentframe+1 == ob.wendframe) {
var lo = ob.getwleftOver();
d = lo + d ;
tw = ob.gettrackWidth(); // Call: sets tw and th local variables equal to trackWidth and trackHeight property values
var nw; // local variables
nw = tw + d;
ob.settrackWidth(nw); // Call: calls settrackWidth and assigns nw(new-width) to trackWidth property
ob.element.style.width = nw+'px';
} else {
tw = ob.gettrackWidth(); // Call: sets tw and th local variables equal to trackWidth and trackHeight property values
var nw; // local variables
nw = tw + d;
ob.settrackWidth(nw); // Call: calls settrackWidth and assigns nw(new-width) to trackWidth property
ob.element.style.width = nw+'px';
}
}
ob.incrementwcurrentFrame(); // Call: increments currentframe property by calling incrementcurrentFrame method
}

this.applydisplacementHeight = applydisplacementHeight; // method appled height displcement change
function applydisplacementHeight(ob) {
if(ob.hcurrentframe == ob.hendframe) {
var sh = ob.getstartHeight();
var oh = ob.getoldHeight();
var hd = ob.getheightDif();
var e = ob.hendframe;
var l = ob.hleftover;
var tra = ob.gettrackHeight();
var s = sh + ' ' + oh + ' ' + hd + ' ' + e + ' ' + l+' ' + tra;
ob.sethcurrentFrame(0); // Call: sets currentframe property to zero
ob.hfreezeFrame();
//alert(s);
return ob.image.setAttribute("style","visibility:visible;");
} else {
var th; var th;var d; // local variables
d = ob.gethDisplacement(); // Call: sets d local variable equal to hdisplacement property value
if(ob.hcurrentframe+1 == ob.hendframe) {
var lo = ob.gethleftOver();
d = lo + d;
th = ob.gettrackHeight(); // Call: sets tw and th local variables equal to trackWidth and trackHeight property values
var nh; // local variables
nh = th + d;
ob.settrackHeight(nh); // Call: calls settrackHeight and assigns nh(new-height) to trackHeight property
ob.element.style.height = nh+'px';
ob.leftover = 0;
} else {
th = ob.gettrackHeight(); // Call: sets tw and th local variables equal to trackWidth and trackHeight property values
var nh; // local variables
nh = th + d;
ob.settrackHeight(nh); // Call: calls settrackHeight and assigns nh(new-height) to trackHeight property
ob.element.style.height = nh+'px';
}
}
ob.incrementhcurrentFrame(); // Call: increments currentframe property by calling incrementcurrentFrame method
}

this.freeze = freeze; // method freezes antire animation
function freeze(ob) { // ob is this object
clearInterval(ob.interval); // stops animation
}

this.wfreezeFrame = wfreezeFrame; // method stops animation interval
function wfreezeFrame() { // object so that leftover property can be added
clearInterval(this.interval); // Call: stops interval using pre-dfined javascript method
return this.startAnimationHeight(); // Call: starts height animation sequence by calling startAnimationHeight method
}

this.hfreezeFrame = hfreezeFrame; // method stops animation interval
function hfreezeFrame() { // object so that leftover property can be added
clearInterval(this.interval); // Call: stops interval using pre-dfined javascript method
}

tZ
12-07-2007, 01:43 PM
frameextenderclass.js cont.

this.startAnimationProp = startAnimationProp; // method starts frame animation sequence
function startAnimationProp() {
this.interval = setInterval(this.applydisplacementProp,40,this); // Assignment and Call: Assigns interval property the value of setInterval. setInterval method continuously calls applydisplacement change method to create animation effect
}

this.startAnimationWidth = startAnimationWidth; // method starts frame animation width sequence
function startAnimationWidth() {
this.interval = setInterval(this.applydisplacementWidth,40,this); // Assignment and Call: Assigns interval property the value of setInterval. setInterval method continuously calls applydisplacement width change method to create width animation effect
}

this.startAnimationHeight = startAnimationHeight; // method start frame animation height sequence
function startAnimationHeight() {
this.interval = setInterval(this.applydisplacementHeight,40,this); // Assignment and Call: Assigns interval property the value of setInterval. setInterval method continuously calls applydisplacement height change method to create height animation effect
}

this.route = route; // Compares and checks that animation has completed for width and height sequences.
function route(ob,ow,oh) { // ob is this object
var w; var h; // local variables
w = this.getwcurrentFrame(); // Call: calls getscurrentFrame method to set local variable w value to wcurrentFrame value
h = this.gethcurrentFrame(); // Call: calls gethcurrentFrame method to set local variable h value to hcurrentFrame value
if(w != 0) {
ob.freeze(ob);
var tw; var th; // local variables
tw = this.gettrackWidth();
th = this.gettrackHeight();
this.setImageWH(ob,tw,th);
} else if (h != 0) {
ob.freeze(ob);
var th; // local variables
th = this.gettrackHeight();
this.setImageWH(ob,ow,th);
} else {
this.setImageWH(ob,ow,oh);
}
}

this.setImageWH = setImageWH; // method thats sets startWidth and startHeight properties by calling setImageWidth and setImageHeight methods
function setImageWH(el,w,h) { // el,w,h was passed for extended class
this.element = el.getElement();
this.setoldWH(w,h); // Call: calls setoldWH method to set oldWidth and oldheight properties to height and width of old image
//alert([this.getoldWidth(),this.getoldHeight()]); // alert: alerts old image width and height that was passed
this.setImageWidth(); // Call: calls setImageWidth method
this.setImageHeight(); // Call: calls setImageHeight method
//alert([this.getstartWidth(),this.getstartHeight()]); // alert
//this.setFrameSize(); // Call: sets NEW frame size
this.setoldFrameSize(); // call to set old frame size;
this.animateElement(); // Call: animation start - !IMPORTANT
//this.image.setAttribute("style","visibility:visible;"); // IMPORTANT: ineracts
}

/*................................................. .........................*/
}

MenuInterface.prototype = new FrameExtender ; // Class Bird EXTENDS class Foo - if we create a FOO then foo
MenuInterface.prototype.constructer = MenuInterface;

window.onload = function() {
var menu = new MenuInterface();
menu.setMenu(document.getElementById('PhotographMe nu'));
menu.setElement(document.getElementById('PictureFr ame')); // Instructions: Insert tag id name. Tag must have a image child and it can only have one.
}


javascript –interfaceclass.js

/* Class is responsible for canceling clicks and reloading images */

function MenuInterface() {
this.menu; // property references unordered list node in html document.
this.list; // property creates array to reference list items that are children of menu in html document.
this.anchors; // property creates array to reference anchors that are children of menu in html document.

this.setMenu = setMenu; // method thats assigns value to menu
function setMenu(x) {
if(x.nodeType != 1) return alert("Menu can only be an element node."); // Robust - verifies that x is a element node.
this.menu = x; // Assignment: assigns x to menu property
this.setList(); // Call: calls setList method
}

this.setList = setList; // method assigns array to list property then calls setAnchors method;
function setList() {
if(this.menu.nodeType != 1) return alert("Method setList can't continue because property menu has not been assigned a vlaue."); // Robust: verifies menu property value is an element node.
if(!this.menu.getElementsByTagName('li')) return alert("Menu must have a child list items elements."); // Robust - verifies menu has child list item element nodes.
this.list = this.menu.getElementsByTagName('li'); // Assignment: assigns list property an array of list item element nodes that are children of menu.
this.setAnchors(); // Call: calls setAnchors method
}

this.setAnchors = setAnchors; // method assigns values to anchors array property
function setAnchors() {
this.anchors = new Array(this.list.length); // Assignment: creates array object and assigns value to anchors property
for(var x=0;x < this.list.length;x++) { // loop
this.anchors[x] = this.list[x].getElementsByTagName('a')[0]; // Assignment: assigns anchor node in html to every index of achors property array
}
this.callListeners(); // Call: calls callListener method
}

this.callListeners = callListeners; // method calls Listener method for every anchor in anchors property
function callListeners() {
for(var x=0;x < this.anchors.length;x++) { // loop through anchors property
this.Listener(this.anchors[x],'click','false'); // IMPORTANT: sets type of event
this.anchors[x].onclick = function() { return false; } // safari hack
}
}

this.Listener = Listener; // method that sorts out browser inconsistencies and adds listeners to values of anchor
function Listener(object,evType,useCapture) {
if(object.addEventListener) {
return object.addEventListener(evType,this.getEventObject (object,this,evType), useCapture);
} else if(object.attachEvent) {
return object.attachEvent('on'+evType,this.getEventObject (object,this,evType));
} else {
return object['on'+evType]=this.getEventObject(object,this,evType);
}
}

this.getEventObject = getEventObject; // method that returns another function for listener application
function getEventObject(object,clas,type) {
return function(e) {eventHandler(e,object,clas,type);};
}
}

MenuInterface.prototype.eventHandler = eventHandler; // prototype that handles behavior for event
function eventHandler(e,object,clas,type) {
var el;
if(window.event && window.event.srcElement) el = window.event.srcElement;
if(e && e.target) el = e.target;
while(el !== object && el.nodeName.toLowerCase() != 'body') el = el.parentNode;
if(el.nodeName.toLowerCase() == 'body') return;

if(window.event) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if(e && e.stopPropagation && e.preventDefault) {
e.stopPropagation();
e.preventDefault();
}
if(!clas.pl) { clas.pl = el; } else {
if(clas.pl == el) return; else clas.pl = el;
}

var newimage = new Image(); // creates image object

clas.image.setAttribute("style","visibility:hidden;opacity:0;"); // hides image

newimage.src = el.href; // places image into image object
var w = parseFloat(clas.image.getAttribute("width"));
var h = parseFloat(clas.image.getAttribute("height"));

clas.image.setAttribute("width",newimage.width); // sets width attribute of img tag in html
clas.image.setAttribute("height", newimage.height); // sets height tag attribute of img tag in html
clas.image.src = el.href; // changes out image
newimage = null; // destroys newimage

clas.route(clas,w,h); // variables w and h are height and width of the old image
}

tZ
12-07-2007, 01:43 PM
Maybe someone can spot something…

JPnyc
12-07-2007, 02:54 PM
How is the function called, and when? Nevermind, I see it's on page load. Try adding a set timeout to the function call.

tZ
12-07-2007, 07:49 PM
setTimeout to what function?

JPnyc
12-12-2007, 05:08 PM
to the function that is called on the body load