The following code works fine on Mozilla but generates an error* on IE,
when the button calling the function is pressed and the slideshow is
either on the first slide or last slide. * I can't remember the exact
error and I'm on Linux/Mozilla at the moment, but I think it had a problem
with the object model?!?
The slideshow has a stack of div tags and the buttons are used to change
the z-order. Each div contains two other divs: one with a picture and one
with a description.
All this is generated on the fly in php, from a mySQL database, hence the
DOM parsing to find the appropriate div to bring to the front.
Thanks,
Greg
=============== =======
//The code that calls this function is an image in a table: <img
id='ex2-stepForward' name='stepForwa rd'
src='./images/site/stepForward.gif '
width='24'
height='24'
border='0'
onmouseover="ch angeImages(this .id, './images/site/stepForward-over.gif');
return true; "
onmouseout="cha ngeImages(this. id, './images/site/stepForward.gif ');
return true; "
onmousedown="ch angeImages(this .id, './images/site/stepForward-down.gif');
return true; "
onmouseup="chan geImages(this.i d, './images/site/stepForward-over.gif');
stepOne(event, this, 'forward'); return true; ">
=============== =============
//Steps back and forward in the stack of image/description containers
//for the group associated with the control pressed function stepOne(evt,
thisExercise, direction){
var nodeStep = thisExercise;
//parse UP the tree by parent
while (nodeStep.class Name != 'maskGroup'){
nodeStep = nodeStep.parent Node;
}
//parse DOWN the tree by sibling
while (nodeStep.class Name != 'picDescPair'){
nodeStep = nodeStep.nextSi bling;
}
//this is the first PicDescPair node
var firstPicDescPai rNode = nodeStep;
//this is the last sibling (We'll parse from firstPicDescPai rNode to the
last sibling looking for other PicDescPairs) var lastSiblingNode =
firstPicDescPai rNode.parentNod e.lastChild; //use an array to store all
the PicDescPairs found var arrayIdx = 0;
var picDescPairArra y = new Array(0);
//store the ID of the first one
picDescPairArra y[arrayIdx] = firstPicDescPai rNode.id; arrayIdx ++;
// loop until the last sibling, looking for more. A DO/WHILE loop might
be preferable? Check limiting case of single nodeStep while (nodeStep !=
lastSiblingNode ){
nodeStep = nodeStep.nextSi bling;
if ((nodeStep.clas sName == 'picDescPair') && (nodeStep.nodeN ame ==
'DIV')){
picDescPairArra y[arrayIdx] = nodeStep.id; //store the ID of each one
arrayIdx ++;
}
}
// The above loop omits the last sibling, so add it to the array after
the loop completes if ((nodeStep.clas sName == 'picDescPair') &&
(nodeStep.nodeN ame == 'DIV')){
picDescPairArra y[arrayIdx] = nodeStep.id; //store the ID
}
}
/*Look in the array for the div with the highest z-index or use the last
div, if the z-indexes are all the same. Record it.
Set all the div.z-indexes to a low number (3) Then using the div
preceding the recorded div increase the z-index to a higher number (5).
If it is the first, ignore the instruction. */
var arrayIndexOfHig hestZIndexObj = 0; var lengthOfArray =
picDescPairArra y.length; //last entry is on top (subtract 1 as it's a '0'
based array) var currentlyHighes tZIndexObjId =
picDescPairArra y[lengthOfArray-1]; var currentlyHighes tZIndex =
document.getEle mentById(curren tlyHighestZInde xObjId).style.z Index;
//checking to see if anything is higher than the last item var sameSoFar
= true;
for (var i=0; i <= picDescPairArra y.length-1; i++){
if (document.getEl ementById(picDe scPairArray[i]).style.zIndex >
currentlyHighes tZIndex){
sameSoFar = false;
currentlyHighes tZIndex =
document.getEle mentById(picDes cPairArray[i]).style.zIndex;
currentlyHighes tZIndexObjId = picDescPairArra y[i];
arrayIndexOfHig hestZIndexObj = i;
}else if (sameSoFar){ //the last one through - just in case they're all
}the same level
arrayIndexOfHig hestZIndexObj = i;
}
}
//Set parameters to step in correct direction if (direction == 'back'){
var deltaStep = 1;
var limitingCase = picDescPairArra y.length-1;
} else if (direction == 'forward'){
var deltaStep = -1;
var limitingCase = 0;
}
//if this is not the limiting extent (first or last) item in the array,
change the z-index of all the items to 3 if (arrayIndexOfHi ghestZIndexObj
!= limitingCase){
for (i=0; i <= picDescPairArra y.length-1; i++){
document.getEle mentById(picDes cPairArray[i]).style.zIndex = 3;
}
}
var newHighest = arrayIndexOfHig hestZIndexObj + deltaStep;
document.getEle mentById(picDes cPairArray[newHighest]).style.zIndex = 5;
//------------------
// Stop click event propagation in parent div hierarchy if (document.all)
{
// Code for IE browsers
window.event.ca ncelBubble=true ;
} else if (!document.all && document.getEle mentById) {
// Code for Mozilla browsers
evt.stopPropaga tion();
}
}
}
when the button calling the function is pressed and the slideshow is
either on the first slide or last slide. * I can't remember the exact
error and I'm on Linux/Mozilla at the moment, but I think it had a problem
with the object model?!?
The slideshow has a stack of div tags and the buttons are used to change
the z-order. Each div contains two other divs: one with a picture and one
with a description.
All this is generated on the fly in php, from a mySQL database, hence the
DOM parsing to find the appropriate div to bring to the front.
Thanks,
Greg
=============== =======
//The code that calls this function is an image in a table: <img
id='ex2-stepForward' name='stepForwa rd'
src='./images/site/stepForward.gif '
width='24'
height='24'
border='0'
onmouseover="ch angeImages(this .id, './images/site/stepForward-over.gif');
return true; "
onmouseout="cha ngeImages(this. id, './images/site/stepForward.gif ');
return true; "
onmousedown="ch angeImages(this .id, './images/site/stepForward-down.gif');
return true; "
onmouseup="chan geImages(this.i d, './images/site/stepForward-over.gif');
stepOne(event, this, 'forward'); return true; ">
=============== =============
//Steps back and forward in the stack of image/description containers
//for the group associated with the control pressed function stepOne(evt,
thisExercise, direction){
var nodeStep = thisExercise;
//parse UP the tree by parent
while (nodeStep.class Name != 'maskGroup'){
nodeStep = nodeStep.parent Node;
}
//parse DOWN the tree by sibling
while (nodeStep.class Name != 'picDescPair'){
nodeStep = nodeStep.nextSi bling;
}
//this is the first PicDescPair node
var firstPicDescPai rNode = nodeStep;
//this is the last sibling (We'll parse from firstPicDescPai rNode to the
last sibling looking for other PicDescPairs) var lastSiblingNode =
firstPicDescPai rNode.parentNod e.lastChild; //use an array to store all
the PicDescPairs found var arrayIdx = 0;
var picDescPairArra y = new Array(0);
//store the ID of the first one
picDescPairArra y[arrayIdx] = firstPicDescPai rNode.id; arrayIdx ++;
// loop until the last sibling, looking for more. A DO/WHILE loop might
be preferable? Check limiting case of single nodeStep while (nodeStep !=
lastSiblingNode ){
nodeStep = nodeStep.nextSi bling;
if ((nodeStep.clas sName == 'picDescPair') && (nodeStep.nodeN ame ==
'DIV')){
picDescPairArra y[arrayIdx] = nodeStep.id; //store the ID of each one
arrayIdx ++;
}
}
// The above loop omits the last sibling, so add it to the array after
the loop completes if ((nodeStep.clas sName == 'picDescPair') &&
(nodeStep.nodeN ame == 'DIV')){
picDescPairArra y[arrayIdx] = nodeStep.id; //store the ID
}
}
/*Look in the array for the div with the highest z-index or use the last
div, if the z-indexes are all the same. Record it.
Set all the div.z-indexes to a low number (3) Then using the div
preceding the recorded div increase the z-index to a higher number (5).
If it is the first, ignore the instruction. */
var arrayIndexOfHig hestZIndexObj = 0; var lengthOfArray =
picDescPairArra y.length; //last entry is on top (subtract 1 as it's a '0'
based array) var currentlyHighes tZIndexObjId =
picDescPairArra y[lengthOfArray-1]; var currentlyHighes tZIndex =
document.getEle mentById(curren tlyHighestZInde xObjId).style.z Index;
//checking to see if anything is higher than the last item var sameSoFar
= true;
for (var i=0; i <= picDescPairArra y.length-1; i++){
if (document.getEl ementById(picDe scPairArray[i]).style.zIndex >
currentlyHighes tZIndex){
sameSoFar = false;
currentlyHighes tZIndex =
document.getEle mentById(picDes cPairArray[i]).style.zIndex;
currentlyHighes tZIndexObjId = picDescPairArra y[i];
arrayIndexOfHig hestZIndexObj = i;
}else if (sameSoFar){ //the last one through - just in case they're all
}the same level
arrayIndexOfHig hestZIndexObj = i;
}
}
//Set parameters to step in correct direction if (direction == 'back'){
var deltaStep = 1;
var limitingCase = picDescPairArra y.length-1;
} else if (direction == 'forward'){
var deltaStep = -1;
var limitingCase = 0;
}
//if this is not the limiting extent (first or last) item in the array,
change the z-index of all the items to 3 if (arrayIndexOfHi ghestZIndexObj
!= limitingCase){
for (i=0; i <= picDescPairArra y.length-1; i++){
document.getEle mentById(picDes cPairArray[i]).style.zIndex = 3;
}
}
var newHighest = arrayIndexOfHig hestZIndexObj + deltaStep;
document.getEle mentById(picDes cPairArray[newHighest]).style.zIndex = 5;
//------------------
// Stop click event propagation in parent div hierarchy if (document.all)
{
// Code for IE browsers
window.event.ca ncelBubble=true ;
} else if (!document.all && document.getEle mentById) {
// Code for Mozilla browsers
evt.stopPropaga tion();
}
}
}
Comment