Jump to content

Another Filemanager Question


MrFish

Recommended Posts

Now I'm really stumped. I've got a filemanager made out of javascript (jquery) and php. Right now you cannot edit any of the information and nothing important is showing so I feel safe providing a link.http://gamearsenal.net/filemanager.php1. Clicking on a file selects it. Clicking on it again deselects it.2. Clicking on a folder takes you to that directory.3. Clicking on the '?' in the options bar will show you the html currently inside the goldenSubFiles div. <- Very useful for debuggingThe problem is everything only works once.filemanager.php

<div id="goldenSub">		<div class="title">Golden Subdomain</div>		<div class="files" id="goldenSubFiles">			<?				include("filemanager_getfiles.php");			?>		</div>		<div class="fileOptions"><img src="images/question.png" title='HTML Information' id="ask"><img src="images/transferto.png" title='Copy File To' id="transferTo"></div>	</div>

filemanager.js


filemanager.js
	$("#goldenSubFiles li").click(function(){		var type = $(this).attr("type");		//This is a folder		if(type == "folder")		{			//Path to new directory			var newPath = $(this).attr("title");			//Ajax request to filemanager_getfiles.php			$.post("filemanager_getfiles.php", { dir: newPath }, function(data){				//Return the html to goldenSubFiles div				$("#goldenSubFiles").html(data);			});		}		//This is a file		else		{			if($(this).hasClass("selected"))			{				//It's already selected - deselect it.				$(this).removeClass("selected");			}			else			{				//Select it				$(this).addClass("selected");			}		}	});

filemanager_getfile.php

<?	$path = $_REQUEST["dir"];	if($path == "" || $path == null)	{		$path = 'goldensub/';	}		echo "<div class='path'>$path</div>\n<ul>\n";	$handler = opendir($path);		//We need to organize the results. Be default, all files and folders will be	//located by alphabetical order. But we want to list all folders first, followed	//by files. By adding the results to arrays first we can decide to print our	//results in the order we want.		$folderArray = array();	$fileArray = array();		$folderCount = 0;	$fileCount = 0;		while(false !==($file=readdir($handler)))	{			if($file != "" && $file != null && $file != "." && $file != "..")		{						$extensionLocation = strrpos($file, ".");						//Is this a folder or a file?			if($extensionLocation == null && $extensionLocation == "")			{				//This is a folder unless it's the error_log file.				if($file != "error_log")				{					//Nope, it's definitly a folder. Add it to the folder array.					$folderCount++;					$folderArray[$folderCount] = $file;				}			}			else			{				//This is a file. Add it to the file array.				$fileCount++;				$fileArray[$fileCount] = $file;			}		}	}		if($path != 'goldensub/')	{		echo "<li title='goldensub/' type='folder'><img src='images/up.png'> goldensub</li>\n";	}		for($i = 1; $i<=$folderCount; $i++)	{		$newPath = $path.$folderArray[$i].'/';		echo "<li title='$newPath' type='folder'><img src='images/folderOpen.png'> $folderArray[$i]</li>\n";	}		for($i = 1; $i<=$fileCount; $i++)	{		$extensionLocation = strrpos($fileArray[$i], ".");		$nameLength = strlen($fileArray[$i]);		$extensionLength = $nameLength-$extensionLocation;		$nameClean = substr($fileArray[$i], 0, $extensionLocation);		$extension = substr($fileArray[$i], $extensionLocation+1, $nameLength);		echo "<li title='$fileArray[$i]' type='file' extension='$extension'><img src='images/$extension.png'> $nameClean</li>\n";	}	echo "</ul>";	return;?>

Link to comment
Share on other sites

I'm doing more tests to see if I can somehow diagnose the problem. 1. I've edited the '?' button to display html for the whole document. After examining the before and after html I see there is no problems.2. I've added alerts before the request is sent, after the request is sent, And once it's finished all post ajax processes have finished to try and test whether it gets stuck somewhere along the way. It runs fine.3. Last I've checked to see if it was a problem with the click script. I've added an li hover event to display the li information in the log panel. I've found the globally something is wrong with the li's after they are added to the goldenSubFiles div because no other javascripts are affected except ones involving li tags.But the li tags are identical in pre and post html! What could be wrong?!

Link to comment
Share on other sites

I think the problem is, after I call the javascript externally once it caches the page information and if new information is added via ajax request it won't recognize their is new data. I've tried to get around this by calling the javascript file every time I get the new information, and it works somewhat. But now everytime I click the file transfer button or the '?' button it will reoccur more then once (the amount of times I opened a new folder).Any more ideas? Hopefully I can get some answers this time and I don't have to spend another 5 hours debugging :)

Link to comment
Share on other sites

Once you clear out the HTML and replace it you also replace the events. The li elements no longer have click functions defined, because you've replaced all of that. You need to redefine the click functions on your new elements whenever you change the HTML.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...