Jump to content

[SOLVED] Layered onclick events


F1Fan

Recommended Posts

I have a file library program that I'm having issues with. Some people have view access, others have edit access. Everyone can click on a file to open it, while those with edit access  can click on the main image to open it, or they can click a little "X" image to delete it.

 

The X image has a z-index of 2 so it displays on top of the main image. My problem is that if someone clicks the X image to delete it, it will run the deleteLibFile JS function AND the openFile JS function.

 

So, this is my question: how can I stop the openFile function from running if the X was clicked?

 

I tried adding a global variable that openFile checks for. When deleteLibFile is run, the variable is set and openFile will not run. There are two problems with that:

1) If I reset the variable if they click cancel, when they click cancel, it will then run openFile.

2) If I don't reset the variable when they click cancel, then if they try to open the file, that var is still set and openFile won't run.

 

There's a lot more to it than this, but here's the important stuff:

 

PHP:

<?php foreach ($lib->getContents($empnum) as $f){
if ($f['type']=="file") $onclick = "openFile('{$f['file']}',0);";
else $onclick = "openDir('{$f['file']}',0);";
?>
<div class="filediv" onclick="<?php echo $onclick; ?>" id="<?php echo $f['id']; ?>" 
onmouseover="mouseOverTDs('<?php echo $f['id']; ?>');" onmousedown="return nd();" 
onmouseout="mouseOutTDs('<?php echo $f['id']; ?>');">
<table class="filetable" id="table<?php echo $f['id']; ?>">
	<tr>
		<td class="tdimage" id="1td<?php echo $f['id']; ?>">
			<div class="divimage">
				<div class="lockover<?php echo ($f['view_access']?"off":"on"); ?>">
					<image src="images/library/lock.png" title="You do not have access to this 
						<?php echo $f['type']; ?>">
				</div>
				<div class="xover<?php echo ($f['edit_access']?"on":"off"); ?>" 
					onclick="deleteLibFile('<?php echo "{$f['id']}','{$f['type']}','{$f['file']}','".$lib->curdir; ?>');">
					<image onclick="<?php echo $onclick; ?>" src="images/library/no.png" 
						title="Delete <?php echo $f['type']." '".$f['file']; ?>'">
				</div>
				<image src="images/library/<?php echo $f['image']; ?>">
			</div>
		</td>
	</tr>
	<tr>
		<td id="2td<?php echo $f['id']; ?>">
			<div class="tdfile" <?php echo $f['trim_file']==$f['file']?"":"title=\"{$f['file']}\""; ?>>
				<?php echo $f['trim_file'].($f['type']=="directory"?"/":""); ?>
			</div>
		</td>
	</tr>
	<tr>
		<td id="3td<?php echo $f['id']; ?>">
			<div class="tdtitle" <?php echo $f['trim_title']==$f['title']?"":"title=\"{$f['title']}\""; ?>>
				<?php echo $f['trim_title']; ?>
			</div>
		</td>
	</tr>
</table>
</div>
<?php } ?>

 

CSS:

.xoveron{
display: block;
position: absolute;
top: 0px;
right: 43px;
z-index: 2;
}
.xoveroff{
display: none;
}

 

and JS:

var stop = false;
function deleteLibFile(id,type,file,curdir){
stop = true;
if (confirm("Are you sure you want to delete "+type+" \""+file+"\"?")){
	window.location = 'main.php?c[f]=library&c[a]=main&curdir='+curdir+'&delfile='+id;
}
//stop = false;
}
function openFile(file,count){
if (count==5){
	if (!stop){
		window.open('features/library/files/'+file);
	}
}
else{
	count++;
	setTimeout("openFile('"+file+"',"+count+")",10);
}
}

 

Any help will be appreciated.

Link to comment
Share on other sites

Never mind, I figured it out. Just added a little more JS. Here was my solution, it anyone cares:

 

var stop = false;
function deleteLibFile(id,type,file,curdir){
stop = true;
if (confirm("Are you sure you want to delete "+type+" \""+file+"\"?")){
	window.location = 'main.php?c[f]=library&c[a]=main&curdir='+curdir+'&delfile='+id;
}
setTimeout("resetStop()",100)
}
function resetStop(){
stop = false;
}
function openFile(file,count){
if (count==5){
	if (!stop){
		window.open('features/library/files/'+file);
	}
}
else{
	count++;
	setTimeout("openFile('"+file+"',"+count+")",10);
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.