Creating divs programmatically in directory listing function
Hey guys,
I'm trying to use the BarelyFitz javascript Tabber to categorize several hundred user manuals on a page. The user manuals are stored in directories, and I'm trying to create tabs progammatically for each directory. No matter how hard I try, I cannot seem to find a way to accurately determine whether the function is parsing a subdirectory of the previous directory or the orginal root directory. Here's some pseudocode:
At beginning of directory parse loop:
if (currentdirectory is subdir)
{
if (no tab container)
{
add tab container (div)
add tab (div)
}
else
{
add tab
}
}
else
{
list files
}
After subdirectory parse loop:
if (lastdirectory was subdir of this directory)
{
close div (tab container)
}
Here's the CF code:
<cffunction name="fDirectoryListing"
description="Outputs table rows for a directory listing and allows DIRINFO.txt directory name replacement"
returnType="string"
output="true">
<cfargument name="MyRoot" type="string" required="true">
<cfargument name="ThisSub" type="string" required="true">
<cfargument name="DirDepth" type="numeric" default="0">
<cfargument name="ShowNoFiles" type="boolean" default="0">
<cfset var qDirectoryList = "">
<cfset var FileCount = 0>
<cfset var ThisFullDir = "#MyRoot#\#ThisSub#">
<cfset var SpaceMultiplier = 20>
<cfset var Indent = SpaceMultiplier * DirDepth>
<cfset var rootDir = 0>
<cfset var nested = false><cfdirectory action="LIST" directory="#ThisFullDir#" name="qDirectoryList" sort="type ASC, name asc">
<cfoutput>
<cfloop query="qDirectoryList">
<CFIF qDirectoryList.type IS "dir">
<!-- check if this is SubDirectory of root -->
<cfif rootDir lt DirDepth and not nested>
<div class="tabber">Start new tabber
<cfset rootDir = DirDepth>
<cfset nested = true>
Nested: #nested#
</cfif>
<cfif rootDir lt DirDepth and nested>
<cfset nested = false>stop nesting
</cfif>
<div class="tabbertab">start tab, DirDepth: #DirDepth# rootDir: #rootDir#
<!-- end subDir check--><cfset ThisDir = "#ThisSub#\#qDirectoryList.name#">
<cfset DirInfo = "">
<cfif FileExists("#MyRoot#\#ThisDir#\DIRINFO.txt")>
<cffile action="READ" file="#MyRoot#\#ThisDir#\DIRINFO.txt" variable="DirInfo">
<cfelse>
<cfset DirInfo = "#qDirectoryList.name#">
</cfif>
<img src="../images/blank_bullet.gif" width="#Indent#" height="5"><h2>#DirInfo#</h2>
#fDirectoryListing(MyRoot, ThisDir, DirDepth+1)#
<cfelse>
<cfif qDirectoryList.name is not "DIRINFO.txt">
<cfset FileCount = FileCount + 1>
<cfif FileCount is 1 and qDirectoryList.currentrow is not 1><br>
</cfif>
<img src="../images/blank_bullet.gif" width="#Indent#" height="5"><p><a href="GetFile.cfm?ID=#URLEncodedFormat("#ThisSub#\#qDirectoryList.name#")#">#qDirectoryList.name#</a></p>
</cfif>
</CFIF> <cfif nested></div>endnesttab</cfif>
</cfloop><cfif nested is false>endnestdiv nested: #nested# dirdepth: #DirDepth# rootDir: #rootDir#</div></cfif>
</cfoutput><cfif ShowNoFiles and FileCount is 0>
<tr><td><img src="../images/blank_bullet.gif" width="#Indent#" height="5"> [ no Files ]</td></tr>
</cfif></cffunction>
Any thoughts on this?
Thanks,
Scott
